# GAMS Support Wiki

### Site Tools

gams:a_more_complex_parameter_to_set_-_matching_problem

# A more complex Parameter to Set - Matching Problem

Q: 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.

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 (as I did in my example) have a parameter with the proper values. Please find the complete example attached.

```set i /i1*i10/, k /0*9/; alias (i,j);
Parameter nk(k); nk(k) = ord(k)-1;

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) = nk(k);
option ijk:0:0:1; display nk, 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;```
```----      6 PARAMETER nk

1 1.000,    2 2.000,    3 3.000,    4 4.000,    5 5.000,    6 6.000,    7 7.000,    8 8.000,    9 9.000

----      6 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

----      6 SET ijk

i1 .i1.0
i3 .i1.2
i3 .i2.1
i3 .i3.0
i4 .i1.3
i4 .i3.1
i5 .i1.4
i5 .i2.3
i5 .i3.2
i5 .i4.1
i5 .i5.0
i6 .i4.2
i6 .i5.1
i6 .i6.0
i7 .i1.6
i7 .i2.5
i7 .i5.2
i7 .i6.1
i8 .i1.7
i8 .i2.6
i8 .i3.5
i8 .i5.3
i8 .i7.1
i8 .i8.0
i9 .i1.8
i9 .i2.7
i9 .i3.6
i9 .i4.5
i9 .i5.4
i9 .i6.3
i9 .i7.2
i9 .i8.1
i9 .i9.0
i10.i2.8
i10.i3.7
i10.i5.5
i10.i7.3
i10.i9.1```