Page 1 of 1

Initial values for solves within a loop.

Posted: Tue Jan 19, 2016 7:48 pm
by Archiver

Hi folks,

I have a question regarding initial values for problem variables when the solve statement is within a loop.

My model is a MIP model and it is likely that the solution from the first iteration of the loop will be a feasible solution for the second iteration and a good starting point.

I know that I can specify the initial value for a variable using the .l subscript. But since at the end of a loop, the variables have values already, will GAMS automatically use these as a starting point for the next solve?

Or, do I need to do something like the following? It seems like I would be just setting the variables to values they already have?


While( counter lt 10,

v_variable.l=p_initial_value;

solve model using MIP minimizing v_obj;

p_initial_value = v_variable.l;


counter++

);





--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

RE: Initial values for solves within a loop.

Posted: Wed Jan 20, 2016 10:45 am
by Archiver

Hi Jody



Gams will use the solution from the last solve. You can see this for your self in the following example:



positive variable X, Y;



variable util;



equation utility, budget;



parameter income /100/;



utility..

util =E= X**0.2 * Y**0.8;



budget..

income =E= X + Y;



model micro /all/;



solve micro maximizing util using nlp;



income = 120;



micro.iterlim = 0;



solve micro maximizing util using nlp;



If you go to theequation listing in the lst-file, you will find for the first solve



Equation Listing SOLVE micro Using NLP From line 18



---- utility =E=



utility.. (0)*X + (0)*Y + util =E= 0 ; (LHS = 0)





---- budget =E=



budget.. - X - Y =E= -100 ; (LHS = 0, INFES = 100 ****)



---- X



X

(.LO, .L, .UP, .M = 0, 0, +INF, 0)

(0) utility

-1 budget





---- Y



Y

(.LO, .L, .UP, .M = 0, 0, +INF, 0)

(0) utility

-1 budget



Gams puts the initial values in the (linearized) equations: As I didn’t give any values, Gams assumes 0.



For the second solve, the equations listing gives you the following and you can see that Gams uses the solve values of the last solve (I set the iteration limit to 0, which is in fact not necessary as Gams evaluates the starting point in the equations listing).



---- utility =E=



utility.. - (0.606286626604091)*X - (0.606286626604176)*Y + util =E= 0 ; (LHS = 0)





---- budget =E=



budget.. - X - Y =E= -120 ; (LHS = -99.9999999999999, INFES = 20.0000000000001 ****)



GAMS 24.6.0 r55587 BETA Released 24Dec15 WEX-WEI x86 64bit/MS Windows 01/20/16 09:36:03 Page 7

G e n e r a l A l g e b r a i c M o d e l i n g S y s t e m

Column Listing SOLVE micro Using NLP From line 25





---- X



X

(.LO, .L, .UP, .M = 0, 20.0000000000022, +INF, 0)

(-0.6063) utility

-1 budget





---- Y



Y

(.LO, .L, .UP, .M = 0, 79.9999999999977, +INF, EPS)

(-0.6063) utility

-1 budget





Hope this helps



Cheers



Renger





From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of Jody D
Sent: Dienstag, 19. Januar 2016 18:48
To: gamsworld
Subject: Initial values for solves within a loop.



Hi folks,


I have a question regarding initial values for problem variables when the solve statement is within a loop.



My model is a MIP model and it is likely that the solution from the first iteration of the loop will be a feasible solution for the second iteration and a good starting point.



I know that I can specify the initial value for a variable using the .l subscript. But since at the end of a loop, the variables have values already, will GAMS automatically use these as a starting point for the next solve?



Or, do I need to do something like the following? It seems like I would be just setting the variables to values they already have?





While( counter lt 10,

v_variable.l=p_initial_value;

solve model using MIP minimizing v_obj;

p_initial_value = v_variable.l;


counter++

);




--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

Re: Initial values for solves within a loop.

Posted: Mon Jun 04, 2018 10:35 am
by Corsafan95
Hi Jody, hi Renger,

recently I'm facing nearly the same problem like Jody about two years ago.
I've written a loop which looks like this:

loop(instance,
load_sum(t) = input(t,instance);
Solve Quartiersspeicher using LP minimize Ctotal;
PVtest(instance)=PVOpt.l;
SoCtest(instance)=SoCOpt.l+EPS;
Speicherstand(instance,t)=SoC.l(t)+EPS;
Posladen(instance,t)=charge.l(t)+EPS;
Negladen(instance,t)=discharge.l(t)+EPS
;)

My problem is that GAMS uses for the Solving of the model the values from the previous instance.
Is there any posibility to solve the Model several times (for the instances) without a dependency on the last solve?

Thanks for your Help!!

Andreas

Re: Initial values for solves within a loop.

Posted: Tue Jun 05, 2018 9:14 am
by Renger
Hi

If you really want to start from scratch, you might use put commands in a loop over the values from the original table input(t,instance) to write a batch file that would look a little bit like this, :

call gams mygamsfile --myparam1 = 1 --myparam2 =2
call gams mygamsfile --myparam1 = 3 --myparam2 = 1
....

You then can replace %myparam1% and %myparam2% in the gams file and do without the loop.
If you gather the results in a gdx file with the name having %myparam1% and %myparam2% in it, you can then afterwards merge all the gdx files:
$gdxout 'myresults_%myparam1%_%myparam2.gdx'
$unload
Hope this helps.
Cheers
Renger