Multi-dimensional sets to quickly affect values over subsets

Dear all,

I am trying to affect values of several continents to each country of that continent in a Gams program. Since I might not be clear I created a small example to illustrate my problem which you can copy below the Example section of this post.
I set up 90 countries and 3 continents (a,b,c). Let’s say I have growth rates forecasts over several continents and I want to affect this value to each country of that continent without having to do it manually. In the exampe below this operation is represented with parameter test2(ctry). My problem is that if some countries are missing (11
30) I get a value of 1 for these countries where I would like a 0 value see (Display section). Do you have any idea of what is happening here? Maybe I used the wrong trick?

Thanks in advance for your help. It is deeply appreciated!

Jon


*=============================================================================
*EXAMPLE
*=============================================================================

sets

reg/a,b,c/
reg2(reg)/b,c/

ctry/1*90/

regtoctry(reg,ctry)
/
a.(110)
b.(31
60)
c.(61*90)
/
;


display regtoctry;

parameter test(reg)
/ a 33
b 66
c 99
/;

parameter test0(ctry)
/ 130 1
31
60 2
61*90 3
/;

display test0;

*!Sum of country values for each region

parameter test1(reg);
test1(reg)=sum(regtoctry(reg,ctry), test0(ctry));
display test1;

*!Apply regional values to each country of the region

parameter test2(ctry);
test2(ctry)=prod(regtoctry(reg,ctry),test(reg));

display test2;


$ontext

parameter test3 (reg2);

test3(reg2)=sum(regtoctry(reg2,ctry),test0(ctry));

*display test3;

parameter test4(reg);

test4(“a”)=sum(reg2, test(reg2));

*display test4;


set
notregtoctry(reg,ctry)
;

notregtoctry(reg,ctry)=not regtoctry(reg,ctry);

display notregtoctry;


$offtext

*============================ End Of File ======================================

*=============================================================================
*DISPLAY
*=============================================================================

$ontext


---- 59 PARAMETER test2

1 33.000, 2 33.000, 3 33.000, 4 33.000, 5 33.000, 6 33.000, 7 33.000, 8 33.000
9 33.000, 10 33.000, 11 1.000, 12 1.000, 13 1.000, 14 1.000, 15 1.000, 16 1.000
17 1.000, 18 1.000, 19 1.000, 20 1.000, 21 1.000, 22 1.000, 23 1.000, 24 1.000
25 1.000, 26 1.000, 27 1.000, 28 1.000, 29 1.000, 30 1.000, 31 66.000, 32 66.000
33 66.000, 34 66.000, 35 66.000, 36 66.000, 37 66.000, 38 66.000, 39 66.000, 40 66.000
41 66.000, 42 66.000, 43 66.000, 44 66.000, 45 66.000, 46 66.000, 47 66.000, 48 66.000
49 66.000, 50 66.000, 51 66.000, 52 66.000, 53 66.000, 54 66.000, 55 66.000, 56 66.000
57 66.000, 58 66.000, 59 66.000, 60 66.000, 61 99.000, 62 99.000, 63 99.000, 64 99.000
65 99.000, 66 99.000, 67 99.000, 68 99.000, 69 99.000, 70 99.000, 71 99.000, 72 99.000
73 99.000, 74 99.000, 75 99.000, 76 99.000, 77 99.000, 78 99.000, 79 99.000, 80 99.000
81 99.000, 82 99.000, 83 99.000, 84 99.000, 85 99.000, 86 99.000, 87 99.000, 88 99.000
89 99.000, 90 99.000
$offtext


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/d/optout.

Hi Jon

It works if you use sum instead of prod, but it is funny that prod gives you a 1…

Perhaps somebody from Gams could explain this behavior.

Renger



From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of Jonathan
Sent: Monday, October 27, 2014 9:56 AM
To: gamsworld@googlegroups.com
Subject: Multi-dimensional sets to quickly affect values over subsets



Dear all,

I am trying to affect values of several continents to each country of that continent in a Gams program. Since I might not be clear I created a small example to illustrate my problem which you can copy below the Example section of this post.
I set up 90 countries and 3 continents (a,b,c). Let’s say I have growth rates forecasts over several continents and I want to affect this value to each country of that continent without having to do it manually. In the exampe below this operation is represented with parameter test2(ctry). My problem is that if some countries are missing (11
30) I get a value of 1 for these countries where I would like a 0 value see (Display section). Do you have any idea of what is happening here? Maybe I used the wrong trick?

Thanks in advance for your help. It is deeply appreciated!

Jon


*=============================================================================
*EXAMPLE
*=============================================================================

sets

reg/a,b,c/
reg2(reg)/b,c/

ctry/1*90/

regtoctry(reg,ctry)
/
a.(110)
b.(31
60)
c.(61*90)
/
;


display regtoctry;

parameter test(reg)
/ a 33
b 66
c 99
/;

parameter test0(ctry)
/ 130 1
31
60 2
61*90 3
/;

display test0;

*!Sum of country values for each region

parameter test1(reg);
test1(reg)=sum(regtoctry(reg,ctry), test0(ctry));
display test1;

*!Apply regional values to each country of the region

parameter test2(ctry);
test2(ctry)=prod(regtoctry(reg,ctry),test(reg));

display test2;


$ontext

parameter test3 (reg2);

test3(reg2)=sum(regtoctry(reg2,ctry),test0(ctry));

*display test3;

parameter test4(reg);

test4(“a”)=sum(reg2, test(reg2));

*display test4;


set
notregtoctry(reg,ctry)
;

notregtoctry(reg,ctry)=not regtoctry(reg,ctry);

display notregtoctry;


$offtext

*============================ End Of File ======================================

*=============================================================================
*DISPLAY
*=============================================================================

$ontext


---- 59 PARAMETER test2

1 33.000, 2 33.000, 3 33.000, 4 33.000, 5 33.000, 6 33.000, 7 33.000, 8 33.000
9 33.000, 10 33.000, 11 1.000, 12 1.000, 13 1.000, 14 1.000, 15 1.000, 16 1.000
17 1.000, 18 1.000, 19 1.000, 20 1.000, 21 1.000, 22 1.000, 23 1.000, 24 1.000
25 1.000, 26 1.000, 27 1.000, 28 1.000, 29 1.000, 30 1.000, 31 66.000, 32 66.000
33 66.000, 34 66.000, 35 66.000, 36 66.000, 37 66.000, 38 66.000, 39 66.000, 40 66.000
41 66.000, 42 66.000, 43 66.000, 44 66.000, 45 66.000, 46 66.000, 47 66.000, 48 66.000
49 66.000, 50 66.000, 51 66.000, 52 66.000, 53 66.000, 54 66.000, 55 66.000, 56 66.000
57 66.000, 58 66.000, 59 66.000, 60 66.000, 61 99.000, 62 99.000, 63 99.000, 64 99.000
65 99.000, 66 99.000, 67 99.000, 68 99.000, 69 99.000, 70 99.000, 71 99.000, 72 99.000
73 99.000, 74 99.000, 75 99.000, 76 99.000, 77 99.000, 78 99.000, 79 99.000, 80 99.000
81 99.000, 82 99.000, 83 99.000, 84 99.000, 85 99.000, 86 99.000, 87 99.000, 88 99.000
89 99.000, 90 99.000
$offtext


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/d/optout.


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/d/optout.

Hi,

If you have an empty product in GAMS (meaning prod(aSet,…) with aSet empty) this will return the multiplicative identity 1. Similarly, the result of sum over an empty set results in the additive identity 0. And to complete this list: smin over an empty set will return +Inf and smax will return -Inf.

I hope that helps,
Lutz


On 10/27/2014 5:19 AM, Renger van Nieuwkoop wrote:

Hi Jon

It works if you use sum instead of prod, but it is funny that prod gives
you a 1…

Perhaps somebody from Gams could explain this behavior.

Renger

From:gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com]
*On Behalf Of *Jonathan
Sent: Monday, October 27, 2014 9:56 AM
To: gamsworld@googlegroups.com
Subject: Multi-dimensional sets to quickly affect values over subsets

Dear all,

I am trying to affect values of several continents to each country of
that continent in a Gams program. Since I might not be clear I created a
small example to illustrate my problem which you can copy below the
Example section of this post.
I set up 90 countries and 3 continents (a,b,c). Let’s say I have growth
rates forecasts over several continents and I want to affect this value
to each country of that continent without having to do it manually. In
the exampe below this operation is represented with parameter
test2(ctry). My problem is that if some countries are missing (11
30) I
get a value of 1 for these countries where I would like a 0 value see
(Display section). Do you have any idea of what is happening here? Maybe
I used the wrong trick?

Thanks in advance for your help. It is deeply appreciated!

Jon

*=============================================================================
*EXAMPLE
*=============================================================================

sets

reg/a,b,c/
reg2(reg)/b,c/

ctry/1*90/

regtoctry(reg,ctry)
/
a.(110)
b.(31
60)
c.(61*90)
/
;

display regtoctry;

parameter test(reg)
/ a 33
b 66
c 99
/;

parameter test0(ctry)
/ 130 1
31
60 2
61*90 3
/;

display test0;

*!Sum of country values for each region

parameter test1(reg);
test1(reg)=sum(regtoctry(reg,ctry), test0(ctry));
display test1;

*!Apply regional values to each country of the region

parameter test2(ctry);
test2(ctry)=prod(regtoctry(reg,ctry),test(reg));

display test2;

$ontext

parameter test3 (reg2);

test3(reg2)=sum(regtoctry(reg2,ctry),test0(ctry));

*display test3;

parameter test4(reg);

test4(“a”)=sum(reg2, test(reg2));

*display test4;

set
notregtoctry(reg,ctry)
;

notregtoctry(reg,ctry)=not regtoctry(reg,ctry);

display notregtoctry;

$offtext

*============================ End Of File

*=============================================================================
*DISPLAY
*=============================================================================

$ontext

---- 59 PARAMETER test2

1 33.000, 2 33.000, 3 33.000, 4 33.000, 5 33.000, 6
33.000, 7 33.000, 8 33.000
9 33.000, 10 33.000, 11 1.000, 12 1.000, 13 1.000,
14 1.000, 15 1.000, 16 1.000
17 1.000, 18 1.000, 19 1.000, 20 1.000, 21 1.000,
22 1.000, 23 1.000, 24 1.000
25 1.000, 26 1.000, 27 1.000, 28 1.000, 29 1.000,
30 1.000, 31 66.000, 32 66.000
33 66.000, 34 66.000, 35 66.000, 36 66.000, 37 66.000, 38
66.000, 39 66.000, 40 66.000
41 66.000, 42 66.000, 43 66.000, 44 66.000, 45 66.000, 46
66.000, 47 66.000, 48 66.000
49 66.000, 50 66.000, 51 66.000, 52 66.000, 53 66.000, 54
66.000, 55 66.000, 56 66.000
57 66.000, 58 66.000, 59 66.000, 60 66.000, 61 99.000, 62
99.000, 63 99.000, 64 99.000
65 99.000, 66 99.000, 67 99.000, 68 99.000, 69 99.000, 70
99.000, 71 99.000, 72 99.000
73 99.000, 74 99.000, 75 99.000, 76 99.000, 77 99.000, 78
99.000, 79 99.000, 80 99.000
81 99.000, 82 99.000, 83 99.000, 84 99.000, 85 99.000, 86
99.000, 87 99.000, 88 99.000
89 99.000, 90 99.000
$offtext


You received this message because you are subscribed to the Google
Groups “gamsworld” group.
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/d/optout.


You received this message because you are subscribed to the Google
Groups “gamsworld” group.
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/d/optout.



Lutz Westermann LWestermann@gams.com
GAMS Development Corporation GAMS Software GmbH
1217 Potomac St. NW, P.O. Box 40 59
Washington DC, 20007, USA 50216 Frechen, Germany
Fon/Fax: +1 202 342-0180/1 Fon/Fax: +49 221 949-9170/1
http://www.gams.com


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/d/optout.

Hello,

Sorry for the late reply I thought I apparently missed the notification from google. Thanks Lutz and Renger for you answers I understand why I have this issue. I can use a condition with [prod(set)1]. The problem is then to sort the values that equals 1 before transformation. I came up with the solution below knowing that my values are going from 0 to 1. I replaced all ones by 9999 and then replaced them after transformation.

test(reg)$(test(reg)=1)=9999;

parameter test2(ctry);
test2(ctry)
$[prod(regtoctry(reg,ctry),test(reg))1]
=prod(regtoctry(reg,ctry),test(reg));

test2(ctry)$[test2(ctry)=9999]
=1;

I would prefer using a variable instead of 9999. When I do it I come up with an error value. Is it possible to replace a specific value (1 in that case) by a variable (say x)?

Thank you very much!




Le lundi 27 octobre 2014 10:44:19 UTC+1, Lutz Westermann a écrit :

Hi,

If you have an empty product in GAMS (meaning prod(aSet,…) with aSet
empty) this will return the multiplicative identity 1. Similarly, the
result of sum over an empty set results in the additive identity 0. And
to complete this list: smin over an empty set will return +Inf and smax
will return -Inf.

I hope that helps,
Lutz


On 10/27/2014 5:19 AM, Renger van Nieuwkoop wrote:

Hi Jon

It works if you use sum instead of prod, but it is funny that prod gives
you a 1…

Perhaps somebody from Gams could explain this behavior.

Renger

*From:*gams…@googlegroups.com [mailto:gams...@googlegroups.com]
*On Behalf Of *Jonathan
Sent: Monday, October 27, 2014 9:56 AM
To: gams...@googlegroups.com
Subject: Multi-dimensional sets to quickly affect values over subsets

Dear all,

I am trying to affect values of several continents to each country of
that continent in a Gams program. Since I might not be clear I created a
small example to illustrate my problem which you can copy below the
Example section of this post.
I set up 90 countries and 3 continents (a,b,c). Let’s say I have growth
rates forecasts over several continents and I want to affect this value
to each country of that continent without having to do it manually. In
the exampe below this operation is represented with parameter
test2(ctry). My problem is that if some countries are missing (11
30) I
get a value of 1 for these countries where I would like a 0 value see
(Display section). Do you have any idea of what is happening here? Maybe
I used the wrong trick?

Thanks in advance for your help. It is deeply appreciated!

Jon

*=============================================================================
*EXAMPLE
*=============================================================================

sets

reg/a,b,c/
reg2(reg)/b,c/

ctry/1*90/

regtoctry(reg,ctry)
/
a.(110)
b.(31
60)
c.(61*90)
/
;

display regtoctry;

parameter test(reg)
/ a 33
b 66
c 99
/;

parameter test0(ctry)
/ 130 1
31
60 2
61*90 3
/;

display test0;

*!Sum of country values for each region

parameter test1(reg);
test1(reg)=sum(regtoctry(reg,ctry), test0(ctry));
display test1;

*!Apply regional values to each country of the region

parameter test2(ctry);
test2(ctry)=prod(regtoctry(reg,ctry),test(reg));

display test2;

$ontext

parameter test3 (reg2);

test3(reg2)=sum(regtoctry(reg2,ctry),test0(ctry));

*display test3;

parameter test4(reg);

test4(“a”)=sum(reg2, test(reg2));

*display test4;

set
notregtoctry(reg,ctry)
;

notregtoctry(reg,ctry)=not regtoctry(reg,ctry);

display notregtoctry;

$offtext

*============================ End Of File

*=============================================================================
*DISPLAY
*=============================================================================

$ontext

---- 59 PARAMETER test2

1 33.000, 2 33.000, 3 33.000, 4 33.000, 5 33.000, 6
33.000, 7 33.000, 8 33.000
9 33.000, 10 33.000, 11 1.000, 12 1.000, 13 1.000,
14 1.000, 15 1.000, 16 1.000
17 1.000, 18 1.000, 19 1.000, 20 1.000, 21 1.000,
22 1.000, 23 1.000, 24 1.000
25 1.000, 26 1.000, 27 1.000, 28 1.000, 29 1.000,
30 1.000, 31 66.000, 32 66.000
33 66.000, 34 66.000, 35 66.000, 36 66.000, 37 66.000, 38
66.000, 39 66.000, 40 66.000
41 66.000, 42 66.000, 43 66.000, 44 66.000, 45 66.000, 46
66.000, 47 66.000, 48 66.000
49 66.000, 50 66.000, 51 66.000, 52 66.000, 53 66.000, 54
66.000, 55 66.000, 56 66.000
57 66.000, 58 66.000, 59 66.000, 60 66.000, 61 99.000, 62
99.000, 63 99.000, 64 99.000
65 99.000, 66 99.000, 67 99.000, 68 99.000, 69 99.000, 70
99.000, 71 99.000, 72 99.000
73 99.000, 74 99.000, 75 99.000, 76 99.000, 77 99.000, 78
99.000, 79 99.000, 80 99.000
81 99.000, 82 99.000, 83 99.000, 84 99.000, 85 99.000, 86
99.000, 87 99.000, 88 99.000
89 99.000, 90 99.000
$offtext


You received this message because you are subscribed to the Google
Groups “gamsworld” group.
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/d/optout.


You received this message because you are subscribed to the Google
Groups “gamsworld” group.
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/d/optout.



Lutz Westermann LWest...@gams.com
GAMS Development Corporation GAMS Software GmbH
1217 Potomac St. NW, P.O. Box 40 59
Washington DC, 20007, USA 50216 Frechen, Germany
Fon/Fax: +1 202 342-0180/1 Fon/Fax: +49 221 949-9170/1
http://www.gams.com


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/d/optout.

What do you exactly mean by “replacing by a variable”? A parameter or variable? In an equation or an assignment?
Cheers

Renger



From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of Jonathan
Sent: Thursday, October 30, 2014 9:39 AM
To: gamsworld@googlegroups.com
Subject: Re: Multi-dimensional sets to quickly affect values over subsets



Hello,

Sorry for the late reply I thought I apparently missed the notification from google. Thanks Lutz and Renger for you answers I understand why I have this issue. I can use a condition with [prod(set)1]. The problem is then to sort the values that equals 1 before transformation. I came up with the solution below knowing that my values are going from 0 to 1. I replaced all ones by 9999 and then replaced them after transformation.

test(reg)$(test(reg)=1)=9999;

parameter test2(ctry);
test2(ctry)
$[prod(regtoctry(reg,ctry),test(reg))1]
=prod(regtoctry(reg,ctry),test(reg));

test2(ctry)$[test2(ctry)=9999]
=1;

I would prefer using a variable instead of 9999. When I do it I come up with an error value. Is it possible to replace a specific value (1 in that case) by a variable (say x)?

Thank you very much!




Le lundi 27 octobre 2014 10:44:19 UTC+1, Lutz Westermann a écrit :

Hi,

If you have an empty product in GAMS (meaning prod(aSet,…) with aSet
empty) this will return the multiplicative identity 1. Similarly, the
result of sum over an empty set results in the additive identity 0. And
to complete this list: smin over an empty set will return +Inf and smax
will return -Inf.

I hope that helps,
Lutz


On 10/27/2014 5:19 AM, Renger van Nieuwkoop wrote:

Hi Jon

It works if you use sum instead of prod, but it is funny that prod gives
you a 1…

Perhaps somebody from Gams could explain this behavior.

Renger

*From:*gams…@googlegroups.com [mailto:gams...@googlegroups.com]
*On Behalf Of *Jonathan
Sent: Monday, October 27, 2014 9:56 AM
To: gams...@googlegroups.com
Subject: Multi-dimensional sets to quickly affect values over subsets

Dear all,

I am trying to affect values of several continents to each country of
that continent in a Gams program. Since I might not be clear I created a
small example to illustrate my problem which you can copy below the
Example section of this post.
I set up 90 countries and 3 continents (a,b,c). Let’s say I have growth
rates forecasts over several continents and I want to affect this value
to each country of that continent without having to do it manually. In
the exampe below this operation is represented with parameter
test2(ctry). My problem is that if some countries are missing (11
30) I
get a value of 1 for these countries where I would like a 0 value see
(Display section). Do you have any idea of what is happening here? Maybe
I used the wrong trick?

Thanks in advance for your help. It is deeply appreciated!

Jon

*=============================================================================
*EXAMPLE
*=============================================================================

sets

reg/a,b,c/
reg2(reg)/b,c/

ctry/1*90/

regtoctry(reg,ctry)
/
a.(110)
b.(31
60)
c.(61*90)
/
;

display regtoctry;

parameter test(reg)
/ a 33
b 66
c 99
/;

parameter test0(ctry)
/ 130 1
31
60 2
61*90 3
/;

display test0;

*!Sum of country values for each region

parameter test1(reg);
test1(reg)=sum(regtoctry(reg,ctry), test0(ctry));
display test1;

*!Apply regional values to each country of the region

parameter test2(ctry);
test2(ctry)=prod(regtoctry(reg,ctry),test(reg));

display test2;

$ontext

parameter test3 (reg2);

test3(reg2)=sum(regtoctry(reg2,ctry),test0(ctry));

*display test3;

parameter test4(reg);

test4(“a”)=sum(reg2, test(reg2));

*display test4;

set
notregtoctry(reg,ctry)
;

notregtoctry(reg,ctry)=not regtoctry(reg,ctry);

display notregtoctry;

$offtext

*============================ End Of File

*=============================================================================
*DISPLAY
*=============================================================================

$ontext

---- 59 PARAMETER test2

1 33.000, 2 33.000, 3 33.000, 4 33.000, 5 33.000, 6
33.000, 7 33.000, 8 33.000
9 33.000, 10 33.000, 11 1.000, 12 1.000, 13 1.000,
14 1.000, 15 1.000, 16 1.000
17 1.000, 18 1.000, 19 1.000, 20 1.000, 21 1.000,
22 1.000, 23 1.000, 24 1.000
25 1.000, 26 1.000, 27 1.000, 28 1.000, 29 1.000,
30 1.000, 31 66.000, 32 66.000
33 66.000, 34 66.000, 35 66.000, 36 66.000, 37 66.000, 38
66.000, 39 66.000, 40 66.000
41 66.000, 42 66.000, 43 66.000, 44 66.000, 45 66.000, 46
66.000, 47 66.000, 48 66.000
49 66.000, 50 66.000, 51 66.000, 52 66.000, 53 66.000, 54
66.000, 55 66.000, 56 66.000
57 66.000, 58 66.000, 59 66.000, 60 66.000, 61 99.000, 62
99.000, 63 99.000, 64 99.000
65 99.000, 66 99.000, 67 99.000, 68 99.000, 69 99.000, 70
99.000, 71 99.000, 72 99.000
73 99.000, 74 99.000, 75 99.000, 76 99.000, 77 99.000, 78
99.000, 79 99.000, 80 99.000
81 99.000, 82 99.000, 83 99.000, 84 99.000, 85 99.000, 86
99.000, 87 99.000, 88 99.000
89 99.000, 90 99.000
$offtext


You received this message because you are subscribed to the Google
Groups “gamsworld” group.
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/d/optout.


You received this message because you are subscribed to the Google
Groups “gamsworld” group.
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/d/optout.



Lutz Westermann LWest...@gams.com
GAMS Development Corporation GAMS Software GmbH
1217 Potomac St. NW, P.O. Box 40 59
Washington DC, 20007, USA 50216 Frechen, Germany
Fon/Fax: +1 202 342-0180/1 Fon/Fax: +49 221 949-9170/1
http://www.gams.com


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/d/optout.


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/d/optout.

I think I found the answer! I just needed to create a susbset for all values equal to one before transformation. Code below in my example.
Thanks for helping me out :slight_smile:. Jonathan


*!Creating a set for all the values equal to 1

set ones(reg);
ones(reg)$[test(reg)=1]=yes;

display ones;

*!Apply regional values to each country of the region

parameter test2(ctry);
test2(ctry)
$[prod(regtoctry(reg,ctry),test(reg))1]
=prod(regtoctry(reg,ctry),test(reg));

test2(ctry)
$[prod(regtoctry(ones,ctry),test(ones))]
=1;

display test2;


Le jeudi 30 octobre 2014 13:51:25 UTC+1, Renger van Nieuwkoop a écrit :

What do you exactly mean by “replacing by a variable”? A parameter or variable? In an equation or an assignment?
Cheers

Renger



From: gams...@googlegroups.com [mailto:gams...@googlegroups.com] On Behalf Of Jonathan
Sent: Thursday, October 30, 2014 9:39 AM
To: gams...@googlegroups.com
Subject: Re: Multi-dimensional sets to quickly affect values over subsets



Hello,

Sorry for the late reply I thought I apparently missed the notification from google. Thanks Lutz and Renger for you answers I understand why I have this issue. I can use a condition with [prod(set)1]. The problem is then to sort the values that equals 1 before transformation. I came up with the solution below knowing that my values are going from 0 to 1. I replaced all ones by 9999 and then replaced them after transformation.

test(reg)$(test(reg)=1)=9999;

parameter test2(ctry);
test2(ctry)
$[prod(regtoctry(reg,ctry),test(reg))1]
=prod(regtoctry(reg,ctry),test(reg));

test2(ctry)$[test2(ctry)=9999]
=1;

I would prefer using a variable instead of 9999. When I do it I come up with an error value. Is it possible to replace a specific value (1 in that case) by a variable (say x)?

Thank you very much!




Le lundi 27 octobre 2014 10:44:19 UTC+1, Lutz Westermann a écrit :

Hi,

If you have an empty product in GAMS (meaning prod(aSet,…) with aSet
empty) this will return the multiplicative identity 1. Similarly, the
result of sum over an empty set results in the additive identity 0. And
to complete this list: smin over an empty set will return +Inf and smax
will return -Inf.

I hope that helps,
Lutz


On 10/27/2014 5:19 AM, Renger van Nieuwkoop wrote:

Hi Jon

It works if you use sum instead of prod, but it is funny that prod gives
you a 1…

Perhaps somebody from Gams could explain this behavior.

Renger

*From:*gams…@googlegroups.com [mailto:gams...@googlegroups.com]
*On Behalf Of *Jonathan
Sent: Monday, October 27, 2014 9:56 AM
To: gams...@googlegroups.com
Subject: Multi-dimensional sets to quickly affect values over subsets

Dear all,

I am trying to affect values of several continents to each country of
that continent in a Gams program. Since I might not be clear I created a
small example to illustrate my problem which you can copy below the
Example section of this post.
I set up 90 countries and 3 continents (a,b,c). Let’s say I have growth
rates forecasts over several continents and I want to affect this value
to each country of that continent without having to do it manually. In
the exampe below this operation is represented with parameter
test2(ctry). My problem is that if some countries are missing (11
30) I
get a value of 1 for these countries where I would like a 0 value see
(Display section). Do you have any idea of what is happening here? Maybe
I used the wrong trick?

Thanks in advance for your help. It is deeply appreciated!

Jon

*=============================================================================
*EXAMPLE
*=============================================================================

sets

reg/a,b,c/
reg2(reg)/b,c/

ctry/1*90/

regtoctry(reg,ctry)
/
a.(110)
b.(31
60)
c.(61*90)
/
;

display regtoctry;

parameter test(reg)
/ a 33
b 66
c 99
/;

parameter test0(ctry)
/ 130 1
31
60 2
61*90 3
/;

display test0;

*!Sum of country values for each region

parameter test1(reg);
test1(reg)=sum(regtoctry(reg,ctry), test0(ctry));
display test1;

*!Apply regional values to each country of the region

parameter test2(ctry);
test2(ctry)=prod(regtoctry(reg,ctry),test(reg));

display test2;

$ontext

parameter test3 (reg2);

test3(reg2)=sum(regtoctry(reg2,ctry),test0(ctry));

*display test3;

parameter test4(reg);

test4(“a”)=sum(reg2, test(reg2));

*display test4;

set
notregtoctry(reg,ctry)
;

notregtoctry(reg,ctry)=not regtoctry(reg,ctry);

display notregtoctry;

$offtext

*============================ End Of File

*=============================================================================
*DISPLAY
*=============================================================================

$ontext

---- 59 PARAMETER test2

1 33.000, 2 33.000, 3 33.000, 4 33.000, 5 33.000, 6
33.000, 7 33.000, 8 33.000
9 33.000, 10 33.000, 11 1.000, 12 1.000, 13 1.000,
14 1.000, 15 1.000, 16 1.000
17 1.000, 18 1.000, 19 1.000, 20 1.000, 21 1.000,
22 1.000, 23 1.000, 24 1.000
25 1.000, 26 1.000, 27 1.000, 28 1.000, 29 1.000,
30 1.000, 31 66.000, 32 66.000
33 66.000, 34 66.000, 35 66.000, 36 66.000, 37 66.000, 38
66.000, 39 66.000, 40 66.000
41 66.000, 42 66.000, 43 66.000, 44 66.000, 45 66.000, 46
66.000, 47 66.000, 48 66.000
49 66.000, 50 66.000, 51 66.000, 52 66.000, 53 66.000, 54
66.000, 55 66.000, 56 66.000
57 66.000, 58 66.000, 59 66.000, 60 66.000, 61 99.000, 62
99.000, 63 99.000, 64 99.000
65 99.000, 66 99.000, 67 99.000, 68 99.000, 69 99.000, 70
99.000, 71 99.000, 72 99.000
73 99.000, 74 99.000, 75 99.000, 76 99.000, 77 99.000, 78
99.000, 79 99.000, 80 99.000
81 99.000, 82 99.000, 83 99.000, 84 99.000, 85 99.000, 86
99.000, 87 99.000, 88 99.000
89 99.000, 90 99.000
$offtext


You received this message because you are subscribed to the Google
Groups “gamsworld” group.
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/d/optout.


You received this message because you are subscribed to the Google
Groups “gamsworld” group.
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/d/optout.



Lutz Westermann LWest...@gams.com
GAMS Development Corporation GAMS Software GmbH
1217 Potomac St. NW, P.O. Box 40 59
Washington DC, 20007, USA 50216 Frechen, Germany
Fon/Fax: +1 202 342-0180/1 Fon/Fax: +49 221 949-9170/1
http://www.gams.com


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/d/optout.


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/d/optout.