transport13.py
Go to the documentation of this file.
6 
7 import sys
8 from gams import *
9 from transport_class import Transport
10 
11 plants = ["Seattle", "San-Diego"]
12 markets = ["New-York", "Chicago", "Topeka"]
13 capacity = {"Seattle": 350.0, "San-Diego": 600.0}
14 demand = {"New-York": 325.0, "Chicago": 300.0, "Topeka": 275.0}
15 distance = {("Seattle", "New-York"): 2.5, \
16  ("Seattle", "Chicago"): 1.7, \
17  ("Seattle", "Topeka"): 1.8, \
18  ("San-Diego", "New-York"): 2.5, \
19  ("San-Diego", "Chicago"): 1.8, \
20  ("San-Diego", "Topeka"): 1.4 \
21  }
22 
23 if __name__ == "__main__":
24  if len(sys.argv) > 1:
25  ws = GamsWorkspace(system_directory = sys.argv[1])
26  else:
27  ws = GamsWorkspace()
28 
29  t = Transport(ws)
30 
31  for p in plants:
32  t.i.add_record(p)
33  for m in markets:
34  t.j.add_record(m)
35  for p in plants:
36  t.a.add_record(p).value = capacity[p]
37  for m in markets:
38  t.b.add_record(m).value = demand[m]
39  for k, v in iter(distance.items()):
40  t.d.add_record(k).value = v
41 
42  t.f.add_record().value = 90
43  t.opt.all_model_types = "cplex"
44  t.run(output=sys.stdout)
45 
46  print("Objective: " + str(t.z.first_record().level))
47 
48  for rec in t.x:
49  print(rec)