2using System.Collections.Generic;
23 static void Main(
string[] args)
26 if (Environment.GetCommandLineArgs().Length > 1)
27 ws =
new GAMSWorkspace(systemDirectory: Environment.GetCommandLineArgs()[1]);
32 List<string> plants =
new List<string>()
34 "Seattle",
"San-Diego"
36 List<string> markets =
new List<string>()
38 "New-York",
"Chicago",
"Topeka"
40 Dictionary<string, double> capacity =
new Dictionary<string, double>()
42 {
"Seattle", 350.0 }, {
"San-Diego", 600.0 }
44 Dictionary<string, double> demand =
new Dictionary<string, double>()
46 {
"New-York", 325.0 }, {
"Chicago", 300.0 }, {
"Topeka", 275.0 }
48 Dictionary<Tuple<string, string>,
double> distance =
new Dictionary<Tuple<string, string>,
double>()
50 {
new Tuple<string,string> (
"Seattle",
"New-York"), 2.5 },
51 {
new Tuple<string,string> (
"Seattle",
"Chicago"), 1.7 },
52 {
new Tuple<string,string> (
"Seattle",
"Topeka"), 1.8 },
53 {
new Tuple<string,string> (
"San-Diego",
"New-York"), 2.5 },
54 {
new Tuple<string,string> (
"San-Diego",
"Chicago"), 1.8 },
55 {
new Tuple<string,string> (
"San-Diego",
"Topeka"), 1.4 }
62 foreach (
string p
in plants)
65 GAMSSet j = db.AddSet(
"j", 1,
"markets");
66 foreach (
string m
in markets)
69 GAMSParameter a = db.AddParameter(
"a",
"capacity of plant i in cases", i);
70 foreach (
string p
in plants)
73 GAMSParameter b = db.AddParameter(
"b",
"demand at market j in cases", j);
74 foreach (
string m
in markets)
77 GAMSParameter d = db.AddParameter(
"d",
"distance in thousands of miles", i, j);
78 foreach (Tuple<string, string> t
in distance.Keys)
81 GAMSParameter f = db.AddParameter(
"f",
"freight in dollars per case per thousand miles");
85 db.Export(
"data.gdx");
91 List<string> plants2 =
new List<string>();
93 plants2.Add(item.
Key(0));
95 List<string> markets2 =
new List<string>();
97 markets2.Add(item.
Key(0));
99 Dictionary<string, double> capacity2 =
new Dictionary<string, double>();
101 capacity2.Add(item.
Key(0), item.Value);
103 Dictionary<string, double> demand2 =
new Dictionary<string, double>();
105 demand2.Add(item.
Key(0), item.Value);
107 Dictionary<Tuple<string, string>,
double> distance2 =
new Dictionary<Tuple<string, string>,
double>();
109 distance2.Add(
new Tuple<string, string>(item.
Key(0), item.
Key(1)), item.Value);
112 Console.WriteLine(
"Data read from data.gdx");
113 Console.WriteLine(
"\nSet i:");
114 foreach (
string p
in plants2)
115 Console.WriteLine(
" " + p);
116 Console.WriteLine(
"\nSet j:");
117 foreach (
string m
in markets2)
118 Console.WriteLine(
" " + m);
119 Console.WriteLine(
"\nParameter a:");
120 foreach (var item
in capacity2)
121 Console.WriteLine(
" " + item.
Key +
": " + item.Value);
122 Console.WriteLine(
"\nParameter b:");
123 foreach (var item
in demand2)
124 Console.WriteLine(
" " + item.
Key +
": " + item.Value);
125 Console.WriteLine(
"\nParameter d:");
126 foreach (var item
in distance2)
127 Console.WriteLine(
" " + item.
Key +
": " + item.Value);
GAMSSet AddSet(string identifier, int dimension, string explanatoryText="", SetType setType=SetType.multi)
new GAMSParameterRecord AddRecord(params string[] keys)
new GAMSSetRecord AddRecord(params string[] keys)
GAMSDatabase AddDatabase(string databaseName=null, string inModelName=null)
This example shows the use of the GAMSDatabase class for reading and writing GDX files....