dumpsol.gms : Alternate Solutions for a Simple Facility Location Problem

Description

A simple version of a facility location problem is used to show how the
solution pool and the tools associated with it work. This example is taken
from the Cplex 11 User's Manual (ILOG, Cplex 11 User's Manual, 2007)

A company is considering opening as many as four warehouses in order to serve
nine different regions. The goal is to minimize the sum of fixed costs
associated with opening warehouses as well as the various transportation
costs incurred to ship goods from the warehouses to the regions.

Whether or not to open a warehouse is represented by binary variable ow.
Whether or not to ship goods from warehouse i to region j is represented
by binary variable oa.

Each region needs a specified amount of goods, and each warehouse can store
only a limited quantity of goods. In addition, each region must be served
by exactly one warehouse.


Small Model of Type : GAMS


Category : GAMS Test library


Main file : dumpsol.gms

$Title Alternate Solutions for a Simple Facility Location Problem (DUMPSOL,SEQ=476)
$Ontext

A simple version of a facility location problem is used to show how the
solution pool and the tools associated with it work. This example is taken
from the Cplex 11 User's Manual (ILOG, Cplex 11 User's Manual, 2007)

A company is considering opening as many as four warehouses in order to serve
nine different regions. The goal is to minimize the sum of fixed costs
associated with opening warehouses as well as the various transportation
costs incurred to ship goods from the warehouses to the regions.

Whether or not to open a warehouse is represented by binary variable ow.
Whether or not to ship goods from warehouse i to region j is represented
by binary variable oa.

Each region needs a specified amount of goods, and each warehouse can store
only a limited quantity of goods. In addition, each region must be served
by exactly one warehouse.


The following GAMS program demonstrates how to collect the solutions
found during optimization in several GAMS solvers. GAMS will store the
individual solutions in GDX containers/files which can then be further
used by other programs or the same GAMS run. The solver links will name
these GDX containers 'soln_loc_pNN.gdx', where NN will be the serial
number of the solution found. To manage the different solutions, the
names of the GDX containers created by the solver link will be stored in
dumpsol.gdx in the set 'index' using the set elements file*.

$offtext

Set i    warehouses   / w1*w4 /
    j    regions      / r1*r9 /
Parameters
    f(i) fixed costs  / w1 130, w2 150, w3 170, w4 180 /
    c(i) capacity     / w1  90, w2 110, w3 130, w4 150 /
    d(j) demand       / r1 10, r2 10, r3 12, r4 15, r5 15,
                        r6 15, r7 20, r8 20, r9 30 /;

Table t(j,i) transport costs
        w1   w2   w3   w4
    r1  10   30   25   55
    r2  10   25   25   45
    r3  20   23   30   40
    r4  25   10   26   40
    r5  28   12   20   29
    r6  36   19   16   22
    r7  40   39   22   27
    r8  75   65   55   35
    r9  34   43   41   62;

Variables
    totcost    total cost
    fcost      fixed cost
    tcost      transportation cost
    ow(i)      indicator for open warehouse
    oa(i,j)    indicator for open shipment arc warehouse to region
Binary variables ow, oa;

Equations
    deftotcost definition total cost
    deffcost   definition fixed cost
    deftcost   definition transportation cost
    defwcap(i) limit utilization of warehouse by its capacity
    onew(j)    only one warehouse per region
    defow(i,j) warehouse open if shipment from i to j;

deftotcost.. totcost =e= fcost + tcost;

deffcost..   fcost =e= sum(i, f(i)*ow(i));

deftcost..   tcost =e= sum((i,j), t(j,i)*oa(i,j));

defwcap(i).. sum(j, d(j)*oa(i,j)) =l= c(i);

onew(j)..    sum(i, oa(i,j)) =e= 1;

defow(i,j).. ow(i) =g= oa(i,j);

Model loc /all/ ;


* --- Define sets, parameters and files to hold solutions

Sets soln           possible solutions /file1*file1000,soln_loc_p1*soln_loc_p1000/
     solnpool(soln) actual solutions;
Scalar cardsoln     number of solutions;

* create empty dumpsol.gdx in case solver finds optimal solution right away (e.g., cbc)
execute_unload 'dumpsol.gdx', solnpool=index;

Alias (soln,s1,s2), (*,u);
Parameters
    owX(soln,i)    warehouse indicator by solution
    oaX(soln,i,j)  arc indicator by solution
    totcostX(soln) total cost
    fcostX(soln)   fixed cost
    tcostX(soln)   transportation cost
    xcostX(soln,*) cost structure by solution
    mcostX(soln,*) cost structure by solution;
files fsoln;
option limrow=0, limcol=0, optcr=0;
loc.optfile=1; loc.solprint=%solprint.Quiet%; loc.savepoint = 1;

$if %gams.mip% == cbc    $echo dumpsolutions dumpsol.gdx          > cbc.opt
$if %gams.mip% == copt   $echo solnpool      dumpsol.gdx          > copt.opt
$if %gams.mip% == cplex  $echo solnpool      dumpsol.gdx          > cplex.opt
$if %gams.mip% == gurobi $echo solnpool      dumpsol.gdx          > gurobi.opt
$if %gams.mip% == scip   $echo gams/dumpsolutions = "dumpsol.gdx" > scip.opt
$if %gams.mip% == xpress $echo solnpool      dumpsol.gdx          > xpress.opt
solve loc min totcost using mip;

execute_load 'dumpsol.gdx', solnpool=index;
cardsoln = card(solnpool); display cardsoln;
oaX(soln,i,j) = 0; owX(soln,i) = 0; xcostX(soln,u) = 0;
loop(solnpool(soln),
  put_utility fsoln 'gdxin' / solnpool.te(soln);
  execute_loadpoint;
  oaX(soln,i,j)             = round(oa.l(i,j));
  owX(soln,i)               = round(ow.l(i));
  xcostX(soln,'totcost')    = totcost.l;
  xcostX(soln,'tcost')      = tcost.l;
  xcostX(soln,'fcost')      = fcost.l;
);
* Restore the solution reported to GAMS
execute_loadpoint 'loc_p.gdx';
display xcostX;

$if %gams.mip% == cbc    $echo dumpsolutionsmerged dumpsol.gdx          > cbc.op2
$if %gams.mip% == copt   $echo solnpoolMerge       dumpsol.gdx          > copt.op2
$if %gams.mip% == cplex  $echo solnpoolMerge       dumpsol.gdx          > cplex.op2
$if %gams.mip% == gurobi $echo solnpoolMerge       dumpsol.gdx          > gurobi.op2
$if %gams.mip% == scip   $echo gams/dumpsolutionsmerged = "dumpsol.gdx" > scip.op2
$if %gams.mip% == xpress $echo solnpoolMerge       dumpsol.gdx          > xpress.op2


* create empty dumpsol.gdx in case solver finds optimal solution right away (e.g., cbc)
option clear=solnpool;
execute_unload 'dumpsol.gdx', solnpool=index, oaX=oa, owX=ow, totcostX=totcost, tcostX=tcost, fcostX=fcost;

loc.optfile=2;
solve loc min totcost using mip;
execute_load 'dumpsol.gdx', solnpool=index, oaX=oa, owX=ow, totcostX=totcost, tcostX=tcost, fcostX=fcost;

mcostX(solnpool,'totcost') = totcostX(solnpool);
mcostX(solnpool,'tcost')   = tcostX(solnpool);
mcostX(solnpool,'fcost')   = fcostX(solnpool);

display xcostX, mcostX;