Conditionalize Variable Attribute

Hi everyone,

I’m trying to conditionalize the following constraint:

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:

$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

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



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

Hi Leo

You could try working with a subset:

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

Thanks a lot, I’ll try that!