Conditionalize Variable Attribute

Problems with syntax of GAMS
Post Reply
Likey
User
User
Posts: 6
Joined: 4 years ago

Conditionalize Variable Attribute

Post by Likey »

Hi everyone,

I'm trying to conditionalize the following constraint:

Code: Select all

INVE.UP("windOn","FRA")$(card(r)<=2)   =50;
"Allow investment in France of up to 50 GW, if the number of regions is set to 2 or more"

r is a set defined in the set up of the model:

Code: Select all

$IFi %REGIONS%=='2R'             $set r                  FRA,GER
Unfortunately I keep getting the error 170: Domain violation for element, when running the model with only one region

Code: Select all

$IFi %REGIONS%=='1R'             $set r                  GER

Code: Select all

3243  INVE.UP("windOn","FRA")$(card(r)<=2)   =50;
****                       $170
**** LINE     21 INCLUDE     C:\Users\Leo\Desktop\Model Test - Endogenous Allocation - 06172019 1006 incl. countries incl. agg share - WIP\scen\y_windshare.gms
**** LINE   2541 INPUT       C:\Users\Leo\Desktop\Model Test - Endogenous Allocation - 06172019 1006 incl. countries incl. agg share - WIP\EMMA.gms
**** 170  Domain violation for element
Why do I get this error? How can I avoid it?

Best,

Leo
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Conditionalize Variable Attribute

Post by Renger »

Hi Leo

You could try working with a subset:

Code: Select all


set r region /GER,FRA/;

set ra(r) /GER,FRA/;
variable INVE(*,r);

if(
INVE.UP("windOn","FRA")$card(ra) >1)    =50;
);
display INVE.UP;

In your model code, you probably have to define the equations over the main set r and put a $ra(r) behind the equations.
Hope this helps!
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Likey
User
User
Posts: 6
Joined: 4 years ago

Re: Conditionalize Variable Attribute

Post by Likey »

Thanks a lot, I'll try that!
Post Reply