-
-
Notifications
You must be signed in to change notification settings - Fork 385
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
Comments
import pulp #define whether you gonna minimize or maximize ur objective #define your variables define Objective functionlp_solve += set your Constraintslp_solve += #call solver |
your example seems to be strange as x+y >=2 includes x+y == 2 so you only
need the first.
however in general you will need to at binary integer decision variables to
your model to use 'or' constraints
Stu
Stuart Mitchell
PhD Engineering Science
Extraordinary Freelance Programmer and Optimisation Guru
www.stuartmitchell.com
…On Mon, Apr 30, 2018 at 3:50 AM, naveenashwa77 ***@***.***> wrote:
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 += (x+y) == 25 - x
lp_solve += (x + y) >= 2
#call solver
lp_solve.solve()
for variable in lp_solve.variables():
print "{} = {}".format(variable.name, variable.varValue)
print pulp.value(my_lp_problem.objective)
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#173 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAtEWeokYDe9UKpd8Z8qJsBofRjuQJ8Xks5tteEogaJpZM4TrY7C>
.
|
Thank you for help but so sorry to find I made a mistake, the constraints should be: |
have a look at this video
https://www.youtube.com/watch?v=-3my1TkyFiM
Stuart Mitchell
PhD Engineering Science
Extraordinary Freelance Programmer and Optimisation Guru
www.stuartmitchell.com
…On Mon, Apr 30, 2018 at 1:08 PM, 张文喆 ***@***.***> wrote:
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?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#173 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAtEWcAHMNp4oMyP5EZhtFoF7xzj-Agkks5ttmPwgaJpZM4TrY7C>
.
|
Thank you for help! Finally I solved it with nonlinear programming : ) |
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?
The text was updated successfully, but these errors were encountered: