10 from multiprocessing
import Lock, Process, Queue
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(cp_file, bmult_queue, queue_lock, io_lock):
66 cp = ws.add_checkpoint(cp_file)
67 mi = cp.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 bmult_queue.empty():
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])
99 ws = GamsWorkspace(debug=DebugLevel.KeepFiles)
101 cp = ws.add_checkpoint()
105 t8.run(checkpoint=cp)
106 cp_file = os.path.join(ws.working_directory, cp.name) +
".g00"
108 bmult_queue = Queue()
109 bmult_data = [ 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3 ]
110 for bmult
in bmult_data:
111 bmult_queue.put(bmult)
119 for i
in range(nr_workers):
120 processes[i] = Process(target=scen_solve, args=(cp_file, bmult_queue, queue_lock, io_lock))
122 for i
in range(nr_workers):