Converting docplex expression into string

107 views Asked by At

How can I store the text version of a constraint defined as a docplex.mp.linear.LinearExpr variable into a Python string variable?

1

There are 1 answers

0
Philippe Couronne On BEST ANSWER

Use its string representation as returned by str(ct).

nbbus50 = mdl.integer_var(name='nbBus50')
nbbus40 = mdl.integer_var(name='nbBus40')
nbbus30 = mdl.integer_var(name='nbBus30')

ct1 = nbbus50 * 50 + nbbus40 * 40 + nbbus30 * 30 >= 200
print(f"str(ct1)= {str(ct1)}")

str(ct1)= 50nbBus50+40nbBus40+30nbBus30 >= 200