How to write the equations compactly in GAMS?

Dear all,

I’m the new users of GAMs, so I really appreciate for your help.

I define three set tt, w1,w2, such that tt is the subset of w1 and w2, but w1 is not equal to w2. I also define the variables and parameters in w1 and w2. Now, how can I define the equations which only include variables and parameters in tt? Please check my code and error information. It seems that GAMS does not allow me to define the tt as the subset both of w1 and w2.

Thanks a lot.

Regards,


1 *$oninline
2 Set w1 /tt1,tt2,tt3,er/;
3 Set w2 /pt,tt1,tt2,tt3/;
4 Set tt /tt1,tt2,tt3/;
5 Set row /k1,k2/;
6 Table r1(w1,row)
7 k1 k2
8 tt1 1 0
9 tt2 0 2
10 tt3 3 1
11 er 3 0;
12
13 Table r2(w2,row)
14 k1 k2
15 pt 10 -5
16 tt1 1 0.2
17 tt2 -0.9 2
18 tt3 3 1;
19
20 Variables x(w1), y(w2), obj;
21 Positive Variables x, y
22
23 Equations
24
25 balance1(tt)
26
27 Total;
28
29 balance1(tt)… x(tt)*r1(tt,‘k1’)+y(tt)*r2(tt,‘k2’)=g=25;
**** $171 $171 $171 $171
30
31 Total… obj=e=sum(w1, x(w1))+sum(w2, y(w2));
32 Model Ref /all/ ;
33 Solve Ref using lp minimizing obj;
**** $257
GAMS 24.1.3 r41464 Released Jul 26, 2013 WEX-WEI x86_64/MS Windows 12/13/13 11:37:56 Page 2
G e n e r a l A l g e b r a i c M o d e l i n g S y s t e m
Error Messages

171 Domain violation for set
257 Solve statement not checked because of previous errors
**** 5 ERROR(S) 0 WARNING(S)


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/groups/opt_out.

Hi

Here a quick solution (take a good look in the manual how to define subsets, as you did not define any subsets at all!)

The trick I used is to define a superset with all the elements.

Cheers



Renger



Set w /tt1,tt2,tt3,er, pt/,

w1(w) /tt1,tt2,tt3,er/,

w2(w) /pt,tt1,tt2,tt3/,

tt(w1) /tt1,tt2,tt3/,

row /k1,k2/;

Table r1(w,row)

k1 k2

tt1 1 0

tt2 0 2

tt3 3 1

er 3 0;



Table r2(w,row)

k1 k2

pt 10 -5

tt1 1 0.2

tt2 -0.9 2

tt3 3 1;



Variables x(w), y(w), obj;

Positive Variables x, y



Equations



balance1(tt)



Total;



balance1(tt)… x(tt)*r1(tt,‘k1’)+y(tt)*r2(tt,‘k2’)=g=25;

Total… obj=e=sum(w1, x(w1))+sum(w2, y(w2));

Model Ref /all/ ;

Solve Ref using lp minimizing obj;



From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of yyang6@ualberta.ca
Sent: Friday, December 13, 2013 5:45 PM
To: gamsworld@googlegroups.com
Subject: How to write the equations compactly in GAMS?



Dear all,



I’m the new users of GAMs, so I really appreciate for your help.



I define three set tt, w1,w2, such that tt is the subset of w1 and w2, but w1 is not equal to w2. I also define the variables and parameters in w1 and w2. Now, how can I define the equations which only include variables and parameters in tt? Please check my code and error information. It seems that GAMS does not allow me to define the tt as the subset both of w1 and w2.



Thanks a lot.



Regards,





1 *$oninline
2 Set w1 /tt1,tt2,tt3,er/;
3 Set w2 /pt,tt1,tt2,tt3/;
4 Set tt /tt1,tt2,tt3/;
5 Set row /k1,k2/;
6 Table r1(w1,row)
7 k1 k2
8 tt1 1 0
9 tt2 0 2
10 tt3 3 1
11 er 3 0;
12
13 Table r2(w2,row)
14 k1 k2
15 pt 10 -5
16 tt1 1 0.2
17 tt2 -0.9 2
18 tt3 3 1;
19
20 Variables x(w1), y(w2), obj;
21 Positive Variables x, y
22
23 Equations
24
25 balance1(tt)
26
27 Total;
28
29 balance1(tt)… x(tt)*r1(tt,‘k1’)+y(tt)*r2(tt,‘k2’)=g=25;
**** $171 $171 $171 $171
30
31 Total… obj=e=sum(w1, x(w1))+sum(w2, y(w2));
32 Model Ref /all/ ;
33 Solve Ref using lp minimizing obj;
**** $257
GAMS 24.1.3 r41464 Released Jul 26, 2013 WEX-WEI x86_64/MS Windows 12/13/13 11:37:56 Page 2
G e n e r a l A l g e b r a i c M o d e l i n g S y s t e m
Error Messages


171 Domain violation for set
257 Solve statement not checked because of previous errors

**** 5 ERROR(S) 0 WARNING(S)


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/groups/opt_out.


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/groups/opt_out.

Thanks a lot!! I will employ this strategy.

Regards,

Yu

On Sunday, December 15, 2013 1:02:00 PM UTC-5, Renger van Nieuwkoop wrote:

Hi

Here a quick solution (take a good look in the manual how to define subsets, as you did not define any subsets at all!)

The trick I used is to define a superset with all the elements.

Cheers



Renger



Set w /tt1,tt2,tt3,er, pt/,

w1(w) /tt1,tt2,tt3,er/,

w2(w) /pt,tt1,tt2,tt3/,

tt(w1) /tt1,tt2,tt3/,

row /k1,k2/;

Table r1(w,row)

k1 k2

tt1 1 0

tt2 0 2

tt3 3 1

er 3 0;



Table r2(w,row)

k1 k2

pt 10 -5

tt1 1 0.2

tt2 -0.9 2

tt3 3 1;



Variables x(w), y(w), obj;

Positive Variables x, y



Equations



balance1(tt)



Total;



balance1(tt)… x(tt)*r1(tt,‘k1’)+y(tt)*r2(tt,‘k2’)=g=25;

Total… obj=e=sum(w1, x(w1))+sum(w2, y(w2));

Model Ref /all/ ;

Solve Ref using lp minimizing obj;



From: gams...@googlegroups.com [mailto:gams...@googlegroups.com] On Behalf Of yya…@ualberta.ca
Sent: Friday, December 13, 2013 5:45 PM
To: gams...@googlegroups.com
Subject: How to write the equations compactly in GAMS?



Dear all,



I’m the new users of GAMs, so I really appreciate for your help.



I define three set tt, w1,w2, such that tt is the subset of w1 and w2, but w1 is not equal to w2. I also define the variables and parameters in w1 and w2. Now, how can I define the equations which only include variables and parameters in tt? Please check my code and error information. It seems that GAMS does not allow me to define the tt as the subset both of w1 and w2.



Thanks a lot.



Regards,





1 *$oninline
2 Set w1 /tt1,tt2,tt3,er/;
3 Set w2 /pt,tt1,tt2,tt3/;
4 Set tt /tt1,tt2,tt3/;
5 Set row /k1,k2/;
6 Table r1(w1,row)
7 k1 k2
8 tt1 1 0
9 tt2 0 2
10 tt3 3 1
11 er 3 0;
12
13 Table r2(w2,row)
14 k1 k2
15 pt 10 -5
16 tt1 1 0.2
17 tt2 -0.9 2
18 tt3 3 1;
19
20 Variables x(w1), y(w2), obj;
21 Positive Variables x, y
22
23 Equations
24
25 balance1(tt)
26
27 Total;
28
29 balance1(tt)… x(tt)*r1(tt,‘k1’)+y(tt)*r2(tt,‘k2’)=g=25;
**** $171 $171 $171 $171
30
31 Total… obj=e=sum(w1, x(w1))+sum(w2, y(w2));
32 Model Ref /all/ ;
33 Solve Ref using lp minimizing obj;
**** $257
GAMS 24.1.3 r41464 Released Jul 26, 2013 WEX-WEI x86_64/MS Windows 12/13/13 11:37:56 Page 2
G e n e r a l A l g e b r a i c M o d e l i n g S y s t e m
Error Messages


171 Domain violation for set
257 Solve statement not checked because of previous errors

**** 5 ERROR(S) 0 WARNING(S)


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/groups/opt_out.


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/groups/opt_out.