2using System.Collections.Generic;
12 #region private fields
32 fCutstockData = ws.
AddDatabase(inModelName:
"gdxincname");
35 fopt.
Defines.Add(
"dbOut1",
"dbOut1");
37 fWidths = fCutstockData.
AddSet(
"i",
"widths");
38 fRawWidth = fCutstockData.
AddParameter(
"r",
"raw width");
39 fDemand = fCutstockData.
AddParameter(
"d",
"demand", fWidths);
40 fWidth = fCutstockData.
AddParameter(
"w",
"width", fWidths);
45 public void Run(TextWriter output =
null)
48 throw new GAMSException(
"Domain Errors in Cutstock Database");
49 job.
Run(fopt,
null, output,
false, fCutstockData);
56 {
get {
return fWidths; } }
59 {
get {
return fRawWidth; } }
62 {
get {
return fDemand; } }
65 {
get {
return fWidth; } }
68 #region Output Symbols
70 {
get {
return fPatRep; } }
74 {
get {
return fopt; } }
76 public string GetModelSource()
79$Title Cutting Stock - A Column Generation Approach (CUTSTOCK,SEQ=294)
82 The task is to cut out some paper products of different sizes from a
83 large raw paper roll, in order to meet a customer's order. The objective
84 is to minimize the required number of paper rolls.
87P. C. Gilmore and R. E. Gomory, A linear programming approach to the
88cutting stock problem, Part I, Operations Research 9 (1961), 849-859.
90P. C. Gilmore and R. E. Gomory, A linear programming approach to the
91cutting stock problem, Part II, Operations Research 11 (1963), 863-888.
100$if not set gdxincname $abort 'no include file name for data file provided'
105* Gilmore-Gomory column generation algorithm
107Set p possible patterns /p1*p1000/
108 pp(p) dynamic subset of p
110 aip(i,p) number of width i in pattern growing in p;
114Variable xp(p) patterns used
116Integer variable xp; xp.up(p) = sum(i, d(i));
118Equation numpat number of patterns used
119 demand(i) meet demand;
121numpat.. z =e= sum(pp, xp(pp));
122demand(i).. sum(pp, aip(i,pp)*xp(pp)) =g= d(i);
124model master /numpat, demand/;
126* Pricing problem - Knapsack model
127Variable y(i) new pattern;
128Integer variable y; y.up(i) = ceil(r/w(i));
131 knapsack knapsack constraint;
133defobj.. z =e= 1 - sum(i, demand.m(i)*y(i));
134knapsack.. sum(i, w(i)*y(i)) =l= r;
136model pricing /defobj, knapsack/;
138* Initialization - the initial patterns have a single width
139pp(p) = ord(p)<=card(i);
140aip(i,pp(p))$(ord(i)=ord(p)) = floor(r/w(i));
143Scalar done loop indicator /0/
144Set pi(p) set of the last pattern; pi(p) = ord(p)=card(pp)+1;
146option optcr=0,limrow=0,limcol=0,solprint=off;
148While(not done and card(pp)<card(p),
149 solve master using rmip minimizing z;
150 solve pricing using mip minimizing z;
152* pattern that might improve the master model found?
154 aip(i,pi) = round(y.l(i));
155 pp(pi) = yes; pi(p) = pi(p-1);
160display 'lower bound for number of rolls', master.objval;
163solve master using mip minimizing z;
165Parameter patrep Solution pattern report
166 demrep Solution demand supply report;
168patrep('# produced',p) = round(xp.l(p));
169patrep(i,p)$patrep('# produced',p) = aip(i,p);
170patrep(i,'total') = sum(p, patrep(i,p));
171patrep('# produced','total') = sum(p, patrep('# produced',p));
173demrep(i,'produced') = sum(p,patrep(i,p)*patrep('# produced',p));
174demrep(i,'demand') = d(i);
175demrep(i,'over') = demrep(i,'produced') - demrep(i,'demand');
177display patrep, demrep;
179$if not set dbOut1 $abort 'no file name for out-database 1 file provided'
180execute_unload '%dbOut1%', patrep;
GAMSSet AddSet(string identifier, int dimension, string explanatoryText="", SetType setType=SetType.multi)
GAMSParameter GetParameter(string parameterIdentifier)
GAMSParameter AddParameter(string identifier, int dimension, string explanatoryText="")
void Run(GAMSOptions gamsOptions=null, GAMSCheckpoint checkpoint=null, TextWriter output=null, Boolean createOutDB=true)
Dictionary< string, string > Defines
GAMSJob AddJobFromString(string gamsSource, GAMSCheckpoint checkpoint=null, string jobName=null)
GAMSDatabase AddDatabaseFromGDX(string gdxFileName, string databaseName=null, string inModelName=null)
GAMSDatabase AddDatabase(string databaseName=null, string inModelName=null)
GAMSOptions AddOptions(GAMSOptions optFrom=null)