2

How do I write such constraints in CPLEX (linear-programming) ?

forall(p in P, x in X, y in Y)
  if ((remx[p,x] <= 0) OR (remy[p,y] <= 0)) then
    pbl[p,x,y] == 0 // MUST be 0
  else 
    pbl[p,x,y] == 1 OR == 0 // can be 0 or 1

where pbl is a decision variable (matrix), remx and remy is a normal matrix variable and p,x,y are indices.

I can not use if-then

Thanks,

1 Answer 1

1

I believe this cannot be done using (continuous) linear programming, but using mixed-integer programming we can use binary variables.

One way to attack this is using a bunch of inequalities, something like:

remx[p,x] <= 0 + bx[p,x]*M
remx[p,x] >= 0 - (1-bx[p,x])*M
remy[p,y] <= 0 + by[p,y]*M
remy[p,y] >= 0 - (1-by[p,y])*M
pbl[p,x,y] >= bx[p,x]+by[p,y]-1
pbl[p,x,y] <= bx[p,x]
pbl[p,x,y] <= bx[p,x]
bx[p,x],bx[p,x] in {0,1}

where M is indicating a sufficiently large number (they form a bound on remx and remy). Alternatively you can use the indicator constraints in Cplex to model implications:

bx[p,x]=0 => remx[p,x] <= 0
bx[p,x]=1 => remx[p,x] >= 0
by[p,y]=0 => remy[p,y] <= 0
by[p,y]=1 => remy[p,y] >= 0
pbl[p,x,y] = 1 => bx[p,x]+by[p,y] = 2
pbl[p,x,y] = 0 => bx[p,x]+by[p,y] <= 1

(Note: the question has changed, so these fragments are no longer 100% correct).

Sign up to request clarification or add additional context in comments.

3 Comments

It works! But I left something... pbl[p,x,y] must be 0 if the condition is true, but if not, could be 1 or 0... I mean, there are other constraints that manage this
One way implications are typically easier to model
So, Is it possible to do it without mixed-integer programming?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.