10 from gams
import GamsWorkspace, GamsModifier
17 i canning plants / seattle, san-diego /
18 j markets / new-york, chicago, topeka / ;
22 a(i) capacity of plant i in cases
26 b(j) demand at market j in cases
31 Table d(i,j) distance in thousands of miles
32 new-york chicago topeka
34 san-diego 2.5 1.8 1.4 ;
36 Scalar f freight in dollars per case per thousand miles /90/ ;
37 Scalar bmult demand multiplier /1/;
39 Parameter c(i,j) transport cost in thousands of dollars per case ;
41 c(i,j) = f * d(i,j) / 1000 ;
44 x(i,j) shipment quantities in cases
45 z total transportation costs in thousands of dollars ;
50 cost define objective function
51 supply(i) observe supply limit at plant i
52 demand(j) satisfy demand at market j ;
54 cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
56 supply(i) .. sum(j, x(i,j)) =l= a(i) ;
58 demand(j) .. sum(i, x(i,j)) =g= bmult*b(j) ;
60 Model transport /all/ ;
64 def scen_solve(workspace, checkpoint, bmult_list, list_lock, io_lock):
66 mi = checkpoint.add_modelinstance()
68 bmult = mi.sync_db.add_parameter(
"bmult", 0,
"demand multiplier")
69 opt = ws.add_options()
70 opt.all_model_types =
"cplex"
73 mi.instantiate(
"transport use lp min z", GamsModifier(bmult), opt)
74 bmult.add_record().value = 1.0
79 if 0 == len(bmult_list):
84 bmult.first_record().value = b
89 print(
"Scenario bmult=" + str(b) +
":")
90 print(
" Modelstatus: " + str(mi.model_status))
91 print(
" Solvestatus: " + str(mi.solver_status))
92 print(
" Obj: " + str(mi.sync_db.get_variable(
"z").find_record().level))
95 if __name__ ==
"__main__":
97 ws = GamsWorkspace(system_directory = sys.argv[1])
101 cp = ws.add_checkpoint()
105 t8.run(checkpoint=cp)
107 bmult_list = [ 1.3, 1.2, 1.1, 1.0, 0.9, 0.8, 0.7, 0.6 ]
110 list_lock = threading.Lock()
111 io_lock = threading.Lock()
116 for i
in range(nr_workers):
117 threads[i] = threading.Thread(target=scen_solve, args=(ws, cp, bmult_list, list_lock, io_lock))
119 for i
in range(nr_workers):