I'm solving an LP using pulp. I want to add constraints to my model. Most friendly way is :
model += lhs == rhs
When we want to add constraints using apply
method in pandas.DataFrame
, since lambda methods don't take +=
sign in them, we need to do something like this:
df['variable'].apply(lambda x: model.__iadd__(lhs==rhs))
Now, I don't want to use __iadd__()
method directly, rather I want to make a function for this.
What I'm trying to achieve is something like this:
`expression is our constraint`: lhs == rhs
def add_to_model(model, expression):
return model.__iadd__(expression)
An example:
def add_to_model(model, x==0)
return model.__iadd__(x==0)
Because in the above function, expression
variable will be treated as Boolean
, this is not serving the purpose. Any suggestions on how to achieve this?