System.Collections.Generic;
6usingSystem.Runtime.Remoting.Channels;
7usingSystem.Runtime.Remoting.Channels.Tcp;
29 static intMain(
string[] args)
32 boolRunLocal =
false;
35List<string> plants =
newList<string>()
37 "Seattle",
"San-Diego" 39List<string> markets =
newList<string>()
41 "New-York",
"Chicago",
"Topeka" 43Dictionary<string, double> capacity =
newDictionary<string, double>()
45{
"Seattle", 350.0 }, {
"San-Diego", 600.0 }
47Dictionary<string, double> demand =
newDictionary<string, double>()
49{
"New-York", 325.0 }, {
"Chicago", 300.0 }, {
"Topeka", 275.0 }
51Dictionary<Tuple<string, string>,
double> distance =
newDictionary<Tuple<string, string>,
double>()
53{
newTuple<string,string> (
"Seattle",
"New-York"), 2.5 },
54{
newTuple<string,string> (
"Seattle",
"Chicago"), 1.7 },
55{
newTuple<string,string> (
"Seattle",
"Topeka"), 1.8 },
56{
newTuple<string,string> (
"San-Diego",
"New-York"), 2.5 },
57{
newTuple<string,string> (
"San-Diego",
"Chicago"), 1.8 },
58{
newTuple<string,string> (
"San-Diego",
"Topeka"), 1.4 }
67 foreach(
stringp
inplants)
70 GAMSSetj = db.AddSet(
"j", 1,
"markets");
71 foreach(
stringm
inmarkets)
74 GAMSParametera = db.AddParameter(
"a", 1,
"capacity of plant i in cases");
75 foreach(
stringp
inplants)
78 GAMSParameterb = db.AddParameter(
"b", 1,
"demand at market j in cases");
79 foreach(
stringm
inmarkets)
82 GAMSParameterd = db.AddParameter(
"d", 2,
"distance in thousands of miles");
83 foreach(Tuple<string, string> t
indistance.Keys)
86 GAMSParameterf = db.AddParameter(
"f", 0,
"freight in dollars per case per thousand miles");
90opt.AllModelTypes =
"soplex";
96opt.
Defines.Add(
"GDXInFile", db.Name);
97opt.
Defines.Add(
"GDXOutFile", Path.Combine(ws.WorkingDirectory, ws.ScratchFilePrefix + Path.GetRandomFileName()));
98 GAMSJobjob = ws.AddJobFromString(GetModelText());
99job.
Run(opt, Console.Out,
false, db);
100dbResult = ws.AddDatabaseFromGDX(opt.
Defines[
"GDXOutFile"]);
104 stringoptFile = Path.Combine(ws.WorkingDirectory, ws.ScratchFilePrefix + Path.GetRandomFileName());
106 byte[] ParameterFile = File.ReadAllBytes(optFile);
109 stringGDXInFileName = Path.ChangeExtension(Path.Combine(ws.WorkingDirectory, ws.ScratchFilePrefix + Path.GetRandomFileName()),
".gdx");
110db.Export(GDXInFileName);
111 byte[] GDXInFile = File.ReadAllBytes(GDXInFileName);
113ChannelServices.RegisterChannel(
newTcpClientChannel(),
false);
117Console.WriteLine(
"Could not locate GAMS server");
121 byte[] GDXOutFile =
new byte[0];
122 stringLogOutput =
string.Empty;
123 stringMessage =
string.Empty;
125 intrCode = rGAMS.RunServer(GetModelText(), GDXInFile, ParameterFile, ref GDXOutFile, ref LogOutput, ref Message);
129Console.WriteLine(LogOutput.ToString());
130Console.WriteLine(
"Problems with Remote GAMS Object:\n{0}"+ Message);
135Console.WriteLine(LogOutput);
136Console.WriteLine(Message);
137 stringGDXOutFileName = Path.Combine(ws.WorkingDirectory, ws.ScratchFilePrefix + Path.GetRandomFileName());
138File.WriteAllBytes(GDXOutFileName, GDXOutFile);
139dbResult = ws.AddDatabaseFromGDX(GDXOutFileName);
144Console.WriteLine(
"x("+ rec.Key(0) +
","+ rec.Key(1) +
"): level="+ rec.
Level+
" marginal="+ rec.
Marginal);
148 static stringGetModelText()
156 a(i) capacity of plant i in cases 157 b(j) demand at market j in cases 158 d(i,j) distance in thousands of miles 159 Scalar f freight in dollars per case per thousand miles; 161$if not set GDXInFile $abort 'no input file name for data file provided' 162$if not set GDXOutFile $abort 'no output file name for result file provided' 167 Parameter c(i,j) transport cost in thousands of dollars per case ; 169 c(i,j) = f * d(i,j) / 1000 ; 172 x(i,j) shipment quantities in cases 173 z total transportation costs in thousands of dollars ; 175 Positive Variable x ; 178 cost define objective function 179 supply(i) observe supply limit at plant i 180 demand(j) satisfy demand at market j ; 182 cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ; 184 supply(i) .. sum(j, x(i,j)) =l= a(i) ; 186 demand(j) .. sum(i, x(i,j)) =g= b(j) ; 188 Model transport /all/ ; 190 Solve transport using lp minimizing z ; 192 execute_unload '%GDXOutFile%', x, z, demand, supply;This example demonstrates how to implement a simple GAMS Server. The example has two parts: GAMSServe...
This example demonstrates how to implement a simple GAMS Server. The example has two parts: GAMSServe...
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
void Export(string filePath)
new GAMSParameterRecord AddRecord(params string[] keys)
new GAMSSetRecord AddRecord(params string[] keys)
GAMSDatabase AddDatabase(string databaseName=null, string inModelName=null)
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