1package com.gams.examples.cutstock;
3 import java.io.PrintStream;
38 fopt.
defines(
"gdxincname",
"gdxincname");
40 fopt.
defines(
"dbOut1",
"dbOut1");
42 fWidths = fCutstockData.
addSet(
"i",
"widths");
43 fRawWidth = fCutstockData.
addParameter(
"r",
"raw width");
44 fDemand = fCutstockData.
addParameter(
"d",
"demand", fWidths);
45 fWidth = fCutstockData.
addParameter(
"w",
"width", fWidths);
58 public void run(PrintStream output) {
60 throw new GAMSException(
"Domain Errors in Cutstock Database");
62 job.
run(fopt,
null, output,
false, fCutstockData);
89 "$Title Cutting Stock - A Column Generation Approach (CUTSTOCK,SEQ=294) \n" +
92 "The task is to cut out some paper products of different sizes from a \n" +
93 "large raw paper roll, in order to meet a customer's order. The objective \n" +
94 "is to minimize the required number of paper rolls. \n" +
96 "P. C. Gilmore and R. E. Gomory, A linear programming approach to the \n" +
97 "cutting stock problem, Part I, Operations Research 9 (1961), 849-859. \n" +
99 "P. C. Gilmore and R. E. Gomory, A linear programming approach to the \n" +
100 "cutting stock problem, Part II, Operations Research 11 (1963), 863-888. \n" +
107 " d(i) demand ; \n" +
109 "$if not set gdxincname $abort 'no include file name for data file provided'\n" +
110 "$gdxin %gdxincname% \n" +
114 "* Gilmore-Gomory column generation algorithm \n" +
116 "Set p possible patterns /p1*p1000/ \n" +
117 " pp(p) dynamic subset of p \n" +
119 " aip(i,p) number of width i in pattern growing in p; \n" +
121 "* Master model \n" +
122 "Variable xp(p) patterns used \n" +
123 " z objective variable \n" +
124 "Integer variable xp; xp.up(p) = sum(i, d(i)); \n" +
126 "Equation numpat number of patterns used \n" +
127 " demand(i) meet demand; \n" +
129 "numpat.. z =e= sum(pp, xp(pp)); \n" +
130 "demand(i).. sum(pp, aip(i,pp)*xp(pp)) =g= d(i); \n" +
132 "model master /numpat, demand/; \n" +
134 "* Pricing problem - Knapsack model \n" +
135 "Variable y(i) new pattern; \n" +
136 "Integer variable y; y.up(i) = ceil(r/w(i)); \n" +
138 "Equation defobj \n" +
139 " knapsack knapsack constraint; \n" +
141 "defobj.. z =e= 1 - sum(i, demand.m(i)*y(i)); \n" +
142 "knapsack.. sum(i, w(i)*y(i)) =l= r; \n" +
144 "model pricing /defobj, knapsack/; \n" +
146 "* Initialization - the initial patterns have a single width \n" +
147 "pp(p) = ord(p)<=card(i); \n" +
148 "aip(i,pp(p))$(ord(i)=ord(p)) = floor(r/w(i)); \n" +
151 "Scalar done loop indicator /0/ \n" +
152 "Set pi(p) set of the last pattern; pi(p) = ord(p)=card(pp)+1; \n" +
154 "option optcr=0,limrow=0,limcol=0,solprint=off; \n" +
156 "While(not done and card(pp)<card(p), \n" +
157 " solve master using rmip minimizing z; \n" +
158 " solve pricing using mip minimizing z; \n" +
160 "* pattern that might improve the master model found? \n" +
161 " if(z.l < -0.001, \n" +
162 " aip(i,pi) = round(y.l(i)); \n" +
163 " pp(pi) = yes; pi(p) = pi(p-1); \n" +
168 "display 'lower bound for number of rolls', master.objval; \n" +
170 "option solprint=on; \n" +
171 "solve master using mip minimizing z; \n" +
173 "Parameter patrep Solution pattern report \n" +
174 " demrep Solution demand supply report; \n" +
176 "patrep('# produced',p) = round(xp.l(p)); \n" +
177 "patrep(i,p)$patrep('# produced',p) = aip(i,p); \n" +
178 "patrep(i,'total') = sum(p, patrep(i,p)); \n" +
179 "patrep('# produced','total') = sum(p, patrep('# produced',p)); \n" +
181 "demrep(i,'produced') = sum(p,patrep(i,p)*patrep('# produced',p)); \n" +
182 "demrep(i,'demand') = d(i); \n" +
183 "demrep(i,'over') = demrep(i,'produced') - demrep(i,'demand'); \n" +
185 "display patrep, demrep; \n" +
186 "$if not set dbOut1 $abort 'no file name for out-database 1 file provided' \n" +
187 "execute_unload '%dbOut1%', patrep; \n" +
String getDefinitionOf(String str)
String getModelSource()
get the source of cutstock model
GAMSParameter getPatRep()
get an output symbol, patrep : Solution pattern report
GAMSParameter getParameter(String identifier)
void run()
Executes the cutstock model.
CutstockModel(GAMSWorkspace ws)
CutstockModel constructor.
GAMSParameter getRawWidth()
get an input symbol, r : raw width
GAMSParameter getWidth()
get an input symbol, w : width
void run(PrintStream output)
Executes the cutstock model.
void defines(String defStr, String asStr)
GAMSDatabase addDatabaseFromGDX(String gdxFileName)
GAMSSet getWidths()
get an input symbol, i : widths
void setSolveLink(GAMSOptions.ESolveLink x)
GAMSParameter addParameter(String identifier, int dimension)
GAMSSet addSet(String identifier, int dimension)
GAMSDatabase addDatabase()
GAMSJob addJobFromString(String source)
GAMSParameter getDemand()
get an input symbol, d : demand
This example shows the wrapper model of a cutstock problem based on the simple GAMS [cutstock] model ...
GAMSOptions getOpt()
get Options for the execution of the cutstock model