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