'How to use nested IF-THEN constraints in DOCPLEX (Python)?

I am modeling the situation I want using python cplex. While using it, a few questions arose, and these are:

  1. Can I use nested IF-THEN constraints in CPLEX?

First, I could find below how to use the basic IF-THEN constraint.

How to use Continuous Variables for IF-THEN constraints on DOCPLEX (Python)?

However, I couldn't find a way to use nested IF-THEN constraints even there, so I did some thinking.

To explain by citing the answer above, I want the following situation:

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(mdl.if_then(((nbbus40>=3) and (nbbus40<=7)),(nbbus30>=7)))**
mdl.minimize(nbbus40*500 + nbbus30*400)

If I try something like line 5 of the code above, can't I use nested IF-THEN constraints?

If this is wrong, how should I use nested IF-THEN constraints?

  1. In general, I understand that inequality can be used as a constraint in CPLEX. For example, if I want to give the condition of A=1, I can satisfy it by giving both the condition A>=1 and the condition A<=1. My question is, is there a way to specify (constrain) a value using only the equal sign (I think 2 conditions in 1 constraint is wasteful)?

Thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source