-1

I'm implementing an OR logic with Gurobi. Specifically, I have two decision variables $x$ and $y$ and I want $x \neq y$. However, Gurobi doesn't support inequalities. So I tried to use OR logic like $x >= y + \epsilon OR y >= x + \epsilon$.

I've read the documentation of Gurobi and found they have the addGenConstrOr() function. I tried to implement it according to the example usage model.addGenConstrOr((z, [x>=y+\epsilon, y>=x+\epsilon], "orconstr"). However, the program returned an error gurobipy.Model.addGenConstrOr gurobipy.GurobiError: Invalid data in vars array. It seems the data in the vars array of this function needs to be binary boolean variables. So my question is how to change this x>=y+\epsilon into a boolean variable such that I can fit this into the model.addGenConstrOr function? Or is there any better method to implement the inequality constraint in Gurobi?

Francis
  • 189
  • 1
  • 11

1 Answers1

0

I assume the variables x and y are continuous variables. addGenConstrOr is for binary variables so that is not immediately applicable.

Indeed, you can write x ≠ y as:

x ≤ y - ε OR x ≥ y + ε 

There are different ways to implement this: (1) using binary variables, (2) using indicator constraints, and (3) using SOS1 sets. As you did not provide information on bounds on x and y, let's assume they are not available. In that case, indicator constraints are a good candidate:

 δ = 0 =>  x ≤ y - ε
 δ = 1 =>  x ≥ y + ε 
 δ ∈ {0,1}

See: https://www.gurobi.com/documentation/9.1/refman/py_model_agc_indicator.html

Erwin Kalvelagen
  • 15,677
  • 2
  • 14
  • 39
  • Thanks for the suggestion, but I'm wondering how can I write the "delta \in {0,1}" constraint in Gurobi. Or is it true that the first two constraints is enough for an OR relation? But I guess in that case I need to specify \delta is a binary variable somewhere? – Francis Mar 28 '21 at 17:48
  • Obviously that is notation for a binary variable. – Erwin Kalvelagen Mar 28 '21 at 20:04