cutstock Namespace Reference

Functions

def get_master_model ()
 
def get_sub_model ()
 

Variables

 ws = GamsWorkspace(system_directory = sys.argv[1])
 
 opt = ws.add_options()
 
 cutstock_data = ws.add_database("csdata")
 
 all_model_types
 
 optcr
 
int maxpattern = 35
 
dictionary d = {"i1": 97, "i2": 610, "i3":395, "i4": 211}
 
dictionary w = {"i1": 47, "i2": 36, "i3": 31, "i4": 14}
 
int r = 100
 
 widths = cutstock_data.add_set("i", 1, "widths")
 
 raw_width = cutstock_data.add_parameter("r", 0, "raw width")
 
 demand = cutstock_data.add_parameter("d", 1, "demand")
 
 width = cutstock_data.add_parameter("w", 1, "width")
 
 value
 
 master_cp = ws.add_checkpoint()
 
 master_init_job = ws.add_job_from_string(get_master_model())
 
 databases
 
 master_job = ws.add_job_from_string("execute_load 'csdata', aip, pp; solve master min z using %solveMasterAs%;", master_cp)
 
 pattern = cutstock_data.add_set("pp", 1, "pattern index")
 
 pattern_data = cutstock_data.add_parameter("aip", 2, "pattern data")
 
int pattern_count = 0
 
 sub_cp = ws.add_checkpoint()
 
 sub_job = ws.add_job_from_string(get_sub_model())
 
 sub_mi = sub_cp.add_modelinstance()
 
 demand_dual = sub_mi.sync_db.add_parameter("demdual", 1, "dual of demand from master")
 
bool pattern_added = True
 
 s = pattern.add_record(str(pattern_count))
 
 end
 
 aip = master_job.out_db["aip"].first_record((" ", xp.key(0)))
 

Function Documentation

◆ get_master_model()

def cutstock.get_master_model ( )

Definition at line 16 of file cutstock.py.

17 return '''
18$Title Cutting Stock - Master problem
19
20Set i widths
21Parameter
22 w(i) width
23 d(i) demand
24Scalar
25 r raw width;
26$gdxin csdata
27$load i w d r
28
29$if not set pmax $set pmax 1000
30Set p possible patterns /1*%pmax%/
31 pp(p) dynamic subset of p
32Parameter
33 aip(i,p) number of width i in pattern growing in p;
34
35* Master model
36Variable xp(p) patterns used
37 z objective variable
38Integer variable xp; xp.up(p) = sum(i, d(i));
39
40Equation numpat; numpat.. z =e= sum(pp, xp(pp));
41Equation demand(i); demand(i).. sum(pp, aip(i,pp)*xp(pp)) =g= d(i);
42
43model master /numpat, demand/;'''
44
def get_master_model()
Definition: cutstock.py:16

◆ get_sub_model()

def cutstock.get_sub_model ( )

Definition at line 45 of file cutstock.py.

45def get_sub_model():
46 return '''
47$Title Cutting Stock - Pricing problem is a knapsack model
48
49Set i widths
50Parameter
51 w(i) width;
52Scalar
53 r raw width;
54
55$gdxin csdata
56$load i w r
57
58Parameter
59 demdual(i) duals of master demand constraint /#i eps/;
60
61Variable z, y(i) new pattern;
62Integer variable y; y.up(i) = ceil(r/w(i));
63
64Equation defobj; defobj.. z =e= 1 - sum(i, demdual(i)*y(i));
65Equation knapsack; knapsack.. sum(i, w(i)*y(i)) =l= r;
66model pricing /defobj, knapsack/;'''
67
68
69
def get_sub_model()
Definition: cutstock.py:45

Variable Documentation

◆ aip

cutstock.aip = master_job.out_db["aip"].first_record((" ", xp.key(0)))

Definition at line 157 of file cutstock.py.

◆ all_model_types

cutstock.all_model_types

Definition at line 78 of file cutstock.py.

◆ cutstock_data

cutstock.cutstock_data = ws.add_database("csdata")

Definition at line 77 of file cutstock.py.

◆ d

dictionary cutstock.d = {"i1": 97, "i2": 610, "i3":395, "i4": 211}

Definition at line 85 of file cutstock.py.

◆ databases

cutstock.databases

Definition at line 104 of file cutstock.py.

◆ demand

cutstock.demand = cutstock_data.add_parameter("d", 1, "demand")

Definition at line 91 of file cutstock.py.

◆ demand_dual

cutstock.demand_dual = sub_mi.sync_db.add_parameter("demdual", 1, "dual of demand from master")

Definition at line 122 of file cutstock.py.

◆ end

cutstock.end

Definition at line 156 of file cutstock.py.

◆ master_cp

cutstock.master_cp = ws.add_checkpoint()

Definition at line 102 of file cutstock.py.

◆ master_init_job

cutstock.master_init_job = ws.add_job_from_string(get_master_model())

Definition at line 103 of file cutstock.py.

◆ master_job

cutstock.master_job = ws.add_job_from_string("execute_load 'csdata', aip, pp; solve master min z using %solveMasterAs%;", master_cp)

Definition at line 105 of file cutstock.py.

◆ maxpattern

int cutstock.maxpattern = 35

Definition at line 80 of file cutstock.py.

◆ opt

cutstock.opt = ws.add_options()

Definition at line 76 of file cutstock.py.

◆ optcr

cutstock.optcr

Definition at line 79 of file cutstock.py.

◆ pattern

cutstock.pattern = cutstock_data.add_set("pp", 1, "pattern index")

Definition at line 107 of file cutstock.py.

◆ pattern_added

bool cutstock.pattern_added = True

Definition at line 126 of file cutstock.py.

◆ pattern_count

int cutstock.pattern_count = 0

Definition at line 111 of file cutstock.py.

◆ pattern_data

cutstock.pattern_data = cutstock_data.add_parameter("aip", 2, "pattern data")

Definition at line 108 of file cutstock.py.

◆ r

int cutstock.r = 100

Definition at line 87 of file cutstock.py.

◆ raw_width

cutstock.raw_width = cutstock_data.add_parameter("r", 0, "raw width")

Definition at line 90 of file cutstock.py.

◆ s

cutstock.s = pattern.add_record(str(pattern_count))

Definition at line 142 of file cutstock.py.

◆ sub_cp

cutstock.sub_cp = ws.add_checkpoint()

Definition at line 116 of file cutstock.py.

◆ sub_job

cutstock.sub_job = ws.add_job_from_string(get_sub_model())

Definition at line 117 of file cutstock.py.

◆ sub_mi

cutstock.sub_mi = sub_cp.add_modelinstance()

Definition at line 119 of file cutstock.py.

◆ value

cutstock.value

Definition at line 94 of file cutstock.py.

◆ w

dictionary cutstock.w = {"i1": 47, "i2": 36, "i3": 31, "i4": 14}

Definition at line 86 of file cutstock.py.

◆ width

cutstock.width = cutstock_data.add_parameter("w", 1, "width")

Definition at line 92 of file cutstock.py.

◆ widths

cutstock.widths = cutstock_data.add_set("i", 1, "widths")

Definition at line 89 of file cutstock.py.

◆ ws

cutstock.ws = GamsWorkspace(system_directory = sys.argv[1])

Definition at line 72 of file cutstock.py.