GAMS [ Home | Downloads | Documentation | Solvers | APIs | Tools | Model Libraries | Resources | Sales | Support | Contact Us | Search ]

cutstock_class.Cutstock Class Reference
Inheritance diagram for cutstock_class.Cutstock:

Pulic Methods

def __init__ (self, ws)
 
def run (self, output=None)
 
def get_model_source (self)
 

Public Attributes

 opt
 
 widths
 
 raw_width
 
 demand
 
 width
 
 pat_rep
 

Detailed Description

Definition at line 11 of file cutstock_class.py.

Constructors

◆ __init__()

def cutstock_class.Cutstock.__init__ (   self,
  ws 
)

Definition at line 13 of file cutstock_class.py.

References cutstock_class.Cutstock._ws.

13  def __init__(self, ws):
14  self._ws = ws
15  self.opt = ws.add_options()
16  self._cutstock_data = ws.add_database(in_model_name = "gdxincname")
17 
18  self.opt.solvelink = SolveLink.LoadLibrary
19  self.opt.defines["dbOut1"] = "dbOut1"
20 
21  self.widths = self._cutstock_data.add_set("i", 1, "widths")
22  self.raw_width = self._cutstock_data.add_parameter("r", 0, "raw width")
23  self.demand = self._cutstock_data.add_parameter_dc("d", [self.widths], "demand")
24  self.width = self._cutstock_data.add_parameter_dc("w", [self.widths], "width")
25 
26  self._job = ws.add_job_from_string(self.get_model_source())
27 

Methods

◆ get_model_source()

def cutstock_class.Cutstock.get_model_source (   self)

Definition at line 33 of file cutstock_class.py.

33  def get_model_source(self):
34  return '''
35 $Title Cutting Stock - A Column Generation Approach (CUTSTOCK,SEQ=294)
36 
37 $ontext
38  The task is to cut out some paper products of different sizes from a
39  large raw paper roll, in order to meet a customer's order. The objective
40  is to minimize the required number of paper rolls.
41 
42 
43 P. C. Gilmore and R. E. Gomory, A linear programming approach to the
44 cutting stock problem, Part I, Operations Research 9 (1961), 849-859.
45 
46 P. C. Gilmore and R. E. Gomory, A linear programming approach to the
47 cutting stock problem, Part II, Operations Research 11 (1963), 863-888.
48 $offtext
49 
50 Set i widths
51 Parameter
52  r raw width
53  w(i) width
54  d(i) demand ;
55 
56 $if not set gdxincname $abort 'no include file name for data file provided'
57 $gdxin %gdxincname%
58 $load r i w d
59 $gdxin
60 
61 * Gilmore-Gomory column generation algorithm
62 
63 Set p possible patterns /p1*p1000/
64  pp(p) dynamic subset of p
65 Parameter
66  aip(i,p) number of width i in pattern growing in p;
67 
68 
69 * Master model
70 Variable xp(p) patterns used
71  z objective variable
72 Integer variable xp; xp.up(p) = sum(i, d(i));
73 
74 Equation numpat number of patterns used
75  demand(i) meet demand;
76 
77 numpat.. z =e= sum(pp, xp(pp));
78 demand(i).. sum(pp, aip(i,pp)*xp(pp)) =g= d(i);
79 
80 model master /numpat, demand/;
81 
82 * Pricing problem - Knapsack model
83 Variable y(i) new pattern;
84 Integer variable y; y.up(i) = ceil(r/w(i));
85 
86 Equation defobj
87  knapsack knapsack constraint;
88 
89 defobj.. z =e= 1 - sum(i, demand.m(i)*y(i));
90 knapsack.. sum(i, w(i)*y(i)) =l= r;
91 
92 model pricing /defobj, knapsack/;
93 
94 * Initialization - the initial patterns have a single width
95 pp(p) = ord(p)<=card(i);
96 aip(i,pp(p))$(ord(i)=ord(p)) = floor(r/w(i));
97 *display aip;
98 
99 Scalar done loop indicator /0/
100 Set pi(p) set of the last pattern; pi(p) = ord(p)=card(pp)+1;
101 
102 option optcr=0,limrow=0,limcol=0,solprint=off;
103 
104 While(not done and card(pp)<card(p),
105  solve master using rmip minimizing z;
106  solve pricing using mip minimizing z;
107 
108 * pattern that might improve the master model found?
109  if(z.l < -0.001,
110  aip(i,pi) = round(y.l(i));
111  pp(pi) = yes; pi(p) = pi(p-1);
112  else
113  done = 1;
114  );
115 );
116 display 'lower bound for number of rolls', master.objval;
117 
118 option solprint=on;
119 solve master using mip minimizing z;
120 
121 Parameter patrep Solution pattern report
122  demrep Solution demand supply report;
123 
124 patrep('# produced',p) = round(xp.l(p));
125 patrep(i,p)$patrep('# produced',p) = aip(i,p);
126 patrep(i,'total') = sum(p, patrep(i,p));
127 patrep('# produced','total') = sum(p, patrep('# produced',p));
128 
129 demrep(i,'produced') = sum(p,patrep(i,p)*patrep('# produced',p));
130 demrep(i,'demand') = d(i);
131 demrep(i,'over') = demrep(i,'produced') - demrep(i,'demand');
132 
133 display patrep, demrep;
134 
135 $if not set dbOut1 $abort 'no file name for out-database 1 file provided'
136 execute_unload '%dbOut1%', patrep;
137 '''
138 

◆ run()

def cutstock_class.Cutstock.run (   self,
  output = None 
)

Definition at line 28 of file cutstock_class.py.

References cutstock_class.Cutstock._cutstock_data, cutstock_class.Cutstock._dbout, cutstock_class.Cutstock._job, cutstock_class.Cutstock._ws, gams::options::GamsOptions.opt, TransportSeq::Transport.opt, and cutstock_class.Cutstock.opt.

28  def run(self, output = None):
29  self._job.run(self.opt, None, output, databases=self._cutstock_data)
30  self._dbout = self._ws.add_database_from_gdx(self.opt.defines["dbOut1"] + ".gdx")
31  self.pat_rep = self._dbout.get_parameter("patrep")
32 

Member Data Documentation

◆ demand

cutstock_class.Cutstock.demand

Definition at line 23 of file cutstock_class.py.

◆ opt

cutstock_class.Cutstock.opt

Definition at line 15 of file cutstock_class.py.

Referenced by cutstock_class.Cutstock.run(), and transport_class.Transport.run().

◆ pat_rep

cutstock_class.Cutstock.pat_rep

Definition at line 31 of file cutstock_class.py.

◆ raw_width

cutstock_class.Cutstock.raw_width

Definition at line 22 of file cutstock_class.py.

◆ width

cutstock_class.Cutstock.width

Definition at line 24 of file cutstock_class.py.

◆ widths

cutstock_class.Cutstock.widths

Definition at line 21 of file cutstock_class.py.