11from threading
import Lock, Thread
12from gams
import GamsWorkspace, GamsModifier
16 i 'canning plants' / seattle, san-diego /
17 j
'markets' / new-york, chicago, topeka /;
20 a(i)
'capacity of plant i in cases'
24 b(j)
'demand at market j in cases'
29Table d(i,j)
'distance in thousands of miles'
30 new-york chicago topeka
32 san-diego 2.5 1.8 1.4;
35 f
'freight in dollars per case per thousand miles' / 90 /
36 bmult
'demand multiplier' / 1 /;
38Parameter c(i,j)
'transport cost in thousands of dollars per case';
39c(i,j) = f*d(i,j)/1000;
42 x(i,j)
'shipment quantities in cases'
43 z
'total transportation costs in thousands of dollars';
48 cost
'define objective function'
49 supply(i)
'observe supply limit at plant i'
50 demand(j)
'satisfy demand at market j';
52cost.. z =e= sum((i,j), c(i,j)*x(i,j));
54supply(i).. sum(j, x(i,j)) =l= a(i);
56demand(j).. sum(i, x(i,j)) =g= bmult*b(j);
62def scen_solve(checkpoint, bmult_list, list_lock, io_lock):
64 mi = checkpoint.add_modelinstance()
66 bmult = mi.sync_db.add_parameter("bmult", 0,
"demand multiplier")
67 opt = ws.add_options()
68 opt.all_model_types =
"cplex"
71 mi.instantiate(
"transport use lp min z", GamsModifier(bmult), opt)
72 bmult.add_record().value = 1.0
82 bmult.first_record().value = b
87 print(f
"Scenario bmult={b}:")
88 print(f
" Modelstatus: {mi.model_status}")
89 print(f
" Solvestatus: {mi.solver_status}")
90 print(f
" Obj: {mi.sync_db['z'].first_record().level}")
94if __name__ ==
"__main__":
95 sys_dir = sys.argv[1]
if len(sys.argv) > 1
else None
96 ws = GamsWorkspace(system_directory=sys_dir)
98 cp = ws.add_checkpoint()
101 job = ws.add_job_from_string(GAMS_MODEL)
102 job.run(checkpoint=cp)
104 bmult_list = [1.3, 1.2, 1.1, 1.0, 0.9, 0.8, 0.7, 0.6]
113 for i
in range(nr_workers):
115 target=scen_solve, args=(cp, bmult_list, list_lock, io_lock)
118 for i
in range(nr_workers):