Originally posted by: SystemAdmin
[EdKlotz said:]
I have a program with two constraint sets, Cons1: x - x[j]>= 1-z[i,j] and Cons2: x[j] - x>= 1-z[i,j]
for each i and j, I want to add a constraint in which at least one of Cons1 or Cons2 is satisfied.
For this purpose, I write (in C#):
for each i,j:
cplex.Or(cplex.AddGe(cplex.Sum(x, cplex.Prod(-1, x[j]), z[count]), 1), cplex.AddGe(cplex.Sum(x[j], cplex.Prod(-1, x), z[count]), 1));
Cplex solver adds both the constraints Cons1 and Cons2 and solves the program (therefore it obtains z[i,j]=1 and x = x[j]). I was wondering if any could help me to solve the problem.
Paul Rubin pointed out the problem here. When you call cplex.AddGe, it not only returns the constraint,
but it adds it to the model contained in the IloCplex class. So the above call actually creates
3 constraints:
x - x[j]>= 1-z[i,j]
x[j] - x>= 1-z[i,j]
x - x[j]>= 1-z[i,j] or x[j] - x>= 1-z[i,j]
That explains why CPLEX always gave you a solution that satisfied the first two constraints.
To solve this, create the first two constraints without adding them to the IloCplex object.
In other words, create separate IloRanges or IloConstraints for the first two constraints,
then call IloCplex.Or with the two constraints.
#CPLEXOptimizers#DecisionOptimization