Loading...
Searching...
No Matches
simple_cutstock.py
Go to the documentation of this file.
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 cs = Cutstock(sys_dir)
17
18 r = 100 # raw width
19 cs.raw_width.add_record().value = r
20
21 d = {"i1": 97, "i2": 610, "i3": 395, "i4": 211}
22 for i in d:
23 cs.widths.add_record(i)
24 for k, v in d.items():
25 cs.demand.add_record(k).value = v
26
27 w = {"i1": 47, "i2": 36, "i3": 31, "i4": 14}
28 for k, v in w.items():
29 cs.width.add_record(k).value = v
30 cs.opt.all_model_types = "cplex"
31
32 try:
33 cs.run(output=sys.stdout)
34 for rep in cs.pat_rep:
35 print(f"{rep.key(0)}, pattern {rep.key(1)}: {rep.value}")
36 except GamsException as e:
37 raise Exception(f"Error in GAMS: {e}")
38 except Exception as e:
39 raise Exception(f"System Error: {e}")