## A more complex parameter to set - matching problem

Frequently asked questions about GAMS

Moderator: aileen

Forum rules
Please ask questions in the other sub-forums
aileen
User
Posts: 121
Joined: 1 year ago

### A more complex parameter to set - matching problem

I want to create a parameter a(k) and multiply a(k)*x(i,j) where x is a variable and k= ord(i) - ord(j) with the complication that x(i,j) is not full for all i and j. I can't seem to get this to work.

aileen
User
Posts: 121
Joined: 1 year ago

### Re: A more complex parameter to set - matching problem

I would make a set ijk(i,j,k). The elements of this set are the matching tuples. The problem is that k is a set element and not a number. So your k in k=ord(i)-ord(j) also needs a function that maps it to a value, like ord. Depending on the range of ord(i)-ord(j) you can either work with ord or have a parameter with the proper values or (as in the example below) work with k.val.

Code: Select all

``````set i /i1*i10/, k /0*9/; alias (i,j);

set ij(i,j); ij(i,j) = ord(i)>=ord(j) and uniform(0,1)<0.5;
set ijk(i,j,k); ijk(ij(i,j),k) = ord(i)-ord(j) = k.val;
option ijk:0:2:1; display ij, ijk;

binary variable x(i,j); variable z;
parameter a(k); a(k) = uniform(-10,10);
equation e; e.. z =e= sum(ijk(ij,k), a(k)*x(ij));
model m /all/;
solve m max z using mip;``````

Code: Select all

``````----      5 SET ij

i1          i2          i3          i4          i5          i6          i7          i8          i9

i1          YES
i3          YES         YES         YES
i4          YES                     YES
i5          YES         YES         YES         YES         YES
i6                                              YES         YES         YES
i7          YES         YES                                 YES         YES
i8          YES         YES         YES                     YES                     YES         YES
i9          YES         YES         YES         YES         YES         YES         YES         YES         YES
i10                     YES         YES                     YES                     YES                     YES

----      5 SET ijk

0           1           2           3           4           5           6           7           8

i1 .i1         YES
i3 .i1                                 YES
i3 .i2                     YES
i3 .i3         YES
i4 .i1                                             YES
i4 .i3                     YES
i5 .i1                                                         YES
i5 .i2                                             YES
i5 .i3                                 YES
i5 .i4                     YES
i5 .i5         YES
i6 .i4                                 YES
i6 .i5                     YES
i6 .i6         YES
i7 .i1                                                                                 YES
i7 .i2                                                                     YES
i7 .i5                                 YES
i7 .i6                     YES
i8 .i1                                                                                             YES
i8 .i2                                                                                 YES
i8 .i3                                                                     YES
i8 .i5                                             YES
i8 .i7                     YES
i8 .i8         YES
i9 .i1                                                                                                         YES
i9 .i2                                                                                             YES
i9 .i3                                                                                 YES
i9 .i4                                                                     YES
i9 .i5                                                         YES
i9 .i6                                             YES
i9 .i7                                 YES
i9 .i8                     YES
i9 .i9         YES
i10.i2                                                                                                         YES
i10.i3                                                                                             YES
i10.i5                                                                     YES
i10.i7                                             YES
i10.i9                     YES``````