Dimension Different Error (Electricity Pricing Model)

Problems with syntax of GAMS
Post Reply
omarrossan
User
User
Posts: 9
Joined: 10 months ago

Dimension Different Error (Electricity Pricing Model)

Post by omarrossan »

Hello Everyone,

I am developing a pricing model, where I need to determine the price of selling electricity as a part of my research project for a master's degree. This is my first time using GAMS and I kindly ask for help to add the model into GAMS and run it without errors.

In the pricing model, I have two pricing schemes; one pricing scheme (called RTP) has hourly values (over the year), and the other scheme (called ToU) has only 3 values over the whole year, where each value corresponds to a period of set of hours of each day. The hours and the periods do not change over the year.

On the other hand, the demand for electricity in both pricing schemes is changing hourly. This means that there is agreement in the time periods between one pricing scheme and disagreement with the other pricing scheme. Equation to clarify,

i Real Time Pricing Sectors /Residential, Commercial/
j Time of Use Tariff Sectors /Industrial, Water/
k Time Periods /1*8760/
p Pricing Periods in Time of Use Tariff /1*3/
d Number of Days in a Year /1*365/
n Number of Hours in a day /1*24/
h Number of Hours in a Period /1*8/;

- The Demand_RTP(i,k) matches in terms of sets the Price_RTP(i,k)
- The Demand_ToU(j,k) does not match in terms of set the Price_ToU(j,p)

Note: Price_ToU(j,p), Price_RTP(i,k), Demand_RTP(i,k), Demand_ToU(j,k) are all variables to be determined by the optimisation problem.

I need to calculate the total payments for sectors set (j), which essentially Price_ToU(j,p)*Demand_ToU(j,k), and to multiply the demand of certain hour of a certain day with the correspondsing pricing period, I developed this equation:
k= (d-1)*24+(p-1)*8+h,
to help me allocate the demand value of each (k) period into each respective period over the whole year. However, I could not translate this into GAMS, where I receive the following errors,

146 Total_Bills.. B=e=sum((i,k),Price_RTP(i,k)*Demand_RTP(i,k))+sum[j,sum(d,sum[p(sum[(h),Price_ToU(j,p)*Demand_ToU(j,(p-1)*8+(d-1)*24+h)])])];
**** $145 $145,278 $148,133$148,133,133,654,300
**** 133 Incompatible operands for addition
**** 145 Set identifier or quoted element expected
**** 148 Dimension different - The symbol is referenced with more/less
**** indices as declared
**** 278 Lags are not allowed on maps
**** 300 Remaining errors not printed for this line
**** 408 Too many ),] or }
**** 654 The right side of an equation cannot be a set expression

In addition, I am trying to add a constraint that make sure that there is no change in the daily demand energy consumption before and after the pricing policy implementation. Since, the demand is hourly based values, I created this equation,
k=n+(d-1)*24,

to help sum each 24 hours and compare them with the coressponding day before the implementation of the policy, but I also fail into translate this into GAMS and receive the following errors:

138 Energy_Consumption_Residential(d).. Demand_BeforeResidential(d)=e=sum(n,Demand_RTP('Residential',n+(d-1)*24));
**** $171,148,133,147,8,408
**** 8 ')' expected
**** 133 Incompatible operands for addition
**** 147 Real value for lag operator expected
**** 148 Dimension different - The symbol is referenced with more/less
**** indices as declared
**** 171 Domain violation for set
**** 408 Too many ),] or },

where Demand_BeforeResidential(d) is a known parameters, and the Demand_RTP is orginally indexed with (i,k).

I am sorry for the long question, I sincerely apprecaite any inputs or help!

kind regards,
Omar
Attachments
Fourth Draft.gms
(10.5 KiB) Downloaded 102 times
Wind_Available.xlsx
(215.81 KiB) Downloaded 101 times
PV_Available.xlsx
(185.61 KiB) Downloaded 99 times
Demand_BeforeWater.xlsx
(12.19 KiB) Downloaded 85 times
Demand_BeforeResidential.xlsx
(12.18 KiB) Downloaded 99 times
Demand_BeforeIndustrial.xlsx
(12.19 KiB) Downloaded 93 times
Demand_BeforeCommercial.xlsx
(12.19 KiB) Downloaded 101 times
Tatjana
User
User
Posts: 8
Joined: 5 years ago

Re: Dimension Different Error (Electricity Pricing Model)

Post by Tatjana »

Hi omarrossan,

First of all, the line
**** $145 $145,278 $148,133$148,133,133,654,300
helps you to find the precise spot within the equation where the error plopped up. Have a look at your listing file and you'll see that it is right under the variable or parameter that caused the issue.
Here you can see that it put all these errors right underneath pretty much every use of a set.

That's because you're using Sets in a way that's not valid in GAMS. Sets are meant to serve as dimensions, not as values.
Let's say you'd like to define a Parameter for Distance. And you have different cities, such as New York, Miami and Seattle. Then you can define a
Set city /New-York, Miami, Seattle/;
alias(city,city1);
Parameter Distance(city,city1) "distance in miles"
/New-York.Miami 1283
New-York.Seattle 4645
Miami.Seattle 3300/;
Display Distance;
Here, your parameter "distance" has two dimensions, the first and the second city.

You can then use those dimesions, to tell GAMS, for instance, that if there is a Parameter Distance where no value has been assigned, you want to assign the distance value of the opposite direction.
Distance(city,city1)$(not Distance(city,city1)) = Distance(city1,city);
Display Distance;

You can also write a number on a set, but notice that it is a string then - to GAMS, it is merely a name, not a value. For instance, if you'd like to have a Parameter of Population over the years, you could define a set and a parameter like this:
Set year /1996, 2011, 2023/;
Parameter Population(city,year);
you cannot tell GAMS to calculate with these sets, giving it some assignment like
following_year = year+1
- to GAMS, that makes as much sense as if you would have asked it to take Miami+1.
(once you're deeper in the modelling, you can find some commands that are actually able to "use" the name of the set, such as sameas(year,"1996"), or that make use of the position of an item within a set, such as ord(year) - but for starters, you just don't want to use set definitions to give values to GAMS).

Errors with Dimensions will then typically appear if you write some nonsense like
Distance("Miami","New-York","Seattle") = 5000;
- because then GAMS will tell you that you used more Dimensions then you defined for this Parameter (in the words of GAMS: "Dimension different - The symbol is referenced with more/less indices as declared"). Or if you write something like
Population("Paris","1996") = 800000;
- because then GAMS will tell you that "Paris" is simply not an item of your set city (in the words of GAMS: "Domain violation for element").

In your case, these errors appear, however, because you define Sets where you actually want to give values to GAMS. You want to calculate with them, as in
k= (d-1)*24+(p-1)*8+h
So k, d, p and h don't act as Sets in your model. They should be Parameters, Scalars or Variables, depending on what you exaclty want to do with them - but not Sets. Reconsider where you want to have values that the model can change (-> Variables), where you want to have values that are just given and unchangable by the solver (-> Parameters) and where you want to give values that are just given and unchangable by the solver and that don't have any Dimensions (-> Scalars).

Another tip: If you're just starting out and are a bit overwhelmed with the amount of errors that you get in the start, try making a new line and put the command
$stop
to the point where you are rather confident with your code. Let it run. It will only run up to that point where you stop it. If there are errors, you can correct them and run it again, until this part of your code is clean. Then you put the $stop some lines lower and check how this part of your code is doing. You will have the same amount of errors to fix, but it helps keeping the frustration lower, helps you fix one error at a time, and you notice quickly at which line things go south.
Post Reply