3using System.Collections.Generic;
20 static void Main(
string[] args)
22 #region Static data section
23 List<string> plants =
new List<string>()
25 "Seattle",
"San-Diego"
27 List<string> markets =
new List<string>()
29 "New-York",
"Chicago",
"Topeka"
31 Dictionary<string, double> capacity =
new Dictionary<string, double>()
33 {
"Seattle", 350.0 }, {
"San-Diego", 600.0 }
35 Dictionary<string, double> demand =
new Dictionary<string, double>()
37 {
"New-York", 325.0 }, {
"Chicago", 300.0 }, {
"Topeka", 275.0 }
39 Dictionary<Tuple<string, string>,
double> distance =
new Dictionary<Tuple<string, string>,
double>()
41 {
new Tuple<string,string> (
"Seattle",
"New-York"), 2.5 },
42 {
new Tuple<string,string> (
"Seattle",
"Chicago"), 1.7 },
43 {
new Tuple<string,string> (
"Seattle",
"Topeka"), 1.8 },
44 {
new Tuple<string,string> (
"San-Diego",
"New-York"), 2.5 },
45 {
new Tuple<string,string> (
"San-Diego",
"Chicago"), 1.8 },
46 {
new Tuple<string,string> (
"San-Diego",
"Topeka"), 1.4 }
48 #endregion Static data section
52 if (Environment.GetCommandLineArgs().Length > 1)
53 ws =
new GAMSWorkspace(systemDirectory: Environment.GetCommandLineArgs()[1]);
59 #region Input data binding
60 foreach (
string p
in plants)
63 foreach (
string m
in markets)
66 foreach (
string p
in plants)
67 t.a.AddRecord(p).Value = capacity[p];
69 foreach (
string m
in markets)
70 t.b.AddRecord(m).Value = demand[m];
72 foreach (Tuple<string, string> dis
in distance.Keys)
73 t.d.AddRecord(dis.Item1, dis.Item2).Value = distance[dis];
75 t.f.AddRecord().Value = 90;
76 #endregion Input data binding
78 t.opt.AllModelTypes =
"cplex";
80 t.Run(output: Console.Out);
82 #region Output data binding
83 Console.WriteLine(
"Objective: " + t.z.FirstRecord().Level);
86 Console.WriteLine(
"x(" + rec.Key(0) +
"," + rec.Key(1) +
"): level=" + rec.
Level +
" marginal=" + rec.
Marginal);
87 #endregion Output data binding
110 private string GetModelSource()
118 a(i) capacity of plant i in cases
119 b(j) demand at market j in cases
120 d(i,j) distance in thousands of miles
121 Scalar f freight in dollars per case per thousand miles;
123$if not set dbIn1 $abort 'no file name for in-database 1 file provided'
127$if not set dbIn2 $abort 'no file name for in-database 2 file provided'
132 Parameter c(i,j) transport cost in thousands of dollars per case ;
134 c(i,j) = f * d(i,j) / 1000 ;
137 x(i,j) shipment quantities in cases
138 z total transportation costs in thousands of dollars ;
140 Positive Variable x ;
143 cost define objective function
144 supply(i) observe supply limit at plant i
145 demand(j) satisfy demand at market j ;
147 cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
149 supply(i) .. sum(j, x(i,j)) =l= a(i) ;
151 demand(j) .. sum(i, x(i,j)) =g= b(j) ;
153 Model transport /all/ ;
155 Solve transport using lp minimizing z ;
157$if not set dbOut1 $abort 'no file name for out-database 1 file provided'
158 execute_unload '%dbOut1%', x, z;
174 fopt.AllModelTypes =
"Cplex";
175 fopt.
Defines.Add(
"dbOut1",
"dbOut1");
177 fi = fDbIn1.
AddSet(
"i",
"canning plants");
178 fj = fDbIn1.
AddSet(
"j",
"markets");
179 fa = fDbIn1.
AddParameter(
"a",
"capacity of plant i in cases", fi);
180 fb = fDbIn1.
AddParameter(
"b",
"demand at market j in cases", fj);
181 fd = fDbIn1.
AddParameter(
"d",
"distance in thousands of miles", fi, fj);
182 ff = fDbIn2.
AddParameter(
"f",
"freight in dollars per case per thousand miles");
197 job.
Run(fopt, checkpoint, output,
false, fDbIn1, fDbIn2);
204 #region Data input symbols
209 {
get {
return fi; } }
215 {
get {
return fj; } }
221 {
get {
return fa; } }
227 {
get {
return fb; } }
233 {
get {
return fd; } }
239 {
get {
return ff; } }
240 #endregion Data input symbols
242 #region Data output symbols
247 {
get {
return fx; } }
253 {
get {
return fz; } }
254 #endregion Data output symbols
260 {
get {
return fopt; } }
GAMSVariable GetVariable(string variableIdentifier)
GAMSSet AddSet(string identifier, int dimension, string explanatoryText="", SetType setType=SetType.multi)
GAMSParameter AddParameter(string identifier, int dimension, string explanatoryText="")
void Run(GAMSOptions gamsOptions=null, GAMSCheckpoint checkpoint=null, TextWriter output=null, Boolean createOutDB=true)
Dictionary< string, string > Defines
GAMSJob AddJobFromString(string gamsSource, GAMSCheckpoint checkpoint=null, string jobName=null)
GAMSDatabase AddDatabaseFromGDX(string gdxFileName, string databaseName=null, string inModelName=null)
GAMSDatabase AddDatabase(string databaseName=null, string inModelName=null)
GAMSOptions AddOptions(GAMSOptions optFrom=null)
This is the 13th model in a series of tutorial examples. Here we show: How to run a GAMSJob using a w...
Wrapper class for GAMS trnsport model.
GAMSVariable z
z: total transportation costs in thousands of dollars
Transport(GAMSWorkspace ws)
A Transportation Problem.
GAMSParameter d
d(i,j): distance in thousands of miles
GAMSOptions opt
Options for the execution of the trnsport model.
GAMSVariable x
x(i,j): shipment quantities in cases
GAMSParameter a
a(i): capacity of plant i in cases
GAMSParameter b
b(i): demand at market j in cases
GAMSParameter f
f: freight in dollars per case per thousand miles
void Run(GAMSCheckpoint checkpoint=null, TextWriter output=null)
Executes the trnsport model.
GAMSSet i
i(i): canning plants