59{
60 cout << "---------- Domain Checking --------------" << endl;
61
62
63 vector<string> plants { "Seattle", "San-Diego" };
64 vector<string> markets { "New-York", "Chicago", "Topeka" };
65 map<string, double> capacity { { "Seattle", 350.0 }, { "San-Diego", 600.0 } };
66 map<string, double> demand { { "New-York", 325.0 }, { "Chicago", 300.0 }, { "Topeka", 275.0 } };
67 map<tuple<string, string>, double> distance {
68 { make_tuple<string,string> ("Seattle", "New-York"), 2.5 },
69 { make_tuple<string,string> ("Seattle", "Chicago"), 1.7 },
70 { make_tuple<string,string> ("Seattle", "Topeka"), 1.8 },
71 { make_tuple<string,string> ("San-Diego", "New-York"), 2.5 },
72 { make_tuple<string,string> ("San-Diego", "Chicago"), 1.8 },
73 { make_tuple<string,string> ("San-Diego", "Topeka"), 1.4 }
74 };
75
76
77 try {
79 if (argc > 1)
82
84
85
87 for (auto plant: plants)
90 for (auto market: markets)
92
93
95 for (string plant: plants)
97
98
100 cout << "*** Unexpected domain violation in a" << endl;
101 return 1;
102 }
103
104
106 for (string market: markets)
108
109
111 cout << "*** Unexpected domain violation in b" << endl;
112 return 1;
113 }
114
115
117 for (auto t : distance) {
118 auto tuple = t.first;
119 auto t1 = get<0>(tuple);
120 auto t2 = get<1>(tuple);
122 }
123
124
126 cout << "*** Unexpected domain violation in d" << endl;
127 return 1;
128 }
129
130
132 cout << "*** Unexpected domain violation in db" << endl;
133 return 1;
134 }
135
136
143
144
146 cout << "*** Domain violation for db not recognized" << endl;
147 return 1;
148 }
150 cout << "*** Domain violation for a not recognized" << endl;
151 return 1;
152 }
154 cout << "*** Domain violation for d not recognized" << endl;
155 return 1;
156 }
157
158
160 cout << "*** Unexpected domain violation in b" << endl;
161 return 1;
162 }
163
164
165 int dvCnt = 0;
166 cout << "Domain Violations of a:" << endl;
168 cout << " > ";
169 for (bool vi: sdv.violInd())
170 cout << (vi ? "true " : "false ");
171 cout << "<> ";
172 for (string k: sdv.violRec().keys())
173 cout << k << " ";
174 cout << "<<" << endl;
175 dvCnt++;
176 }
177 if (dvCnt != 2) {
178 cout << "*** Number of domain violations for a should be 2 but saw " << dvCnt << endl;
179 return 1;
180 }
181
182
183 dvCnt = 0;
184 cout << "Domain Violations of d:" << endl;
186 cout << " > ";
187 for (bool vi: sdv.violInd()) {
188 cout << (vi ? "true " : "false ");
189 if (vi)
190 dvCnt++;
191 }
192 cout << "<> ";
193 for (string k: sdv.violRec().keys())
194 cout << k << " ";
195 cout << "<<" << endl;
196 }
197 if (dvCnt != 3) {
198 cout << "*** Number of domain violations for a should be 3 but saw " << dvCnt << endl;
199 return 1;
200 }
201
202
203 dvCnt = 0;
204 cout << "Domain Violations of db:" << endl;
206 cout << " > " + DDV.violSym().name() + ": " << endl;
208 cout << " ";
209 for (bool vi: sdv.violInd()) {
210 cout << vi << " ";
211 if (vi)
212 dvCnt++;
213 }
214 cout << "<> ";
215 for (string k: sdv.violRec().keys())
216 cout << k << " ";
217 cout << "<<" << endl;
218 }
219 }
220 if (dvCnt != 5) {
221 cout << "*** Number of domain violations for db should be 5 but saw " << dvCnt << endl;
222 return 1;
223 }
224
225
226 dvCnt = 0;
227 cout << "Domain Violations of db:" << endl;
229 cout << " > " + DDV.violSym().name() + ": " << endl;
231 cout << " ";
232 for (bool vi: sdv.violInd())
233 cout << vi << " ";
234 cout << "<> ";
235 for (string k: sdv.violRec().keys())
236 cout << k << " ";
237 cout << "<<" << endl;
238 dvCnt++;
239 }
240 }
241 if (dvCnt != 3) {
242 cout << "*** Number of domain violations for db should be 3 but saw " << dvCnt << endl;
243 return 1;
244 }
245
246 dvCnt = 0;
247 cout << "Domain Violations of db:" << endl;
249 cout << " > " + DDV.violSym().name() + ": " << endl;
251 cout << " ";
252 for (bool vi: sdv.violInd())
253 cout << vi << " ";
254 cout << "<> ";
255 for (string k: sdv.violRec().keys())
256 cout << k << " ";
257 cout << "<<" << endl;
258 dvCnt++;
259 }
260 }
261 if (dvCnt != 2) {
262 cout << "*** Number of domain violations for db should be 2 but saw " << dvCnt << endl;
263 return 1;
264 }
265
266
267 bool sawException = false;
268 try {
270 } catch (...) {
271 sawException = true;
274 }
275 if (!sawException) {
276 cout << "*** It should not be possible to export a GAMSDatabase containing domain violations by default" << endl;
277 return 1;
278 }
279
280
283
284
286 if (!item.isRelaxed()) {
287 GAMSSet domSet = item.getSet();
288 if (domSet.
name() ==
"i") {
290 if (find(plants.begin(), plants.end(), uel.key(0)) == plants.end()) {
291 cout << "*** Unexpected uel " + uel.key(0) + " found in domain i" << endl;
292 return 1;
293 }
294 } else if (domSet.name() == "j") {
296 if (find(markets.begin(), markets.end(), uel.key(0)) == markets.end()) {
297 cout << "*** Unexpected uel " + uel.key(0) + " found in domain j" << endl;
298 return 1;
299 }
300 } else {
301 cout << "*** Expected GAMSSet i and j but found " + domSet.name() << endl;
302 return 1;
303 }
304 }
305 else
306 {
307 cout << "*** Expected GAMSSet as domain but found relaxed domain " + item.name() << endl;
308 return 1;
309 }
310 }
311
312
313
314
315
316
317
321 cout << "Elements of aliased Set:" << endl;
323 cout << " > " + item.key(0) << endl;
324
327
328
330 cout << "Elements of test Set after adding empty UEL:" << endl;
332
333
335 cout << "Record ' a ' should be the same as ' a':" << endl;
337
338
339
340 testSet.
addRecord(
"123456789012345678901234567890123456789012345678901234567890123 ").
setText(
"OK");
341
342 sawException = false;
343 try {
344 testSet.
addRecord(
"1234567890123456789012345678901234567890123456789012345678901234").
setText(
"not OK");
345 } catch (...) {
346 sawException = true;
347 }
348 if (!sawException) {
349 cout << "*** It should not be possible to add a record with more than 63 characters" << endl;
350 return 1;
351 }
352
353
354 testDB.
addSet(
"textOK",
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345");
355 sawException = false;
356 try {
357 testDB.
addSet(
"textNotOK",
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456");
358 } catch (...) {
359 sawException = true;
360 }
361 if (!sawException) {
362 cout << "*** It should not be possible to add an explanatory text with more than 255 characters" << endl;
363 return 1;
364 }
365
366 testSet.
addRecord(
"OK").
setText(
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345");
367 sawException = false;
368 try {
369 testSet.
addRecord(
"notOK").
setText(
"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456");
370 } catch (...) {
371 sawException = true;
372 }
373 if (!sawException) {
374 cout << "*** It should not be possible to add an explanatory text with more than 255 characters" << endl;
375 return 1;
376 }
377
378
381 sawException = false;
382 try {
384 } catch (...) {
385 sawException = true;
386 }
387 if (!sawException) {
388 cout << "*** It should not be possible to add a record single AND double quote" << endl;
389 return 1;
390 }
391
394 cout << "GAMSException occured: " << ex.what() << endl;
395 } catch (exception &ex) {
396 cout << ex.what() << endl;
397 }
398
399 return 0;
400}
std::vector< GAMSDatabaseDomainViolation > getDatabaseDVs(int maxViol=0, int maxViolPerSym=0)
GAMSSet addSet(const std::string &name, const int dimension, const std::string &explanatoryText="", GAMSEnum::SetType setType=GAMSEnum::SetType::Multi)
GAMSParameter addParameter(const std::string &name, const int dimension, const std::string &explanatoryText="")
void doExport(const std::string &filePath="")
GAMSSet getSet(const std::string &name)
GAMSParameter getParameter(const std::string &name)
void setSuppressAutoDomainChecking(bool value)
void setValue(const double val)
GAMSParameterRecord addRecord(const std::vector< std::string > &keys)
void setText(const std::string &text)
GAMSSetRecord findRecord(const std::vector< std::string > &keys)
GAMSSetRecord addRecord(const std::vector< std::string > &keys)
std::vector< GAMSSymbolDomainViolation > getSymbolDVs(int maxViol=0)
std::string & name() const
int numberRecords() const
std::vector< GAMSDomain > domains()
void setSystemDirectory(const std::string &systemDir)
std::string getDataText()