Skip to content

Commit

Permalink
Nash:
Browse files Browse the repository at this point in the history
Add two conditions for auto-debug mode. Only start auto-debug mode if
  1) not all regions are infeasible
  2) if not already in manual debug mode
Activate equation and column listing in debug mode
Remove solprint statement in solve.gms that was always overwritten in loop.gms
  • Loading branch information
dklein-pik committed Mar 27, 2024
1 parent cae7629 commit 0818b58
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
11 changes: 7 additions & 4 deletions core/loop.gms
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ $batinclude "./modules/include.gms" presolve
*cb 20140305 submit.R looks for the unique string in the following line and replaces it with the offlisting include into the full.gms at this position
***cb20140305readinpositionforfinxingfiles

*AJS* In case of fixing, fix to prices from input_ref.gdx (t < cm_startyear).
*** In case of fixing, fix to prices from input_ref.gdx (t < cm_startyear).
*** Parameters are not automatically treated by the fixing mechanism above.
if( (cm_startyear gt 2005),
Execute_Loadpoint "input_ref" p_pvpRef = pm_pvp;
Expand All @@ -71,10 +71,13 @@ if( (cm_startyear gt 2005),
***--------------------------------------------------------------------------
*** SOLVE
***--------------------------------------------------------------------------
*** This disables solprint in cm_nash_mode=1 (debug) case by default. It is switched on in case of infes in nash/solve.gms
*** For faster debugging, turn solprint immediately on
*** Set options for debugging
if (cm_nash_mode eq 1,
option solprint = on;
option
solprint = on
limcol = 2147483647
limrow = 2147483647
;
);


Expand Down
18 changes: 11 additions & 7 deletions modules/80_optimization/nash/postsolve.gms
Original file line number Diff line number Diff line change
Expand Up @@ -659,14 +659,18 @@ if (cm_abortOnConsecFail gt 0,
);

if (smax(regi, p80_trackConsecFail(regi)) >= cm_abortOnConsecFail,
if (s80_runInDebug eq 0,
s80_runInDebug = 1;
cm_nash_mode = 1;
display "Starting nash in debug mode after maximum number of consecutive failures was reached in at least one region.";
else
if ((s80_runInDebug eq 0) AND (cm_nash_mode ne 1), !! auto-start debug only if not already in debug mode
if (sum(regi, pm_SolNonInfes(regi) ne 0) eq 0, !! if all regions are infeasible debug makes no sense
execute_unload "abort.gdx";
abort "Run was aborted because the maximum number of consecutive failures was reached in at least one region! No debug started since all regions are infeasible.";
else !! start debug mode only if at leat one region was feasible
s80_runInDebug = 1;
cm_nash_mode = 1;
display "Starting nash in debug mode after maximum number of consecutive failures was reached in at least one region.";
);
else !! s80_runInDebug eq 1 AND/OR cm_nash_mode eq 1
execute_unload "abort.gdx";
display p80_trackConsecFail;
abort "Run was aborted because the maximum number of consecutive failures was reached in at least one region!";
abort "After debug mode run was aborted because the maximum number of consecutive failures was still reached in at least one region!";
);
else
!! Set nash mode back to parallel because all regions got feasible after they have been automatically restarted as debug
Expand Down
22 changes: 8 additions & 14 deletions modules/80_optimization/nash/solve.gms
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ $endif.repeatNonOpt

solve hybrid using nlp maximizing vm_welfareGlob;

if(cm_nash_mode eq 1,
p80_repy_thisSolitr(all_regi,"solvestat") = hybrid.solvestat;
p80_repy_thisSolitr(all_regi,"modelstat") = hybrid.modelstat;
p80_repy_thisSolitr(all_regi,"resusd") = hybrid.resusd;
p80_repy_thisSolitr(all_regi,"objval") = hybrid.objval;
if (p80_repy_thisSolitr(all_regi,"modelstat") eq 2,
p80_repyLastOptim(all_regi,"objval") = p80_repy(all_regi,"objval");
if(cm_nash_mode eq 1,
p80_repy_thisSolitr(all_regi,"solvestat") = hybrid.solvestat;
p80_repy_thisSolitr(all_regi,"modelstat") = hybrid.modelstat;
p80_repy_thisSolitr(all_regi,"resusd") = hybrid.resusd;
p80_repy_thisSolitr(all_regi,"objval") = hybrid.objval;
if (p80_repy_thisSolitr(all_regi,"modelstat") eq 2,
p80_repyLastOptim(all_regi,"objval") = p80_repy(all_regi,"objval");
);
);
);

regi(all_regi) = NO;
p80_handle(all_regi) = hybrid.handle;
Expand Down Expand Up @@ -122,12 +122,6 @@ $else.repeatNonOpt
= smax(regi, p80_repy(regi,"modelstat")); !! also taking into account status 7
$endif.repeatNonOpt

*** in cm_nash_mode=1 (debug) mode, enable solprint for next sol_itr when last
*** iteration was non-optimal:
if(cm_nash_mode eq 1 AND o_modelstat ne 2,
option solprint = on;
);

!! add information if this region was solved in this iteration
p80_repy_iteration(regi,solveinfo80,iteration)$(
p80_repy_thisSolitr(regi,solveinfo80) )
Expand Down

0 comments on commit 0818b58

Please sign in to comment.