0

I am studying Cplex CP in Python, and I have two integer variables x and y.

I do some calculations and I find x's value, for example:

y = ..some calculations..

x = 3600 / y

I want to do this, If the x is lower than the 200(limit of x), x is 3600 / y. But, If the x is higher than the 200, x is 200.

I tried these expressions:

1:

((x >= limit_x) == limit_x ) or ((x <= limit_x) == 3600 / y )

1.revised:

((x >= limit_x) == limit_x ) and ((x <= limit_x) == 3600 / y )

2:

x == 3600 / y
x <= limit_x

3:

(x <= limit_x) == 3600 / y

I couldn't find any solution. I need your bits of help.

Best regards,

0

1 Answer 1

0

Let me mix

disjuntion and Constraint Programming

And I get

from docplex.cp.model import CpoModel

mdl = CpoModel(name='buses')
nbbus40 = mdl.integer_var(0,1000,name='nbBus40')
nbbus30 = mdl.integer_var(0,1000,name='nbBus30')
mdl.add(nbbus40*40 + nbbus30*30 >= 300)

mdl.add(1==mdl.logical_or(nbbus40>=7,nbbus40<=3))
mdl.minimize(nbbus40*500 + nbbus30*400)

msol=mdl.solve()

print(msol[nbbus40]," buses 40 seats")
print(msol[nbbus30]," buses 30 seats") 

that gives

3  buses 40 seats
6  buses 30 seats
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your answer Mr. Fleischer. I saw this example from your LinkedIn account, but I have some problems here. The value of x could be 0 or 3600 / y or the limit of x. Can I use the nested logical or?
Sure. In my tiny example I can write mdl.add(1==mdl.logical_or(nbbus40>=10,mdl.logical_or(nbbus40==2,nbbus40==1)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.