mcp10.gms : MCP model with negative equ.var

Description

Builds on transmcp and tests the 'sign flipping' for different solvelink values

Contributor: Alex


Small Model of Type : GAMS


Category : GAMS Test library


Main file : mcp10.gms

$title MCP model with negative equ.var (MCP10,SEQ=604)

$ontext
Builds on transmcp and tests the 'sign flipping' for different solvelink values

Contributor: Alex
$offtext

Sets
     i   canning plants   / seattle, san-diego /
     j   markets          / new-york, chicago, topeka / ;

Parameters

     a(i)  capacity of plant i in cases (when prices are unity)
       /    seattle     350
            san-diego   600  /,

     b(j)  demand at market j in cases (when prices equal unity)
       /    new-york    325
            chicago     300
            topeka      275  /,

      esub(j)  price elasticity of demand (at prices equal to unity)
       /    new-york    1.5
            chicago     1.2
            topeka      2.0  /;

* changed distance to get some non-zero PIs on the supply constraint

Table d(i,j)  distance in thousands of miles
                  new-york       chicago      topeka
    seattle          2.5           1.7          1.8
    san-diego       52.5          31.8          1.4  ;

Scalar f  freight in dollars per case per thousand miles  /90/ ;

Parameter c(i,j)  transport cost in thousands of dollars per case ;

          c(i,j) = f * d(i,j) / 1000 ;

Variables
     x(i,j)  shipment quantities in cases
     z       total transportation costs in thousands of dollars ;

positive variable x;

Equations
     cost        define objective function
     supply(i)   observe supply limit at plant i
     demand(j)   satisfy demand at market j ;

cost ..        z  =e=  sum((i,j), c(i,j)*x(i,j)) ;

supply(i) ..   sum(j, x(i,j))  =l=  a(i);

demand(j) ..   sum(i, x(i,j))  =g=  b(j) ;

* new equs and vars needed for mcp

Positive variables
     w(i)             shadow price at supply node i,
     p(j)             shadow price at demand node j;


Equations
     supplyx(i)       reoriented equation
     profit(i,j)      zero profit conditions;

profit(i,j)..   w(i) + c(i,j)   =g= p(j);

supplyx(i)..     a(i) =g= sum(j, x(i,j));


*     declare models including specification of equation-variable
*     association:


models transport / cost,supply ,demand /
       transx    / cost,supplyx,demand /
       transmcp  / profit.x,-supply.w , demand.p/
       transmcpX / profit.x, supplyx.w, demand.p/ ;

sets runs        / lp,lpX,mcpX,0*6 /
     slink(runs) /             0*6 /;

parameter rep(i,runs) Q&D summary report on supply marginals;

option limcol=0,limrow=0;

solve transport min z us lp;
rep(i,'lp') = -supply.m(I);

solve transx us lp min z;
rep(i,'lpX') = supplyx.m(I);

solve transmcpx us mcp;
rep(i,'mcpX') = supplyx.m(I);

option solprint=off;

scalar handle,count,rc;

loop {slink,
   transmcp.solvelink=slink.val;
   supply.m(i) = 0;
   solve transmcp us mcp;
   if {slink.val=3,
      handle = transmcp.handle;
      count = 0;
      while {not handlecollect(handle),
         abort$[count >= 10] 'waited but grid solve not finished';
         count = count + 1;
         display$sleep(0.1) 'was sleeping for 0.1 secs', count;
      };
      display$handledelete(handle) 'trouble deleting handle';
   };
   if {slink.val=6,
      handle = transmcp.handle;
      rc = readyCollect(handle,10);
      abort$rc 'waited but multi-threaded solve not finished';
      abort$[0=handlecollect(handle)] 'error collecting model solution';
      display$handledelete(handle) 'trouble deleting handle';
   };
   rep(i,slink) = supply.m(I);
};

display rep;

parameter repx(i,runs) differences above tolerance;

repx(i,runs) = max(0,abs(rep(i,runs)-rep(i,'lp'))-1e-6);

display repx;

abort$card(repx) 'marginals are incorrect';