Search code examples
cplexinteger-programmingopl

Traversing the elements of set in a set of tuples using OPL


I am trying to model a problem using OPL, cplex. I got stuck at a constraint. I have a set of tuples in the format:

N_set = {
 <1, {180}>
 <8, {546, 154}>
 <11, {193, 532, 43, 363}>
 ...
};

So I basically try to use a map structure. Given an integer, I want to be able to reach the set coresponding to it. I used a tuple that includes a set to achieve this. The code below is not complete, it is a simplified version of what I am trying to do, but still not working. Below is the error I get:

Definition of formal parameter "t2" of type {int} not supported in this context.

I mainly want to learn how I can iterate through the items j in this set t2. Assume dec1 and dec2 are my decision variables. My structure is as follows:

tuple Neighborhood {
 int e1;
 {int} neigh;  
}

{Neighborhood} N_set = ...;

forall(p in P)
{               
    sum(<t1, t2> in N_set, j in t2) dec1[j][p]) == card(t2) * dec2[p]; 
};

I am complete new to the language. Maybe what I am trying to do is completely wrong. I'd appreciate any suggestions.

Thank you.


Solution

  • You cannot sum over the tuple the way you tried. However, you can write it like this:

    sum(t in N_set, j in t.neigh) ...
    

    Instead of heaving the tuple's field in t1 and t2 you just have them in t.e1 and t.neigh now.