transport5.py
Go to the documentation of this file.
8
9from __future__ import print_function
10from gams import *
11import sys
12
14 return '''
15 Sets
16 i canning plants / seattle, san-diego /
17 j markets / new-york, chicago, topeka / ;
18
19 Parameters
20
21 a(i) capacity of plant i in cases
22 / seattle 350
23 san-diego 600 /
24
25 b(j) demand at market j in cases
26 / new-york 325
27 chicago 300
28 topeka 275 / ;
29
30 Table d(i,j) distance in thousands of miles
31 new-york chicago topeka
32 seattle 2.5 1.7 1.8
33 san-diego 2.5 1.8 1.4 ;
34
35
36
37
38
39 Scalar f freight in dollars per case per thousand miles /90/ ;
40 Scalar bmult demand multiplier /1/;
41
42 Parameter c(i,j) transport cost in thousands of dollars per case ;
43
44 c(i,j) = f * d(i,j) / 1000 ;
45
46 Variables
47 x(i,j) shipment quantities in cases
48 z total transportation costs in thousands of dollars ;
49
50 Positive Variable x ;
51
52 Equations
53 cost define objective function
54 supply(i) observe supply limit at plant i
55 demand(j) satisfy demand at market j ;
56
57 cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
58
59 supply(i) .. sum(j, x(i,j)) =l= a(i) ;
60
61 demand(j) .. sum(i, x(i,j)) =g= bmult*b(j) ;
62
63 Model transport /all/ ;
64 Scalar ms 'model status', ss 'solve status'; '''
65
66
67if __name__ == "__main__":
68 if len(sys.argv) > 1:
69 ws = GamsWorkspace(system_directory = sys.argv[1])
70 else:
71 ws = GamsWorkspace()
72
73 cp = ws.add_checkpoint()
74
75 # initialize a GAMSCheckpoint by running a GAMSJob
76 t5 = ws.add_job_from_string(get_model_text())
77 t5.run(checkpoint=cp)
78
79 bmultlist = [ 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3 ]
80
81 # create a new GAMSJob that is initialized from the GAMSCheckpoint
82 for b in bmultlist:
83 t5 = ws.add_job_from_string("bmult=" + str(b) + "; solve transport min z use lp; ms=transport.modelstat; ss=transport.solvestat;", cp)
84 t5.run()
85 print("Scenario bmult=" + str(b) + ":")
86 print(" Modelstatus: " + str(t5.out_db["ms"].find_record().value))
87 print(" Solvestatus: " + str(t5.out_db["ss"].find_record().value))
88 print(" Obj: " + str(t5.out_db["z"].find_record().level))
89
90
def get_model_text()
Definition: transport5.py:13