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 15 of file cutstock.py.

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

◆ get_sub_model()

def cutstock.get_sub_model ( )

Definition at line 44 of file cutstock.py.

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

Variable Documentation

◆ aip

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

Definition at line 156 of file cutstock.py.

◆ all_model_types

cutstock.all_model_types

Definition at line 77 of file cutstock.py.

◆ cutstock_data

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

Definition at line 76 of file cutstock.py.

◆ d

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

Definition at line 84 of file cutstock.py.

◆ databases

cutstock.databases

Definition at line 103 of file cutstock.py.

◆ demand

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

Definition at line 90 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 121 of file cutstock.py.

◆ end

cutstock.end

Definition at line 155 of file cutstock.py.

◆ master_cp

cutstock.master_cp = ws.add_checkpoint()

Definition at line 101 of file cutstock.py.

◆ master_init_job

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

Definition at line 102 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 104 of file cutstock.py.

◆ maxpattern

int cutstock.maxpattern = 35

Definition at line 79 of file cutstock.py.

◆ opt

cutstock.opt = ws.add_options()

Definition at line 75 of file cutstock.py.

◆ optcr

cutstock.optcr

Definition at line 78 of file cutstock.py.

◆ pattern

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

Definition at line 106 of file cutstock.py.

◆ pattern_added

bool cutstock.pattern_added = True

Definition at line 125 of file cutstock.py.

◆ pattern_count

int cutstock.pattern_count = 0

Definition at line 110 of file cutstock.py.

◆ pattern_data

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

Definition at line 107 of file cutstock.py.

◆ r

int cutstock.r = 100

Definition at line 86 of file cutstock.py.

◆ raw_width

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

Definition at line 89 of file cutstock.py.

◆ s

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

Definition at line 141 of file cutstock.py.

◆ sub_cp

cutstock.sub_cp = ws.add_checkpoint()

Definition at line 115 of file cutstock.py.

◆ sub_job

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

Definition at line 116 of file cutstock.py.

◆ sub_mi

cutstock.sub_mi = sub_cp.add_modelinstance()

Definition at line 118 of file cutstock.py.

◆ value

cutstock.value

Definition at line 93 of file cutstock.py.

◆ w

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

Definition at line 85 of file cutstock.py.

◆ width

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

Definition at line 91 of file cutstock.py.

◆ widths

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

Definition at line 88 of file cutstock.py.

◆ ws

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

Definition at line 71 of file cutstock.py.