Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use as a regular LP solver -> no API to forcibly set the objective. #17

Closed
SylvainCorlay opened this issue Oct 27, 2015 · 3 comments
Closed

Comments

@SylvainCorlay
Copy link

The only way I could find to specify the objective function for the LP was to have all the constraint strengths be equal to zero except one, which is made so that the corresponding slack variable is what I want to minimize (up to a constant).

Is there a more elegant way to do this?

@SylvainCorlay SylvainCorlay changed the title Use as a regular LP solver -> no API to forcible set the constraint. Use as a regular LP solver -> no API to forcibly set the objective. Oct 27, 2015
@sccolbert
Copy link
Member

Rather than trying to reason about how the solver is building it's internal objective function, just create your own and minimize the result:

a = Variable('a')
b = Variable('b')
c = Variable('c')

cn1 = a <= 2
cn2 = b >= -3
cn3 = (c == 0) | 'weak'  # minimize objective
objective = 2 * a + 3 * b == c

solver.addConstraint(cn1)
solver.addConstraint(cn2)
solver.addConstraint(cn3)
solver.addConstraint(objective)

solver.updateVariables()

@sccolbert
Copy link
Member

Please close this issue if that answers your question.

@SylvainCorlay
Copy link
Author

Yes it does, thanks.

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

No branches or pull requests

2 participants