You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was thinking of adding conjunction and disjunction helpers lpOr and lpAnd that automatically convert constraints.
These operators should become nestable.
Then we can write something like this:
constraint=lpOr([is_married<1, age>=18])
Even more convenient would be to extend & and | operators of LpConstraint, so this can be written as:
constraint= (is_married<1) | (age>=18)
However, there is a conflict, because LpConstraint is inheriting from OrderedDict which already implements |. Maybe consider not inheriting from MutableMapping or accept an exception to this protocol.
More consequences of this:
Often new discrete helper variable and new constraints needs to be added to the model.
As a result the problem is no longer LP, but becomes MILP as soon as a boolean operator is used.
Additional info
Please answer these questions before submitting your feature request.
Does this feature exist in another product or project? Please provide a link.
In https://github.com/lverweijen/FellegiHolt/blob/main/fellegiholt/rewrite_linear.py I managed to convert a few rules to linear ones like 'and', 'or', 'not', 'implication'. I took a different approach from above and started directly convert ast.Nodes.
There might be better ways of doing this, but it works for me. I would still be interested in having something like this.
Occasionally, real life constraints may get the form of:
if is_married then age >= 18
These can be expressed in pulp by writing something like this:
but it isn't very readable.
Describe the new feature
I was thinking of adding conjunction and disjunction helpers
lpOr
andlpAnd
that automatically convert constraints.These operators should become nestable.
Then we can write something like this:
Even more convenient would be to extend
&
and|
operators of LpConstraint, so this can be written as:However, there is a conflict, because LpConstraint is inheriting from
OrderedDict
which already implements|
. Maybe consider not inheriting from MutableMapping or accept an exception to this protocol.More consequences of this:
Additional info
Please answer these questions before submitting your feature request.
Does this feature exist in another product or project? Please provide a link.
Not sure, but Gurobi seems to support some mathematical operators as general constraints: https://www.gurobi.com/documentation/current/refman/general_constraints.html
The text was updated successfully, but these errors were encountered: