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

how to use piecewise linear constraint in pulp? #173

Closed
pancerZH opened this issue Apr 28, 2018 · 5 comments
Closed

how to use piecewise linear constraint in pulp? #173

pancerZH opened this issue Apr 28, 2018 · 5 comments

Comments

@pancerZH
Copy link

For example, I have one constraints goes:
x + y >=2 or x + y ==2
there are many such constraints in my model, so how to express the or in pulp?

@naveenashwa77
Copy link

naveenashwa77 commented Apr 29, 2018

import pulp

#define whether you gonna minimize or maximize ur objective
lp_solve = pulp.LpProblem("My LP Problem", pulp.LpMaximize or pulp.LpMinimize)

#define your variables
x = pulp.LpVariable('x', lowBound=0, cat='Continuous')
y = pulp.LpVariable('y', lowBound=2, cat='Continuous')

define Objective function

lp_solve +=

set your Constraints

lp_solve +=

#call solver
lp_solve.solve()
for variable in lp_solve.variables():
print "{} = {}".format(variable.name, variable.varValue)
print pulp.value(lp_solve.objective)

@stumitchell
Copy link
Contributor

stumitchell commented Apr 29, 2018 via email

@pancerZH
Copy link
Author

Thank you for help but so sorry to find I made a mistake, the constraints should be:
x + y >= 2 or x + y == 0
I have tried to write them like this:
lp_solve += (x+y)>=2
lp_solve += (x+y)==0
It just did not work(obviously) and no result returned.
And I can't use constraint as lp_solve += (x+y)>=0, because I don't want the (0, 2) part.
Then how to deal with it?

@stumitchell
Copy link
Contributor

stumitchell commented May 1, 2018 via email

@pancerZH
Copy link
Author

pancerZH commented May 1, 2018

Thank you for help! Finally I solved it with nonlinear programming : )

@pancerZH pancerZH closed this as completed May 1, 2018
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

3 participants