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