lp12.gms : Test solution quality with solvelink=3/6

Description

This test is a modified version of lp01.  In this model, we use
m.solvelink = %SOLVELINK.AsyncGrid% so we can test the solution returned in this case.

N.B.: An alternate way to test this is to use m.solvelink = %SOLVELINK.AsyncSimulate% which
uses handles and their associated calls (e.g. handlestatus,
execute_loadhandle) internally without requiring any changes to the
model.  There should be at least one explicit test of m.solvelink = %SOLVELINK.AsyncGrid%
though.

Tests include:
  a) correct model attributes
  b) correct levels and marginals on rows and cols

Update for GAMS 24.6: Do not test %SOLVELINK.AsyncGrid% only but also %SOLVELINK.AsyncThreads%.

Contributor: Steve Dirkse


Small Model of Type : LP


Category : GAMS Test library


Main file : lp12.gms

$title 'Test solution quality with solvelink=%SOLVELINK.AsyncGrid%/%SOLVELINK.AsyncThreads%' (LP12,SEQ=252)

$ontext
This test is a modified version of lp01.  In this model, we use
m.solvelink = %SOLVELINK.AsyncGrid% so we can test the solution returned in this case.

N.B.: An alternate way to test this is to use m.solvelink = %SOLVELINK.AsyncSimulate% which
uses handles and their associated calls (e.g. handlestatus,
execute_loadhandle) internally without requiring any changes to the
model.  There should be at least one explicit test of m.solvelink = %SOLVELINK.AsyncGrid%
though.

Tests include:
  a) correct model attributes
  b) correct levels and marginals on rows and cols

Update for GAMS 24.6: Do not test %SOLVELINK.AsyncGrid% only but also %SOLVELINK.AsyncThreads%.

Contributor: Steve Dirkse
$offtext

$if not set MTYPE       $set MTYPE lp
$if not set solvedasmcp $set solvedasmcp 0
$if not set SKIPUNBND   $set SKIPUNBND 0
scalar skipUnBnd / %SKIPUNBND% /;


variable obj;

equations defobje
          defobjl
          defobjg;

defobje.. obj =e= 1;
defobjl.. obj =l= 1;
defobjg.. obj =g= 1;

model lp01e /defobje/
      lp01l /defobjl/
      lp01g /defobjg/;

option limcol=0,limrow=0,bratio=1;

scalar tol / 1e-6 /;
scalar h;

set sl SolveLink settings to be tested
       / %SOLVELINK.AsyncGrid%,
         %SOLVELINK.AsyncThreads% /;

loop(sl,
  lp01e.solvelink = sl.val;
  lp01l.solvelink = sl.val;
  lp01g.solvelink = sl.val;

  solve lp01e max obj us %MTYPE%;
    h = lp01e.handle;
    repeat
      if {handlestatus(h)=%HANDLESTATUS.Ready%,
        execute_loadhandle lp01e;
        abort$(handledelete(h)) 'trouble deleting handle';
        h = 0;
      };
      execute$h 'sleep 1';
    until (h = 0) or (timeelapsed > 100);
    abort$(lp01e.solvestat <> %solvestat.NormalCompletion% or lp01e.modelstat <> %modelstat.Optimal%) 'wrong status codes';
    abort$(lp01e.numnopt  <> 0) '    NONOPT flags set';
    abort$(lp01e.numinfes <> 0) 'INFEASIBLE flags set';
    abort$(abs(lp01e.objval - 1) > tol) 'bad m.objval';
    abort$(abs(defobje.l - 1) > tol)    'bad equation level';
    abort$(abs(defobje.m - 1) > tol)    'bad equation marginal';
    abort$(abs(obj.l - 1)     > tol)    'bad variable level';
    abort$(abs(obj.m - 0)     > tol)    'bad variable marginal';

  solve lp01l max obj us %MTYPE%;
    h = lp01l.handle;
    repeat
      if {handlestatus(h)=%HANDLESTATUS.Ready%,
        execute_loadhandle lp01l;
        abort$(handledelete(h)) 'trouble deleting handle';
        h = 0;
      };
      execute$h 'sleep 1';
    until (h = 0) or (timeelapsed > 100);
    abort$(lp01l.solvestat <> %solvestat.NormalCompletion% or lp01l.modelstat <> %modelstat.Optimal%) 'wrong status codes';
    abort$(lp01l.numnopt  <> 0) '    NONOPT flags set';
    abort$(lp01l.numinfes <> 0) 'INFEASIBLE flags set';
    abort$(abs(lp01l.objval - 1) > tol) 'bad m.objval';
    abort$(abs(defobjl.l - 1) > tol)    'bad equation level';
    abort$(abs(defobjl.m - 1) > tol)    'bad equation marginal';
    abort$(abs(obj.l - 1)     > tol)    'bad variable level';
    abort$(abs(obj.m - 0)     > tol)    'bad variable marginal';

  if {not skipUnBnd,
    solve lp01g max obj us %MTYPE%;
      h = lp01g.handle;
      repeat
        if {handlestatus(h)=%HANDLESTATUS.Ready%,
          execute_loadhandle lp01g;
          abort$(handledelete(h)) 'trouble deleting handle';
          h = 0;
        };
        execute$h 'sleep 1';
      until (h = 0) or (timeelapsed > 100);
      abort$(lp01g.solvestat <> %solvestat.NormalCompletion%
             or ( (lp01g.modelstat <> %modelstat.Unbounded%) and (lp01g.modelstat <> %modelstat.Unbounded-NoSolution%)
                  and ((lp01g.modelstat <> %modelstat.Infeasible%) or (%solvedasmcp% = 0)))) 'wrong status codes';
  }

  solve lp01e min obj us %MTYPE%;
    h = lp01e.handle;
    repeat
      if {handlestatus(h)=%HANDLESTATUS.Ready%,
        execute_loadhandle lp01e;
        abort$(handledelete(h)) 'trouble deleting handle';
        h = 0;
      };
      execute$h 'sleep 1';
    until (h = 0) or (timeelapsed > 100);
    abort$(lp01e.solvestat <> %solvestat.NormalCompletion% or lp01e.modelstat <> %modelstat.Optimal%) 'wrong status codes';
    abort$(lp01e.numnopt  <> 0) '    NONOPT flags set';
    abort$(lp01e.numinfes <> 0) 'INFEASIBLE flags set';
    abort$(abs(lp01e.objval - 1) > tol) 'bad m.objval';
    abort$(abs(defobje.l - 1) > tol)    'bad equation level';
    abort$(abs(defobje.m - 1) > tol)    'bad equation marginal';
    abort$(abs(obj.l - 1)     > tol)    'bad variable level';
    abort$(abs(obj.m - 0)     > tol)    'bad variable marginal';

  if {not skipUnBnd,
    solve lp01l min obj us %MTYPE%;
      h = lp01l.handle;
      repeat
        if {handlestatus(h)=%HANDLESTATUS.Ready%,
          execute_loadhandle lp01l;
          abort$(handledelete(h)) 'trouble deleting handle';
          h = 0;
        };
        execute$h 'sleep 1';
      until (h = 0) or (timeelapsed > 100);
      abort$(lp01l.solvestat <> %solvestat.NormalCompletion%
             or ( (lp01l.modelstat <> %modelstat.Unbounded%) and (lp01l.modelstat <> %modelstat.Unbounded-NoSolution%)
                  and ((lp01l.modelstat <> %modelstat.Infeasible%) or (%solvedasmcp% = 0)))) 'wrong status codes';
  }

  solve lp01g min obj us %MTYPE%;
    h = lp01g.handle;
    repeat
      if {handlestatus(h)=%HANDLESTATUS.Ready%,
        execute_loadhandle lp01g;
        abort$(handledelete(h)) 'trouble deleting handle';
        h = 0;
      };
      execute$h 'sleep 1';
    until (h = 0) or (timeelapsed > 100);
    abort$(lp01g.solvestat <> %solvestat.NormalCompletion% or lp01g.modelstat <> %modelstat.Optimal%) 'wrong status codes';
    abort$(lp01g.numnopt  <> 0) '    NONOPT flags set';
    abort$(lp01g.numinfes <> 0) 'INFEASIBLE flags set';
    abort$(abs(lp01g.objval - 1) > tol) 'bad m.objval';
    abort$(abs(defobjg.l - 1) > tol)    'bad equation level';
    abort$(abs(defobjg.m - 1) > tol)    'bad equation marginal';
    abort$(abs(obj.l - 1)     > tol)    'bad variable level';
    abort$(abs(obj.m - 0)     > tol)    'bad variable marginal';
);

obj.lo = -1000; obj.up = 1000;

loop(sl,
  lp01e.solvelink = sl.val;
  lp01l.solvelink = sl.val;
  lp01g.solvelink = sl.val;

  solve lp01e max obj us %MTYPE%;
    h = lp01e.handle;
    repeat
      if {handlestatus(h)=%HANDLESTATUS.Ready%,
        execute_loadhandle lp01e;
        abort$(handledelete(h)) 'trouble deleting handle';
        h = 0;
      };
      execute$h 'sleep 1';
    until (h = 0) or (timeelapsed > 100);
    abort$(lp01e.solvestat <> %solvestat.NormalCompletion% or lp01e.modelstat <> %modelstat.Optimal%) 'wrong status codes';
    abort$(lp01e.numnopt  <> 0) '    NONOPT flags set';
    abort$(lp01e.numinfes <> 0) 'INFEASIBLE flags set';
    abort$(abs(lp01e.objval - 1) > tol)    'bad m.objval';
    abort$(abs(defobje.l - 1)    > tol)    'bad equation level';
    abort$(abs(defobje.m - 1)    > tol)    'bad equation marginal';
    abort$(abs(obj.l - 1)        > tol)    'bad variable level';
    abort$(abs(obj.m - 0)        > tol)    'bad variable marginal';

  solve lp01l max obj us %MTYPE%;
    h = lp01l.handle;
    repeat
      if {handlestatus(h)=%HANDLESTATUS.Ready%,
        execute_loadhandle lp01l;
        abort$(handledelete(h)) 'trouble deleting handle';
        h = 0;
      };
      execute$h 'sleep 1';
    until (h = 0) or (timeelapsed > 100);
    abort$(lp01l.solvestat <> %solvestat.NormalCompletion% or lp01l.modelstat <> %modelstat.Optimal%) 'wrong status codes';
    abort$(lp01l.numnopt  <> 0) '    NONOPT flags set';
    abort$(lp01l.numinfes <> 0) 'INFEASIBLE flags set';
    abort$(abs(lp01l.objval - 1) > tol)    'bad m.objval';
    abort$(abs(defobjl.l - 1)    > tol)    'bad equation level';
    abort$(abs(defobjl.m - 1)    > tol)    'bad equation marginal';
    abort$(abs(obj.l - 1)        > tol)    'bad variable level';
    abort$(abs(obj.m - 0)        > tol)    'bad variable marginal';

  solve lp01g max obj us %MTYPE%;
    h = lp01g.handle;
    repeat
      if {handlestatus(h)=%HANDLESTATUS.Ready%,
        execute_loadhandle lp01g;
        abort$(handledelete(h)) 'trouble deleting handle';
        h = 0;
      };
      execute$h 'sleep 1';
    until (h = 0) or (timeelapsed > 100);
    abort$(lp01g.solvestat <> %solvestat.NormalCompletion% or lp01g.modelstat <> %modelstat.Optimal%) 'wrong status codes';
    abort$(lp01g.numnopt  <> 0) '    NONOPT flags set';
    abort$(lp01g.numinfes <> 0) 'INFEASIBLE flags set';
    abort$(abs(lp01g.objval - 1000) > tol) 'bad m.objval';
    abort$(abs(defobjg.l - 1000) > tol)    'bad equation level';
    abort$(abs(defobjg.m - 0)    > tol)    'bad equation marginal';
    abort$(abs(obj.l - 1000)     > tol)    'bad variable level';
    abort$(abs(obj.m - 1)        > tol)    'bad variable marginal';

  solve lp01e min obj us %MTYPE%;
    h = lp01e.handle;
    repeat
      if {handlestatus(h)=%HANDLESTATUS.Ready%,
        execute_loadhandle lp01e;
        abort$(handledelete(h)) 'trouble deleting handle';
        h = 0;
      };
      execute$h 'sleep 1';
    until (h = 0) or (timeelapsed > 100);
    abort$(lp01e.solvestat <> %solvestat.NormalCompletion% or lp01e.modelstat <> %modelstat.Optimal%) 'wrong status codes';
    abort$(lp01e.numnopt  <> 0) '    NONOPT flags set';
    abort$(lp01e.numinfes <> 0) 'INFEASIBLE flags set';
    abort$(abs(lp01e.objval - 1) > tol)    'bad m.objval';
    abort$(abs(defobje.l - 1)    > tol)    'bad equation level';
    abort$(abs(defobje.m - 1)    > tol)    'bad equation marginal';
    abort$(abs(obj.l - 1)        > tol)    'bad variable level';
    abort$(abs(obj.m - 0)        > tol)    'bad variable marginal';

  solve lp01l min obj us %MTYPE%;
    h = lp01l.handle;
    repeat
      if {handlestatus(h)=%HANDLESTATUS.Ready%,
        execute_loadhandle lp01l;
        abort$(handledelete(h)) 'trouble deleting handle';
        h = 0;
      };
      execute$h 'sleep 1';
    until (h = 0) or (timeelapsed > 100);
    abort$(lp01l.solvestat <> %solvestat.NormalCompletion% or lp01l.modelstat <> %modelstat.Optimal%) 'wrong status codes';
    abort$(lp01l.numnopt  <> 0) '    NONOPT flags set';
    abort$(lp01l.numinfes <> 0) 'INFEASIBLE flags set';
    abort$(abs(lp01l.objval + 1000) > tol) 'bad m.objval';
    abort$(abs(defobjl.l + 1000) > tol)    'bad equation level';
    abort$(abs(defobjl.m - 0)    > tol)    'bad equation marginal';
    abort$(abs(obj.l + 1000)     > tol)    'bad variable level';
    abort$(abs(obj.m - 1)        > tol)    'bad variable marginal';

  solve lp01g min obj us %MTYPE%;
    h = lp01g.handle;
    repeat
      if {handlestatus(h)=%HANDLESTATUS.Ready%,
        execute_loadhandle lp01g;
        abort$(handledelete(h)) 'trouble deleting handle';
        h = 0;
      };
      execute$h 'sleep 1';
    until (h = 0) or (timeelapsed > 100);
    abort$(lp01g.solvestat <> %solvestat.NormalCompletion% or lp01g.modelstat <> %modelstat.Optimal%) 'wrong status codes';
    abort$(lp01g.numnopt  <> 0) '    NONOPT flags set';
    abort$(lp01g.numinfes <> 0) 'INFEASIBLE flags set';
    abort$(abs(lp01g.objval - 1) > tol)    'bad m.objval';
    abort$(abs(defobjg.l - 1)    > tol)    'bad equation level';
    abort$(abs(defobjg.m - 1)    > tol)    'bad equation marginal';
    abort$(abs(obj.l - 1)        > tol)    'bad variable level';
    abort$(abs(obj.m - 0)        > tol)    'bad variable marginal';
);