0

This is similar to a problem of moving from a decentralized system to a centralized one. Therefore, I want to identify the optimal locations to use as centralized points and the locations that need to be closed. These are my binary decision variables Xi and Yj. I have two constraints that include an if-statement with decision variables. I have read that in this case I must use logical constraints, so I did.

forall (i in Drives, j in Locations)(Y[j]==1 && Distance[j][i]<=20) => X[i]==0;

I want this constraint to say that if a location j is chosen (Yj = 1) and if the distance between i and j is less than 20 , then => I want to close location i (Xi = 0)

forall (j in Locations, k in Locations)(Y[j]==1 && Distance2[j][k]<=40) => Y[k]==0;

Similarly, this constraint says that if a location j is chosen (Yj = 1) and if the distance between 2 potential locations is less than 40, then I do not want to choose location k (Yk = 0)

The model gives a result but as I check the numbers, it seems to ignore these 2 constraints. So, something is not working properly in the terms used.

1 Answer 1

2

The constraints look mostly correct to me. What looks a bit fishy in the second constraint is that you don't exclude the case j==k. If Y[j]==1 then probably Distance2[j][j]==0 and thus the second constraint implies Y[j]==0. A contradiction! Are you sure that CPLEX claims your solution optimal? Or are you maybe looking at a relaxed solution (which would then be allowed to violate constraints)?

Assuming Distance is data and not a decision variable, your constraints could be written in a more efficient way. For example the first one:

forall(i in Drives)
   forall(j in Locations : Distance[j][i] <= 20)
      X[i] <= 1 - Y[j]; // If Y[j]==1 then the right-hand side becomes zero and forces X[i]==0

Similary, the second constraint could be written as

forall(j in Locations)
   forall(k in Locations : k != j && Distance2[j][k] <= 40)
      Y[k] <= 1 - Y[j]; // If Y[j]==1 then the right-hand side becomes zero and forces Y[k]==0

Can you try with these more explicit constraints or at least with excluding the case j==k in the second constraint?

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

2 Comments

Thank you. I have used the constraints format you have suggested and they seem to be working. However, another problem arises and I am not quite sure if it's relevant to these constraints or not. Maybe you can give me your insight about that: X[i] belongs to a set of locations from 1 till 715 and Y[j] belongs to a set of locations from 1 till 78. The results I receive only consider the first 78 points in my X[i] and not the whole list. I cannot identify the problem, and I'm not sure if it is arising from these 2 constraints.
This smells like you are using the wrong index set in some place. Double check that you always use the correct one of Locations and Drives in all places. If you cannot find the problem then please create a new question and attach your full model.

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.