Michael Vander Meiden
Michael Vander Meiden

Reputation: 13

Adding an OR constraint in JuMP/Gurobi

I'm trying to add a constraint to a model that constrains a variable to be one of the values in a set, i.e. constrains X to be 0 OR 3 OR 4.

Current code is as follows:

@addConstraint(m, x==4)

But I would like to do something like:

@addConstraint(m, x==0 or x==3 or x==4)

Is this possible in julia? Using JuMP as the solver.

Upvotes: 1

Views: 351

Answers (1)

Bogumił Kamiński
Bogumił Kamiński

Reputation: 69829

Define helper variables h3, h4 to be binary and then set constraints: x = 3*h3 + 4*h4 and h3 + h4 <= 1.

Upvotes: 2

Related Questions