8from threading
import Lock, Thread
9from gams
import GamsWorkspace
14 self.
_ws = GamsWorkspace(system_directory=system_directory)
18 db = self.
_ws.add_database()
20 f = db.add_parameter(
"f", 0,
"freight in dollars per case per thousand miles")
21 f.add_record().value = 90 * bmult
22 job = self.
_ws.add_job_from_string(Optimizer.GAMS_MODEL)
23 opt = self.
_ws.add_options()
24 opt.defines[
"gdxincname"] = db.name
25 job.run(opt, databases=db)
26 return job.out_db[
"z"].first_record().level
30 i 'canning plants' / seattle, san-diego /
31 j
'markets' / new-york, chicago, topeka /;
34 a(i)
'capacity of plant i in cases'
38 b(j)
'demand at market j in cases'
43Table d(i,j)
'distance in thousands of miles'
44 new-york chicago topeka
46 san-diego 2.5 1.8 1.4;
48Scalar f
'freight in dollars per case per thousand miles';
50$
if not set gdxincname $abort
'no include file name for data file provided'
55Parameter c(i,j)
'transport cost in thousands of dollars per case';
56c(i,j) = f*d(i,j)/1000;
59 x(i,j)
'shipment quantities in cases'
60 z
'total transportation costs in thousands of dollars';
65 cost
'define objective function'
66 supply(i)
'observe supply limit at plant i'
67 demand(j)
'satisfy demand at market j';
69cost.. z =e= sum((i,j), c(i,j)*x(i,j));
71supply(i).. sum(j, x(i,j)) =l= a(i);
73demand(j).. sum(i, x(i,j)) =g= b(j);
77solve transport using lp minimizing z;
83if __name__ == "__main__":
84 sys_dir = sys.argv[1] if len(sys.argv) > 1
else None
86 bmult_list = [0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3]
90 obj = optimizer.solve(bmult, lock)
92 print(f
"Scenario bmult={bmult}, Obj:{obj}")
95 for bmult
in bmult_list:
96 t = Thread(target=run_scenario, args=(optimizer, bmult, lock))
def __init__(self, system_directory=None)
def solve(self, bmult, lock)
def run_scenario(optimizer, bmult, lock)