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