9 import gamstransfer
as gt
22 a(i) "capacity of plant i in cases"
23 b(j) "demand at market j in cases"
24 d(i,j) "distance in thousands of miles"
25 Scalar f "freight in dollars per case per thousand miles";
27 $if not set gdxincname $abort "no include file name for data file provided"
32 Parameter c(i,j) "transport cost in thousands of dollars per case";
33 c(i,j) = f * d(i,j) / 1000;
36 x(i,j) "shipment quantities in cases"
37 z "total transportation costs in thousands of dollars";
42 cost "define objective function"
43 supply(i) "observe supply limit at plant i"
44 demand(j) "satisfy demand at market j";
47 bmult "demand multiplier" /1/;
49 cost .. z =e= sum((i,j), c(i,j)*x(i,j));
51 supply(i) .. sum(j, x(i,j)) =l= a(i);
53 demand(j) .. sum(i, x(i,j)) =g= bmult*b(j);
55 Model transport /all/;
57 Solve transport using lp minimizing z;'''
59 if __name__ ==
"__main__":
61 ws = GamsWorkspace(system_directory = sys.argv[1])
63 ws = GamsWorkspace(working_directory=
'.')
66 i = m.addSet(
'i', records=[
"Seattle",
"San-Diego" ])
67 j = m.addSet(
'j', records=[
"New-York",
"Chicago",
"Topeka" ])
68 m.addParameter(
'a', [i], records=np.array([350, 600]))
69 m.addParameter(
'b', [j], records=np.array([325, 300, 275]))
70 m.addParameter(
'd', [i,j], records=np.array([[2.5, 1.7, 1.8],
72 m.addParameter(
'f', records=90)
75 opt = ws.add_options()
76 opt.defines[
"gdxincname"] =
"gtin.gdx"
77 opt.all_model_types =
"xpress"
80 m.write(os.path.join(ws.working_directory, opt.defines[
"gdxincname"]))
81 cp = ws.add_checkpoint()
82 tm.run(gams_options=opt, checkpoint=cp, create_out_db=
False)
83 tmOut = gt.Container(os.path.join(ws.working_directory, opt.gdx))
86 mi = cp.add_modelinstance()
87 bmult = mi.sync_db.add_parameter(
"bmult", 0,
"demand multiplier")
88 opt = ws.add_options()
89 opt.all_model_types =
"cplex"
92 mi.instantiate(
"transport use lp min z", GamsModifier(bmult), opt)
94 bmult.add_record().value = 1.0
95 bmultlist = [ 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3 ]
98 gt_bmult = m.addParameter(
'bmult', records=1.0);
100 gt_bmult.setRecords(b)
103 mOut = gt.Container(mi.sync_db)
104 print(
"Scenario bmult=" + str(b) +
":")
105 print(
" Modelstatus: " + str(mi.model_status))
106 print(
" Solvestatus: " + str(mi.solver_status))
107 print(
" Obj: " + str(mOut.data[
'z'].records[
'level'].iloc[0]))
110 mi = cp.add_modelinstance()
111 x = mi.sync_db.add_variable(
"x", 2, VarType.Positive)
112 xup = mi.sync_db.add_parameter(
"xup", 2,
"upper bound on x")
115 mi.instantiate(
"transport use lp min z", GamsModifier(x, UpdateAction.Upper, xup))
119 gt_xup = m.addParameter(
'xup', [
'i',
'j']);
120 for i
in tmOut.data[
'i'].records[
'i_0']:
121 for j
in tmOut.data[
'j'].records[
'j_0']:
122 gt_xup.setRecords([(i,j,-0.0)])
125 mOut = gt.Container(mi.sync_db)
126 print(
"Scenario link blocked: " + i +
" - " + j)
127 print(
" Modelstatus: " + str(mi.model_status))
128 print(
" Solvestatus: " + str(mi.solver_status))
129 print(
" Obj: " + str(mOut.data[
'z'].records[
'level'].iloc[0]))