docplex issue : TypeError: Cannot convert linear constraint to a boolean value: 0 <= 1

38 views Asked by At

Issue at binary constraint in docplex

Binary constraint is initialised as if i am trying to initialise it directly without list binary variable is consisting of default value and i am not able to clear it Binary constraint is initialised as

Constraints are given as

Binay Constraint are given as

Error: Error

Please help me in finding (i)what is the mistake i have done
(ii)how can i correct it

1

There are 1 answers

1
Alex Fleischer On

You should use a range instead.

Let me start from the zoo example

And suppose you want to have nbbus40 between 4 and 5 you can write:

from docplex.mp.model import Model

mdl = Model(name='buses')
nbbus40 = mdl.integer_var(name='nbBus40')
nbbus30 = mdl.integer_var(name='nbBus30')
mdl.add_constraint(nbbus40*40 + nbbus30*30 >= 300, 'kids')

#mdl.add_constraint(4<=nbbus40<=5)
mdl.add_range(4, nbbus40, 5)

mdl.minimize(nbbus40*500 + nbbus30*400)

mdl.solve(log_output=True,)

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