00001
00104 #define DEBUG
00105
00106
00107 #define COMPONENT_DEBUG // program logic, especially parser testing
00108
00109
00110 #include <cppad/cppad.hpp>
00111
00112 #include "OSCoinSolver.h"
00113 #include "OSConfig.h"
00114 #include "OSmps2osil.h"
00115 #include "OSResult.h"
00116 #include "OSOption.h"
00117 #include "OSiLReader.h"
00118 #include "OSiLWriter.h"
00119 #include "OSoLReader.h"
00120 #include "OSoLWriter.h"
00121 #include "OSrLReader.h"
00122 #include "OSrLWriter.h"
00123 #include "OSInstance.h"
00124 #include "OSFileUtil.h"
00125 #include "CoinError.hpp"
00126
00127 #include "OSDefaultSolver.h"
00128 #include "OSWSUtil.h"
00129 #include "OSSolverAgent.h"
00130 #include "OShL.h"
00131 #include "OSErrorClass.h"
00132 #include "OSBase64.h"
00133 #include "OSCommonUtil.h"
00134 #include "OSMathUtil.h"
00135
00136
00137 #include <CoinMpsIO.hpp>
00138 #include <CoinPackedMatrix.hpp>
00139
00140
00141
00142
00143 #ifdef COIN_HAS_GLPK
00144 #include <OsiGlpkSolverInterface.hpp>
00145 #endif
00146
00147 #ifdef COIN_HAS_COUENNE
00148 #include "OSCouenneSolver.h"
00149 #endif
00150
00151 #ifdef COIN_HAS_ASL
00152 #include "OSnl2osil.h"
00153 #endif
00154
00155 #ifdef COIN_HAS_LINDO
00156 #include "OSLindoSolver.h"
00157 #endif
00158
00159 #ifdef COIN_HAS_IPOPT
00160 #include "OSIpoptSolver.h"
00161 #endif
00162
00163 #ifdef COIN_HAS_BONMIN
00164 #include "OSBonminSolver.h"
00165 #endif
00166
00167
00168
00169
00170 #ifdef HAVE_CTIME
00171 # include <ctime>
00172 #else
00173 # ifdef HAVE_TIME_H
00174 # include <time.h>
00175 # else
00176 # error "don't have header file for time"
00177 # endif
00178 #endif
00179
00180
00181 #ifdef HAVE_CMATH
00182 # include <cmath>
00183 #else
00184 # ifdef HAVE_CMATH_H
00185 # include <cmath.h>
00186 # endif
00187 #endif
00188
00189
00190
00191 #ifdef HAVE_CSTDIO
00192 # include <cstdio>
00193 #else
00194 # ifdef HAVE_STDIO_H
00195 # include <stdio.h>
00196 # else
00197 # error "don't have header file for stdio"
00198 # endif
00199 #endif
00200
00201
00202
00203
00204
00205 using std::cout;
00206 using std::endl;
00207 using std::ostringstream;
00208
00209
00210
00211
00212 int main(int argC, char* argV[])
00213 {
00214
00215
00216
00217 WindowsErrorPopupBlocker();
00218 double getObjVal(std::string osrl);
00219
00220 bool ok;
00221 double check;
00222
00223
00224 cout << "START UNIT TEST" << endl;
00225 int nOfTest = 0;
00226
00227 FileUtil *fileUtil = NULL;
00228 #ifdef COIN_HAS_ASL
00229 OSnl2osil *nl2osil = NULL;
00230 #endif
00231 OSmps2osil *mps2osil = NULL;
00232 DefaultSolver *solver = NULL;
00233 OSiLReader *osilreader = NULL;
00234 OSoLReader *osolreader = NULL;
00235 OSrLReader *osrlreader = NULL;
00236 OSrLWriter *osrlwriter = NULL;
00237 OSrLWriter *tmp_writer = NULL;
00238
00239 std::string osilFileName;
00240 std::string osolFileName;
00241 std::string osrlFileName;
00242 std::string nlFileName;
00243 std::string mpsFileName;
00244 std::string osil;
00245 std::string osol;
00246 ostringstream unitTestResult;
00247 ostringstream unitTestResultFailure;
00248
00249 const char dirsep = CoinFindDirSeparator();
00250
00251 std::string dataDir;
00252 dataDir = dirsep == '/' ? "../data/" : "..\\data\\";
00253 nlFileName = dataDir + "amplFiles" + dirsep + "parinc.nl";
00254 mpsFileName = dataDir + "mpsFiles" + dirsep + "parinc.mps";
00255 fileUtil = new FileUtil();
00256
00257
00258 #ifdef INSTALLATION_TEST
00259
00260
00261 try{
00262 std::cout << endl << "TEST " << ++nOfTest << ": Try to read a sample file" << endl << endl;
00263 osilFileName = dataDir + "osilFiles" + dirsep + "parincLinearByRow.osil";
00264
00265 std::cout << "The file is: " ;
00266 std::cout << osilFileName << std::endl;
00267 osil = fileUtil->getFileAsString( osilFileName.c_str() );
00268 std::cout << "Done reading the test file" << std::endl;
00269 osilreader = new OSiLReader();
00270
00271
00272 unitTestResult << "Reading files successfully" << std::endl;
00273 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
00274 OSiLWriter osilwriter;
00275 osilwriter.m_bWhiteSpace = true;
00276
00277 delete osilreader;
00278 osilreader = NULL;
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 cout << endl << "TEST " << ++nOfTest << ": Lossless I/O" << endl << endl;
00314
00315 mpsFileName = dataDir + "mpsFiles" + dirsep + "parinc.mps";
00316 mps2osil = new OSmps2osil( mpsFileName);
00317
00318 mps2osil->createOSInstance() ;
00319
00320 OSInstance *osinstance1 = mps2osil->osinstance;
00321 std::string sOSiL = osilwriter.writeOSiL( osinstance1 );
00322
00324
00325 osilreader = new OSiLReader();
00326 OSInstance *osinstance2 = osilreader->readOSiL( sOSiL);
00327
00328 int nvals = osinstance1->instanceData->linearConstraintCoefficients->numberOfValues;
00329 double theDiff, theMax;
00330 int theIndex = -1;
00331 theMax = 0;
00332 for(int i = 0; i < nvals; i++){
00333 theDiff = fabs(osinstance1->instanceData->linearConstraintCoefficients->value->el[ i] -
00334 osinstance2->instanceData->linearConstraintCoefficients->value->el[ i])/ fabs(osinstance1->instanceData->linearConstraintCoefficients->value->el[ i]);
00335 if(theDiff > theMax){
00336 theMax = theDiff;
00337 theIndex = i;
00338 }
00339
00340 }
00341 std::cout << "MAXIMUM DIFF = " << theMax << std::endl;
00342 std::cout << "MAXIMUM DIFF INDEX = " << theIndex << std::endl;
00343 if(theMax > 0) unitTestResult << "WARNING: you do not have lossless IO" << std::endl;
00344 else
00345 { unitTestResult << "Passed lossless IO test" << std::endl;
00346 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
00347 }
00348 delete mps2osil;
00349 delete osilreader;
00350 osilreader = NULL;
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409 }
00410 catch(const ErrorClass& eclass){
00411 unitTestResultFailure << "Sorry Unit Test Failed Reading a file: " + eclass.errormsg<< endl;
00412
00413 unitTestResultFailure << "Since we can't read files we are terminating" << endl;
00414 cout << unitTestResultFailure.str() << endl << endl;
00415 cout << "Conclusion: FAILURE" << endl;
00416 return 1;
00417 }
00418
00419 try{
00420 cout << endl << "TEST " << ++nOfTest << ": Clp solver on parincLinearByRow.osil" << endl << endl;
00421 ok = true;
00422 std::cout << "create a new COIN Clp for OSiL string solution" << std::endl;
00423 osilFileName = dataDir + "osilFiles" + dirsep + "parincLinearByRow.osil";
00424 osolFileName = dataDir + "osolFiles" + dirsep + "parincLinearByRow_clp.osol";
00425 osil = fileUtil->getFileAsString( osilFileName.c_str());
00426 osol = fileUtil->getFileAsString( osolFileName.c_str());
00427
00428 std::cout << "create a new Solver object" << std::endl;
00429 osilreader = new OSiLReader();
00430 osolreader = new OSoLReader();
00431 solver = new CoinSolver();
00432 solver->sSolverName = "clp";
00433 solver->osinstance = osilreader->readOSiL( osil);
00434 std::cout << " Done reading the OSiL" << std::endl;
00435
00436 OSiLWriter *osilwriter;
00437 osilwriter = new OSiLWriter();
00438 osilwriter->m_bWhiteSpace = true;
00439 std::cout << " Write the OSiL" << std::endl;
00440 osil = osilwriter->writeOSiL( solver->osinstance) ;
00441
00442 std::cout << " Done writing the OSiL" << std::endl;
00443 solver->osoption = osolreader->readOSoL( osol);
00444 cout << "call the COIN - clp Solver for parincLinearbyRow" << endl;
00445
00446 solver->solve();
00447 cout << "Here is the COIN clp solver solution for parincLinearByRow" << endl;
00448 cout << solver->osrl << endl;
00449 check = 7668;
00450 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00451
00452 if(ok == false) throw ErrorClass(" Fail unit test with clp on parincLinearByRow.osil");
00453
00454 osrlreader = new OSrLReader();
00455 cout << "First osrl file\n" << solver->osrl << endl;
00456 osrlreader->readOSrL( solver->osrl);
00457 cout << "read successfully" << endl;
00458 delete osilreader;
00459 cout << "osilreader successfully deleted" << endl;
00460 osilreader = NULL;
00461 delete osolreader;
00462 cout << "osolreader successfully deleted" << endl;
00463 osolreader = NULL;
00464 delete solver;
00465 cout << "solver successfully deleted" << endl;
00466 solver = NULL;
00467 delete osilwriter;
00468 cout << "osilwriter successfully deleted" << endl;
00469 osilwriter = NULL;
00470 delete osrlreader;
00471 cout << "osrlreader successfully deleted" << endl;
00472 osrlreader = NULL;
00473 unitTestResult << "Solved problem parincLinearByRow.osil with Clp" << std::endl;
00474 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
00475 }
00476 catch(const ErrorClass& eclass){
00477 unitTestResultFailure << "Sorry Unit Test Failed Testing Clp Solver:" + eclass.errormsg<< endl;
00478 }
00479
00480
00481 try{
00482 cout << endl << "TEST " << ++nOfTest << ": Cbc solver on p0033.osil" << endl << endl;
00483 std::cout << "create a new COIN Cbc for OSiL string solution" << std::endl;
00484 ok = true;
00485 osilFileName = dataDir + "osilFiles" + dirsep + "p0033.osil";
00486 osolFileName = dataDir + "osolFiles" + dirsep + "p0033_cbc.osol";
00487 osil = fileUtil->getFileAsString( osilFileName.c_str());
00488 osol = fileUtil->getFileAsString( osolFileName.c_str());
00489 osilreader = new OSiLReader();
00490 osolreader = new OSoLReader();
00491 solver = new CoinSolver();
00492 solver->sSolverName ="cbc";
00493 solver->osil = osil;
00494 solver->osol = osol;
00495 solver->osinstance = NULL;
00496 solver->osoption = NULL;
00497 cout << "call the COIN - Cbc Solver for p0033" << endl;
00498 solver->buildSolverInstance();
00499 solver->solve();
00500 cout << "Here is the COIN Cbc solver solution for p0033" << endl;
00501
00502 check = 3089;
00503
00504 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00505 if(ok == false) throw ErrorClass(" Fail unit test with Cbc on p0033.osil");
00506 delete solver;
00507 solver = NULL;
00508 delete osilreader;
00509 osilreader = NULL;
00510 delete osolreader;
00511 osolreader = NULL;
00512 unitTestResult << "Solved problem p0033.osil with Cbc" << std::endl;
00513 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
00514 }
00515 catch(const ErrorClass& eclass){
00516 unitTestResultFailure << "Sorry Unit Test Failed Testing Cbc Solver:" + eclass.errormsg<< endl;
00517 }
00518
00519 #ifdef THOROUGH
00520
00521 try{
00522 cout << endl << "TEST " << ++nOfTest << ": Cbc solver on p0201.osil" << endl << endl;
00523 ok = true;
00524 osilFileName = dataDir + "osilFiles" + dirsep + "p0201.osil";
00525 osolFileName = dataDir + "osolFiles" + dirsep + "p0201_cbc.osol";
00526 osil = fileUtil->getFileAsString( osilFileName.c_str());
00527 osol = fileUtil->getFileAsString( osolFileName.c_str());
00528 solver = new CoinSolver();
00529 solver->sSolverName ="cbc";
00530 solver->osil = osil;
00531 osilreader = new OSiLReader();
00532 osolreader = new OSoLReader();
00533 solver->osol = "";
00534 solver->osinstance = NULL;
00535 solver->osoption = NULL;
00536 cout << "call the COIN - Cbc Solver for p0201" << endl;
00537 solver->solve();
00538 cout << "Here is the COIN Cbc solver solution for p0201" << endl;
00539 check = 7615;
00540
00541 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00542 if(ok == false) throw ErrorClass(" Fail unit test with Cbc on p0201.osil");
00543 delete solver;
00544 solver = NULL;
00545 delete osilreader;
00546 osilreader = NULL;
00547 delete osolreader;
00548 osolreader = NULL;
00549 unitTestResult << "Solved problem p0201.osil with Cbc" << std::endl;
00550 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
00551 }
00552 catch(const ErrorClass& eclass){
00553 unitTestResultFailure << "Sorry Unit Test Failed Testing Cbc Solver:" + eclass.errormsg<< endl;
00554 }
00555
00556 cout << endl << "TEST " << ++nOfTest << ": Cbc solver on parincInteger.osil" << endl << endl;
00557 ok = true;
00558 osilFileName = dataDir + "osilFiles" + dirsep + "parincInteger.osil";
00559 osolFileName = dataDir + "osolFiles" + dirsep + "parincInteger_cbc.osol";
00560 osil = fileUtil->getFileAsString( osilFileName.c_str());
00561 osol = fileUtil->getFileAsString( osolFileName.c_str());
00562 osilreader = new OSiLReader();
00563 osolreader = new OSoLReader();
00564
00565 solver = new CoinSolver();
00566 solver->sSolverName ="cbc";
00567 solver->osinstance = osilreader->readOSiL( osil);
00568 solver->osol = osol;
00569 cout << "call the COIN - Cbc Solver for parincInteger" << endl;
00570
00571 solver->solve();
00572 cout << "Here is the Cbc solver solution for parincInteger" << endl;
00573 check = 7668;
00574
00575 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00576 if(ok == false) throw ErrorClass(" Fail unit test with Cbc on parincInteger.osil");
00577 unitTestResult << "Solved problem parincInteger.osil with Cbc" << std::endl;
00578 delete osilreader;
00579 osilreader = NULL;
00580 delete osolreader;
00581 osolreader = NULL;
00582 delete solver;
00583 solver = NULL;
00584 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
00585
00586
00587 #endif
00588
00589 #ifdef COIN_HAS_IPOPT
00590 IpoptSolver *ipoptSolver = NULL;
00591 try{
00592 cout << endl << "TEST " << ++nOfTest << ": Ipopt solver with avion2.osil" << endl << endl;
00593 ipoptSolver = new IpoptSolver();
00594 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00595 ok = true;
00596
00597
00598
00599 #ifndef XLC_
00600 osilFileName = dataDir + "osilFiles" + dirsep + "avion2.osil";
00601 osolFileName = dataDir + "osolFiles" + dirsep + "avion2_ipopt.osol";
00602 osil = fileUtil->getFileAsString( osilFileName.c_str());
00603 osol = fileUtil->getFileAsString( osolFileName.c_str());
00604 cout << "IPOPT Solver created for OSiL string solution" << endl;
00605 ipoptSolver->osol = osol;
00606 osilreader = new OSiLReader();
00607 osolreader = new OSoLReader();
00608 ipoptSolver->osinstance = osilreader->readOSiL( osil);
00609 ipoptSolver->osol = osol;
00610 cout << "call the IPOPT Solver" << endl;
00611 ipoptSolver->buildSolverInstance();
00612 ipoptSolver->solve();
00613 cout << "Here is the IPOPT solver solution for avion2" << endl;
00614 check = 9.46801e+07;
00615
00616 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00617 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on avion2.osil");
00618 delete osilreader;
00619 osilreader = NULL;
00620 delete osolreader;
00621 osolreader = NULL;
00622 delete ipoptSolver;
00623 ipoptSolver = NULL;
00624 unitTestResult << "Solved problem avion2.osil with Ipopt" << std::endl;
00625 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
00626 #endif
00627
00628 #ifdef THOROUGH
00629
00630 cout << endl << "TEST " << ++nOfTest << ": Ipopt solver with HS071_NLPMod.osil" << endl << endl;
00631 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00632 ipoptSolver = new IpoptSolver();
00633
00634 osilFileName = dataDir + "osilFiles" + dirsep + "HS071_NLPMod.osil";
00635 osolFileName = dataDir + "osolFiles" + dirsep + "HS071_NLPMod_ipopt.osol";
00636 osil = fileUtil->getFileAsString( osilFileName.c_str());
00637 osol = fileUtil->getFileAsString( osolFileName.c_str());
00638 cout << "IPOPT Solver created for OSiL string solution" << endl;
00639
00640 osilreader = new OSiLReader();
00641 osolreader = new OSoLReader();
00642 ipoptSolver->osinstance = osilreader->readOSiL( osil);
00643 ipoptSolver->osoption = osolreader->readOSoL( osol);
00644 ipoptSolver->osol = osol;
00645 ipoptSolver->buildSolverInstance();
00646 ipoptSolver->solve();
00647 cout << "Here is the IPOPT solver solution for HS071_NLP" << endl;
00648 check = 17.014;
00649
00650 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00651 delete osilreader;
00652 osilreader = NULL;
00653 delete osolreader;
00654 osolreader = NULL;
00655 delete ipoptSolver;
00656 ipoptSolver = NULL;
00657 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on HS071_NLP.osil");
00658 unitTestResult << "Solved problem HS071.osil with Ipopt" << std::endl;
00659 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
00660
00661 cout << endl << "TEST " << ++nOfTest << ": Ipopt solver on rosenbrockmod.osil" << endl << endl;
00662 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00663 ipoptSolver = new IpoptSolver();
00664
00665
00666 osilFileName = dataDir + "osilFiles" + dirsep + "rosenbrockmod.osil";
00667 osolFileName = dataDir + "osolFiles" + dirsep + "rosenbrockmod_ipopt.osol";
00668 osil = fileUtil->getFileAsString( osilFileName.c_str());
00669 osol = fileUtil->getFileAsString( osolFileName.c_str());
00670 cout << "IPOPT Solver created for OSiL string solution" << endl;
00671 osilreader = new OSiLReader();
00672 osolreader = new OSoLReader();
00673 ipoptSolver->osil = osil;
00674 ipoptSolver->osoption = osolreader->readOSoL( osol);
00675 cout << "call the IPOPT Solver" << endl;
00676 ipoptSolver->buildSolverInstance();
00677 ipoptSolver->solve();
00678 check = 6.7279;
00679
00680 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00681 if(ok == false)
00682 throw ErrorClass(" Fail unit test with Ipopt on rosenbrockmod.osil");
00683 delete osilreader;
00684 osilreader = NULL;
00685 delete osolreader;
00686 osolreader = NULL;
00687 unitTestResult << "Solved problem rosenbrockmod.osil with Ipopt" << std::endl;
00688 delete ipoptSolver;
00689 ipoptSolver = NULL;
00690 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
00691
00692 cout << endl << "TEST " << ++nOfTest << ": Ipopt solver on parincQuadratic.osil" << endl << endl;
00693 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00694 ipoptSolver = new IpoptSolver();
00695
00696
00697 osilFileName = dataDir + "osilFiles" + dirsep + "parincQuadratic.osil";
00698 osolFileName = dataDir + "osolFiles" + dirsep + "parincQuadratic_ipopt.osol";
00699 osil = fileUtil->getFileAsString( osilFileName.c_str());
00700 osol = fileUtil->getFileAsString( osolFileName.c_str());
00701 cout << "IPOPT Solver created for OSiL string solution" << endl;
00702 osilreader = new OSiLReader();
00703 osolreader = new OSoLReader();
00704 ipoptSolver->osinstance = osilreader->readOSiL( osil);
00705 ipoptSolver->osil = osil;
00706 ipoptSolver->osol = osol;
00707 cout << "call the IPOPT Solver" << endl;
00708 ipoptSolver->buildSolverInstance();
00709 ipoptSolver->solve();
00710 cout << "Here is the IPOPT solver solution for parincQuadratic" << endl;
00711 check = 49920.5;
00712
00713 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00714 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on parincQuadradic.osil");
00715 delete osilreader;
00716 osilreader = NULL;
00717 delete osolreader;
00718 osolreader = NULL;
00719 unitTestResult << "Solved problem parincQuadratic.osil with Ipopt" << std::endl;
00720 delete ipoptSolver;
00721 ipoptSolver = NULL;
00722 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
00723
00724 cout << endl << "TEST " << ++nOfTest << ": Ipopt solver on parincLinear.osil" << endl << endl;
00725 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00726 ipoptSolver = new IpoptSolver();
00727
00728
00729 osilFileName = dataDir + "osilFiles" + dirsep + "parincLinear.osil";
00730 osolFileName = dataDir + "osolFiles" + dirsep + "parincLinear_ipopt.osol";
00731 osil = fileUtil->getFileAsString( osilFileName.c_str());
00732 osol = fileUtil->getFileAsString( osolFileName.c_str());
00733 cout << "IPOPT Solver created for OSiL string solution" << endl;
00734 osilreader = new OSiLReader();
00735 osolreader = new OSoLReader();
00736 ipoptSolver->osinstance = osilreader->readOSiL( osil);
00737 ipoptSolver->osoption = NULL;
00738 ipoptSolver->osol = "";
00739 cout << "call the IPOPT Solver" << endl;
00740 ipoptSolver->buildSolverInstance();
00741 ipoptSolver->solve();
00742 cout << "Here is the IPOPT solver solution for parincLinear" << endl;
00743 check = 7668;
00744
00745 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00746 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on parincLinear.osil");
00747 unitTestResult << "Solved problem parincLinear.osil with Ipopt" << std::endl;
00748 delete osilreader;
00749 osilreader = NULL;
00750 delete osolreader;
00751 osolreader = NULL;
00752 delete ipoptSolver;
00753 ipoptSolver = NULL;
00754 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
00755
00756 cout << endl << "TEST " << ++nOfTest << ": Ipopt solver on callBackTest.osil" << endl << endl;
00757 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00758 ipoptSolver = new IpoptSolver();
00759
00760
00761 osilFileName = dataDir + "osilFiles" + dirsep + "callBackTest.osil";
00762 osolFileName = dataDir + "osolFiles" + dirsep + "callBackTest_ipopt.osol";
00763 osil = fileUtil->getFileAsString( osilFileName.c_str());
00764 osol = fileUtil->getFileAsString( osolFileName.c_str());
00765 cout << "IPOPT Solver created for OSiL string solution" << endl;
00766 osilreader = new OSiLReader();
00767 osolreader = new OSoLReader();
00768 ipoptSolver->osinstance = osilreader->readOSiL( osil);
00769 ipoptSolver->osoption = osolreader->readOSoL( osol);
00770 ipoptSolver->osol = osol;
00771 cout << "call the IPOPT Solver" << endl;
00772 ipoptSolver->buildSolverInstance();
00773 ipoptSolver->solve();
00774 cout << "Here is the IPOPT solver solution for callBackTest" << endl;
00775 check = 1.00045e+06;
00776
00777 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00778 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on callBackTest.osil");
00779 unitTestResult << "Solved problem callBackTest.osil with Ipopt" << std::endl;
00780 delete osilreader;
00781 osilreader = NULL;
00782 delete osolreader;
00783 osolreader = NULL;
00784 delete ipoptSolver;
00785 ipoptSolver = NULL;
00786 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
00787
00788 cout << endl << "TEST " << ++nOfTest << ": Ipopt solver on callBackTestRowMajor.osil" << endl << endl;
00789 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00790 ipoptSolver = new IpoptSolver();
00791
00792
00793 osilFileName = dataDir + "osilFiles" + dirsep + "callBackTestRowMajor.osil";
00794 osolFileName = dataDir + "osolFiles" + dirsep + "callBackTestRowMajor_ipopt.osol";
00795 osil = fileUtil->getFileAsString( osilFileName.c_str());
00796 osol = fileUtil->getFileAsString( osolFileName.c_str());
00797 cout << "IPOPT Solver created for OSiL string solution" << endl;
00798 osilreader = new OSiLReader();
00799 osolreader = new OSoLReader();
00800 ipoptSolver->osinstance = NULL;
00801 ipoptSolver->osoption = NULL;
00802 ipoptSolver->osil = osil;
00803 ipoptSolver->osol = osol;
00804 cout << "call the IPOPT Solver" << endl;
00805
00806 ipoptSolver->solve();
00807 cout << "Here is the IPOPT solver solution for callBackTestRowMajor" << endl;
00808 check = 1.00045e+06;
00809
00810 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00811 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on callBackTestRowMajor.osil");
00812 delete osilreader;
00813 osilreader = NULL;
00814 delete osolreader;
00815 osolreader = NULL;
00816 delete ipoptSolver;
00817 ipoptSolver = NULL;
00818 unitTestResult << "Solved problem callBackRowMajor.osil with Ipopt" << std::endl;
00819 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
00820
00821 cout << endl << "TEST " << ++nOfTest << ": Ipopt solver on nonconvex.osil" << endl << endl;
00822
00823 osilreader = new OSiLReader();
00824 osolreader = new OSoLReader();
00825 ok = true;
00826 osilFileName = dataDir + "osilFiles" + dirsep + "nonconvex.osil";
00827
00828 osil = fileUtil->getFileAsString( osilFileName.c_str());
00829
00830 osol = "";
00831 solver = new IpoptSolver();
00832 solver->sSolverName = "ipopt";
00833 solver->osil = osil;
00834 solver->osol = osol;
00835
00836
00837 cout << "call the COIN - Ipopt Solver for nonconvex.osil" << endl;
00838 solver->buildSolverInstance();
00839
00840 std::cout << " CALL SOLVE " << std::endl;
00841 solver->solve();
00842
00843 cout << "Here is the Ipopt solver solution for nonconvex.osil" << endl;
00844
00845
00846 tmp_writer = new OSrLWriter();
00847 solver->osrl = tmp_writer->writeOSrL(solver->osresult);
00848 delete tmp_writer;
00849 tmp_writer = NULL;
00850
00851 cout << solver->osrl << endl << endl;
00852
00853
00854
00855
00856
00857
00858 delete solver;
00859 solver = NULL;
00860 unitTestResult << "Solved problem nonconvex.osil with Ipopt" << std::endl;
00861
00862
00863 delete osilreader;
00864 osilreader = NULL;
00865 delete osolreader;
00866 osolreader = NULL;
00867 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
00868
00869 cout << endl << "TEST " << ++nOfTest << ": Ipopt solver on rosenbrockorig.osil" << endl << endl;
00870
00871 osilreader = new OSiLReader();
00872 osolreader = new OSoLReader();
00873 ok = true;
00874 osilFileName = dataDir + "osilFiles" + dirsep + "rosenbrockorig.osil";
00875
00876 osil = fileUtil->getFileAsString( osilFileName.c_str());
00877
00878 osol = "";
00879 solver = new IpoptSolver();
00880 solver->sSolverName = "ipopt";
00881 solver->osil = osil;
00882 solver->osol = osol;
00883
00884
00885 cout << "call the COIN - Ipopt Solver for rosenbrockorig" << endl;
00886 solver->buildSolverInstance();
00887
00888 std::cout << " CALL SOLVE " << std::endl;
00889 solver->solve();
00890
00891 cout << "Here is the Ipopt solver solution for rosenbrockorig" << endl;
00892
00893
00894 tmp_writer = new OSrLWriter();
00895 solver->osrl = tmp_writer->writeOSrL(solver->osresult);
00896 delete tmp_writer;
00897 tmp_writer = NULL;
00898
00899 cout << solver->osrl << endl << endl;
00900
00901
00902
00903
00904
00905
00906 delete solver;
00907 solver = NULL;
00908 unitTestResult << "Solved problem rosenbrockorig.osil with Ipopt" << std::endl;
00909
00910
00911 delete osilreader;
00912 osilreader = NULL;
00913 delete osolreader;
00914 osolreader = NULL;
00915 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
00916
00917 cout << endl << "TEST " << ++nOfTest << ": Ipopt solver on HS071_feas.osil" << endl << endl;
00918 try {
00919 osilreader = new OSiLReader();
00920 osolreader = new OSoLReader();
00921 ok = true;
00922 osilFileName = dataDir + "osilFiles" + dirsep + "HS071_feas.osil";
00923
00924 osil = fileUtil->getFileAsString( osilFileName.c_str());
00925
00926 osol = "";
00927 solver = new IpoptSolver();
00928 solver->sSolverName = "ipopt";
00929 solver->osil = osil;
00930 solver->osol = osol;
00931
00932
00933 cout << "call the COIN - Ipopt Solver for HS071_feas.osil" << endl;
00934 solver->buildSolverInstance();
00935
00936 std::cout << " CALL SOLVE " << std::endl;
00937 solver->solve();
00938 }
00939 catch(const ErrorClass& eclass)
00940 {
00941 ok = (solver->osresult->getGeneralMessage() == "Ipopt NEEDS AN OBJECTIVE FUNCTION");
00942 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on HS071_feas.osil");
00943 }
00944
00945 cout << "Received error message from Ipopt: \"Ipopt NEEDS AN OBJECTIVE FUNCTION\"" << endl;
00946 unitTestResult << "Correctly diagnosed problem HS071_feas with Ipopt" << std::endl;
00947
00948 delete solver;
00949 solver = NULL;
00950 delete osilreader;
00951 osilreader = NULL;
00952 delete osolreader;
00953 osolreader = NULL;
00954
00955 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
00956
00957 #endif // end of #ifdef THOROUGH
00958 }
00959 catch(const ErrorClass& eclass){
00960 unitTestResultFailure << "Sorry Unit Test Failed Testing the Ipopt Solver:" + eclass.errormsg<< endl;
00961 }
00962 #endif // end of #ifdef COIN_HAS_IPOPT
00963
00964
00965 #ifdef COIN_HAS_BONMIN
00966 try{
00967 cout << endl << "TEST " << ++nOfTest << ": Bonmin solver on bonminEx1.osil" << endl << endl;
00968
00969 osilreader = new OSiLReader();
00970 osolreader = new OSoLReader();
00971 ok = true;
00972 osilFileName = dataDir + "osilFiles" + dirsep + "bonminEx1.osil";
00973 osolFileName = dataDir + "osolFiles" + dirsep + "bonminEx1_Bonmin.osol";
00974 osil = fileUtil->getFileAsString( osilFileName.c_str());
00975 osol = fileUtil->getFileAsString( osolFileName.c_str());
00976 solver = new BonminSolver();
00977
00978
00979 solver->osil = osil;
00980 solver->osoption = osolreader->readOSoL( osol);
00981 cout << "call the COIN - Bonmin Solver for bonminEx1" << endl;
00982
00983 solver->solve();
00984 cout << "Here is the Bonmin solver solution for bonminEx1" << endl;
00985 cout << solver->osrl << endl;
00986 check = -1.70711;
00987
00988 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00989 if(ok == false) throw ErrorClass(" Fail unit test with Bonmin on bonminEx1.osil");
00990 delete solver;
00991 solver = NULL;
00992 unitTestResult << "Solved problem bonminEx1.osil with Bonmin" << std::endl;
00993 delete osilreader;
00994 osilreader = NULL;
00995 delete osolreader;
00996 osolreader = NULL;
00997 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
00998
00999 #ifdef THOROUGH
01000 cout << endl << "TEST " << ++nOfTest << ": Bonmin solver on wayneQuadratic.osil" << endl << endl;
01001 ok = true;
01002 osilFileName = dataDir + "osilFiles" + dirsep + "wayneQuadratic.osil";
01003 osolFileName = dataDir + "osolFiles" + dirsep + "wayneQuadratic_Bonmin1.osol";
01004 osil = fileUtil->getFileAsString( osilFileName.c_str());
01005 osol = fileUtil->getFileAsString( osolFileName.c_str());
01006 osilreader = new OSiLReader();
01007 solver = new BonminSolver();
01008 solver->osol = osol;
01009 solver->osinstance = osilreader->readOSiL( osil);
01010 cout << "call the Bonmin Solver for wayneQuadratic" << endl;
01011 solver->buildSolverInstance();
01012
01013 solver->solve();
01014 cout << "Here is the Bonmin solver solution" << endl;
01015 cout << solver->osrl << endl;
01016 check = 2.925;
01017 std::cout << "CALL NEAR_EQUAL" << std::endl;
01018
01019 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01020 std::cout << "CALL NEAR_EQUAL" << std::endl;
01021 if(ok == false) throw ErrorClass(" Fail unit test with Bonmin on wayneQuadratic.osil");
01022 delete solver;
01023 solver = NULL;
01024 delete osilreader;
01025 osilreader = NULL;
01026 unitTestResult << "Solved problem wayneQuadratic.osil with Bonmin" << std::endl;
01027 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01028
01029 cout << endl << "TEST " << ++nOfTest << ": Bonmin solver on wayneQuadratic.osil" << endl << endl;
01030 ok = true;
01031 osilFileName = dataDir + "osilFiles" + dirsep + "wayneQuadratic.osil";
01032 osolFileName = dataDir + "osolFiles" + dirsep + "wayneQuadratic_Bonmin2.osol";
01033 osil = fileUtil->getFileAsString( osilFileName.c_str());
01034 osol = fileUtil->getFileAsString( osolFileName.c_str());
01035 osilreader = new OSiLReader();
01036 osolreader = new OSoLReader();
01037 solver = new BonminSolver();
01038 solver->osol = osol;
01039 solver->osinstance = osilreader->readOSiL( osil);
01040 solver->osoption = osolreader->readOSoL( osol);
01041 cout << "call the Bonmin Solver for wayneQuadratic" << endl;
01042 solver->buildSolverInstance();
01043
01044 solver->solve();
01045 cout << "Here is the Bonmin solver solution" << endl;
01046 cout << solver->osrl << endl;
01047 check = 2.925;
01048 std::cout << "CALL NEAR_EQUAL" << std::endl;
01049
01050 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01051 std::cout << "CALL NEAR_EQUAL" << std::endl;
01052 if(ok == false) throw ErrorClass(" Fail unit test with Bonmin on wayneQuadratic.osil");
01053 delete solver;
01054 solver = NULL;
01055 delete osilreader;
01056 osilreader = NULL;
01057 delete osolreader;
01058 osolreader = NULL;
01059 unitTestResult << "Solved problem wayneQuadratic.osil with Bonmin" << std::endl;
01060 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01061
01062
01063
01064
01065 cout << endl << "TEST " << ++nOfTest << ": Bonmin solver on rosenbrockorig.osil" << endl << endl;
01066 ok = true;
01067 osilFileName = dataDir + "osilFiles" + dirsep + "rosenbrockorig.osil";
01068
01069 osil = fileUtil->getFileAsString( osilFileName.c_str());
01070
01071 osilreader = new OSiLReader();
01072
01073 solver = new BonminSolver();
01074 solver->osol = "";
01075 solver->osinstance = osilreader->readOSiL( osil);
01076
01077 cout << "call the Bonmin Solver for rosenbrockorig" << endl;
01078 solver->buildSolverInstance();
01079 solver->solve();
01080 cout << "Here is the Bonmin solver solution" << endl;
01081 cout << solver->osrl << endl;
01082 check = 2.925;
01083 std::cout << "CALL NEAR_EQUAL" << std::endl;
01084
01085 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01086 std::cout << "CALL NEAR_EQUAL" << std::endl;
01087 if(ok == false) throw ErrorClass(" Fail unit test with Bonmin on rosenbrockorig.osil");
01088 delete solver;
01089 solver = NULL;
01090 delete osilreader;
01091 osilreader = NULL;
01092 delete osolreader;
01093 osolreader = NULL;
01094 unitTestResult << "Solved problem rosenbrockorig.osil with Bonmin" << std::endl;
01095 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01096
01097
01098
01099 cout << endl << "TEST " << ++nOfTest << ": Bonmin solver on rosenbrockinteger.osil" << endl << endl;
01100 ok = true;
01101 osilFileName = dataDir + "osilFiles" + dirsep + "rosenbrockinteger.osil";
01102
01103 osil = fileUtil->getFileAsString( osilFileName.c_str());
01104
01105 osilreader = new OSiLReader();
01106
01107 solver = new BonminSolver();
01108 solver->osol = "";
01109 solver->osinstance = osilreader->readOSiL( osil);
01110
01111 cout << "call the Bonmin Solver for rosenbrockinteger" << endl;
01112 solver->buildSolverInstance();
01113 solver->solve();
01114 cout << "Here is the Bonmin solver solution" << endl;
01115 cout << solver->osrl << endl;
01116 check = 2.925;
01117 std::cout << "CALL NEAR_EQUAL" << std::endl;
01118
01119 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01120 std::cout << "CALL NEAR_EQUAL" << std::endl;
01121 if(ok == false) throw ErrorClass(" Fail unit test with Bonmin on rosenbrockinteger.osil");
01122 delete solver;
01123 solver = NULL;
01124 delete osilreader;
01125 osilreader = NULL;
01126 delete osolreader;
01127 osolreader = NULL;
01128 unitTestResult << "Solved problem rosenbrockinteger.osil with Bonmin" << std::endl;
01129 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01130
01131 #endif // end of #ifdef THOROUGH
01132 }
01133 catch(const ErrorClass& eclass){
01134 cout << "OSrL = " << solver->osrl << endl;
01135 cout << endl << endl << endl;
01136 unitTestResultFailure << "Sorry Unit Test Failed Testing the Bonmin Solver:" + eclass.errormsg << endl;
01137 }
01138 #endif // end of #ifdef COIN_HAS_BONMIN
01139
01140
01141 #ifdef COIN_HAS_COUENNE
01142 try{
01143 cout << endl << "TEST " << ++nOfTest << ": Couenne solver on bonminEx1.osil" << endl << endl;
01144 CouenneSolver *solver = NULL;
01145
01146
01147 osilreader = new OSiLReader();
01148 osolreader = new OSoLReader();
01149 ok = true;
01150 osilFileName = dataDir + "osilFiles" + dirsep + "bonminEx1.osil";
01151 osolFileName = dataDir + "osolFiles" + dirsep + "bonminEx1_Couenne.osol";
01152 osil = fileUtil->getFileAsString( osilFileName.c_str());
01153 osol = fileUtil->getFileAsString( osolFileName.c_str());
01154 solver = new CouenneSolver();
01155 solver->sSolverName = "bonmin";
01156 solver->osil = osil;
01157 solver->osol = osol;
01158
01159
01160 cout << "call the COIN - Couenne Solver for bonminEx1" << endl;
01161 solver->buildSolverInstance();
01162
01163 std::cout << " CALL SOLVE " << std::endl;
01164 solver->solve();
01165
01166 cout << "Here is the Couenne solver solution for bonminEx1" << endl;
01167
01168 tmp_writer = new OSrLWriter();
01169 solver->osrl = tmp_writer->writeOSrL(solver->osresult);
01170 delete tmp_writer;
01171 tmp_writer = NULL;
01172
01173 check = -1.70711;
01174
01175 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01176 if(ok == false) throw ErrorClass(" Fail unit test with Couenne on bonminEx1.osil");
01177
01178 delete solver;
01179 solver = NULL;
01180 unitTestResult << "Solved problem bonminEx1.osil with Couenne" << std::endl;
01181
01182
01183 delete osilreader;
01184 osilreader = NULL;
01185 delete osolreader;
01186 osolreader = NULL;
01187 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01188
01189 #ifdef THOROUGH
01190 cout << endl << "TEST " << ++nOfTest << ": Couenne solver on bonminEx1_Nonlinear.osil" << endl << endl;
01191
01192 osilreader = new OSiLReader();
01193 osolreader = new OSoLReader();
01194 ok = true;
01195 osilFileName = dataDir + "osilFiles" + dirsep + "bonminEx1_Nonlinear.osil";
01196
01197 osil = fileUtil->getFileAsString( osilFileName.c_str());
01198
01199 osol = "";
01200 solver = new CouenneSolver();
01201 solver->sSolverName = "bonmin";
01202 solver->osil = osil;
01203 solver->osol = osol;
01204
01205
01206 cout << "call the COIN - Couenne Solver for bonminEx1_Nonlinear" << endl;
01207 solver->buildSolverInstance();
01208
01209 std::cout << " CALL SOLVE " << std::endl;
01210 solver->solve();
01211
01212 cout << "Here is the Couenne solver solution for bonminEx1_Nonlinear.osil" << endl;
01213
01214
01215 tmp_writer = new OSrLWriter();
01216 solver->osrl = tmp_writer->writeOSrL(solver->osresult);
01217 delete tmp_writer;
01218 tmp_writer = NULL;
01219
01220 cout << solver->osrl << endl << endl;
01221
01222
01223
01224
01225
01226
01227 delete solver;
01228 solver = NULL;
01229 unitTestResult << "Solved problem bonminEx1_Nonlinear with Couenne" << std::endl;
01230
01231
01232 delete osilreader;
01233 osilreader = NULL;
01234 delete osolreader;
01235 osolreader = NULL;
01236 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01237
01238
01239 cout << endl << "TEST " << ++nOfTest << ": Couenne solver on nonconvex.osil" << endl << endl;
01240
01241 osilreader = new OSiLReader();
01242 osolreader = new OSoLReader();
01243 ok = true;
01244 osilFileName = dataDir + "osilFiles" + dirsep + "nonconvex.osil";
01245
01246 osil = fileUtil->getFileAsString( osilFileName.c_str());
01247
01248 osol = "";
01249 solver = new CouenneSolver();
01250 solver->sSolverName = "bonmin";
01251 solver->osil = osil;
01252 solver->osol = osol;
01253
01254
01255 cout << "call the COIN - Couenne Solver for nonconvex.osil" << endl;
01256 solver->buildSolverInstance();
01257
01258 std::cout << " CALL SOLVE " << std::endl;
01259 solver->solve();
01260
01261 cout << "Here is the Couenne solver solution for nonconvex.osil" << endl;
01262
01263
01264 tmp_writer = new OSrLWriter();
01265 solver->osrl = tmp_writer->writeOSrL(solver->osresult);
01266 delete tmp_writer;
01267 tmp_writer = NULL;
01268
01269 cout << solver->osrl << endl << endl;
01270
01271
01272
01273
01274
01275
01276 delete solver;
01277 solver = NULL;
01278 unitTestResult << "Solved problem nonconvex.osil with Couenne" << std::endl;
01279
01280
01281 delete osilreader;
01282 osilreader = NULL;
01283 delete osolreader;
01284 osolreader = NULL;
01285 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01286
01287 cout << endl << "TEST " << ++nOfTest << ": Couenne solver on rosenbrockorig.osil" << endl << endl;
01288
01289 osilreader = new OSiLReader();
01290 osolreader = new OSoLReader();
01291 ok = true;
01292 osilFileName = dataDir + "osilFiles" + dirsep + "rosenbrockorig.osil";
01293
01294 osil = fileUtil->getFileAsString( osilFileName.c_str());
01295
01296 osol = "";
01297 solver = new CouenneSolver();
01298 solver->sSolverName = "bonmin";
01299 solver->osil = osil;
01300 solver->osol = osol;
01301
01302
01303 cout << "call the COIN - Couenne Solver for rosenbrockorig" << endl;
01304 solver->buildSolverInstance();
01305
01306 std::cout << " CALL SOLVE " << std::endl;
01307 solver->solve();
01308
01309 cout << "Here is the Couenne solver solution for rosenbrockorig" << endl;
01310
01311
01312 tmp_writer = new OSrLWriter();
01313 solver->osrl = tmp_writer->writeOSrL(solver->osresult);
01314 delete tmp_writer;
01315 tmp_writer = NULL;
01316
01317 cout << solver->osrl << endl << endl;
01318
01319
01320
01321
01322
01323
01324 delete solver;
01325 solver = NULL;
01326 unitTestResult << "Solved problem rosenbrockorig.osil with Couenne" << std::endl;
01327
01328
01329 delete osilreader;
01330 osilreader = NULL;
01331 delete osolreader;
01332 osolreader = NULL;
01333 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01334
01335
01336
01337 cout << endl << "TEST " << ++nOfTest << ": Couenne solver on rosenbrockinteger.osil" << endl << endl;
01338
01339 osilreader = new OSiLReader();
01340 osolreader = new OSoLReader();
01341 ok = true;
01342 osilFileName = dataDir + "osilFiles" + dirsep + "rosenbrockinteger.osil";
01343
01344 osil = fileUtil->getFileAsString( osilFileName.c_str());
01345
01346 osol = "";
01347 solver = new CouenneSolver();
01348 solver->sSolverName = "bonmin";
01349 solver->osil = osil;
01350 solver->osol = osol;
01351
01352
01353 cout << "call the COIN - Couenne Solver for rosenbrockinteger" << endl;
01354 solver->buildSolverInstance();
01355
01356 std::cout << " CALL SOLVE " << std::endl;
01357 solver->solve();
01358
01359 cout << "Here is the Couenne solver solution for rosenbrockinteger" << endl;
01360
01361
01362 tmp_writer = new OSrLWriter();
01363 solver->osrl = tmp_writer->writeOSrL(solver->osresult);
01364 delete tmp_writer;
01365 tmp_writer = NULL;
01366
01367 cout << solver->osrl << endl << endl;
01368
01369
01370
01371
01372
01373
01374 delete solver;
01375 solver = NULL;
01376 unitTestResult << "Solved problem rosenbrockinteger.osil with Couenne" << std::endl;
01377
01378
01379 delete osilreader;
01380 osilreader = NULL;
01381 delete osolreader;
01382 osolreader = NULL;
01383 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01384
01385
01386 cout << endl << "TEST " << ++nOfTest << ": Couenne solver on HS071_feas.osil" << endl << endl;
01387
01388 osilreader = new OSiLReader();
01389 osolreader = new OSoLReader();
01390 ok = true;
01391 osilFileName = dataDir + "osilFiles" + dirsep + "HS071_feas.osil";
01392
01393 osil = fileUtil->getFileAsString( osilFileName.c_str());
01394
01395 osol = "";
01396 solver = new CouenneSolver();
01397 solver->sSolverName = "bonmin";
01398 solver->osil = osil;
01399 solver->osol = osol;
01400
01401
01402 cout << "call the COIN - Couenne Solver for HS071_feas.osil" << endl;
01403 solver->buildSolverInstance();
01404
01405 std::cout << " CALL SOLVE " << std::endl;
01406 solver->solve();
01407
01408 cout << "Here is the Couenne solver solution for HS071_feas" << endl;
01409
01410
01411 tmp_writer = new OSrLWriter();
01412 solver->osrl = tmp_writer->writeOSrL(solver->osresult);
01413 delete tmp_writer;
01414 tmp_writer = NULL;
01415
01416 cout << solver->osrl << endl << endl;
01417
01418
01419
01420
01421
01422
01423 delete solver;
01424 solver = NULL;
01425 unitTestResult << "Solved problem HS071_feas with Couenne" << std::endl;
01426
01427
01428 delete osilreader;
01429 osilreader = NULL;
01430 delete osolreader;
01431 osolreader = NULL;
01432 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01433
01434 #endif
01435
01436 }
01437 catch(const ErrorClass& eclass){
01438 cout << "OSrL = " << solver->osrl << endl;
01439 cout << endl << endl << endl;
01440 unitTestResultFailure << "Sorry Unit Test Failed Testing the Couenne Solver:" + eclass.errormsg << endl;
01441
01442 }
01443 #endif
01444
01445
01446
01447 #ifdef COIN_HAS_SYMPHONY
01448 try{
01449 cout << endl << "TEST " << ++nOfTest << ": SYMPHONY solver on p0033.osil" << endl << endl;
01450 ok = true;
01451 osilFileName = dataDir + "osilFiles" + dirsep + "p0033.osil";
01452 osolFileName = dataDir + "osolFiles" + dirsep + "p0033_sym.osol";
01453 osil = fileUtil->getFileAsString( osilFileName.c_str());
01454 osol = fileUtil->getFileAsString( osolFileName.c_str());
01455 osolreader = new OSoLReader();
01456 solver = new CoinSolver();
01457 solver->sSolverName = "symphony";
01458 solver->osil = osil;
01459 solver->osinstance = NULL;
01460 solver->osoption = osolreader->readOSoL( osol);
01461 cout << "build the solver instance for COIN - SYMPHONY" << endl;
01462 solver->buildSolverInstance();
01463
01464 solver->solve();
01465 cout << "Here is the COIN SYMPHONY solver solution for p0033" << endl;
01466 cout << solver->osrl << endl;
01467 check = 3089;
01468
01469 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01470 if(ok == false) throw ErrorClass(" Fail unit test with SYMPHONY on p0033.osil");
01471 delete solver;
01472 solver = NULL;
01473 delete osolreader;
01474 osolreader = NULL;
01475 unitTestResult << "Solved problem p0033.osil with SYMPHONY" << std::endl;
01476 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01477 }
01478 catch(const ErrorClass& eclass){
01479 cout << "OSrL = " << solver->osrl << endl;
01480 cout << endl << endl << endl;
01481 unitTestResultFailure << "Sorry Unit Test Failed Testing the SYMPHONY Solver:" + eclass.errormsg << endl;
01482 }
01483 #endif
01484
01485
01486
01487 #ifdef COIN_HAS_DYLP
01488 try{
01489 cout << endl << "TEST " << ++nOfTest << ": DyLP solver on parincLinear.osil" << endl << endl;
01490 ok = true;
01491 osilFileName = dataDir + "osilFiles" + dirsep + "parincLinear.osil";
01492 osolFileName = dataDir + "osolFiles" + dirsep + "parincLinear_dylp.osol";
01493 osil = fileUtil->getFileAsString( osilFileName.c_str());
01494 osol = fileUtil->getFileAsString( osolFileName.c_str());
01495 osilreader = new OSiLReader();
01496 solver = new CoinSolver();
01497 solver->sSolverName = "dylp";
01498 solver->osol = osol;
01499 solver->osinstance = osilreader->readOSiL( osil);
01500 cout << "call the COIN - DyLP solver for parincLinear" << endl;
01501 solver->buildSolverInstance();
01502 solver->solve();
01503 cout << "Here is the COIN - DyLP solver solution for parincLinear" << endl;
01504 cout << solver->osrl << endl;
01505 check = 7668;
01506
01507 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01508 if(ok == false) throw ErrorClass(" Fail unit test with DyLP on parincLinear.osil");
01509 delete solver;
01510 solver = NULL;
01511 delete osilreader;
01512 osilreader = NULL;
01513 unitTestResult << "Solved problem parincLinear.osil with DyLP" << std::endl;
01514 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01515 }
01516 catch(const ErrorClass& eclass){
01517 cout << "OSrL = " << solver->osrl << endl;
01518 cout << endl << endl << endl;
01519 unitTestResultFailure <<"Sorry Unit Test Failed Testing the DyLP Solver:" + eclass.errormsg << endl;
01520 }
01521 #endif
01522
01523
01524 #ifdef COIN_HAS_VOL
01525 try{
01526 cout << endl << "TEST " << ++nOfTest << ": Vol solver on volumeTest.osil" << endl << endl;
01527 ok = true;
01528 osilFileName = dataDir + "osilFiles" + dirsep + "volumeTest.osil";
01529 osolFileName = dataDir + "osolFiles" + dirsep + "volumeTest_vol.osol";
01530 osil = fileUtil->getFileAsString( osilFileName.c_str());
01531 osol = fileUtil->getFileAsString( osolFileName.c_str());
01532 osolreader = new OSoLReader();
01533 solver = new CoinSolver();
01534 solver->sSolverName = "vol";
01535 solver->osil = osil;
01536 solver->osinstance = NULL;
01537 solver->osoption = osolreader->readOSoL( osol);
01538 cout << "call the COIN - Vol solver for volumeTest" << endl;
01539 solver->buildSolverInstance();
01540 solver->solve();
01541 cout << "Here is the COIN - Vol solver solution for parincLinear" << endl;
01542 cout << solver->osrl << endl;
01543 check = 7;
01544
01545 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01546 if(ok == false) throw ErrorClass(" Fail unit test with Vol on volumeTest.osil");
01547 delete solver;
01548 solver = NULL;
01549 delete osolreader;
01550 osolreader = NULL;
01551 unitTestResult << "Solved problem volumeTest.osil with Vol" << std::endl;
01552 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01553 }
01554 catch(const ErrorClass& eclass){
01555 cout << "OSrL = " << solver->osrl << endl;
01556 cout << endl << endl << endl;
01557 unitTestResultFailure <<"Sorry Unit Test Failed Testing the Vol Solver:" + eclass.errormsg << endl;
01558 }
01559 #endif
01560
01561 #ifdef COIN_HAS_GLPK
01562 try{
01563 cout << endl << "TEST " << ++nOfTest << ": GLPK solver on p0033.osil" << endl << endl;
01564 ok = true;
01565 osilFileName = dataDir + "osilFiles" + dirsep + "p0033.osil";
01566 osolFileName = dataDir + "osolFiles" + dirsep + "p0033_glpk.osol";
01567 osil = fileUtil->getFileAsString( osilFileName.c_str());
01568 osol = fileUtil->getFileAsString( osolFileName.c_str());
01569 osilreader = new OSiLReader();
01570 osolreader = new OSoLReader();
01571 solver = new CoinSolver();
01572 solver->sSolverName = "glpk";
01573 solver->osinstance = osilreader->readOSiL( osil);
01574 solver->osoption = osolreader->readOSoL( osol);
01575 cout << "call the GLPK Solver for p0033" << endl;
01576 solver->buildSolverInstance();
01577 solver->solve();
01578 cout << "Here is the GLPK solver solution for p0033" << endl;
01579 cout << solver->osrl << endl;
01580 check = 3089;
01581
01582 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01583 if(ok == false) throw ErrorClass(" Fail unit test with GLPK on p0033.osil");
01584 delete solver;
01585 solver = NULL;
01586 delete osilreader;
01587 osilreader = NULL;
01588 delete osolreader;
01589 osolreader = NULL;
01590 unitTestResult << "Solved problem p0033.osil with GLPK" << std::endl;
01591 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01592 }
01593 catch(const ErrorClass& eclass){
01594 cout << "OSrL = " << solver->osrl << endl;
01595 cout << endl << endl << endl;
01596 unitTestResultFailure <<"Sorry Unit Test Failed Testing the Glpk Solver:" + eclass.errormsg << endl;
01597 }
01598 #endif
01599
01600
01601
01602 #ifdef COIN_HAS_CPX
01603 try{
01604 cout << endl << "TEST " << ++nOfTest << ": Cplex solver on p0033.osil" << endl << endl;
01605 ok = true;
01606 osilFileName = dataDir + "osilFiles" + dirsep + "p0033.osil";
01607 osolFileName = dataDir + "osolFiles" + dirsep + "p0033_cpx.osol";
01608 osil = fileUtil->getFileAsString( osilFileName.c_str());
01609 osol = fileUtil->getFileAsString( osolFileName.c_str());
01610 solver = new CoinSolver();
01611 solver->sSolverName = "cplex";
01612 solver->osil = osil;
01613 solver->osol = osol;
01614 solver->osinstance = NULL;
01615 cout << "call the CPLEX Solver for p0033" << endl;
01616 solver->buildSolverInstance();
01617 solver->solve();
01618 cout << "Here is the CPLEX solver solution for p0033" << endl;
01619 cout << solver->osrl << endl;
01620 check = 3089;
01621
01622 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01623 if(ok == false) throw ErrorClass(" Fail unit test with CPLEX on p0033.osil");
01624 delete solver;
01625 solver = NULL;
01626 unitTestResult << "Solved problem p0033.osil with CPLEX" << std::endl;
01627 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01628 }
01629 catch(const ErrorClass& eclass){
01630 cout << "OSrL = " << solver->osrl << endl;
01631 cout << endl << endl << endl;
01632 unitTestResultFailure <<"Sorry Unit Test Failed Testing the Cplex Solver:" + eclass.errormsg << endl;
01633 }
01634 #endif
01635
01636
01637 #ifdef COIN_HAS_LINDO
01638 try{
01639 cout << endl << "TEST " << ++nOfTest << ": Lindo solver on lindoapiaddins.osil" << endl << endl;
01640 ok = true;
01641 osilFileName = dataDir + "osilFiles" + dirsep + "lindoapiaddins.osil";
01642 osolFileName = dataDir + "osolFiles" + dirsep + "lindoapiaddins_lindo.osol";
01643 osil = fileUtil->getFileAsString( osilFileName.c_str());
01644 osol = fileUtil->getFileAsString( osolFileName.c_str());
01645 osilreader = new OSiLReader();
01646 cout << "create a new LINDO Solver for OSiL string solution" << endl;
01647 solver = new LindoSolver();
01648 solver->osinstance = osilreader->readOSiL( osil);
01649 solver->osol = osol;
01650 cout << "call the LINDO Solver" << endl;
01651 solver->buildSolverInstance();
01652 solver->solve();
01653 cout << "Here is the LINDO solver solution" << endl;
01654 cout << solver->osrl << endl;
01655 check = 99;
01656
01657 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01658 if(ok == false) throw ErrorClass(" Fail unit test with LINDO on lindoapiaddins.osil");
01659 solver->osinstance = NULL;
01660 delete solver;
01661 solver = NULL;
01662 osilreader = NULL;
01663 delete osolreader;
01664 unitTestResult << "Solved problem lindoapiaddins.osil with Lindo" << std::endl;
01665 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01666
01667 #ifdef THOUROUGH
01668
01669 cout << endl << "TEST " << ++nOfTest << ": Lindo solver on rosenbrockmod.osil" << endl << endl;
01670 osilFileName = dataDir + "osilFiles" + dirsep + "rosenbrockmod.osil";
01671 osolFileName = dataDir + "osolFiles" + dirsep + "rosenbrockmod_lindo.osol";
01672 osil = fileUtil->getFileAsString( osilFileName.c_str());
01673 osol = fileUtil->getFileAsString( osolFileName.c_str());
01674 solver = new LindoSolver();
01675 solver->osil = osil;
01676 solver->osol = osol;
01677 solver->osinstance = NULL;
01678 cout << "call the LINDO Solver" << endl;
01679 solver->buildSolverInstance();
01680 solver->solve();
01681 cout << "Here is the LINDO solver solution" << endl;
01682 cout << solver->osrl << endl;
01683 check = 6.7279;
01684
01685 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01686 if(ok == false) throw ErrorClass(" Fail unit test with LINDO on rosenbrockmod.osil");
01687 solver->osinstance = NULL;
01688 delete solver;
01689 solver = NULL;
01690 unitTestResult << "Solved problem rosenbrockmod.osil with Lindo" << std::endl;
01691 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01692
01693
01694 cout << endl << "TEST " << ++nOfTest << ": Lindo solver on parincQuadratic.osil" << endl << endl;
01695 osilFileName = dataDir + "osilFiles" + dirsep + "parincQuadratic.osil";
01696 osolFileName = dataDir + "osolFiles" + dirsep + "parincQuadratic_lindo.osol";
01697 osil = fileUtil->getFileAsString( osilFileName.c_str());
01698 osol = fileUtil->getFileAsString( osolFileName.c_str());
01699 osolreader = new OSoLReader();
01700 solver = new LindoSolver();
01701 solver->osil = osil;
01702 solver->osol = osol;
01703 solver->osinstance = NULL;
01704 solver->osoption = osolreader->readOSoL( osol);
01705 cout << "call the LINDO Solver" << endl;
01706 solver->buildSolverInstance();
01707 solver->solve();
01708 cout << "Here is the LINDO solver solution" << endl;
01709 cout << solver->osrl << endl;
01710 check = 49920.5;
01711
01712 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01713 if(ok == false) throw ErrorClass(" Fail unit test with LINDO on parincQuadratic.osil");
01714 delete solver;
01715 solver = NULL;
01716 delete osolreader;
01717 osolreader = NULL;
01718 unitTestResult << "Solved problem parincQuadratic.osil with Lindo" << std::endl;
01719 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01720
01721
01722
01723
01724
01725
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749
01750
01751
01752 #endif
01753 }
01754 catch(const ErrorClass& eclass){
01755
01756 cout << endl << endl << endl;
01757 unitTestResultFailure <<"Sorry Unit Test Failed Testing the LINDO Solver:" + eclass.errormsg << endl << endl;
01758 }
01759 #endif
01760
01761
01762
01763
01764
01765 try{
01766 cout << endl << "TEST " << ++nOfTest << ": Cbc solver using MPS file" << endl << endl;
01767 ok = true;
01768
01769
01770 cout << "create a COIN Solver for MPS - OSInstance solution" << endl;
01771 solver = new CoinSolver();
01772 solver->sSolverName = "cbc";
01773 mps2osil = new OSmps2osil( mpsFileName);
01774 mps2osil->createOSInstance() ;
01775 solver->osinstance = mps2osil->osinstance;
01776 osol = "<osol t></osol>";
01777 solver->osol = osol;
01778 cout << "call COIN Solve" << endl;
01779 solver->buildSolverInstance();
01780 solver->solve();
01781 cout << "Here is the COIN solver solution" << endl;
01782 cout << solver->osrl << endl;
01783 check = -7668;
01784
01785 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01786 if(ok == false) throw ErrorClass(" Fail unit test with COIN Solver on MPS test problem parincLinear.mps");
01787 delete solver;
01788 solver = NULL;
01789 delete mps2osil;
01790 mps2osil = NULL;
01791
01792
01793 unitTestResult << "Test the MPS -> OSiL converter on parinc.mps using Cbc" << std::endl;
01794 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01795 }
01796 catch(const ErrorClass& eclass){
01797 cout << "OSrL = " << solver->osrl << endl;
01798 cout << endl << endl << endl;
01799 unitTestResultFailure <<"Sorry Unit Test Failed Testing the MPS converter:" + eclass.errormsg << endl;
01800 }
01801
01802
01803 try{
01804 #ifdef COIN_HAS_ASL
01805 cout << endl << "TEST " << ++nOfTest << ": AMPL solver interface" << endl << endl;
01806 ok = true;
01807 cout << "create a cbc Solver for AMPL nl - OSInstance solution" << endl;
01808 solver = new CoinSolver();
01809 solver->sSolverName = "cbc";
01810 nl2osil = new OSnl2osil( nlFileName);
01811 nl2osil->createOSInstance() ;
01812 solver->osinstance = nl2osil->osinstance;
01813 osol = "";
01814 solver->osol = osol;
01815 cout << "call Cbc Solve" << endl;
01816 solver->buildSolverInstance();
01817 solver->solve();
01818 cout << "Here is the Cbc solver solution" << endl;
01819 cout << solver->osrl << endl;
01820 check = 7668;
01821
01822 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01823 if(ok == false) throw ErrorClass(" Fail unit test with OSnl2osil on problem parinc.nl");
01824 solver->osinstance = NULL;
01825 delete solver;
01826 solver = NULL;
01827 cout << "call delete nl2osil" << endl;
01828 delete nl2osil;
01829 nl2osil = NULL;
01830 unitTestResult << "Test the AMPL nl -> OSiL converter on parinc.nl using Cbc" << std::endl;
01831 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01832 #endif
01833 }
01834 catch(const ErrorClass& eclass){
01835 cout << "OSrL = " << solver->osrl << endl;
01836 cout << endl << endl << endl;
01837 unitTestResultFailure <<"Sorry Unit Test Failed Testing AMPL:" + eclass.errormsg << endl;
01838 }
01839
01840
01841
01842
01843 try{
01844 cout << endl << "TEST " << ++nOfTest << ": b64 operations" << endl << endl;
01845 ok = true;
01846 OSiLWriter osilwriter;
01847 osilwriter.m_bWriteBase64 = true;
01848 solver = new CoinSolver();
01849 solver->sSolverName = "cbc";
01850 mps2osil = new OSmps2osil( mpsFileName);
01851 solver->osinstance = NULL;
01852 osol = "<osol></osol>";
01853 solver->osol = osol;
01854 mps2osil->createOSInstance() ;
01855 solver->osil = osilwriter.writeOSiL( mps2osil->osinstance) ;
01856 std::cout << solver->osil << std::endl;
01857 solver->buildSolverInstance();
01858 solver->solve();
01859 cout << endl << endl;
01860 cout << "COIN solution of a OSiL string in b64 format" << endl;
01861 cout << solver->osrl;
01862 check = -7668;
01863
01864 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01865 if(ok == false) throw ErrorClass(" Fail unit test with COIN Cbc cSolver on b64 test problem parincLinear.mps");
01866 solver->osinstance = NULL;
01867 delete solver;
01868 solver = NULL;
01869 delete mps2osil;
01870 mps2osil = NULL;
01871 unitTestResult << "Test a problem written in b64 and then converted to OSInstance" << std::endl;
01872 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01873 }
01874 catch(const ErrorClass& eclass){
01875 cout << endl << endl;
01876 cout << eclass.errormsg << endl << endl;
01877 cout << "OSrL = " << solver->osrl << endl;
01878 cout << endl << endl << endl;
01879 unitTestResultFailure << "Sorry Unit Test Failed Testing Use of Base 64" << endl;
01880
01881 }
01882 #endif //INSTALLATION_TEST
01883
01884
01885 #ifdef COMPONENT_DEBUG
01886
01887
01888 try{
01889 cout << endl << "TEST " << ++nOfTest << ": postfix and prefix routines" << endl << endl;
01890 std::string expTreeTest = dataDir + "osilFiles" + dirsep + "rosenbrockmod.osil";
01891 osil = fileUtil->getFileAsString( expTreeTest.c_str() ) ;
01892 OSInstance *osinstance = NULL;
01893
01894 OSiLReader *osilreader = NULL;
01895 osilreader = new OSiLReader();
01896
01897 osinstance = osilreader->readOSiL( osil);
01898 OSExpressionTree* expTree = osinstance->getNonlinearExpressionTree( -1);
01899 if(expTree == NULL) throw ErrorClass(" Null expression tree when testing prefix and postfix routines");
01900 std::vector<OSnLNode*> postfixVec;
01901
01902 postfixVec = osinstance->getNonlinearExpressionTreeInPostfix( -1);
01903
01904 unsigned int n = postfixVec.size();
01905
01906 std::string *nodeNames1 = new std::string[ n];
01907 std::string *nodeNames2 = new std::string[ n];
01908 for (int i = 0 ; i < n; i++){
01909 std::cout << postfixVec[i]->snodeName << std::endl;
01910 nodeNames1[i] = postfixVec[i]->snodeName;
01911 }
01912
01913
01914 expTree->m_treeRoot = postfixVec[ n - 1]->createExpressionTreeFromPostfix( postfixVec);
01915
01916
01917 std::vector<OSnLNode*> prefixVec;
01918
01919 prefixVec = osinstance->getNonlinearExpressionTreeInPrefix( -1);
01920
01921
01922 expTree->m_treeRoot = prefixVec[ 0]->createExpressionTreeFromPrefix( prefixVec);
01923
01924
01925 postfixVec = expTree->m_treeRoot->getPostfixFromExpressionTree();
01926
01927 if(postfixVec.size() != n) throw ErrorClass(" Problem with creating expression trees");
01928 std::cout << std::endl << std::endl;
01929 for (int i = 0 ; i < n; i++){
01930
01931 nodeNames2[i] = postfixVec[i]->snodeName;
01932 if( nodeNames1[i] != nodeNames2[ i]) throw ErrorClass(" Problem with creating expression trees");
01933 }
01934
01935
01936 delete[] nodeNames1;
01937 delete[] nodeNames2;
01938
01939 delete osilreader;
01940 osilreader = NULL;
01941 osinstance = NULL;
01942 unitTestResult << "Successful test of prefix and postfix conversion routines" << std::endl;
01943 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01944
01945 }
01946 catch(const ErrorClass& eclass){
01947 cout << endl << endl << endl;
01948 unitTestResultFailure << eclass.errormsg << endl;
01949 }
01950
01951 try{
01952 cout << endl << "TEST " << ++nOfTest << ": nonlinear operators" << endl << endl;
01953 ok = true;
01954 std::string operatorTest = dataDir + "osilFiles" + dirsep + "testOperators.osil";
01955 osil = fileUtil->getFileAsString( operatorTest.c_str() );
01956 OSInstance *osinstance = NULL;
01957
01958 OSiLReader *osilreader = NULL;
01959 osilreader = new OSiLReader();
01960 OSiLWriter *osilwriter = NULL;
01961 osilwriter = new OSiLWriter();
01962
01963 osinstance = osilreader->readOSiL( osil);
01964
01965 OSExpressionTree* expTree = osinstance->getNonlinearExpressionTree( -1);
01966 std::vector<OSnLNode*> postfixVec;
01967 postfixVec = expTree->m_treeRoot->getPostfixFromExpressionTree();
01968 int n = postfixVec.size();
01969 std::string *nodeNames1 = new std::string[ n];
01970 for (int i = 0 ; i < n; i++){
01971 std::cout << postfixVec[i]->snodeName << std::endl;
01972 nodeNames1[i] = postfixVec[i]->snodeName;
01973 }
01974 std::cout << std::endl << std::endl;
01975 std::cout << osilwriter->writeOSiL( osinstance) << std::endl;
01976
01977 double *x = NULL;
01978 x = new double[2];
01979 x[0] = 1;
01980 x[1] = 2;
01981 double parserTestVal = expTree->m_treeRoot->calculateFunction( x);
01982 std::cout << "ParserTest Val = " << parserTestVal << std::endl;
01983 check = 11;
01984
01985 ok = ( fabs(check - expTree->m_treeRoot->calculateFunction( x))/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01986 if(ok == false) throw ErrorClass(" Problem evaluating expression tree");
01987 delete[] x;
01988 delete[] nodeNames1;
01989 delete osilreader;
01990 osilreader = NULL;
01991 delete osilwriter;
01992 osilwriter = NULL;
01993 osinstance = NULL;
01994
01995 unitTestResult << "Successful test of nonlinear operators using file testOperators.osil" << std::endl;
01996 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
01997 }
01998 catch(const ErrorClass& eclass){
01999 cout << endl << endl << endl;
02000 unitTestResultFailure << eclass.errormsg << endl;
02001 }
02002
02003 try{
02004 cout << endl << "TEST " << ++nOfTest << ": Automatic differentiation" << endl << endl;
02005
02006
02007 std::string expTreeTest = dataDir + "osilFiles" + dirsep + "CppADTestLag.osil";
02008
02009
02010
02011
02012
02013
02014
02015
02016 osil = fileUtil->getFileAsString( expTreeTest.c_str() );
02017 OSInstance *osinstance = NULL;
02018
02019 OSiLReader *osilreader = NULL;
02020 osilreader = new OSiLReader();
02021
02022 osinstance = osilreader->readOSiL( osil);
02023 double *x;
02024 x = new double[ 4];
02025 x[0] = 1;
02026 x[1] = 5;
02027 x[2] = 10;
02028 x[3] = 5;
02029 SparseVector *sp;
02030
02031 osinstance->getJacobianSparsityPattern();
02032 sp = osinstance->calculateConstraintFunctionGradient(x, 1, true);
02033 for(int i = 0; i < sp->number; i++){
02034 std::cout << "gradient value " << sp->values[i] << std::endl;
02035 }
02036 ok = true;
02037
02038 double checkPartial2Con1 = 7.0 ;
02039
02040 ok = ( fabs(checkPartial2Con1 - sp->values[ 0] )/(fabs( checkPartial2Con1) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
02041 if(ok == false) throw ErrorClass(" Fail testing gradient calculation");
02042 double checkPartial0Con1 = (1./x[0]) ;
02043
02044 ok = ( fabs(checkPartial0Con1 - sp->values[ 1] )/(fabs( checkPartial0Con1) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
02045 if(ok == false) throw ErrorClass(" Fail testing gradient calculation");
02046 double checkPartial3Con1 = (1./x[3]) ;
02047
02048 ok = ( fabs(checkPartial3Con1 - sp->values[ 2] )/(fabs( checkPartial3Con1) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
02049 if(ok == false) throw ErrorClass(" Fail testing gradient calculation");
02050 delete sp;
02051 SparseHessianMatrix *sh;
02052
02053 osinstance->getLagrangianHessianSparsityPattern( );
02054 sh = osinstance->calculateHessian(x, -1, true);
02055 for(int i = 0; i < sh->hessDimension; i++){
02056 std::cout << "Hessian value " << sh->hessValues[i] << std::endl;
02057 }
02058
02059 ok = ( fabs(2. - sh->hessValues[0] )/(2. + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
02060 if(ok == false) throw ErrorClass(" Fail testing Hessian calculation");
02061
02062 ok = ( fabs(0. - sh->hessValues[ 1] )/(0. + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
02063 if(ok == false) throw ErrorClass(" Fail testing Hessian calculation");
02064
02065 ok = ( fabs(0. - sh->hessValues[2] )/(0. + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
02066 if(ok == false) throw ErrorClass(" Fail testing Hessian calculation");
02067 unitTestResult << "Successful test of AD gradient and Hessian calculations" << std::endl;
02068 delete[] x;
02069 delete osilreader;
02070 osilreader = NULL;
02071 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
02072 }
02073 catch(const ErrorClass& eclass){
02074 cout << endl << endl << endl;
02075 unitTestResultFailure << eclass.errormsg << endl;
02076 }
02077
02078
02079 try{
02080 cout << endl << "TEST " << ++nOfTest << ": OSiL parser" << endl << endl;
02081 clock_t start, finish;
02082 double duration;
02083 OSiLWriter *osilwriter = NULL;
02084 osilwriter = new OSiLWriter();
02085
02086
02087
02088 cout << "TEST PARSING A MODEL" << endl;
02089 cout << "FIRST READ THE FILE INTO A STRING" << endl;
02090 start = clock();
02091 osilFileName = dataDir + "osilFiles" + dirsep + "parincLinear.osil";
02092 osil = fileUtil->getFileAsString( osilFileName.c_str());
02093 finish = clock();
02094 duration = (double) (finish - start) / CLOCKS_PER_SEC;
02095 cout << "Reading the file into a string took (seconds): "<< duration << endl;
02096 OSiLReader *osilreader = NULL;
02097 osilreader = new OSiLReader();
02098 start = clock();
02099 cout << "PARSE THE OSIL STRING INTO AN OSINSTANCE OBJECT" << endl;
02100 osilreader->readOSiL( osil);
02101
02102 delete osilreader;
02103 osilreader = 0;
02104 delete osilwriter;
02105 osilwriter = NULL;
02106 finish = clock();
02107 duration = (double) (finish - start) / CLOCKS_PER_SEC;
02108 cout << "Parsing took (seconds): "<< duration << endl;
02109 unitTestResult << "Successful test of OSiL parser on problem parincLinear.osil" << std::endl;
02110 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
02111 }
02112 catch(const ErrorClass& eclass){
02113 cout << endl << endl << endl;
02114 cout << eclass.errormsg << endl;
02115 unitTestResultFailure << "Sorry Unit Test Failed Testing An OSiL Parser" << endl;
02116
02117 }
02118
02119
02120
02121
02122 try{
02123 cout << endl << "TEST " << ++nOfTest << ": Stochastic extensions to OSiL" << endl << endl;
02124 clock_t start, finish;
02125 double duration;
02126 OSiLWriter *osilwriter = NULL;
02127 osilwriter = new OSiLWriter();
02128
02129
02130
02131 cout << "\nTEST PARSING A STOCHASTIC MODEL" << endl;
02132 cout << "FIRST READ THE FILE INTO A STRING" << endl;
02133 start = clock();
02134 osilFileName = dataDir + "osilFiles" + dirsep + "finplan1.osil";
02135 osil = fileUtil->getFileAsString( &osilFileName[0]);
02136 finish = clock();
02137 duration = (double) (finish - start) / CLOCKS_PER_SEC;
02138 cout << "Reading the file into a string took (seconds): "<< duration << endl;
02139 OSiLReader *osilreader = NULL;
02140 osilreader = new OSiLReader();
02141 start = clock();
02142 cout << "PARSE THE OSIL STRING INTO AN OSINSTANCE OBJECT" << endl;
02143 osilreader->readOSiL( osil);
02144
02145 delete osilreader;
02146 osilreader = 0;
02147 delete osilwriter;
02148 osilwriter = NULL;
02149 finish = clock();
02150 duration = (double) (finish - start) / CLOCKS_PER_SEC;
02151 cout << "Parsing took (seconds): "<< duration << endl;
02152 unitTestResult << "Successful test of OSiL parser on problem finplan1.osil" << std::endl;
02153 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
02154 }
02155 catch(const ErrorClass& eclass){
02156 cout << endl << endl << endl;
02157 cout << eclass.errormsg << endl;
02158 unitTestResultFailure << "Error parsing an osil file with time domain information" << endl;
02159 }
02163 try{
02164 cout << endl << "TEST " << ++nOfTest << ": GET() AND SET() METHODS FOR TimeDomain OBJECT" << endl << endl;
02165 OSInstance *osinstance = NULL;
02166
02167
02168 osilreader = new OSiLReader();
02169
02170 osinstance = osilreader->readOSiL( osil);
02171 std::string f = osinstance->getTimeDomainFormat();
02172 ok = (f == "stages");
02173 int n = osinstance->getTimeDomainStageNumber();
02174 ok &= (n == 6);
02175
02176 std::string* sncheck = new std::string[6];
02177 sncheck[0] = "";
02178 sncheck[1] = "";
02179 sncheck[2] = "";
02180 sncheck[3] = "test";
02181 sncheck[4] = "Wha'zzup?";
02182 sncheck[5] = "";
02183
02184 std::string* sn = osinstance->getTimeDomainStageNames();
02185
02186 for (int i = 0; i < 6; i++)
02187 ok &= (sn[i] == sncheck[i]);
02188
02189 int* nv = osinstance->getTimeDomainStageNumberOfVariables();
02190
02191 int* nvcheck = new int[6];
02192 nvcheck[0] = 2;
02193 nvcheck[1] = 2;
02194 nvcheck[2] = 0;
02195 nvcheck[3] = 0;
02196 nvcheck[4] = 2;
02197 nvcheck[5] = 2;
02198
02199 for (int i = 0; i < 6; i++)
02200 ok &= (nv[i] == nvcheck[i]);
02201
02202 int* nc = osinstance->getTimeDomainStageNumberOfConstraints();
02203
02204 int* nccheck = new int[6];
02205 nccheck[0] = 1;
02206 nccheck[1] = 1;
02207 nccheck[2] = 0;
02208 nccheck[3] = 0;
02209 nccheck[4] = 1;
02210 nccheck[5] = 1;
02211
02212 for (int i = 0; i < 6; i++)
02213 ok &= (nc[i] == nccheck[i]);
02214
02215 int* no = osinstance->getTimeDomainStageNumberOfObjectives();
02216
02217 int* nocheck = new int[6];
02218 nocheck[0] = 1;
02219 nocheck[1] = 1;
02220 nocheck[2] = 1;
02221 nocheck[3] = 0;
02222 nocheck[4] = 1;
02223 nocheck[5] = 1;
02224
02225 for (int i = 0; i < 6; i++)
02226 ok &= (no[i] == nocheck[i]);
02227
02228 int** lv = osinstance->getTimeDomainStageVarList();
02229 int** lc = osinstance->getTimeDomainStageConList();
02230 int** lo = osinstance->getTimeDomainStageObjList();
02231
02232 int** lvcheck = new int*[6];
02233 int** lccheck = new int*[6];
02234 int** locheck = new int*[6];
02235 for (int i = 0; i < 6; i++) {
02236 lvcheck[i] = new int[2];
02237 lccheck[i] = new int[2];
02238 locheck[i] = new int[2];
02239 };
02240 lvcheck[0][0] = 0;
02241 lvcheck[0][1] = 1;
02242 lvcheck[1][0] = 2;
02243 lvcheck[1][1] = 3;
02244 lvcheck[4][0] = 4;
02245 lvcheck[4][1] = 5;
02246 lvcheck[5][0] = 6;
02247 lvcheck[5][1] = 7;
02248 lccheck[0][0] = 0;
02249 lccheck[1][0] = 1;
02250 lccheck[4][0] = 2;
02251 lccheck[5][0] = 3;
02252 locheck[0][0] = -1;
02253 locheck[1][0] = -1;
02254 locheck[2][0] = -1;
02255 locheck[4][0] = -1;
02256 locheck[5][0] = -1;
02257
02258 for (int i = 0; i < 6; i++) {
02259 for (int j = 0; j < nv[i]; j++)
02260 ok &= (lvcheck[i][j] == lv[i][j]);
02261 for (int j = 0; j < nc[i]; j++)
02262 ok &= (lccheck[i][j] == lc[i][j]);
02263 for (int j = 0; j < no[i]; j++)
02264 ok &= (locheck[i][j] == lo[i][j]);
02265 };
02266
02267 std::string* sn1 = new std::string[6];
02268 int* nv1 = new int[6];
02269 int* nc1 = new int[6];
02270 int* no1 = new int[6];
02271 int** lv1 = new int*[6];
02272 int** lc1 = new int*[6];
02273 int** lo1 = new int*[6];
02274 for (int i = 0; i < 6; i++) {
02275 lv1[i] = new int[2];
02276 lc1[i] = new int[2];
02277 lo1[i] = new int[2];
02278 };
02279 for (int i = 0; i < 6; i++) {
02280 sn1[i] = sn[i];
02281 nv1[i] = nv[i];
02282 nc1[i] = nc[i];
02283 no1[i] = no[i];
02284 for (int j = 0; j < nv[i]; j++) {
02285 lv1[i][j] = lv[i][j];
02286 };
02287 for (int j = 0; j < nc[i]; j++) {
02288 lc1[i][j] = lc[i][j];
02289 };
02290 for (int j = 0; j < no[i]; j++) {
02291 lo1[i][j] = lo[i][j];
02292 };
02293 };
02294
02295 ok &= osinstance->setTimeDomain("none");
02296 n = 0;
02297 ok &= osinstance->setTimeDomainStages(n,NULL);
02298 ok &= osinstance->setTimeDomainStages(4,NULL);
02299
02300 n = osinstance->getTimeDomainStageNumber();
02301 ok &= (n == 4);
02302
02303 int *nelem, *startIdx, **VI;
02304 nelem = new int[4];
02305 startIdx = new int[4];
02306 VI = new int*[4];
02307 for (int i = 0; i < 4; i++)
02308 { nelem[i] = 2;
02309 startIdx[i] = 2*i;
02310 VI[i] = new int[2];
02311 VI[i][0] = 2*i;
02312 VI[i][1] = 2*i + 1;
02313 };
02314 ok &= osinstance->setTimeDomainStageVariablesUnordered(4,nelem,VI);
02315
02316 for (int i = 0; i < 4; i++)
02317 { nelem[i] = 1;
02318 startIdx[i] = i;
02319 };
02320 ok &= osinstance->setTimeDomainStageConstraintsOrdered(4,nelem,startIdx);
02321
02322 for (int i = 0; i < 4; i++)
02323 { nelem[i] = 1;
02324 startIdx[i] = -1;
02325 };
02326 ok &= osinstance->setTimeDomainStageObjectivesOrdered(4,nelem,startIdx);
02327
02328 ok &= osinstance->setTimeDomain("none");
02329
02330 ok &= osinstance->setTimeDomain("interval");
02331
02332 ok &= osinstance->setTimeDomainInterval(0.0, 1.0);
02333 double lower = osinstance->getTimeDomainIntervalStart();
02334 ok &= (lower == 0.0);
02335 double upper = osinstance->getTimeDomainIntervalHorizon();
02336 ok &= (upper == 1.0);
02337
02338 ok &= osinstance->setTimeDomain("none");
02339
02340 ok &= osinstance->setTimeDomainStages(6,sncheck);
02341 ok &= osinstance->setTimeDomainStageVariablesUnordered(6,nvcheck,lvcheck);
02342 ok &= osinstance->setTimeDomainStageObjectivesUnordered(6,nocheck,locheck);
02343 ok &= osinstance->setTimeDomainStageConstraintsUnordered(6,nccheck,lccheck);
02344 int n2 = osinstance->getTimeDomainStageNumber();
02345 ok &= (n2 == 6);
02346 std::string* sn2 = osinstance->getTimeDomainStageNames();
02347 int* nv2 = osinstance->getTimeDomainStageNumberOfVariables();
02348 int* nc2 = osinstance->getTimeDomainStageNumberOfConstraints();
02349 int* no2 = osinstance->getTimeDomainStageNumberOfObjectives();
02350 int** lv2 = osinstance->getTimeDomainStageVarList();
02351 int** lc2 = osinstance->getTimeDomainStageConList();
02352 int** lo2 = osinstance->getTimeDomainStageObjList();
02353 for (int i = 0; i < n2; i++)
02354 { ok &= (sn2[i] == sncheck[i]);
02355 ok &= (nv2[i] == nvcheck[i]);
02356 ok &= (nc2[i] == nccheck[i]);
02357 ok &= (no2[i] == nocheck[i]);
02358 for (int j = 0; j < nv2[i]; j++)
02359 ok &= (lv2[i][j] == lvcheck[i][j]);
02360 for (int j = 0; j < nc2[i]; j++)
02361 ok &= (lc2[i][j] == lccheck[i][j]);
02362 for (int j = 0; j < no2[i]; j++)
02363 ok &= (lo2[i][j] == locheck[i][j]);
02364 };
02365 delete [] sncheck;
02366 sncheck = NULL;
02367 delete [] nvcheck;
02368 nvcheck = NULL;
02369 delete [] nccheck;
02370 nccheck = NULL;
02371 delete [] nocheck;
02372 nocheck = NULL;
02373 for (int i = 0; i < 6; i++) {
02374 delete [] lvcheck[i];
02375 delete [] lccheck[i];
02376 delete [] locheck[i];
02377 delete [] lv1[i];
02378 delete [] lc1[i];
02379 delete [] lo1[i];
02380 };
02381 delete [] lvcheck;
02382 lvcheck = NULL;
02383 delete [] lccheck;
02384 lccheck = NULL;
02385 delete [] locheck;
02386 locheck = NULL;
02387 delete [] lv1;
02388 lv1 = NULL;
02389 delete [] lc1;
02390 lc1 = NULL;
02391 delete [] lo1;
02392 lo1 = NULL;
02393 delete [] sn1;
02394 sn1 = NULL;
02395 delete[] nv1;
02396 nv1 = NULL;
02397 delete[] nc1;
02398 nc1 = NULL;
02399 delete[] no1;
02400 no1 = NULL;
02401 delete [] nelem;
02402 nelem = NULL;
02403 delete [] startIdx;
02404 startIdx = NULL;
02405 for (int i = 0; i < 4; i++) {
02406 delete [] VI[i];
02407 };
02408 delete [] VI;
02409 VI = NULL;
02410 delete osilreader;
02411 unitTestResult << "Successful test of osinstance get() and set() methods" << std::endl;
02412 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
02413 }
02414 catch(const ErrorClass& eclass){
02415 cout << endl << endl << endl;
02416 cout << eclass.errormsg << endl;
02417 unitTestResultFailure << "Sorry Unit Test Failed osinstance get() and set() Methods" << endl;
02418 }
02419
02420
02421
02422 OSoLWriter *osolwriter = NULL;
02423
02424
02425
02426
02427 try{
02441 cout << endl << "TEST " << ++nOfTest << ": OSoL parser" << endl << endl;
02442 std::string tmpOSoL;
02443 clock_t start, finish;
02444 double duration;
02445 osolwriter = new OSoLWriter();
02446 osolreader = new OSoLReader();
02447 OSOption *osoption = NULL;
02448
02449 cout << "TEST PARSING AN OSoL FILE" << endl;
02450 cout << "FIRST READ THE OSoL FILE INTO A STRING" << endl;
02451 osolFileName = dataDir + "osolFiles" + dirsep + "parsertest.osol";
02452 start = clock();
02453 std::string osol = fileUtil->getFileAsString( osolFileName.c_str() );
02454 finish = clock();
02455 duration = (double) (finish - start) / CLOCKS_PER_SEC;
02456 cout << "Reading the file into a string took (seconds): "<< duration << endl;
02457 start = clock();
02458 cout << "PARSE THE OSOL STRING INTO AN OSOPTION OBJECT" << endl;
02459 osoption = osolreader->readOSoL( osol);
02460
02461
02462 cout << endl << "Test the add() methods" << endl;
02463
02464 ok = osoption->setAnOtherGeneralOption("testing","one","two three");
02465 ok = osoption->setOtherSystemOptions(0,NULL) && ok;
02466 ok = osoption->setAnOtherSystemOption("Ho Ho Ho","","") && ok;
02467 ok = osoption->setAnOtherServiceOption("OneMore","Option","To Go") && ok;
02468 ok = osoption->setAnotherJobDependency("DoReMi") && ok;
02469 ok = osoption->setAnotherRequiredDirectory("C:\\MSYS") && ok;
02470 ok = osoption->setAnotherRequiredFile("C:\\MSYS\\junk.tmp") && ok;
02471 ok = osoption->setAnotherDirectoryToMake("C:\\tempdir") && ok;
02472 ok = osoption->setAnotherFileToMake("C:\\tempdir\\temp.tmp") && ok;
02473 ok = osoption->setAnotherInputDirectoryToMove("C:\\tempdir","C:\\OS\\calc",true) && ok;
02474 ok = osoption->setAnotherInputFileToMove("C:\\OS\\parinc.osil","C:\\OS\\calc\\input.osil",true) && ok;
02475 ok = osoption->setAnotherOutputFileToMove("C:\\OS\\calc\\putput.osrl","C:\\OS\\parinc.osol",false) && ok;
02476 ok = osoption->setAnotherOutputDirectoryToMove("C:\\OS\\calc","C:\\OS\\save",false) && ok;
02477 ok = osoption->setAnotherFileToDelete("C:\\OS\\calc\\input.osil") && ok;
02478 ok = osoption->setAnotherDirectoryToDelete("C:\\tempdir") && ok;
02479 ok = osoption->setAnotherProcessToKill("ABC123") && ok;
02480 ok = osoption->setAnOtherJobOption("DoReMi","ABC","One Two Three") && ok;
02481 ok = osoption->setAnotherInitVarValue(5,12.3) && ok;
02482 ok = osoption->setAnotherInitVarValueString(6,"BLUE") && ok;
02483 ok = osoption->setAnotherInitBasisStatus(6,"unknown") && ok;
02484 ok = osoption->setAnotherIntegerVariableBranchingWeight(5,100.) && ok;
02485
02486 int SOS3idx[2];
02487 double SOS3val[2];
02488 SOS3idx[0] = 3;
02489 SOS3idx[1] = 6;
02490 SOS3val[0] = 1.0;
02491 SOS3val[1] = 2.0;
02492 int tnvar = osoption->getNumberOfSOS();
02493 ok = osoption->setAnotherSOSVariableBranchingWeight(3,2,1.0,SOS3idx,SOS3val) && ok;
02494 assert (osoption->getNumberOfSOS() == (tnvar + 1));
02495 assert (osoption->optimization->variables->sosVariableBranchingWeights->sos[tnvar]->var[0]->idx == 3);
02496 assert (osoption->optimization->variables->sosVariableBranchingWeights->sos[tnvar]->var[1]->idx == 6);
02497 assert (osoption->optimization->variables->sosVariableBranchingWeights->sos[tnvar]->var[0]->value == 1.0);
02498 assert (osoption->optimization->variables->sosVariableBranchingWeights->sos[tnvar]->var[1]->value == 2.0);
02499 #ifdef DEBUG
02500 cout << endl << "another SOS has been added" << endl << endl;
02501 #endif
02502
02503 OtherVariableOption *varopt;
02504 varopt = new OtherVariableOption();
02505 varopt->name = "testVarOpt";
02506 varopt->numberOfVar = 0;
02507 ok = osoption->setAnOtherVariableOption(varopt) && ok;
02508 delete varopt;
02509 varopt = NULL;
02510
02511 OtherObjectiveOption *objopt;
02512 objopt = new OtherObjectiveOption();
02513 objopt->name = "testObjOpt";
02514 objopt->numberOfObj = 0;
02515 ok = osoption->setAnOtherObjectiveOption(objopt) && ok;
02516 delete objopt;
02517 objopt = NULL;
02518
02519 ok = osoption->setAnotherInitConValue(2,17.0) && ok;
02520 ok = osoption->setAnotherInitDualVarValue(2,0.0,DBL_MAX) && ok;
02521
02522 OtherConstraintOption *conopt;
02523 conopt = new OtherConstraintOption();
02524 conopt->name = "testObjOpt";
02525 conopt->numberOfCon = 2;
02526 conopt->con = new OtherConOption*[2];
02527 conopt->con[0] = new OtherConOption();
02528 conopt->con[0]->idx = 0;
02529 conopt->con[0]->value = "3.0";
02530 conopt->con[1] = new OtherConOption();
02531 conopt->con[1]->idx = 1;
02532 conopt->con[1]->lbValue = "0.0";
02533 conopt->con[1]->ubValue = "10.0";
02534 ok = osoption->setAnOtherConstraintOption(conopt) && ok;
02535 delete conopt;
02536 conopt = NULL;
02537
02538 ok = osoption->setAnotherSolverOption("HoHum","gus","PhoNY","","test","") && ok;
02539
02540 if (!ok)
02541 throw ErrorClass(" Could not add to osoption data structure");
02542
02543
02544 std::string optionstring;
02545 int option_i;
02546 double option_d;
02547 OSOption* osoption2 = new OSOption();
02548
02549 cout << endl << "transfer osoption to another OSOption object" << endl;
02550
02551 optionstring = osoption->getServiceURI();
02552 ok = osoption2->setServiceURI(optionstring);
02553 #ifdef DEBUG
02554 if (!ok)
02555 throw ErrorClass(" error in get/set ServiceURI");
02556 #endif
02557
02558 optionstring = osoption->getServiceName();
02559 ok = osoption2->setServiceName(optionstring) && ok;
02560 #ifdef DEBUG
02561 if (!ok)
02562 throw ErrorClass(" error in get/set ServiceName");
02563 #endif
02564
02565 optionstring = osoption->getInstanceName();
02566 ok = osoption2->setInstanceName(optionstring) && ok;
02567 #ifdef DEBUG
02568 if (!ok)
02569 throw ErrorClass(" error in get/set InstanceName");
02570 #endif
02571
02572 optionstring = osoption->getInstanceLocation();
02573 ok = osoption2->setInstanceLocation(optionstring) && ok;
02574 #ifdef DEBUG
02575 if (!ok)
02576 throw ErrorClass(" error in get/set InstanceLocation");
02577 #endif
02578
02579 optionstring = osoption->getInstanceLocationType();
02580 ok = osoption2->setInstanceLocationType(optionstring) && ok;
02581 #ifdef DEBUG
02582 if (!ok)
02583 throw ErrorClass(" error in get/set InstanceLocationtype");
02584 #endif
02585
02586 optionstring = osoption->getJobID();
02587 ok = osoption2->setJobID(optionstring) && ok;
02588 #ifdef DEBUG
02589 if (!ok)
02590 throw ErrorClass(" error in get/set JobID");
02591 #endif
02592
02593 optionstring = osoption->getSolverToInvoke();
02594 ok = osoption2->setSolverToInvoke(optionstring) && ok;
02595 #ifdef DEBUG
02596 if (!ok)
02597 throw ErrorClass(" error in get/set SolverToInvoke");
02598 #endif
02599
02600 optionstring = osoption->getInstanceLocationType();
02601 ok = osoption2->setInstanceLocationType(optionstring) && ok;
02602 #ifdef DEBUG
02603 if (!ok)
02604 throw ErrorClass(" error in get/set InstanceLocationType");
02605 #endif
02606
02607 optionstring = osoption->getUserName();
02608 ok = osoption2->setUserName(optionstring) && ok;
02609 #ifdef DEBUG
02610 if (!ok)
02611 throw ErrorClass(" error in get/set UserName");
02612 #endif
02613
02614 optionstring = osoption->getPassword();
02615 #ifdef DEBUG
02616 if (!ok)
02617 throw ErrorClass(" error in get/set Password");
02618 #endif
02619 ok = osoption2->setPassword(optionstring) && ok;
02620
02621 optionstring = osoption->getContact();
02622 ok = osoption2->setContact(optionstring) && ok;
02623 #ifdef DEBUG
02624 if (!ok)
02625 throw ErrorClass(" error in get/set Contact");
02626 #endif
02627
02628 optionstring = osoption->getContactTransportType();
02629 ok = osoption2->setContactTransportType(optionstring) && ok;
02630 #ifdef DEBUG
02631 if (!ok)
02632 throw ErrorClass(" error in get/set TransportType");
02633 #endif
02634
02635 int nopt;
02636 OtherOption** otherOpt;
02637 nopt = osoption->getNumberOfOtherGeneralOptions();
02638 otherOpt = osoption->getOtherGeneralOptions();
02639 ok = osoption2->setOtherGeneralOptions(nopt, otherOpt) && ok;
02640 #ifdef DEBUG
02641 if (!ok)
02642 throw ErrorClass(" error in get/set OtherGeneralOption");
02643 #endif
02644
02645 option_d = osoption->getMinDiskSpace();
02646 ok = osoption2->setMinDiskSpace(option_d) && ok;
02647 #ifdef DEBUG
02648 if (!ok)
02649 throw ErrorClass(" error in get/set MinDiskSpace");
02650 #endif
02651
02652 optionstring = osoption->getMinDiskSpaceUnit();
02653 ok = osoption2->setMinDiskSpaceUnit(optionstring) && ok;
02654 #ifdef DEBUG
02655 if (!ok)
02656 throw ErrorClass(" error in get/set MinDiskSpaceUnit");
02657 #endif
02658
02659 option_d = osoption->getMinMemorySize();
02660 ok = osoption2->setMinMemorySize(option_d) && ok;
02661 #ifdef DEBUG
02662 if (!ok)
02663 throw ErrorClass(" error in get/set MinMemorySize");
02664 #endif
02665
02666 optionstring = osoption->getMinMemoryUnit();
02667 ok = osoption2->setMinMemoryUnit(optionstring) && ok;
02668 #ifdef DEBUG
02669 if (!ok)
02670 throw ErrorClass(" error in get/set MinMemoryUnit");
02671 #endif
02672
02673 option_d = osoption->getMinCPUSpeed();
02674 ok = osoption2->setMinCPUSpeed(option_d) && ok;
02675 #ifdef DEBUG
02676 if (!ok)
02677 throw ErrorClass(" error in get/set MinCPUSpeed");
02678 #endif
02679
02680 optionstring = osoption->getMinCPUSpeedUnit();
02681 ok = osoption2->setMinCPUSpeedUnit(optionstring) && ok;
02682 #ifdef DEBUG
02683 if (!ok)
02684 throw ErrorClass(" error in get/set MinCPUSpeedUnit");
02685 #endif
02686
02687 option_i = osoption->getMinCPUNumber();
02688 ok = osoption2->setMinCPUNumber(option_i) && ok;
02689 #ifdef DEBUG
02690 if (!ok)
02691 throw ErrorClass(" error in get/set MinCPUNumber");
02692 #endif
02693
02694 OtherOption** otherOpt2;
02695 nopt = osoption->getNumberOfOtherSystemOptions();
02696 otherOpt2 = osoption->getOtherSystemOptions();
02697 ok = osoption2->setOtherSystemOptions(nopt, otherOpt2) && ok;
02698 #ifdef DEBUG
02699 if (!ok)
02700 throw ErrorClass(" error in get/set OtherSystemOptions");
02701 #endif
02702
02703
02704 optionstring = osoption->getServiceType();
02705 ok = osoption2->setServiceType(optionstring) && ok;
02706 #ifdef DEBUG
02707 if (!ok)
02708 throw ErrorClass(" error in get/set ServiceType");
02709 #endif
02710
02711 OtherOption** otherOpt3;
02712 nopt = osoption->getNumberOfOtherServiceOptions();
02713 otherOpt3 = osoption->getOtherServiceOptions();
02714 ok = osoption2->setOtherServiceOptions(nopt, otherOpt3) && ok;
02715 #ifdef DEBUG
02716 if (!ok)
02717 throw ErrorClass(" error in get/set OtherServiceOptions");
02718 #endif
02719
02720
02721 option_d = osoption->getMaxTime();
02722 ok = osoption2->setMaxTime(option_d) && ok;
02723 #ifdef DEBUG
02724 if (!ok)
02725 throw ErrorClass(" error in get/set MaxTime");
02726 #endif
02727
02728 optionstring = osoption->getMaxTimeUnit();
02729 ok = osoption2->setMaxTimeUnit(optionstring) && ok;
02730 #ifdef DEBUG
02731 if (!ok)
02732 throw ErrorClass(" error in get/set MaxTimeUnit");
02733 #endif
02734
02735 optionstring = osoption->getRequestedStartTime();
02736 ok = osoption2->setRequestedStartTime(optionstring) && ok;
02737 #ifdef DEBUG
02738 if (!ok)
02739 throw ErrorClass(" error in get/set RequestedStartTime");
02740 #endif
02741
02742 nopt = osoption->getNumberOfJobDependencies();
02743 std::string* tJobID = osoption->getJobDependencies();
02744 ok = osoption2->setJobDependencies(nopt, tJobID) && ok;
02745 #ifdef DEBUG
02746 if (!ok)
02747 throw ErrorClass(" error in get/set JobDependencies");
02748 #endif
02749
02750 nopt = osoption->getNumberOfRequiredDirectories();
02751 std::string* reqDir = osoption->getRequiredDirectories();
02752 ok = osoption2->setRequiredDirectories(nopt, reqDir) && ok;
02753 #ifdef DEBUG
02754 if (!ok)
02755 throw ErrorClass(" error in get/set RequiredDirectories");
02756 #endif
02757
02758 nopt = osoption->getNumberOfRequiredFiles();
02759 std::string* reqFil = osoption->getRequiredFiles();
02760 ok = osoption2->setRequiredFiles(nopt, reqFil) && ok;
02761 #ifdef DEBUG
02762 if (!ok)
02763 throw ErrorClass(" error in get/set RequiredFiles");
02764 #endif
02765
02766 nopt = osoption->getNumberOfDirectoriesToMake();
02767 std::string* mkDir = osoption->getDirectoriesToMake();
02768 ok = osoption2->setDirectoriesToMake(nopt, mkDir) && ok;
02769 #ifdef DEBUG
02770 if (!ok)
02771 throw ErrorClass(" error in get/set DirectoriesToMake");
02772 #endif
02773
02774 nopt = osoption->getNumberOfFilesToMake();
02775 std::string* mkFil = osoption->getFilesToMake();
02776 ok = osoption2->setFilesToMake(nopt, mkFil) && ok;
02777 #ifdef DEBUG
02778 if (!ok)
02779 throw ErrorClass(" error in get/set FilesToMake");
02780 #endif
02781
02782 nopt = osoption->getNumberOfInputDirectoriesToMove();
02783 PathPair** inDMv = osoption->getInputDirectoriesToMove();
02784 ok = osoption2->setInputDirectoriesToMove(nopt, inDMv) && ok;
02785 #ifdef DEBUG
02786 if (!ok)
02787 throw ErrorClass(" error in get/set InputDirectoriesToMove");
02788 #endif
02789
02790 nopt = osoption->getNumberOfInputFilesToMove();
02791 PathPair** inFMv = osoption->getInputFilesToMove();
02792 ok = osoption2->setInputFilesToMove(nopt, inFMv) && ok;
02793 #ifdef DEBUG
02794 if (!ok)
02795 throw ErrorClass(" error in get/set InputFilesToMove");
02796 #endif
02797
02798 nopt = osoption->getNumberOfOutputFilesToMove();
02799 PathPair** outFMv = osoption->getOutputFilesToMove();
02800 ok = osoption2->setOutputFilesToMove(nopt, outFMv) && ok;
02801 #ifdef DEBUG
02802 if (!ok)
02803 throw ErrorClass(" error in get/set OutputFilesToMove");
02804 #endif
02805
02806 nopt = osoption->getNumberOfOutputDirectoriesToMove();
02807 PathPair** outDMv = osoption->getOutputDirectoriesToMove();
02808 ok = osoption2->setOutputDirectoriesToMove(nopt, outDMv) && ok;
02809 #ifdef DEBUG
02810 if (!ok)
02811 throw ErrorClass(" error in get/set OutputDirectoriesToMove");
02812 #endif
02813
02814 nopt = osoption->getNumberOfFilesToDelete();
02815 std::string* rmFil = osoption->getFilesToDelete();
02816 ok = osoption2->setFilesToDelete(nopt, rmFil) && ok;
02817 #ifdef DEBUG
02818 if (!ok)
02819 throw ErrorClass(" error in get/set FilesToDelete");
02820 #endif
02821
02822 nopt = osoption->getNumberOfDirectoriesToDelete();
02823 std::string* rmDir = osoption->getDirectoriesToDelete();
02824 ok = osoption2->setDirectoriesToDelete(nopt, rmDir) && ok;
02825 #ifdef DEBUG
02826 if (!ok)
02827 throw ErrorClass(" error in get/set DirectoriesToDelete");
02828 #endif
02829
02830 nopt = osoption->getNumberOfProcessesToKill();
02831 std::string* rmProc = osoption->getProcessesToKill();
02832 ok = osoption2->setProcessesToKill(nopt, rmProc) && ok;
02833 #ifdef DEBUG
02834 if (!ok)
02835 throw ErrorClass(" error in get/set ProcessesToKill");
02836 #endif
02837
02838 OtherOption** otherOpt4;
02839 nopt = osoption->getNumberOfOtherJobOptions();
02840 otherOpt4 = osoption->getOtherJobOptions();
02841 ok = osoption2->setOtherJobOptions(nopt, otherOpt4) && ok;
02842 #ifdef DEBUG
02843 if (!ok)
02844 throw ErrorClass(" error in get/set OtherJobOptions");
02845 #endif
02846
02847 int nvar, nobj, ncon;
02848 nvar = osoption->getOptionInt("numberOfVariables");
02849 ok = osoption2->setNumberOfVariables(nvar) && ok;
02850 nobj = osoption->getOptionInt("numberOfObjectives");
02851 ok = osoption2->setNumberOfObjectives(nobj) && ok;
02852 ncon = osoption->getOptionInt("numberOfConstraints");
02853 ok = osoption2->setNumberOfConstraints(ncon) && ok;
02854 #ifdef DEBUG
02855 if (!ok)
02856 throw ErrorClass(" error in get/set problem dimensions");
02857 #endif
02858
02859
02860 double* IVV;
02861 IVV = osoption->getInitVarValuesDense();
02862 ok = osoption2->setInitVarValuesDense(nvar, IVV) && ok;
02863 #ifdef DEBUG
02864 if (!ok)
02865 throw ErrorClass(" error in get/set InitVarValues");
02866 #endif
02867
02868 nopt = osoption->getNumberOfInitVarValuesString();
02869 InitVarValueString** IVV2;
02870 IVV2 = osoption->getInitVarValuesStringSparse();
02871 ok = osoption2->setInitVarValuesStringSparse(nopt, IVV2) && ok;
02872 #ifdef DEBUG
02873 if (!ok)
02874 throw ErrorClass(" error in get/set InitVarValuesString");
02875 #endif
02876
02877 std::string* IBS;
02878 IBS = osoption->getInitBasisStatusDense();
02879 ok = osoption2->setInitBasisStatusDense(nvar, IBS) && ok;
02880 #ifdef DEBUG
02881 if (!ok)
02882 throw ErrorClass(" error in get/set InitBasisStatus");
02883 #endif
02884
02885 double* IVBW;
02886 IVBW = osoption->getIntegerVariableBranchingWeightsDense();
02887 ok = osoption2->setIntegerVariableBranchingWeightsDense(nvar, IVBW) && ok;
02888 #ifdef DEBUG
02889 if (!ok)
02890 throw ErrorClass(" error in get/set IntegerVariableBranchingWeights");
02891 #endif
02892
02893 SOSWeights** sos;
02894 sos = osoption->getSOSVariableBranchingWeightsSparse();
02895 nopt = osoption->getNumberOfSOS();
02896 ok = osoption2->setSOSVariableBranchingWeights(nopt, sos) && ok;
02897 #ifdef DEBUG
02898 if (!ok)
02899 throw ErrorClass(" error in get/set SOSVariableBranchingWeights");
02900 #endif
02901
02902 OtherVariableOption** otherV;
02903 otherV = osoption->getAllOtherVariableOptions();
02904 nopt = osoption->getNumberOfOtherVariableOptions();
02905 ok = osoption2->setOtherVariableOptions(nopt, otherV) && ok;
02906 #ifdef DEBUG
02907 if (!ok)
02908 throw ErrorClass(" error in get/set OtherVariableOptions");
02909 #endif
02910
02911 double* IOV;
02912 IOV = osoption->getInitObjValuesDense();
02913 ok = osoption2->setInitObjValuesDense(nobj, IOV) && ok;
02914 #ifdef DEBUG
02915 if (!ok)
02916 throw ErrorClass(" error in get/set InitObjValues");
02917 #endif
02918
02919 nopt = osoption->getNumberOfInitObjBounds();
02920 InitObjBound** IOB;
02921 IOB = osoption->getInitObjBoundsSparse();
02922 ok = osoption2->setInitObjBoundsSparse(nopt, IOB) && ok;
02923 #ifdef DEBUG
02924 if (!ok)
02925 throw ErrorClass(" error in get/set InitObjBounds");
02926 #endif
02927
02928 OtherObjectiveOption** otherO;
02929 otherO = osoption->getAllOtherObjectiveOptions();
02930 nopt = osoption->getNumberOfOtherObjectiveOptions();
02931 ok = osoption2->setOtherObjectiveOptions(nopt, otherO) && ok;
02932 #ifdef DEBUG
02933 if (!ok)
02934 throw ErrorClass(" error in get/set OtherObjectiveOptions");
02935 #endif
02936
02937
02938 double* ICV;
02939 ICV = osoption->getInitConValuesDense();
02940 ok = osoption2->setInitConValuesDense(ncon, ICV) && ok;
02941 #ifdef DEBUG
02942 if (!ok)
02943 throw ErrorClass(" error in get/set InitConValues");
02944 #endif
02945
02946 nopt = osoption->getNumberOfInitDualVarValues();
02947 InitDualVarValue** IDV;
02948 IDV = osoption->getInitDualVarValuesSparse();
02949 ok = osoption2->setInitDualVarValuesSparse(nopt, IDV) && ok;
02950 #ifdef DEBUG
02951 if (!ok)
02952 throw ErrorClass(" error in get/set InitDualVarValues");
02953 #endif
02954
02955 OtherConstraintOption** otherC;
02956 otherC = osoption->getAllOtherConstraintOptions();
02957 nopt = osoption->getNumberOfOtherConstraintOptions();
02958 ok = osoption2->setOtherConstraintOptions(nopt, otherC) && ok;
02959 #ifdef DEBUG
02960 if (!ok)
02961 throw ErrorClass(" error in get/set OtherConstraintOptions");
02962 #endif
02963
02964 SolverOption** SO;
02965 SO = osoption->getAllSolverOptions();
02966 nopt = osoption->getNumberOfSolverOptions();
02967 ok = osoption2->setSolverOptions(nopt, SO) && ok;
02968 #ifdef DEBUG
02969 if (!ok)
02970 throw ErrorClass(" error in get/set SolverOptions");
02971 #endif
02972
02973 ok = osoption->IsEqual(osoption2) && ok;
02974 if (!ok)
02975 throw ErrorClass(" OSOption get() and set() methods do not work correctly");
02976
02977 cout << endl << "delete osoption2" << endl;
02978 delete osoption2;
02979 osoption2 = NULL;
02980 cout << "osoption2 deleted" << endl << endl;
02981
02982 cout << "Write the content to a new file" <<endl;
02983 tmpOSoL = osolwriter->writeOSoL( osoption);
02984 cout << endl << "Here is tmpOSoL:" <<endl;
02985 cout << endl << endl << tmpOSoL << endl;
02986 cout << "-----------------------------------------" << endl << endl;
02987
02988
02989
02990
02991 OSoLReader *osolreader2;
02992 osolreader2 = new OSoLReader();
02993 cout << "Read the string back" << endl;
02994
02995 OSOption *osoption3 = NULL;
02996 osoption3 = osolreader2->readOSoL( tmpOSoL);
02997
02998 ok = osoption->IsEqual(osoption3);
02999 if (!ok)
03000 throw ErrorClass(" Loss of information in OSoL write/read");
03001 delete osolreader2;
03002 osolreader2 = NULL;
03003
03004
03005 delete osolwriter;
03006 osolwriter = NULL;
03007 delete osolreader;
03008 osolreader = NULL;
03009 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
03010
03011
03012
03013 cout << endl << "TEST " << ++nOfTest << ": Parse another .osol file" << endl << endl;
03014 osolwriter = new OSoLWriter();
03015 osolreader = new OSoLReader();
03016 cout << "First read the OSoL file into a string" << endl;
03017 osolFileName = dataDir + "osolFiles" + dirsep + "parsertest2.osol";
03018 osol = fileUtil->getFileAsString( osolFileName.c_str() );
03019 finish = clock();
03020 duration = (double) (finish - start) / CLOCKS_PER_SEC;
03021 cout << "Reading the file into a string took (seconds): "<< duration << endl;
03022 cout << "Parse the OSoL string into an OSOption object" << endl;
03023 osoption = osolreader->readOSoL( osol);
03024 tmpOSoL = osolwriter->writeOSoL( osoption) ;
03025 delete osolreader;
03026 osolreader = NULL;
03027 osolreader = new OSoLReader();
03028 osolreader->readOSoL( tmpOSoL);
03029 delete osolwriter;
03030 osolwriter = NULL;
03031 delete osolreader;
03032 osolreader = NULL;
03033
03034
03035 cout << "Test parsing another OSoL file" << endl;
03036 osolwriter = new OSoLWriter();
03037 osolreader = new OSoLReader();
03038 cout << "First read the OSoL file into a string" << endl;
03039 osolFileName = dataDir + "osolFiles" + dirsep + "parsertest3.osol";
03040 osol = fileUtil->getFileAsString( osolFileName.c_str() );
03041 finish = clock();
03042 duration = (double) (finish - start) / CLOCKS_PER_SEC;
03043 cout << "Reading the file into a string took (seconds): "<< duration << endl;
03044 cout << "Parse the OSoL string into an OSOption object" << endl;
03045 osoption = osolreader->readOSoL( osol);
03046 tmpOSoL = osolwriter->writeOSoL( osoption) ;
03047 delete osolreader;
03048 osolreader = NULL;
03049 osolreader = new OSoLReader();
03050 osolreader->readOSoL( tmpOSoL);
03051 delete osolwriter;
03052 osolwriter = NULL;
03053 delete osolreader;
03054 osolreader = NULL;
03055
03056
03057
03058 cout << "Test parsing a trivial string" << endl;
03059 osolreader = new OSoLReader();
03060 osol = "<osol></osol>";
03061 cout << "Parse the OSoL string into an OSOption object" << endl;
03062 osoption = osolreader->readOSoL( osol);
03063 delete osolreader;
03064 osolreader = NULL;
03065
03066
03067 unitTestResult <<
03068 "Successful test of OSoL parser on file parsertest.osol"
03069 << std::endl;
03070 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
03071
03072
03073 }
03074
03075 catch(const ErrorClass& eclass){
03076 cout << endl << endl << endl;
03077 if(osolwriter != NULL) delete osolwriter;
03078 if(osolreader != NULL) delete osolreader;
03079
03080 unitTestResultFailure << eclass.errormsg << endl;
03081 unitTestResultFailure << "There was a failure in the test for reading OSoL" << endl;
03082 }
03083
03084
03085
03086
03087
03088 try{
03097 cout << endl << "TEST " << ++nOfTest << ": OSrL parser" << endl << endl;
03098 std::string tmpOSrL;
03099 clock_t start, finish;
03100 double duration;
03101 osrlwriter = new OSrLWriter();
03102 osrlreader = new OSrLReader();
03103 OSResult *osresult = NULL;
03104
03105 cout << "TEST PARSING AN OSrL FILE" << endl;
03106 cout << "FIRST READ THE OSrL FILE INTO A STRING" << endl;
03107
03108 osrlFileName = dataDir + "osrlFiles" + dirsep + "parserTest.osrl";
03109 start = clock();
03110 std::string osrl = fileUtil->getFileAsString( osrlFileName.c_str() );
03111 finish = clock();
03112 duration = (double) (finish - start) / CLOCKS_PER_SEC;
03113 cout << "Reading the file into a string took (seconds): "<< duration << endl;
03114 cout << osrl << endl;
03115 start = clock();
03116 cout << "PARSE THE OSRL STRING INTO AN OSRESULT OBJECT" << endl;
03117 osresult = osrlreader->readOSrL( osrl);
03118 cout << "Finished read; write OSResult object to temporary string" << endl;
03119 tmpOSrL = osrlwriter->writeOSrL( osresult) ;
03120 cout << tmpOSrL << endl;
03121
03122 delete osrlreader;
03123 osrlreader = NULL;
03124 osrlreader = new OSrLReader();
03125 cout << "Parse temporary string" << endl;
03126 osrlreader->readOSrL( tmpOSrL);
03127 delete osrlwriter;
03128 osrlwriter = NULL;
03129 delete osrlreader;
03130 osrlreader = NULL;
03131
03132
03133
03134
03135
03136
03137
03138
03139
03140
03141
03142
03143
03144
03145
03146
03147
03148
03149
03150
03151
03152
03153
03154
03155 unitTestResult <<
03156 "Successful test of OSrL parser on problems parincLinear.osrl and errorExample.osrl"
03157 << std::endl;
03158 cout << endl << "TEST " << nOfTest << ": Completed successfully" << endl << endl;
03159 }
03160 catch(const ErrorClass& eclass){
03161 cout << endl << endl << endl;
03162 if(osrlwriter != NULL) delete osrlwriter;
03163 if(osrlreader != NULL) delete osrlreader;
03164
03165 unitTestResultFailure << eclass.errormsg << endl;
03166 unitTestResultFailure << "There was a failure in the test for reading OSrL" << endl;
03167 }
03168
03169
03170
03171
03172
03173 #endif // COMPONENT_DEBUG
03174
03175
03176
03177
03178
03179
03180 delete fileUtil;
03181 fileUtil = NULL;
03182
03183 if(unitTestResultFailure.str().length() > 0){
03184 cout << endl << "THE UNIT TEST PASSED THE FOLLOWING:" << endl << endl;
03185 cout << unitTestResult.str() << endl << endl;
03186 cout << "UNFORTUNATELY, YOU FAILED ON THE FOLLOWING:" << endl << endl;
03187 cout << unitTestResultFailure.str() << endl << endl;
03188 cout << "Conclusion: FAILURE" << endl;
03189 return 1;
03190 }
03191 else{
03192 cout << endl << "THE UNIT TEST PASSED THE FOLLOWING:" << endl << endl;
03193 cout << unitTestResult.str() << endl << endl;
03194 cout << "All tests completed successfully" << endl << endl;
03195 return 0;
03196 }
03197 }
03198
03199 double getObjVal( std::string osrl){
03200 std::string sObjVal;
03201 double dObjVal;
03202 string::size_type pos2;
03203 string::size_type pos1 = osrl.find( "<obj ");
03204 if(pos1 != std::string::npos){
03205
03206 pos1 = osrl.find(">", pos1 + 1);
03207 if(pos1 != std::string::npos){
03208
03209 pos2 = osrl.find( "</obj", pos1 + 1);
03210 if( pos2 != std::string::npos){
03211
03212 sObjVal = osrl.substr( pos1 + 1, pos2 - pos1 - 1);
03213
03214
03215 return dObjVal = os_strtod(sObjVal.c_str(), NULL);
03216 }
03217 else return OSNAN;
03218 }
03219 else return OSNAN;
03220 }
03221 else return OSNAN;
03222 }