13 static readonly String PROPERTIES_FILE =
"test.properties";
15 static Logger logger = LogManager.GetCurrentClassLogger();
23 static readonly String MODEL =
25 " i canning plants / seattle, san-diego / \n" +
26 " j markets / new-york, chicago, topeka / ; \n" +
29 " a(i) capacity of plant i in cases \n" +
31 " san-diego 600 / \n" +
33 " b(j) demand at market j in cases \n" +
34 " / new-york 325 \n" +
36 " topeka 275 / ; \n" +
38 "Table d(i,j) distance in thousands of miles \n" +
39 " new-york chicago topeka \n" +
40 "seattle 2.5 1.7 1.8 \n" +
41 "san-diego 2.5 1.8 1.4 ; \n" +
43 "Scalar f freight in dollars per case per thousand miles /90/ ; \n" +
44 "Scalar bmult demand multiplier /1/; \n" +
46 "Parameter c(i,j) transport cost in thousands of dollars per case ; \n" +
47 " c(i,j) = f * d(i,j) / 1000 ; \n" +
50 " x(i,j) shipment quantities in cases \n" +
51 " z total transportation costs in thousands of dollars ; \n" +
53 "Positive Variable x ; \n" +
56 " cost define objective function \n" +
57 " supply(i) observe supply limit at plant i \n" +
58 " demand(j) satisfy demand at market j ; \n" +
60 " cost .. z =e= sum((i,j), c(i,j)*x(i,j)) ; \n" +
62 " supply(i) .. sum(j, x(i,j)) =l= a(i) ; \n" +
64 " demand(j) .. sum(i, x(i,j)) =g= bmult*b(j) ; \n" +
66 "Model transport /all/ ; \n" +
70 public static void OneTimeSetUp()
72 logger.Debug(
"entering TestGAMSModelInstance | SetUpBeforeClass");
74 logger.Info(
"Housekeeper task initialized");
76 wsInfo.WorkingDirectory =
HouseKeeper.gamsWorkingDir;
79 logger.Debug(
"exiting TestGAMSModelInstance | SetUpBeforeClass");
83 public static void TearDown()
113 public void testAddModelInstanceInstantiateAndSolve()
115 logger.Debug(
"entering TestGAMSModelInstance | testAddModelInstanceInstantiateAndSolve");
119 Assert.That(cp !=
null,
"do not expect cp as null");
120 StringAssert.AreEqualIgnoringCase(
new FileInfo(ws.
WorkingDirectory).FullName,
122 "expect [" + ws.
WorkingDirectory +
"] as a checkpoint's working directory.");
124 Assert.NotNull(job,
"do not expect a null job");
133 Assert.NotNull(mi,
"do not expect a null mi");
134 Assert.NotNull(mi.
SyncDB,
"do not expect a null syncDB");
139 opt.AllModelTypes =
"cplex";
141 Assert.NotNull(bmult,
"do not expect a null bmult");
144 Assert.AreEqual(0, bmult.
NumberRecords,
"expect empty records");
148 Assert.AreEqual(1, bmult.
NumberRecords,
"expect one record in bmult");
157 Assert.AreEqual(
ModelStat.InfeasibleGlobal, mi.
ModelStatus,
"expect ModelStatus:INFEASIBLE_GLOBAL");
167 logger.Debug(
"exiting TestGAMSModelInstance | testAddModelInstanceInstantiateAndSolve");
171 public void testCopyModelInstanceAndSolve()
173 logger.Debug(
"entering TestGAMSModelInstance | testAddModelInstanceInstantiateAndSolve");
183 opt.AllModelTypes =
"cplex";
192 Assert.NotNull(copy,
"do not expect a null copy");
197 logger.Debug(
"exiting TestGAMSModelInstance | testCopyModelInstanceAndSolve");
201 public void testSolveWhenDebugIsTrue()
203 logger.Debug(
"entering TestGAMSModelInstance | testSolveWhenDebugIsTrue");
213 opt.AllModelTypes =
"cplex";
219 mi.
Solve(miOpt: MIO);
224 logger.Debug(
"exiting TestGAMSModelInstance | testSolveWhenDebugIsTrue");
228 public void testModelInstanceOptDir()
231 bool optFileNotFound;
233 logger.Debug(
"entering TestGAMSModelInstance | testModelInstanceOptDir");
242 opt.AllModelTypes =
"cbc";
243 tmpDir = Path.GetTempPath();
247 using (TextWriter logFile =
new StreamWriter(
"transport_cbc.log"))
248 mi.
Solve(output:logFile, miOpt: MIO);
249 using (StreamReader sr =
new StreamReader(
"transport_cbc.log"))
251 string contents = sr.ReadToEnd();
252 optFileNotFound = contents.Contains(
"*** Error Cannot open parameter file");
254 Assert.True(optFileNotFound,
"Expected optfile not to be found");
258 using (File.Create(Path.Combine(tmpDir,
"cbc.opt"))) {}
259 using (TextWriter logFile =
new StreamWriter(
"transport_cbc.log"))
260 mi.
Solve(output:logFile, miOpt: MIO);
261 using (StreamReader sr =
new StreamReader(
"transport_cbc.log"))
263 string contents = sr.ReadToEnd();
264 optFileNotFound = contents.Contains(
"*** Error Cannot open parameter file");
266 Assert.False(optFileNotFound,
"Expected optfile to be found");
270 logger.Debug(
"exiting TestGAMSModelInstance | testModelInstanceOptDir");
274 public void testCallingInstantiateForSecondTime()
276 logger.Debug(
"entering TestGAMSModelInstance | testCallingInstantiateForSecondTime");
286 opt.AllModelTypes =
"cplex";
293 logger.Debug(
"exiting TestGAMSModelInstance | testCallingInstantiateForSecondTime");
297 public void testInstantiateWithNullModelDefinition()
299 logger.Debug(
"entering TestGAMSModelInstnace | testInstantiateWithNullModelDefinition");
309 opt.AllModelTypes =
"cplex";
313 logger.Debug(
"exiting TestGAMSModelInstnace | testInstantiateWithNullModelDefinition");
317 public void testInstantiateWithNullModifier1()
319 logger.Debug(
"entering TestGAMSModelInstance | testInstantiateWithNullModifier1");
328 opt.AllModelTypes =
"cplex";
332 logger.Debug(
"exiting TestGAMSModelInstance | testInstantiateWithNullModifier1");
336 public void testInstantiateWithNullModifier2()
338 logger.Debug(
"entering TestGAMSModelInstance | testInstantiateWithNullModifier2");
347 opt.AllModelTypes =
"cplex";
351 logger.Debug(
"exiting TestGAMSModelInstance | testInstantiateWithNullModifier2");
354 public void testCopyModelInstanceBeforeInstantiated()
356 logger.Debug(
"entering TestGAMSModelInstance | testCopyModelInstanceBeforeInstantiated");
367 logger.Debug(
"exiting TestGAMSModelInstance | testCopyModelInstanceBeforeInstantiated");
GAMSModelInstance AddModelInstance(string modelInstanceName=null)
GAMSParameter GetParameter(string parameterIdentifier)
GAMSParameter AddParameter(string identifier, int dimension, string explanatoryText="")
void Run(GAMSOptions gamsOptions=null, GAMSCheckpoint checkpoint=null, TextWriter output=null, Boolean createOutDB=true)
GAMSModelInstance CopyModelinstance(string modelInstanceName=null)
void Solve(SymbolUpdateType updateType=SymbolUpdateType.BaseCase, TextWriter output=null, GAMSModelInstanceOpt miOpt=null)
void Instantiate(string modelDefinition, params GAMSModifier[] modifiers)
new GAMSParameterRecord FirstRecord()
new GAMSParameterRecord AddRecord(params string[] keys)
GAMSJob AddJobFromString(string gamsSource, GAMSCheckpoint checkpoint=null, string jobName=null)
GAMSJob AddJobFromGamsLib(string model, GAMSCheckpoint checkpoint=null, string jobName=null)
GAMSCheckpoint AddCheckpoint(string checkpointName=null)
GAMSOptions AddOptions(GAMSOptions optFrom=null)
static void initializeTestFrom(String filename, String subdir)
initialize class properties from fileName and prepare directory subdir