Use index for another index

Hello,

Let assume I have an index c and j as follows:

c	/1*10/
j	/1*3/

Now, I would like to define subsets of c as below:

c_j

c_j, for example, can be as follows:

c_1	/1*5/
c_2	/5*10/
c_3	/4*6/

So, I can write a constraint like below:

Con(j) .. sum((c_j,r,d), x(c_j,r,d)) =l= y(j);

How can I define c_j?

Thanks, Amir.

You can define a 2D set c_j(c, j) and assign elements to it.

Then you can have

Con(j) .. sum((c, j,r,d)$c_j(c,j), x(c_j,r,d)) =l= y(j);
  • Atharv

Thank you. I want to remove a few elements from the two-dimensional set that I have created. However, it does not work. Do you have any suggestions?

Sets
  c       /1*10/
  t       /1*10/
  tc(c,t) /#c.#t/;

Parameters
  p(c)  /1 3, 2 4, 3 5, 4 2, 5 3, 6 4, 7 5, 8 6, 9 5, 10 5/;

loop((c,t),
if(ord(t)-p(c)+1>card(t),
  tc(c,t) = No;
);
);

Moreover, I think the format that you provided for writing the constraint should be reformulated as follows. This is because when I use your format, I face an error like “Uncontrolled set entered as constant.”

Con(j) .. sum((c,r,d)$c_j(c,j), x(c,r,d)) =l= y(j);

Am I right? Thanks in advance.

Moosavi,

I think the if-test in your loop is never true. If you add p(c) it actually does something.

The attached example does the same thing in a marginally better way.
moosavi.gms (518 Bytes)
BTW, it seems like your formulation of the con(j) constraint is good. Seems right to me.

-Steve