# 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):
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.

edit retag close merge delete

Sort by » oldest newest most voted The 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() ]

more