Ask Your Question
0

Linearization of the objective in "MixedIntegerLinearProgram"

asked 2021-12-05 18:05:11 +0100

CyrilleP gravatar image

updated 2023-05-19 21:53:24 +0100

FrédéricC gravatar image

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.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2021-12-05 18:59:29 +0100

Max Alekseyev gravatar image

updated 2021-12-05 19:05:46 +0100

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() ]

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-12-05 18:05:11 +0100

Seen: 163 times

Last updated: Dec 05 '21