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

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