ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 05 Dec 2021 18:59:29 +0100Linearization of the objective in "MixedIntegerLinearProgram"https://ask.sagemath.org/question/60101/linearization-of-the-objective-in-mixedintegerlinearprogram/ I have a Mixed integer program with non lineazr objective. But as it is the product of power there is no difficulty to linearize. But the program refuses the following modelization.
po=[0.6,0.5,0.55,0.45,0.62,0.54,0.58,0.5]
c=vector([ln(u) for u in po])
nc=3 #nombre de contraintes
nv=8 #nombre de variables
A=matrix(nc,nv,[1,1,1,1,0,0,0,0,
0,0,0,0,1,1,1,1,
500,550,600,700,420,460,500,580])
B0=[40,30,45000] #borne inférieure
B1=[0,0,0] #borne supérieure
P=MixedIntegerLinearProgram(maximization=True, solver="GLPK")
x=P.new_variable(integer=True, nonnegative=False, indices=[0..nv-1])
B
=A*x
zz=c*x
P.set_objective(zz)
for i in range(0,nc):
P.add_constraint(B[i],min=B0[i], max=B1[i])
for i in range(0,nv):
P.set_min(x[i],0)
#xi doit avoir pour minimum 0
P.show()
obviously its `P.set_objective(zz)` which doesn't work.Sun, 05 Dec 2021 18:05:11 +0100https://ask.sagemath.org/question/60101/linearization-of-the-objective-in-mixedintegerlinearprogram/Answer by Max Alekseyev for <p>I have a Mixed integer program with non lineazr objective. But as it is the product of power there is no difficulty to linearize. But the program refuses the following modelization.</p>
<pre><code> po=[0.6,0.5,0.55,0.45,0.62,0.54,0.58,0.5]
c=vector([ln(u) for u in po])
nc=3 #nombre de contraintes
nv=8 #nombre de variables
A=matrix(nc,nv,[1,1,1,1,0,0,0,0,
0,0,0,0,1,1,1,1,
500,550,600,700,420,460,500,580])
B0=[40,30,45000] #borne inférieure
B1=[0,0,0] #borne supérieure
P=MixedIntegerLinearProgram(maximization=True, solver="GLPK")
x=P.new_variable(integer=True, nonnegative=False, indices=[0..nv-1])
B
=A*x
zz=c*x
P.set_objective(zz)
for i in range(0,nc):
P.add_constraint(B[i],min=B0[i], max=B1[i])
for i in range(0,nv):
P.set_min(x[i],0)
#xi doit avoir pour minimum 0
P.show()
</code></pre>
<p>obviously its <code>P.set_objective(zz)</code> which doesn't work.</p>
https://ask.sagemath.org/question/60101/linearization-of-the-objective-in-mixedintegerlinearprogram/?answer=60102#post-id-60102The multiplication `c*x` is not defined (notice that `x` is not a vector). Correspondingly, `zz=c*x` needs to be expressed explicitly - for example, `zz=sum( cc*xx for cc,xx in zip(c,x) )`.
Also, by the same reason the result of `A*x` is not what is expected. So, `B=A*x` also needs to be explicitly expressed - for example, `B = [ sum( aa*xx for aa,xx in zip(row,x) ) for row in A.rows() ]`Sun, 05 Dec 2021 18:59:29 +0100https://ask.sagemath.org/question/60101/linearization-of-the-objective-in-mixedintegerlinearprogram/?answer=60102#post-id-60102