This extends Expressions added in #9 to convert to Objective objects (with an optional sense argument).
Note @funkey : this also changes the name of the method constraint() to as_constraint() ... (and as_objective here). I think it reads a bit clearer, you?
from ilpy import Sense
from ilpy.expressions import Variable
u = Variable("u", index=0)
v = Variable("v", index=1)
e = Variable("e", index=2)
expr = 2 * u - 5 * v + e / 2 - 3
objective = expr.as_objective(Sense.Maximize) # optional arg ... default is Minimize
assert objective.get_constant() == -3
assert objective.get_sense() == Sense.Maximize
assert objective.get_coefficients() == [2.0, -5.0, 0.5]
This extends Expressions added in #9 to convert to
Objective
objects (with an optionalsense
argument).Note @funkey : this also changes the name of the method
constraint()
toas_constraint()
... (andas_objective
here). I think it reads a bit clearer, you?