Looped Distribution Model is very slow

Problems with modeling
Post Reply
FredS
User
User
Posts: 1
Joined: 3 weeks ago

Looped Distribution Model is very slow

Post by FredS » 3 weeks ago

Hi All!

I was writing a small model with e electricity suppliers and v electricity consumers. Everyone of the suppliers and consumers has their own load curve in a 15minutes resolution (which makes roughly 35 k timesteps in year).
My aim is to minimize distribution costs wich depend on the distance and other factors I have included.
Because I want to be able to scale up the number of consumers, I decided to slice the model into a given number p, each containing t timesteps, the model would solve at once.

I used code I found in this forum enabling a sequentual solving and now I am experiencing two things:
a) the building of the solving matrix takes a lot of time,
b) the post solving is very time consuming.

I would say, a model with 30 suppliers and 200 consumers and 1000 timesteps takes about 8 minutes to be build, 30 seconds to be solved and another 3 minutes to do the post solving. It also felt like the RAM would be filled more and more in each of the 35 loops. At least, I was expecting it to be emptied in between loops.

Some ideas on how I can speed up things would be appreciate it.
It really feels like the model should solve faster from my experience with way bigger models!

Thanks in advance,
Cheers!

Fred

This is my code:

Code: Select all


set Zeit(Zeit_Gesamt) /t00001*t35136/;
Alias (Zeit, t)


scalars optperiod 'Laenge des rollierenden Optimierungsintervalls' /1000/;

$eval tSlices ceil(card(Zeit)/optperiod)
SET tSlice          / p1*p%tSlices% /
    Periode(Zeit)           'dynamic subset of Zeit'
    map(tSlice,Zeit)  'mapping of time slice to time steps';

Alias (Periode, p);

map(tSlice,Zeit) = (ord(tSlice)-1)*optperiod < ord(Zeit) and (ord(tSlice))*optperiod >= ord(Zeit);
option map:0:0:1; display map;

*
*###Subsets, Cost functions###
*

* ################
* #   Variable   #
* ################

positive variable Stromlieferung_RLM(t,e,v) 'In einer Zeitscheibe von E nach V gelieferte Strommenge'; 

positive variable Residualstrom(t,v)	'In einer Zeitscheibe vom Grundversorger an V gelieferte Strommenge';

* ######################
* # Objective Function #
* ######################

free variable z;
equation cost;
cost.. z =e= sum((p,e,v), Stromlieferung_RLM(p,e,v)*p_ges(e,v))+sum((p,v),Residualstrom(p,v)*p_residual);


* #################
* #   Equations   #
* #################

equation MaxErzeugung (t,e);
MaxErzeugung(p,e).. erz(p,e) =g= sum(v, Stromlieferung_RLM(p,e,v));
equation MaxVerbrauch_RLM (t,v);
MaxVerbrauch_RLM(p,V_RLM).. ver(p,V_RLM) =e= sum(e, Stromlieferung_RLM(p,e,V_RLM)) + Residualstrom(p,V_RLM);


* ########################
* #   Modell-Parameter   #
* ########################

Model Distribution 'WIP' / all /;


loop(tSlice,
  p(Zeit) = map(tSlice,Zeit); display p, tSlice;

*slices of load curves that are needed for each period modelled
erz(p,e) = Erzeugung(p,e);
ver(p,v) = Verbrauch(p,v);

solve Distribution using lp minimizing z;


Strommengen_kum(e,v) =              Strommengen_kum(e,v)
                                    +sum(p$Stromlieferung_RLM.l(p,e,v), Stromlieferung_RLM.l(p,e,v));


);

User avatar
bussieck
Moderator
Moderator
Posts: 574
Joined: 4 years ago

Re: Looped Distribution Model is very slow

Post by bussieck » 2 weeks ago

I would turn on profile (see https://www.gams.com/latest/docs/UG_Gam ... SAOprofile) to see if generation of any of the equations is particularly slow. For the increased memory over time: GAMS merges the variables and equations into it's database, so for each slice GAMS has to remember more variable and equation levels, since the t index is part of some variables and equations. If you sure you don't need the previous variables because e.g. you stored them in a parameter, you can instruct GAMS to do a replace, see https://www.gams.com/latest/docs/UG_Gam ... AOsolveopt.

-Michael

brucemccarl
User
User
Posts: 11
Joined: 3 years ago

Re: Looped Distribution Model is very slow

Post by brucemccarl » 2 weeks ago

you might look at the speed section of the mccarl guide as it goes into some detail on how to find where the issue is and some ways to fix

ususally this is caused by looking at unnecessary cases

Post Reply