simple_cutstock.py
Go to the documentation of this file.
10
11from __future__ import print_function
12import sys
13from cutstock_class import Cutstock
14from gams import *
15
16d = { "i1": 97, "i2": 610, "i3": 395, "i4": 211 }
17w = { "i1": 47, "i2": 36, "i3": 31, "i4": 14 }
18r = 100 #raw width
19
20if __name__ == "__main__":
21 if len(sys.argv) > 1:
22 ws = GamsWorkspace(system_directory = sys.argv[1])
23 else:
24 ws = GamsWorkspace()
25
26 cs = Cutstock(ws)
27 cs.raw_width.add_record().value = r
28 for i in d:
29 cs.widths.add_record(i)
30 for k,v in iter(d.items()):
31 cs.demand.add_record(k).value = v
32 for k,v in iter(w.items()):
33 cs.width.add_record(k).value = v
34 cs.opt.all_model_types = "cplex"
35
36 try:
37 cs.run(output=sys.stdout)
38 for rep in cs.pat_rep:
39 print(rep.key(0) + ", pattern " + rep.key(1) + ": " + str(rep.value))
40
41 except GamsException as e:
42 raise Exception("Problem in GAMS: " + str(e))
43 except Exception as e:
44 raise Exception("System Error: " + str(e))