Topic
• Latest Post - ‏2012-10-12T12:05:02Z by SystemAdmin
salais
3 Posts

# Pinned topic On conditional constraints involving decision variables

‏2012-10-12T11:36:53Z |
Hello,

I am working on implementing a TSPTW solver according to Pesant et al. in their paper "An exact constraint logic programming algorithm for the tsptw)

However in the model there exists the following constraint:

S[i] = j => S[epsilonj] != beta[i] with the exception that e[j] != (N+1), for all i in Vo (1)

In the above equation, subscripts are represented by square brackets and the operator "=>" means "implies". The constraint functionality that I wish to accomplish would then be something like

// Subtour elimination
forall (i in Vo)
{
if (epsilon[Si] != (N+1))
S[epsilon[Si]] != beta[i];
}

Where epsilon and beta are arrays with the same length as Vo

This however does not work, since according to the documentation: "Conditions in if-else statements must be ground; that is, they must not contain decision variables."
Now this is very problematic since the model presented in the paper implies very strongly that the subscript j I need in eq. (1) to access the epsilon and beta vectors are in fact values of the dvar vector S.

Is there a way around this? Should I be modelling the "implies" operator in a different way? I also tried an alternative approech where i would write

// (4) Subtour elimination
forall (i in Vo : S[i] != (N+1))
{
S[epsilon[Si]] != beta[i];
}

This yielded an error regarding the usage of decision variables.

My variables are

int betaVo;
int epsilonVo;
dvar int SVo;

PS. How does one invoke the proper formatting for code on this forum?
Updated on 2012-10-12T12:05:02Z at 2012-10-12T12:05:02Z by SystemAdmin
623 Posts

#### Re: On conditional constraints involving decision variables

‏2012-10-12T12:05:02Z
Hello.

You can use just "=>" to model implications. For example:
``````
using CP; dvar

int x; subject to
{ x!=1 => x>5;
}```
```

Regarding the code formatting, it is necessary to write tags "(code)" before and after your code, however instead of () brackets use {} brackets. When you write the message there is a table of markups on the right from the edit box with your text. It's very easy to overlook. There's also preview tab above the edit box to see how the message will look like.

Best regards, Petr