$title Sailco: Winston and Albright, p.200

$ontext

Sailco manufactures sailboats. During the next 4 months the company must
meet the following demands for their sailboats:

Month 1: 40
Month 2: 60
Month 3: 75
Month 4: 25

At the beginning of Month 1, Sailco has 10 boats in inventory. Each month
it must determine how many boats to produce. During any month, Sailco can
produce up to 40 boats with regular labor and an unlimited number of boats
with overtime labor. Boats produced with regular labor cost $400 each to
produce, while boats produced with overtime labor cost $450 each. It costs
$20 to hold a boat in inventory from one month to the next. Find the
production and inventory schedule that minimizes the cost of meeting the
next 4 months' demands on time.

Model as a network:

* One node per month, with given demand at each month.

* Inflow to each month node from a "regular labor" node, with capacity 40
* and cost 400

* Inflow to each month node from a "overtime labor" node, with unlimited
* capacity and cost 450

* month-to-month arcs representing inventory, with cost 20

* balance constraints applied only at month nodes.

Gams model by Jeff Linderoth for S13 635 class.

$offtext


* Raw Data

set T /month0*month4/;
parameter demand(T) /month1 40, month2 60, month3 75, month4 25/;

scalar  maxRegularLabor maximum boats produced by regular labor per month /40/
    costRegular cost to build a boat with regular labor /400/
    costOvertime cost to build a boat with overtime labor /450/
    costInv cost to store a boat for one month /20/
    scalar initialSupply Initial supply of sailboats /10/
;


* Now build the network (independently)

set Nodes /Sailboat, Regular, Overtime, 0*4/;
set BuildType(Nodes) /Regular, Overtime/ ;
set Months(Nodes) /0*4/ ;

set Arcs(Nodes, Nodes) ;

alias(Nodes, I, J) ;
alias(Months, M, M2) ;

Arcs('Sailboat', BuildType) = yes;
Arcs(BuildType, Months)$(ord(Months) > 1) = yes;
Arcs(M,M+1) = yes;

option Arcs:0:0:1 ;
display Arcs;


parameters
  c(Nodes,Nodes),
  u(Nodes,Nodes),
  b(Nodes) 
;

b(Months)$(ord(Months) = 1) = initialSupply ;
b(Months)$(ord(Months) > 1) = -sum(T$(ord(T)=ord(Months)), demand(T));

* Need to figure out the b for the master supply node
scalar required;
required = -sum(I, b(I));
b('Sailboat') = required;

display b;

c('Regular',Months)$(ord(Months)>1) = costRegular;
c('Overtime',Months)$(ord(Months)>1) = costOvertime;
u(Arcs) = +INF ;
u('Regular',Months)$(ord(Months)>1) = maxRegularLabor;
c(M,M+1)$(ord(M) > 1) = costInv;

* Now it is just a regular MCNF (using A,b,c,u)

positive variables x(I,J) ;
free variable cost;

equations
  obj_eq,
  flow_balance(I)
;

obj_eq..
  cost =E= sum(Arcs, c(Arcs)*x(Arcs)) ;

flow_balance(I)..
  sum(J$(Arcs(I,J)), x(I,J)) -  sum(J$(Arcs(J,I)), x(J,I)) =E= b(I) ;

x.up(Arcs) = u(Arcs) ;

model comesailaway /all/;
solve comesailaway using lp minimizing cost ;

display cost.L ;



