dimension error

Hi, I want to know the price and total cost assuming there are three scenarios regarding the wind realization.
I can run my code and get the result, but it shows:
**** Dimension error for : generation
**** Dimension error for : price
**** Dimension error for : startup

Could you please check my code and tell me what to do? Thank you very much.

My code is:
##################### Declaring Sets #################################
Sets
i set of conventional generation technologies
r set of RES generation technologies /Wind, PV/
t set of hours /1
8760/
s set of wind scenarios /s1, s2, s3/
*the scenarios for wind powert generation should be used to implement an uncertain wind-feed-in
;


*##################### Declaring Parameters #############################
Parameters
vc(i) unit cost (� per MWh)
sc(i) startup costs (� per MW)
cap(i) installed capacity for each technology i
cap_RES(r) installed capacity for each RES technology r
pf(t,s,r) hourly production factor for RES
af(i) availability factor for conv. technologies
demand(t) electricity demand
g_min(i) minimum generation

RESup upload of hourly production factors for wind and PV
techup technology upload

**************** Implement investment and uncertainty parameters ***********************************
ic(i) annual investment costs
cap_max(i) maximum capacity for technology i

;
*####################### Upload from Excel Excel ##############################

*1.Create Text File which includes the information where which parameter is to find
$onecho > ImportInfo.txt
set=i Rng=Technology!A2 Cdim=0 Rdim=1
Par=techup Rng=Technology!A1 Cdim=1 Rdim=1
Par=RESup Rng=RES!A1 Cdim=2 Rdim=1
Par=demand Rng=Demand!A2 Cdim=0 Rdim=1

$offecho

*2.Convert Excel File to a .gdx file
$call GDXXRW I=Input_SW.xlsx O=Output.gdx @ImportInfo.txt

*3.Read the elements
$gdxin Output.gdx
$Load i
$Load techup, RESup, demand
$gdxin

*Define parameters from the upload-parameter ‘techup’
vc(i)=techup(i,‘vc’) ;
sc(i)=techup(i,‘sc’) ;
g_min(i)=techup(i,‘g_min’) ;
cap(i)=techup(i,‘cap_max’) ;
af(i)=techup(i,‘af’);
pf(t,s,r)=RESup(t,s,r);

*Define renewable parameters
cap_RES(‘wind’) = 61474;
cap_RES(‘pv’) = 51479;

**************** Declare investment and uncertainty parameters ********************
ic(i)=techup(i,‘annual investment costs’)
;

*Display data to see that everything is uploaded correctly
Display i, t, vc, sc, g_min, cap, af, demand, pf, cap_RES, RESup, ic, s;
$stop
$stop
$stop


*##################### Declaring Variables #############################
Variable
COST total cost of electricity production
;

Positive Variables
**************** apply uncertainty to existing variables*******************************

G(s,i,t) generation of technology i at time t under wind scenarios s
G_RES(s,r,t) generation of RES technology r at time t under wind scenarios s
P_ON(s,i,t) online capacity of technology i at time t under wind scenarios s
SU(s,i,t) start up variable under wind scenarios s

**************** Implement investment variables *******************************
iv(i) investment capacity of technology i under wind scenarios s
;

*##################### Declaring Equations #############################
Equations
obj minimizing total costs
res_dem energy balance (supplly=demand)
res_G_RES maximum for RES generation depends on hourly pf anc cap_RES
res_start startup restriction
res_min_gen minimum generation
res_max_gen maximum generation
res_max_online maximum online restriction
*************** Implement investment equation *

\


res_max_Cap maximum capacity
;

obj… COST =E=(1/3)*SUM((s,i,t), vc(i)*G(s,i,t)+sc(i)*SU(s,i,t)+iv(i)*ic(i))
;
res_dem(s,t)… SUM(i, G(s,i,t)) + SUM(r,G_RES(s,r,t)) =E= demand(t)
;
res_G_RES(r,t,s)… G_RES(s,r,t) =L= cap_RES(r)*pf(t,s,r)
;
res_start(s,i,t)… SU(s,i,t) =G= P_ON(s,i,t)-P_ON(s,i,t-1)
;
res_min_gen(s,i,t)… P_ON(s,i,t)*g_min(i) =L= G(s,i,t)
;
res_max_gen(s,i,t)… G(s,i,t) =L= P_ON(s,i,t)
;
res_max_online(s,i,t)… P_ON(s,i,t) =L= cap(i)*af(i)
;

*************** Declate investment equation and adapt previous *******************************
res_max_Cap(i)… iv(i) =L= cap(i)

;

  • ######################### Solving the Model ##############################
    model PSE
    /all/
    ;

solve PSE using LP minimizing COST
;

  • ######################### Reporting ######################################
    Declaring Report Parameters
    parameter
    generation(s,t,
    ,i)
    price(t,,s)
    startup(s
    ,i,t)
    modelstats()
    solvestats(
    )
    ;

generation(s,t,‘no_uncertainty’,i) = G.L(s,i,t) ;
price(t,‘no_uncertainty’,s) = res_dem.M(t,s) ;

  • Marginal of Energy Balance gives the price (Shadow variable of the energy balance)

startup(s,t,‘no_uncertainty’,i) = SU.L(s,i,t) ;
modelstats(‘no_uncertainty’) = PSE.modelstat ;
solvestats(‘no_uncertainty’) = PSE.modelstat ;

display generation, price, startup, modelstats, solvestats ;

  • or: sometimes it is enough to just display the results in GAMS.
  • e.g.:
    display G.L, P_ON.L, res_dem.M ;

*################################# Excel Export ###############################
*1. Create Text file which includes the information where which parameter is to put
$onecho >out.tmp
Par=generation Rng=generation!A2 Cdim=2 Rdim=1
Par=price Rng=Price!A2 Cdim=1 Rdim=1
Par=startup Rng=StartUp!B2 Cdim=1 Rdim=2
Par=modelstats Rng=Stats!B2 Cdim=0 Rdim=1
Par=solvestats Rng=Stats!E2 Cdim=0 Rdim=1
$offecho

*2. Put the data in a .gdx file
execute_unload ‘Results.gdx’
;
*3.Convert the .gdx file to an excel file
execute ‘gdxxrw Results.gdx o=Results.xlsx @out.tmp
Top
1 Post • Page 1 Of 1
Return To “Syntax”

Don’t just paste your GAMS source as normal text. There are fine code boxes in the forum editor. Also this issue is related to data so upload your Excel and GDX file as well so one can reproduce the error.

-Michael

Thank you for your suggestion. I attach the excel and gms file here.
final.gms (6.05 KB)
Input_SW.xlsx (732 KB)

The attached program succeeds without a problem. If I remove the $stop and let GAMS continue, I get compilation errors when compiling “startup(s*,i,t)”, you probably means “startup(s,t,*,i)” at least that makes sense from the code you have later. Now after fixing all this, I get to see the error message from the gdxxrw call when you want to write your results to Excel:

--- Executing after solve: elapsed 0:00:14.215[LST:1473041]
--- Final.gms(168) 224 Mb[FIL:"C:\Users\mbuss\Downloads\Final.gms",168,0]
--- GDX File (execute_unload) C:\Users\mbuss\Downloads\Results.gdx[FIL:"C:\Users\mbuss\Downloads\Results.gdx",0,0]
--- Final.gms(171) 224 Mb[FIL:"C:\Users\mbuss\Downloads\Final.gms",171,0]

GDXXRW           43.4.1 3da5975b Jun 22, 2023          WEI x86 64bit/MS Window
Input file : C:\Users\mbuss\Downloads\Results.gdx
Output file: C:\Users\mbuss\Downloads\Results.xlsx
Adding new sheet: Price
Adding new sheet: StartUp
Adding new sheet: Stats
****  Dimension error for : generation
****  Dimension error for : price
****  Dimension error for : startup

Any changes made to the spreadsheet were not saved
Total time = 593 Ms
*** Status: Normal completion[LST:1500914]

Here is the issue, you instruct gdxxrw to write out parameters but with dimension information that does not match the dimensions of the symbols in GAMS:

Par=generation           Rng=generation!A2   Cdim=2 Rdim=1
Par=price                Rng=Price!A2        Cdim=1 Rdim=1
Par=startup              Rng=StartUp!B2      Cdim=1 Rdim=2

but in GAMS generation is 4 dimensional, price 3 dimensional, and startup (after my fix) 4 dimensional. You are one dimension short in your gdxxrw instruction file. Just add one to rdim (or cdim) and things are okay

Par=generation           Rng=generation!A2   Cdim=2 Rdim=2
Par=price                Rng=Price!A2        Cdim=1 Rdim=2
Par=startup              Rng=StartUp!B2      Cdim=1 Rdim=3

-Michael

Thank you very much for your help. I did as you said and it do not show dimension error now. But in the output result excel it shows nothing in price.
I attach the new code and my result excel here.

-Bai Zitao
Results.xlsx (987 KB)
Input_SW.xlsx (732 KB)
final.gms (6.04 KB)

GAMS has domain checking for a good reason. If you circumvent this by declaring your equations without a domain, then the system can’t help you with your own mistakes. Your equation res_dem is defined over (s,t) but you access this (to assign to price) as res_dem.M(t,s). If you would have declared with a domain, e.g. res_dem(s,t) the compiler would have told you about your swapped indexes in the assignment. With the code as is GAMS just gives you 0 because as a sparse system all non-existing records default to 0.

-Michael