cutstock_class.Cutstock Class Reference

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 10 of file cutstock_class.py.

Constructors

◆ __init__()

def cutstock_class.Cutstock.__init__ (   self,
  ws 
)

Definition at line 12 of file cutstock_class.py.

References cutstock_class.Cutstock._ws.

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

Methods

◆ get_model_source()

def cutstock_class.Cutstock.get_model_source (   self)

Definition at line 32 of file cutstock_class.py.

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

◆ run()

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

Definition at line 27 of file cutstock_class.py.

References cutstock_class.Cutstock._cutstock_data, cutstock_class.Cutstock._dbout, cutstock_class.Cutstock._job, cutstock_class.Cutstock._ws, and cutstock_class.Cutstock.opt.

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

Member Data Documentation

◆ demand

cutstock_class.Cutstock.demand

Definition at line 22 of file cutstock_class.py.

◆ opt

cutstock_class.Cutstock.opt

Definition at line 14 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 30 of file cutstock_class.py.

◆ raw_width

cutstock_class.Cutstock.raw_width

Definition at line 21 of file cutstock_class.py.

◆ width

cutstock_class.Cutstock.width

Definition at line 23 of file cutstock_class.py.

◆ widths

cutstock_class.Cutstock.widths

Definition at line 20 of file cutstock_class.py.