System.Collections.Generic;
22 static voidMain(
string[] args)
25 if(Environment.GetCommandLineArgs().Length > 1)
26ws =
new GAMSWorkspace(systemDirectory: Environment.GetCommandLineArgs()[1]);
31List<string> plants =
newList<string>()
33 "Seattle",
"San-Diego" 35List<string> markets =
newList<string>()
37 "New-York",
"Chicago",
"Topeka" 39Dictionary<string, double> capacity =
newDictionary<string, double>()
41{
"Seattle", 350.0 }, {
"San-Diego", 600.0 }
43Dictionary<string, double> demand =
newDictionary<string, double>()
45{
"New-York", 325.0 }, {
"Chicago", 300.0 }, {
"Topeka", 275.0 }
47Dictionary<Tuple<string,string>,
double> distance =
newDictionary<Tuple<string,string>,
double>()
49{
newTuple<string,string> (
"Seattle",
"New-York"), 2.5 },
50{
newTuple<string,string> (
"Seattle",
"Chicago"), 1.7 },
51{
newTuple<string,string> (
"Seattle",
"Topeka"), 1.8 },
52{
newTuple<string,string> (
"San-Diego",
"New-York"), 2.5 },
53{
newTuple<string,string> (
"San-Diego",
"Chicago"), 1.8 },
54{
newTuple<string,string> (
"San-Diego",
"Topeka"), 1.4 }
61 foreach(
stringp
inplants)
64 GAMSSetj = db.AddSet(
"j", 1,
"markets");
65 foreach(
stringm
inmarkets)
68 GAMSParametera = db.AddParameter(
"a",
"capacity of plant i in cases", i);
69 foreach(
stringp
inplants)
72 GAMSParameterb = db.AddParameter(
"b",
"demand at market j in cases", j);
73 foreach(
stringm
inmarkets)
76 GAMSParameterd = db.AddParameter(
"d",
"distance in thousands of miles", i, j);
77 foreach(Tuple<string,string> t
indistance.Keys)
80 GAMSParameterf = db.AddParameter(
"f",
"freight in dollars per case per thousand miles");
84 GAMSJobt4 = ws.AddJobFromString(GetModelText());
87opt.
Defines.Add(
"gdxincname", db.Name);
88opt.AllModelTypes =
"xpress";
91Console.WriteLine(
"x("+ rec.Key(0) +
","+ rec.Key(1) +
"): level="+ rec.
Level+
" marginal="+ rec.
Marginal);
95 staticString GetModelText()
103 a(i) capacity of plant i in cases 104 b(j) demand at market j in cases 105 d(i,j) distance in thousands of miles 106 Scalar f freight in dollars per case per thousand miles; 108$if not set gdxincname $abort 'no include file name for data file provided' 113 Parameter c(i,j) transport cost in thousands of dollars per case ; 115 c(i,j) = f * d(i,j) / 1000 ; 118 x(i,j) shipment quantities in cases 119 z total transportation costs in thousands of dollars ; 121 Positive Variable x ; 124 cost define objective function 125 supply(i) observe supply limit at plant i 126 demand(j) satisfy demand at market j ; 128 cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ; 130 supply(i) .. sum(j, x(i,j)) =l= a(i) ; 132 demand(j) .. sum(i, x(i,j)) =g= b(j) ; 134 Model transport /all/ ; 136 Solve transport using lp minimizing z ;GAMSVariable GetVariable(string variableIdentifier)
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)
GAMSDatabase AddDatabase(string databaseName=null, string inModelName=null)
This is the 4th model in a series of tutorial examples. Here we show: How to define data using C# dat...
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4