$ontext ==================================================================
LAST MODIFIED: 02 October, 2003
FILENAME: restime.gms
PURPOSE: Creates table showing solver resource times for a given model
test set. If model is solved optimally or feasibly, resource
time in seconds is listed. Otherwise, the status is returned.
Additionally, model sizes are listed.
Output is in .txt or in .html files. Also lists model
sizes
Works for all modeltypes.
REQUIRED INPUTS:
--trace1: trace file of solver 1
--trace2: trace file of solver 2
...
--trace8: trace file of solver 8 (min is 2, max is 8 files)
OPTIONAL INPUTS:
--modelfile: modelfile containing models to be considered
in comparison
--outfile: root filename of restimes output file (default
is timings --> timings.txt, timings.htm)
REMARKS: Each tracefile can contain information from only one (1)
solver for a given set of models. For example, tracefiles
containing solver A and solver B will cause error message
upon compilation.
$offtext =================================================================
*=== Create trace reading routine (readtrace.gms)
$onecho > %gams.scrdir%readtrace.gms
$eolcom ,#
display '++++ TRACEOPT=3';
Set modelname, modeltype, solvername, nlpdef, mipdef;
Set col /julian, direction,eqnum,varnum,dvarnum,nz,nlnz, optfile,modelstat,solvestat,obj,objest,res,iter,dom,nodes/
Alias(u1,u2,u3,u4,u5,*);
Set domain(*,*,*,*,*);
Table tracedata(*,*,*,*,*,col)
$ondelim
modelname, modeltype, solvername, nlpdef, mipdef, julian, direction,eqnum,varnum,dvarnum,nz,nlnz, optfile,modelstat,solvestat,obj,objest,res,iter,dom,nodes
$offlisting
$include %tracefile%
$onlisting
$offdelim
;
domain(u1,u2,u3,u4,u5)$sum( col, tracedata(u1,u2,u3,u4,u5,col)) = yes;
loop(domain(u1,u2,u3,u4,u5),
modelname(u1) = yes;
modeltype(u2) = yes;
solvername(u3) = yes;
nlpdef(u4) = yes;
mipdef(u5) = yes;
);
*execute 'rm -f tracedata'
$offecho
*=== Convert non-GAMS data files to GAMS trace files
$onecho > %gams.scrdir%tconvawk
{print $1 "," $2 "," $3 ",none,none,-1", $4, "-1,-1,-1,-1,-1,-1," $5 "," $6 "," $7 ",-1," $8 "," $9 ",-1,-1,#"}
$offecho
$set trace1set no
$set trace2set n
$set trace3set no
$set trace4set no
$set trace5set no
$set trace6set no
$set trace7set no
$set trace8set no
$if set trace1 $set trace1set yes
$if set trace2 $set trace2set yes
$if set trace3 $set trace3set yes
$if set trace4 $set trace4set yes
$if set trace5 $set trace5set yes
$if set trace6 $set trace6set yes
$if set trace7 $set trace7set yes
$if set trace8 $set trace8set yes
*=== Error checks
$if not set trace1 $goto errors_notrace1
$if not set trace2 $goto errors_notrace2
$if not exist %trace1% $goto errors_trace1notexist
$if not exist %trace2% $goto errors_trace2notexist
*=== Set defaults
$if not set bnd $set bnd 1e-5
$if not set outfile $set outfile timings
$if not set modelfile $goto nomodelfile
*=== If only the subset of models as listed in "modelfile" is to be
*=== analyzed
Set m(*) the subset of models to consider /
$onempty
$include %modelfile%
$offempty
/;
$echo > %gams.scrdir%tracedata
$if set trace1 $echo '$include %trace1%' >> %gams.scrdir%tracedata
$if set trace2 $echo '$include %trace2%' >> %gams.scrdir%tracedata
$if set trace3 $echo '$include %trace3%' >> %gams.scrdir%tracedata
$if set trace4 $echo '$include %trace4%' >> %gams.scrdir%tracedata
$if set trace5 $echo '$include %trace5%' >> %gams.scrdir%tracedata
$if set trace6 $echo '$include %trace6%' >> %gams.scrdir%tracedata
$if set trace7 $echo '$include %trace7%' >> %gams.scrdir%tracedata
$if set trace8 $echo '$include %trace8%' >> %gams.scrdir%tracedata
$set tracefile %gams.scrdir%tracedata
$include %gams.scrdir%readtrace.gms
$goto donemodelfile
*=== All models in trace files are to be analyzed
$label nomodelfile
$echo > %gams.scrdir%tracedata
$if set trace1 $echo '$include %trace1%' >> %gams.scrdir%tracedata
$if set trace2 $echo '$include %trace2%' >> %gams.scrdir%tracedata
$if set trace3 $echo '$include %trace3%' >> %gams.scrdir%tracedata
$if set trace4 $echo '$include %trace4%' >> %gams.scrdir%tracedata
$if set trace5 $echo '$include %trace5%' >> %gams.scrdir%tracedata
$if set trace6 $echo '$include %trace6%' >> %gams.scrdir%tracedata
$if set trace7 $echo '$include %trace7%' >> %gams.scrdir%tracedata
$if set trace8 $echo '$include %trace8%' >> %gams.scrdir%tracedata
$set tracefile %gams.scrdir%tracedata
$include %gams.scrdir%readtrace.gms
Set m(*);
m(modelname) = yes;
$label donemodelfile
*=== Set default options
$if not set resmin $set resmin 5e-2
$if not set tsame $set tsame 10
$if not set tfaster $set tfaster 50
*=== Possible solver outcomes
Set all_results /opt "optimal",
feas "feasible",
infes "infeasible",
unbnd "unbounded",
f "fail"
/;
Set result_cont(all_results) "possible results for cont. models"
result_disc (all_results) "possible results for discrete models"
;
result_cont("opt") = yes;
result_cont("feas") = yes;
result_cont("infes") = yes;
result_cont("unbnd") = yes;
result_cont("f") = yes;
result_disc("opt") = yes;
result_disc("feas") = yes;
result_disc("infes") = yes;
result_disc("unbnd") = yes;
result_disc("f") = yes;
Parameter is_discrete/0/;
Set discrete_mods / MIP, MINLP/;
loop(modeltype,
is_discrete = sum(discrete_mods, sameas(modeltype, discrete_mods));
);
Set result(*), resultA(*), resultB(*);
if(is_discrete,
result(result_disc) = yes;
resultA(result_disc) = yes;
resultB(result_disc) = yes;
else
result(result_cont) = yes;
resultA(result_cont) = yes;
resultB(result_cont) = yes;
);
Parameter solvernum /0/
nummodels /0/
ratio /0/;
Alias(solvers,solvername)
Parameter timings(*,*,*) GAMS solver results;
timings(modelname,solvername,all_results) = no;
timings(modelname,solvername,"restime") = -1;
*=== Determine solvers in tracefiles
Set solverA, solverB;
Parameter i /1/;
loop(solvername,
if(i eq 1,
solverA(solvername) = solvername(solvername);
elseif(i eq 2),
solverB(solvername) = solvername(solvername);
);
i = 2;
);
*=== Compute totals
Parameter scale(*) "this is the scaling factor"
optimal(*) "this is 1 if optimal solution found"
error(*) "relative error between solutions of A and B"
;
Parameter bound "relative objc func difference threshold"
/ %bnd% /
resourcemin "min resource time threshold for ratio"
/ %resmin%/
;
*=== Determine scale
loop((modelname,modeltype,nlpdef,mipdef),
scale(modelname) = max(smax(solvername, abs(tracedata(modelname,modeltype,
solvername,nlpdef,mipdef,"obj"))), 1e-4);
);
*=== Determine error
loop((modelname,modeltype,nlpdef,mipdef),
error(modelname) = abs( sum(solverA,
tracedata(modelname,modeltype,solverA,nlpdef,mipdef,"obj"))
- sum(solverB,
tracedata(modelname,modeltype,solverB,nlpdef,mipdef,"obj")) )
/ scale(modelname);
);
Parameter modstat /0/;
Parameter solstat /0/;
*=== Compute result totals
loop( (modelname(m),modeltype,solvername,nlpdef,mipdef),
i = i+1;
modstat =
tracedata(modelname,modeltype,solvername,nlpdef,mipdef,'modelstat');
solstat =
tracedata(modelname,modeltype,solvername,nlpdef,mipdef,'solvestat');
*=== Assign DISCRETE model timings only if data exists
if(is_discrete,
if (modstat and solstat,
if( (modstat=1 or modstat=15) and solstat=1,
timings(modelname,solvername,"opt") = yes;
timings(modelname,solvername,"restime") =
tracedata(modelname,modeltype,solvername,nlpdef,mipdef,'res');
elseif( (modstat=2 or modstat=8 or modstat=16) and
(solstat=1 or solstat=2 or solstat=3 or solstat=4 or solstat=5)),
timings(modelname,solvername,"feas") = yes;
timings(modelname,solvername,"restime") =
tracedata(modelname,modeltype,solvername,nlpdef,mipdef,'res');
elseif( (modstat=4 or modstat=5 or modstat=10 or modstat=19)and solstat=1),
timings(modelname,solvername,"infes") = yes;
elseif( (modstat=3 or modstat=18) and solstat=1 ),
timings(modelname,solvername,"unbnd") = yes;
else
timings(modelname,solvername,"f") = yes;
);
);
*=== Assign CONTINUOUS model square only if data exists
else
if (modstat and solstat,
if( (modstat=1 or modstat=15) and solstat=1,
timings(modelname,solvername,"opt") = yes;
timings(modelname,solvername,"restime") =
tracedata(modelname,modeltype,solvername,nlpdef,mipdef,'res');
elseif( (modstat=2 or modstat=16 or modstat=17) and
(solstat=1 or solstat=2 or solstat=3 or solstat=4 or solstat=5)),
timings(modelname,solvername,"feas") = yes;
timings(modelname,solvername,"restime") =
tracedata(modelname,modeltype,solvername,nlpdef,mipdef,'res');
elseif( (modstat=4 or modstat=5 or modstat=19) and solstat=1),
timings(modelname,solvername,"infes") = yes;
elseif( (modstat=3 or modstat=18) and solstat=1),
timings(modelname,solvername,"unbnd") = yes;
else
timings(modelname,solvername,"f") = yes;
);
);
);
);
*=========================================================================
*==== Create text file with timings
*=========================================================================
file ftxt /%outfile%.txt/;
put ftxt;
put 'DATE/TIME: %system.date% %system.time%' //;
put "BENCHMARKS FOR THE FOLLOWING SOLVERS:"//;
loop(solvername,
put '- ' solvername.tl:0 /;
);
put / 'Solver resource times are given in seconds.'
/ 'If no optimal or feasible solution is found,'
/ 'the status is listed instead of the resource time.'/;
put / '* Status details:'//;
loop(all_results,
put all_results.tl:10 ' - ' all_results.te(all_results):15 /;
);
put '(no data)':10 ' - ' 'no data available in trace file' /;
put / "==================";
loop(solvername,
put "====================";
);
put ftxt /'MODELNAME ':15;
loop(solvername,
put solvername.tl:>20
);
put /;
put "------------------";
loop(solvername,
put "--------------------";
);
put /;
loop(modelname,
put modelname.tl:20
loop(solvername,
loop(all_results$timings(modelname,solvername,all_results),
if (timings(modelname,solvername,"restime")>=0,
put timings(modelname,solvername,"restime"):20;
else
put all_results.tl:>18 ' *';
)
);
if( sum(all_results$timings(modelname,solvername,all_results),1)=0,
put '(no data)':>20;
);
);
put /;
);
put "==================";
loop(solvername,
put "====================";
);
put // "PROBLEM SIZES:"/;
put / "============================================================="
"==============================";
put / "PROBLEM":15 "EQUATIONS":>15 "TOTAL VAR.":>15 "DISCR. VAR":>15
"TOTAL NZ":>15 "NONLINEAR NZ":>15;
put / "============================================================="
"=============================="/;
loop((modelname,modeltype,solverA,nlpdef,mipdef)
$tracedata(modelname,modeltype,solverA,nlpdef,mipdef,"eqnum"),
put modelname.tl:20;
put tracedata(modelname,modeltype,solverA,nlpdef,mipdef,"eqnum"):15:0;
put tracedata(modelname,modeltype,solverA,nlpdef,mipdef,"varnum"):15:0;
if(tracedata(modelname,modeltype,solverA,nlpdef,mipdef,"dvarnum"),
put tracedata(modelname,modeltype,solverA,nlpdef,mipdef,"dvarnum"):15:0;
else
put " ":15;
)
put tracedata(modelname,modeltype,solverA,nlpdef,mipdef,"nz"):15:0;
if(tracedata(modelname,modeltype,solverA,nlpdef,mipdef,"nlnz"),
put tracedata(modelname,modeltype,solverA,nlpdef,mipdef,"nlnz"):15:0;
else
put " ":15;
);
put /;
);
putclose ftxt;
*=========================================================================
*=== Create HTML file
*=========================================================================
file fres_htm /%outfile%.htm/;
put fres_htm;
put / '
Benchmark Resource Time Table - All Models'
/ ''
/ '';
put / '';
put / 'Resource Timings:
' /
put / ''
/ ''
/ ' | Date / Time: | '
/ ' %system.date% %system.time% | '
/ '
'
/ '
'
/ '
';
put / 'Total resource time for all models. '
put / '
'
/ '';
if(%trace1set%,
put / ' | Tracefile 1 : | '
'%trace1% |
'
);
if(%trace2set%,
put / ' | Tracefile 2 : | '
'%trace2% |
';
);
if(%trace3set%,
put / ' | Tracefile 3 : | '
'%trace3% |
';
);
if(%trace4set%,
put / ' | Tracefile 4 : | '
'%trace4% |
';
);
if(%trace5set%,
put / ' | Tracefile 5 : | '
'%trace5% |
';
);
if(%trace6set%,
put / ' | Tracefile 6 : | '
'%trace6% |
';
);
if(%trace7set%,
put / ' | Tracefile 7 : | '
'%trace7% |
';
);
if(%trace8set%,
put / ' | Tracefile 8 : | '
'%trace8% |
';
);
put / ' | Modeltype(s) | '
'';
loop(modeltype,
put '   ' modeltype.tl:0
);
put / ' |
';
put / ' | Solvers used : | ';
put / '';
put / '';
solvernum = 0;
loop(solvers,
solvernum = solvernum+1;
put / ' | ' solvers.tl:0 ' | ';
);
put / ' ';
put / ' |
';
put / '
'
put / '
' //;
put / 'Results available as text file:
'
/ ''
/ ' %outfile%.txt'
/ '';
put / '
' //;
put / 'Top
';
put / 'Resource Time Results:
';
put / '';
put / '| Modelname | ';
loop(solvername,
put / ' ' solvername.tl:0 ' (sec) | ';
);
loop(modelname,
put / '
'
/ ' | ' modelname.tl:0 ' | ';
loop(solvername,
loop(all_results$timings(modelname,solvername,all_results),
put / ' ';
if (timings(modelname,solvername,"restime")>=0,
put timings(modelname,solvername,"restime"):10;
else
put '' all_results.te(all_results):0 '';
)
put / ' | ';
);
if( sum(all_results$timings(modelname,solvername,all_results),1)=0,
put / ' '
'(no data)':>12
/ ' | ';
);
);
put '
'/;
);
put / '
';
put / '
' //;
*==== Output model sizes
put / ''
put / 'Top
'
/ 'Model Statistics:
'
/ '';
put / '| Modelname | '
/ ' Equations | '
/ ' Total Variables | '
/ ' Discrete Variables | '
/ ' Total Nonzeros | '
/ ' Nonlinear Nonzeros | '
/ '
';
loop((modelname,modeltype,solvername,nlpdef,mipdef)$
tracedata(modelname,modeltype,solvername,nlpdef,mipdef,"eqnum"),
put / ''
/ ' | ' modelname.tl:0 ' | '
/ ' '
tracedata(modelname,modeltype,solvername,nlpdef,mipdef,"eqnum"):15:0
' | '
' '
tracedata(modelname,modeltype,solvername,nlpdef,mipdef,"varnum"):15:0
' | ';
if(tracedata(modelname,modeltype,solvername,nlpdef,mipdef,"dvarnum"),
put / ' '
tracedata(modelname,modeltype,solvername,nlpdef,mipdef,"dvarnum"):15:0
' | ';
else
put / ' -- | ';
);
put / ' '
tracedata(modelname,modeltype,solvername,nlpdef,mipdef,"nz"):15:0
' | ';
if(tracedata(modelname,modeltype,solvername,nlpdef,mipdef,"nlnz"),
put / ' '
tracedata(modelname,modeltype,solvername,nlpdef,mipdef,"nlnz"):15:0
' | ';
else
put / ' -- | ';
);
put / '
';
);
put / '
';
put / 'Top
';
put / ''
/ '';
putclose fres_htm;
$goto noerrors
*=== Error messages
$label errors_notrace1
log "--- ABORTING --trace1 or --ntrace1 option required: Trace file not specified..."
$abort "Aborting because --trace1 or --ntrace1 option not specified"
$label errors_notrace2
log "--- ABORTING --trace2 or --ntrace2 option required: Trace file not specified..."
$abort "Aborting because --trace2 or --ntrace2 option not specified"
$label errors_trace1notexist
log "--- ABORTING --trace1 or --ntrace1 file not found..."
$abort "Aborting because trace or ntrace file 1 not found"
$label errors_trace2notexist
log "--- ABORTING --trace2 or --ntrace2 file not found..."
$abort "Aborting because trace or ntrace file 2 not found"
$label noerrors