Use index for another index Topic is solved

Problems with syntax of GAMS
Post Reply
moosavi_69
User
User
Posts: 31
Joined: 6 years ago

Use index for another index

Post by moosavi_69 »

Hello,

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

Code: Select all

c	/1*10/
j	/1*3/
Now, I would like to define subsets of c as below:

Code: Select all

c_j


c_j, for example, can be as follows:

Code: Select all

c_1	/1*5/
c_2	/5*10/
c_3	/4*6/
So, I can write a constraint like below:

Code: Select all

Con(j) .. sum((c_j,r,d), x(c_j,r,d)) =l= y(j);
How can I define c_j?

Thanks, Amir.
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: Use index for another index

Post by abhosekar »

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

Then you can have

Code: Select all

Con(j) .. sum((c, j,r,d)$c_j(c,j), x(c_j,r,d)) =l= y(j);
- Atharv
moosavi_69
User
User
Posts: 31
Joined: 6 years ago

Re: Use index for another index

Post by moosavi_69 »

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?

Code: Select all

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."

Code: Select all

Con(j) .. sum((c,r,d)$c_j(c,j), x(c,r,d)) =l= y(j);
Am I right? Thanks in advance.
User avatar
dirkse
Moderator
Moderator
Posts: 214
Joined: 7 years ago
Location: Fairfax, VA

Re: Use index for another index

Post by dirkse »

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) Downloaded 225 times
BTW, it seems like your formulation of the con(j) constraint is good. Seems right to me.

-Steve
Post Reply