Skip to content

Add conversion from Expression to Objective#13

Merged
tlambert03 merged 10 commits intofunkelab:mainfrom
tlambert03:objective-expressions
Apr 7, 2023
Merged

Add conversion from Expression to Objective#13
tlambert03 merged 10 commits intofunkelab:mainfrom
tlambert03:objective-expressions

Conversation

@tlambert03
Copy link
Copy Markdown
Member

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]

@tlambert03 tlambert03 requested a review from funkey March 25, 2023 15:59
@tlambert03
Copy link
Copy Markdown
Member Author

@funkey ... i'll take care of the cleanup here. you can just check if the general pattern looks ok

@funkey
Copy link
Copy Markdown
Member

funkey commented Apr 7, 2023

...too late ;)

@funkey
Copy link
Copy Markdown
Member

funkey commented Apr 7, 2023

Haha, I see, I missed a few more. Sorry for the noise, and thanks for cleaning up :)

@tlambert03 tlambert03 merged commit 6cc54b3 into funkelab:main Apr 7, 2023
@tlambert03 tlambert03 deleted the objective-expressions branch April 7, 2023 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants