2using System.Collections.Generic;
21 static void Main(
string[] args)
26 string wDir = Path.Combine(
".",
"tmp");
27 CreateSaveRestart(Path.Combine(wDir,
"tbase"));
30 List<string> plants =
new List<string>()
32 "Seattle",
"San-Diego"
34 List<string> markets =
new List<string>()
36 "New-York",
"Chicago",
"Topeka"
38 Dictionary<string, double> capacity =
new Dictionary<string, double>()
40 {
"Seattle", 350.0 }, {
"San-Diego", 600.0 }
42 Dictionary<string, double> demand =
new Dictionary<string, double>()
44 {
"New-York", 325.0 }, {
"Chicago", 300.0 }, {
"Topeka", 275.0 }
46 Dictionary<Tuple<string, string>,
double> distance =
new Dictionary<Tuple<string, string>,
double>()
48 {
new Tuple<string,string> (
"Seattle",
"New-York"), 2.5 },
49 {
new Tuple<string,string> (
"Seattle",
"Chicago"), 1.7 },
50 {
new Tuple<string,string> (
"Seattle",
"Topeka"), 1.8 },
51 {
new Tuple<string,string> (
"San-Diego",
"New-York"), 2.5 },
52 {
new Tuple<string,string> (
"San-Diego",
"Chicago"), 1.8 },
53 {
new Tuple<string,string> (
"San-Diego",
"Topeka"), 1.4 }
57 if (Environment.GetCommandLineArgs().Length > 1)
58 ws =
new GAMSWorkspace(workingDirectory: wDir, systemDirectory: Environment.GetCommandLineArgs()[1]);
65 foreach (
string p
in plants)
68 GAMSSet j = db.AddSet(
"j", 1,
"markets");
69 foreach (
string m
in markets)
72 GAMSParameter a = db.AddParameter(
"a",
"capacity of plant i in cases", i);
73 foreach (
string p
in plants)
76 GAMSParameter b = db.AddParameter(
"b",
"demand at market j in cases", j);
77 foreach (
string m
in markets)
80 GAMSParameter d = db.AddParameter(
"d",
"distance in thousands of miles", i, j);
81 foreach (Tuple<string, string> t
in distance.Keys)
84 GAMSParameter f = db.AddParameter(
"f",
"freight in dollars per case per thousand miles");
91 GAMSJob t4 = ws.AddJobFromString(GetModelText(), cpBase);
92 opt.
Defines.Add(
"gdxincname", db.Name);
93 opt.AllModelTypes =
"xpress";
96 Console.WriteLine(
"x(" + rec.
Key(0) +
"," + rec.
Key(1) +
"): level=" + rec.Level +
" marginal=" + rec.
Marginal);
100 static void CreateSaveRestart(
string cpFileName)
103 if (Environment.GetCommandLineArgs().Length > 1)
104 ws =
new GAMSWorkspace(workingDirectory: Path.GetDirectoryName(cpFileName), systemDirectory: Environment.GetCommandLineArgs()[1]);
106 ws =
new GAMSWorkspace(workingDirectory: Path.GetDirectoryName(cpFileName));
119 static String GetBaseModelText()
124 i(*) canning plants / /
128 a(i) capacity of plant i in cases / /
129 b(j) demand at market j in cases / /
130 d(i,j) distance in thousands of miles / /
131 Scalar f freight in dollars per case per thousand miles /0/;
133 Parameter c(i,j) transport cost in thousands of dollars per case ;
135 c(i,j) = f * d(i,j) / 1000 ;
138 x(i,j) shipment quantities in cases
139 z total transportation costs in thousands of dollars ;
141 Positive Variable x ;
144 cost define objective function
145 supply(i) observe supply limit at plant i
146 demand(j) satisfy demand at market j ;
148 cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ;
150 supply(i) .. sum(j, x(i,j)) =l= a(i) ;
152 demand(j) .. sum(i, x(i,j)) =g= b(j) ;
154 Model transport /all/ ;
156 Solve transport using lp minimizing z ;
163 static String GetModelText()
166$if not set gdxincname $abort 'no include file name for data file provided'
GAMSSet AddSet(string identifier, int dimension, string explanatoryText="", SetType setType=SetType.multi)
void Run(GAMSOptions gamsOptions=null, GAMSCheckpoint checkpoint=null, TextWriter output=null, Boolean createOutDB=true)
Dictionary< string, string > Defines
new GAMSParameterRecord AddRecord(params string[] keys)
new GAMSSetRecord AddRecord(params string[] keys)
GAMSJob AddJobFromString(string gamsSource, GAMSCheckpoint checkpoint=null, string jobName=null)
GAMSDatabase AddDatabase(string databaseName=null, string inModelName=null)
GAMSCheckpoint AddCheckpoint(string checkpointName=null)
GAMSOptions AddOptions(GAMSOptions optFrom=null)
This is the 11th model in a series of tutorial examples. Here we show: How to create and use a save/r...