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

General Information and Sales
U.S. (+1) 202 342-0180
Europe: (+49) 221 949-9170