Creating diferent instances with changing parameters

Problems with modeling
Post Reply
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Creating diferent instances with changing sets

Post by Renger »

Hi
Your idea of loops is correct. However, you should read all your different data sets before you start the loop.

Say, you have three sets you loop over a set of three different inputs. InputA, InputB, InputC. You would then define a set s /A,B,C/; and read the data from these include files and assign them to a parameter over s.

Code: Select all

s /A,B,C/;

* Read the include files with parameter inputA, inputB, inputC.

* Add a parameter and assign the values:
parameter input(S,...);

inputS("A",...) = inputA(...);
inputS("B",...) = inputB(...);
inputS("C",...) = inputC(...);
* Loop over the set S and solve your model

loop(S,
    modelinput(S,...) = inputS(S,...);
    solve 
);    
Usually, it is easier to have the different inputs in an excel file in one big table with an additional column for the set s. You can then read the parameter inputS in one sweep.
Hope this helps
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Creating diferent instances with changing parameters

Post by Renger »

Hi
Sorry for being not clear enough. If your data looks like this

Code: Select all

*HOMO
hc(k)    euro per unit   /k0 0, k1 0.05,k2 0.05,k3 0.05/
pq(k)    kW              /k0 1, k1 162.72, k2 162.72, k3 162.72/ 
*TO HETERO
*hc(k)    euro per unit   /k0 0, k1 0.025,k2 0.05,k3 0.075/
*pq(k)    kW              /k0 1, k1 81.36, k2 162.72, k3 244.08/ 
Then, I would do the following:

Code: Select all

set scenario /HOMO, HETERO/;

* Use your data info
parameter
hcho(k)    euro per unit   /k0 0, k1 0.05,k2 0.05,k3 0.05/
pqhe(k)    kW              /k0 1, k1 162.72, k2 162.72, k3 162.72/ 
*TO HETERO
hche(k)    euro per unit   /k0 0, k1 0.025,k2 0.05,k3 0.075/
pqhe(k)    kW              /k0 1, k1 81.36, k2 162.72, k3 244.08/;
;
parameter 
	hcs(scenario, k) Euro per unit,
	pqs(scenario, k) kW;
	
hcs("HOMO",k) = hcho(k);
hcs("HETERO",k) = hche(k);

* same for pq

parameter
   hc(k), pq(k);

loop(scenario,
       hc(k) = hcs(scenario,k);
       pq(k) = pq(scenario, k);
       
* Solve your model
* Report the solutions in something like
     report(scenario, "MYVAR",k) = MYVAR.L(k);       
); 

Let me know if this helps.
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Post Reply