transport6.py
Go to the documentation of this file.
6
7 from gams import *
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  Scalar f freight in dollars per case per thousand miles /90/ ;
34  Scalar bmult demand multiplier /1/;
35
36  Parameter c(i,j) transport cost in thousands of dollars per case ;
37
38  c(i,j) = f * d(i,j) / 1000 ;
39
40  Variables
41  x(i,j) shipment quantities in cases
42  z total transportation costs in thousands of dollars ;
43
44  Positive Variable x ;
45
46  Equations
47  cost define objective function
48  supply(i) observe supply limit at plant i
49  demand(j) satisfy demand at market j ;
50
51  cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
52
53  supply(i) .. sum(j, x(i,j)) =l= a(i) ;
54
55  demand(j) .. sum(i, x(i,j)) =g= bmult*b(j) ;
56
57  Model transport /all/ ;
58  Scalar ms 'model status', ss 'solve status'; '''
59
60
61 def run_scenario(workspace, checkpoint, io_lock, b):
62  t6 = workspace.add_job_from_string("bmult=" + str(b) + "; solve transport min z use lp; ms=transport.modelstat; ss=transport.solvestat;", checkpoint)
63  t6.run()
64  # we need to make the ouput a critical section to avoid messed up report informations
65  io_lock.acquire()
66  print("Scenario bmult=" + str(b) + ":")
67  print(" Modelstatus: " + str(t6.out_db["ms"][()].value))
68  print(" Solvestatus: " + str(t6.out_db["ss"][()].value))
69  print(" Obj: " + str(t6.out_db["z"][()].level))
70  io_lock.release()
71
72
73 if __name__ == "__main__":
74  if len(sys.argv) > 1:
75  ws = GamsWorkspace(system_directory = sys.argv[1])
76  else:
77  ws = GamsWorkspace()
78
80
81  # initialize a GAMSCheckpoint by running a GAMSJob
83  t6.run(checkpoint=cp)
84  bmultlist = [ 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3 ]
85
86  # run multiple parallel jobs using the created GAMSCheckpoint
89  for b in bmultlist: