Cplex for Linear Program: Are DOCplex decision variables assumed to be non-negative?

363 views Asked by At

I want to write a simple LP using docplex. Suppose I have three variables: x, y, and z, the constraint is 4x + 9y - 18.7 <= z. I wrote the constraint with the code model.add_constraint(4 * x + 9 * y - 18.7 <= z). Then I set minimize z as my objective by model.minimize(z).

After solving the model, I get the result of z = 0.000. Can anyone explain the result to me? I don't understand why 0 is the optimal value of this LP. I also tried to print the details of this model:

status = optimal

time = 0 s.

problem = LP

z: 0.000; None

objective: z

constraint: 4z+9y-18.700 <= z

When I tried to model.print_solution(), the program prints z: 0.000; None where I don't understand what does "None" mean, does that mean x and y are None?


Update: Forgot to mention, I created the variable using model.continuous_var()

1

There are 1 answers

0
Alex Fleischer On BEST ANSWER

Indeed if you do not give a range they are non negative.

Small example out of the zoo story:

from docplex.mp.model import Model

mdl = Model(name='buses')
nbbus40 = mdl.continuous_var(name='nbBus40')
nbbus30 = mdl.continuous_var(name='nbBus30')
mdl.add_constraint(nbbus40*40 + nbbus30*30 >= 300, 'kids')
mdl.minimize(nbbus40*500 + nbbus30*400)
mdl.solve(log_output=False,)
print("nbbus40.lb =",nbbus40.lb)

for v in mdl.iter_continuous_vars():
    print(v," = ",v.solution_value)

mdlv2 = Model(name='buses2')
nbbus40v2 = mdlv2.continuous_var(-2,200,name='nbBus40')
nbbus30v2 = mdlv2.continuous_var(-2,200,name='nbBus30')
mdlv2.add_constraint(nbbus40v2*40 + nbbus30v2*30 >= 300, 'kids')
mdlv2.minimize(nbbus40v2*500 + nbbus30v2*400)
mdlv2.solve(log_output=False,)

print("nbbus40v2.lb =",nbbus40v2.lb)

for v in mdlv2.iter_continuous_vars():
    print(v," = ",v.solution_value)

gives

nbbus40.lb = 0
nbBus40  =  7.5
nbBus30  =  0
nbbus40v2.lb = -2
nbBus40  =  9.0
nbBus30  =  -2.0