Matthew Loh
Matthew Loh

Reputation: 147

Gurobi : Adding a constraint with lower and upper bounds

I am trying to add a constraint containing lower and upper bounds into my linear programming problem.

con1 = m3.addConstr(500 <= 52*x1 + 89*x2 + 57*x3 + 147*x4 + 53*x5 <= 3000, name="con1")

This is the code that I used. Although this is a valid syntax, I am unable to get any solution to my problem. Am I doing things correctly?

Upvotes: 0

Views: 790

Answers (1)

Silke Horn
Silke Horn

Reputation: 460

What you want is a range constraint; here is the syntax:

con1 = m3.addRange(52*x1 + 89*x2 + 57*x3 + 147*x4 + 53*x5, 500, 3000 name="con1")

or

con1 = m3.addConstr(52*x1 + 89*x2 + 57*x3 + 147*x4 + 53*x5 == [500, 3000], name="con1")

Here is the documentation. These forms are equivalent; they add a ranged variable r and the following constraints:

52*x1 + 89*x2 + 57*x3 + 147*x4 + 53*x5 + r == 3000
0 <= r <= 3000 - 500

Upvotes: 1

Related Questions