and would like to define myconstraint(i,j) only if i, j = 1:10 when i <> j (for example when
defining the distance between points i and j). What is the correct way to define it? I tried
several variants with the $ conditional with no success

Hi, I think you can define a parameter that contains the distance between the two points (distance (i, j)).
For example, the following equation is defined only if the distance between points is greater than or equal to 3

myconstraint(i,j)$(distancie(i,j) ge 3)… function(i,j) =e= 0;

The quick way to do this is with a dollar condition in the constraint:

set i /1*10/
alias(i, j);
equations myconstraint(i,j);
myconstraint(i,j)$[not sameas(i,j)] … function(i,j) =e= 0;

The logic is all part of the myconstraint definition. Since it’s simple, that works well.

For more complicated conditions, it’s better to create a dynamic set and use that. For example, I could add this code:

set sub(i,j);
sub(i,j) = [not sameas(i,j)] and [(ord(i) - 2) <= ord(j)] and [(ord(i) + 2) >= ord(j)];
execute_unload 'lookAtMe', i,j, sub;
equation con2(i,j);
con2(sub(i,j)) .. function(i,j) =e= 0;

If I look at the set sub(i,j) in the GDX browser of the IDE (just open the file lookAtMe.gdx), I will get a nice picture of the data and will know what’s right or wrong.