2using System.Collections.Generic;
29 static int Main(
string[] args)
32 if (Environment.GetCommandLineArgs().Length > 1)
33 ws =
new GAMSWorkspace(systemDirectory: Environment.GetCommandLineArgs()[1]);
38 List<string> plants =
new List<string>() {
"Seattle",
"San-Diego" };
39 List<string> markets =
new List<string>() {
"New-York",
"Chicago",
"Topeka" };
40 Dictionary<string, double> capacity =
new Dictionary<string, double>() { {
"Seattle", 350.0 }, {
"San-Diego", 600.0 } };
41 Dictionary<string, double> demand =
new Dictionary<string, double>() { {
"New-York", 325.0 }, {
"Chicago", 300.0 }, {
"Topeka", 275.0 } };
42 Dictionary<Tuple<string, string>,
double> distance =
new Dictionary<Tuple<string, string>,
double>()
44 {
new Tuple<string,string> (
"Seattle",
"New-York"), 2.5 },
45 {
new Tuple<string,string> (
"Seattle",
"Chicago"), 1.7 },
46 {
new Tuple<string,string> (
"Seattle",
"Topeka"), 1.8 },
47 {
new Tuple<string,string> (
"San-Diego",
"New-York"), 2.5 },
48 {
new Tuple<string,string> (
"San-Diego",
"Chicago"), 1.8 },
49 {
new Tuple<string,string> (
"San-Diego",
"Topeka"), 1.4 }
57 foreach (
string p
in plants)
60 foreach (
string m
in markets)
64 GAMSParameter a = db.AddParameter(
"a",
"capacity at plant", i);
65 foreach (
string p
in plants)
69 if (!a.CheckDomains())
71 Console.WriteLine(
"*** Unexpected domain violation in a");
76 GAMSParameter b = db.AddParameter(
"b",
"demand at market j in cases",
"j");
77 foreach (
string m
in markets)
81 if (!b.CheckDomains())
83 Console.WriteLine(
"*** Unexpected domain violation in b");
88 GAMSParameter d = db.AddParameter(
"d",
"distance in thousands of miles", i, j);
89 foreach (Tuple<string, string> t
in distance.Keys)
93 if (!d.CheckDomains())
95 Console.WriteLine(
"*** Unexpected domain violation in d");
100 if (!db.CheckDomains())
102 Console.WriteLine(
"*** Unexpected domain violation in db");
107 d.AddRecord(
"Seattle",
"aa").Value = 1;
108 d.AddRecord(
"bb",
"Seattle").Value = 1;
109 a.AddRecord(
"aa").Value = 1;
110 a.AddRecord(
"bb").Value = 1;
111 b.AddRecord(
"aa").Value = 1;
112 b.AddRecord(
"bb").Value = 1;
115 if (db.CheckDomains())
117 Console.WriteLine(
"*** Domain violation for db not recognized");
120 if (a.CheckDomains())
122 Console.WriteLine(
"*** Domain violation for a not recognized");
125 if (d.CheckDomains())
127 Console.WriteLine(
"*** Domain violation for d not recognized");
132 if (!b.CheckDomains())
134 Console.WriteLine(
"*** Unexpected domain violation in b");
140 Console.WriteLine(
"Domain Violations of a:");
143 Console.Write(
" > ");
144 foreach (
bool vi
in SDV.
ViolInd)
145 Console.Write(vi +
" ");
146 Console.Write(
"<> ");
148 Console.Write(k +
" ");
149 Console.WriteLine(
"<<");
154 Console.WriteLine(
"*** Number of domain violations for a should be 2 but saw " + dvCnt);
160 Console.WriteLine(
"Domain Violations of d:");
163 Console.Write(
" > ");
164 foreach (
bool vi
in SDV.
ViolInd)
166 Console.Write(vi +
" ");
170 Console.Write(
"<> ");
172 Console.Write(k +
" ");
173 Console.WriteLine(
"<<");
177 Console.WriteLine(
"*** Number of domain violations for a should be 3 but saw " + dvCnt);
183 Console.WriteLine(
"Domain Violations of db:");
186 Console.WriteLine(
" > " + DDV.
ViolSym.
Name +
": ");
190 foreach (
bool vi
in SDV.
ViolInd)
192 Console.Write(vi +
" ");
196 Console.Write(
"<> ");
198 Console.Write(k +
" ");
199 Console.WriteLine(
"<<");
204 Console.WriteLine(
"*** Number of domain violations for db should be 5 but saw " + dvCnt);
210 Console.WriteLine(
"Domain Violations of db:");
213 Console.WriteLine(
" > " + DDV.
ViolSym.
Name +
": ");
217 foreach (
bool vi
in SDV.
ViolInd)
218 Console.Write(vi +
" ");
219 Console.Write(
"<> ");
221 Console.Write(k +
" ");
222 Console.WriteLine(
"<<");
228 Console.WriteLine(
"*** Number of domain violations for db should be 3 but saw " + dvCnt);
233 Console.WriteLine(
"Domain Violations of db:");
236 Console.WriteLine(
" > " + DDV.
ViolSym.
Name +
": ");
240 foreach (
bool vi
in SDV.
ViolInd)
241 Console.Write(vi +
" ");
242 Console.Write(
"<> ");
244 Console.Write(k +
" ");
245 Console.WriteLine(
"<<");
251 Console.WriteLine(
"*** Number of domain violations for db should be 2 but saw " + dvCnt);
256 bool sawException =
false;
259 db.Export(
"test.gdx");
264 db.SuppressAutoDomainChecking =
true;
265 db.Export(
"test.gdx");
269 Console.WriteLine(
"*** It should not be possible to export a GAMSDatabase containing domain violations by default");
278 foreach (
object item
in d2.Domains)
282 if (((
GAMSSet)item).Name ==
"i")
285 if (!plants.Contains(uel.
Key(0)))
287 Console.WriteLine(
"*** Unexpected uel " + uel.
Key(0) +
" found in domain i");
291 else if (((
GAMSSet)item).Name ==
"j")
294 if (!markets.Contains(uel.
Key(0)))
296 Console.WriteLine(
"*** Unexpected uel " + uel.
Key(0) +
" found in domain j");
302 Console.WriteLine(
"*** Expected GAMSSet i and j but found " + ((
GAMSSet)item).Name);
308 Console.WriteLine(
"*** Expected GAMSSet as domain but found relaxed domain " + (
string)item);
319 GAMSJob jAlias = ws.AddJobFromString(GetDataText());
322 Console.WriteLine(
"Elements of aliased Set:");
324 Console.WriteLine(
" > " + item.Key(0));
331 Console.WriteLine(
"Elements of test Set after adding empty UEL:");
336 Console.WriteLine(
"Record ' a ' should be the same as ' a':");
341 testSet.
AddRecord(
"123456789012345678901234567890123456789012345678901234567890123 ").
Text =
"OK";
343 sawException =
false;
346 testSet.
AddRecord(
"1234567890123456789012345678901234567890123456789012345678901234").
Text =
"not OK";
354 Console.WriteLine(
"*** It should not be possible to add a record with more than 63 characters");
359 testDB.
AddSet(
"textOK",
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345");
360 sawException =
false;
363 testDB.
AddSet(
"textNotOK",
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456");
371 Console.WriteLine(
"*** It should not be possible to add an explanatory text with more than 255 characters");
375 testSet.
AddRecord(
"OK").
Text =
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345";
376 sawException =
false;
379 testSet.
AddRecord(
"notOK").
Text =
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456";
387 Console.WriteLine(
"*** It should not be possible to add an explanatory text with more than 255 characters");
394 sawException =
false;
405 Console.WriteLine(
"*** It should not be possible to add a record single AND double quote");
409 testDB.
Export(
"test.gdx");
414 static String GetDataText()
418 i canning plants / seattle, san-diego /;
List< GAMSSymbolDomainViolation > ViolRecs
GAMSSet AddSet(string identifier, int dimension, string explanatoryText="", SetType setType=SetType.multi)
GAMSParameter GetParameter(string parameterIdentifier)
GAMSSet GetSet(string setIdentifier)
void Export(string filePath=null)
void Run(GAMSOptions gamsOptions=null, GAMSCheckpoint checkpoint=null, TextWriter output=null, Boolean createOutDB=true)
new GAMSParameterRecord AddRecord(params string[] keys)
new GAMSSetRecord AddRecord(params string[] keys)
new GAMSSetRecord FindRecord(params string[] keys)
GAMSDatabase AddDatabase(string databaseName=null, string inModelName=null)