00001
00099 #include <cppad/cppad.hpp>
00100
00101 #include "OSCoinSolver.h"
00102 #include "OSConfig.h"
00103 #include "OSmps2osil.h"
00104 #include "OSResult.h"
00105 #include "OSiLReader.h"
00106 #include "OSiLWriter.h"
00107 #include "OSrLReader.h"
00108 #include "OSrLWriter.h"
00109 #include "OSInstance.h"
00110 #include "OSFileUtil.h"
00111 #include "OSConfig.h"
00112
00113 #include "OSDefaultSolver.h"
00114 #include "OSWSUtil.h"
00115 #include "OSSolverAgent.h"
00116 #include "OShL.h"
00117 #include "OSErrorClass.h"
00118 #include "OSmps2osil.h"
00119 #include "OSBase64.h"
00120 #include "OSCommonUtil.h"
00121
00122
00123 #include <CoinMpsIO.hpp>
00124 #include <CoinPackedMatrix.hpp>
00125
00126
00127 #ifdef COIN_HAS_KNITRO
00128 #include "OSKnitroSolver.h"
00129 #endif
00130
00131 #include "OSMathUtil.h"
00132
00133 #ifdef COIN_HAS_GLPK
00134 #include <OsiGlpkSolverInterface.hpp>
00135 #endif
00136
00137
00138
00139 #ifdef COIN_HAS_LINDO
00140 #include "OSLindoSolver.h"
00141 #endif
00142
00143
00144
00145 #ifdef COIN_HAS_ASL
00146 #include "OSnl2osil.h"
00147 #endif
00148
00149
00150 #ifdef COIN_HAS_IPOPT
00151 #ifndef COIN_HAS_ASL
00152 #include "OSIpoptSolver.h"
00153 #undef COIN_HAS_ASL
00154 #else
00155 #include "OSIpoptSolver.h"
00156 #endif
00157 #endif
00158
00159
00160
00161
00162
00163
00164
00165 #ifdef HAVE_CTIME
00166 # include <ctime>
00167 #else
00168 # ifdef HAVE_TIME_H
00169 # include <time.h>
00170 # else
00171 # error "don't have header file for time"
00172 # endif
00173 #endif
00174
00175
00176 #ifdef HAVE_CMATH
00177 # include <cmath>
00178 #else
00179 # ifdef HAVE_CMATH_H
00180 # include <cmath.h>
00181 # endif
00182 #endif
00183
00184
00185
00186 #ifdef HAVE_CSTDIO
00187 # include <cstdio>
00188 #else
00189 # ifdef HAVE_STDIO_H
00190 # include <stdio.h>
00191 # else
00192 # error "don't have header file for stdio"
00193 # endif
00194 #endif
00195
00196 #undef COIN_HAS_ASL
00197 using std::cout;
00198 using std::endl;
00199 using std::ostringstream;
00200
00201 int main(int argC, char* argV[])
00202 {
00203 double getObjVal(std::string osrl);
00204
00205 bool ok;
00206 double check;
00207
00208
00209
00210 cout << "START UNIT TEST" << endl;
00211
00212 FileUtil *fileUtil = NULL;
00213 #ifdef COIN_HAS_ASL
00214 OSnl2osil *nl2osil = NULL;
00215 #endif
00216 OSmps2osil *mps2osil = NULL;
00217 DefaultSolver *solver = NULL;
00218 OSrLWriter *osrlwriter = NULL;
00219 OSrLReader *osrlreader = NULL;
00220
00221 std::string osilFileName;
00222 std::string osrlFileName;
00223 std::string nlFileName;
00224 std::string mpsFileName;
00225 std::string osil;
00226 ostringstream unitTestResult;
00227 ostringstream unitTestResultFailure;
00228
00229 const char dirsep = CoinFindDirSeparator();
00230
00231 std::string dataDir;
00232 dataDir = dirsep == '/' ? "../data/" : "..\\data\\";
00233 std::string osol = "<osol></osol>";
00234 nlFileName = dataDir + "amplFiles" + dirsep + "parinc.nl";
00235 mpsFileName = dataDir + "mpsFiles" + dirsep + "parinc.mps";
00236 fileUtil = new FileUtil();
00237
00238 unitTestResult << "HERE ARE THE UNIT TEST RESULTS:" << std::endl << std::endl;
00239
00240
00241 try{
00242 osilFileName = dataDir + "osilFiles" + dirsep + "parincLinearByRow.osil";
00243
00244 std::cout << "Try to read a sample file" << std::endl;
00245 std::cout << "The file is: " ;
00246 std::cout << osilFileName << std::endl;
00247 osil = fileUtil->getFileAsString( osilFileName.c_str() );
00248 std::cout << "Done reading the test file" << std::endl;
00249 OSiLReader *osilreader = NULL;
00250 osilreader = new OSiLReader();
00251
00252
00253 unitTestResult << "Reading files successfully" << std::endl;
00254 OSiLWriter osilwriter;
00255 osilwriter.m_bWhiteSpace = true;
00256
00257 delete osilreader;
00258 osilreader = NULL;
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295 mpsFileName = dataDir + "mpsFiles" + dirsep + "parinc.mps";
00296 mps2osil = new OSmps2osil( mpsFileName);
00297
00298 mps2osil->createOSInstance() ;
00299
00300 OSInstance *osinstance1 = mps2osil->osinstance;
00301 std::string sOSiL = osilwriter.writeOSiL( osinstance1 );
00302
00303
00304
00305 osilreader = new OSiLReader();
00306 OSInstance *osinstance2 = osilreader->readOSiL( sOSiL);
00307
00308 int nvals = osinstance1->instanceData->linearConstraintCoefficients->numberOfValues;
00309 double theDiff, theMax;
00310 int theIndex = -1;
00311 theMax = 0;
00312 for(int i = 0; i < nvals; i++){
00313 theDiff = fabs(osinstance1->instanceData->linearConstraintCoefficients->value->el[ i] -
00314 osinstance2->instanceData->linearConstraintCoefficients->value->el[ i])/ fabs(osinstance1->instanceData->linearConstraintCoefficients->value->el[ i]);
00315 if(theDiff > theMax){
00316 theMax = theDiff;
00317 theIndex = i;
00318 }
00319
00320 }
00321 std::cout << "MAXIMUM DIFF = " << theMax << std::endl;
00322 std::cout << "MAXIMUM DIFF INDEX = " << theIndex << std::endl;
00323 if(theMax > 0) unitTestResult << "WARNING: you do not have lossless IO" << std::endl;
00324 else unitTestResult << "passed lossless IO test" << std::endl;
00325 delete mps2osil;
00326 delete osilreader;
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
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 catch(const ErrorClass& eclass){
00389 unitTestResultFailure << "Sorry Unit Test Failed Reading a file: " + eclass.errormsg<< endl;
00390
00391 unitTestResultFailure << "Since we can't read files we are terminating" << endl;
00392 cout << unitTestResultFailure.str() << endl << endl;
00393 cout << "Conclusion: FAILURE" << endl;
00394 return 1;
00395 }
00396
00397 #ifdef COIN_HAS_IPOPT
00398 IpoptSolver *ipoptSolver = NULL;
00399 try{
00400 ipoptSolver = new IpoptSolver();
00401 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00402 ok = true;
00403 OSiLReader *osilreader = NULL;
00404 osilFileName = dataDir + "osilFiles" + dirsep + "avion2.osil";
00405 osil = fileUtil->getFileAsString( osilFileName.c_str() );
00406 cout << "IPOPT Solver created for OSiL string solution" << endl;
00407 ipoptSolver->osol = osol;
00408 osilreader = new OSiLReader();
00409 ipoptSolver->osinstance = osilreader->readOSiL( osil);
00410 cout << "call the IPOPT Solver" << endl;
00411 ipoptSolver->buildSolverInstance();
00412 ipoptSolver->solve();
00413 cout << "Here is the IPOPT solver solution for avion2" << endl;
00414 check = 9.46801e+07;
00415
00416 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00417 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on avion2");
00418 delete osilreader;
00419 osilreader = NULL;
00420 delete ipoptSolver;
00421 ipoptSolver = NULL;
00422 unitTestResult << "Solved problem avion2.osil with Ipopt" << std::endl;
00423
00424 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00425 ipoptSolver = new IpoptSolver();
00426
00427 osilFileName = dataDir + "osilFiles" + dirsep + "HS071_NLPMod.osil";
00428 osil = fileUtil->getFileAsString( osilFileName.c_str());
00429 cout << "IPOPT Solver created for OSiL string solution" << endl;
00430 ipoptSolver->osol = osol;
00431 osilreader = new OSiLReader();
00432 ipoptSolver->osinstance = osilreader->readOSiL( osil);
00433 ipoptSolver->buildSolverInstance();
00434 ipoptSolver->solve();
00435 cout << "Here is the IPOPT solver solution for HS071_NLP" << endl;
00436 check = 17.014;
00437
00438 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00439 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on HS071_NLP");
00440 delete osilreader;
00441 osilreader = NULL;
00442 unitTestResult << "Solved problem HS071.osil with Ipopt" << std::endl;
00443 delete ipoptSolver;
00444 ipoptSolver = NULL;
00445 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00446 ipoptSolver = new IpoptSolver();
00447
00448
00449 osilFileName = dataDir + "osilFiles" + dirsep + "rosenbrockmod.osil";
00450 osil = fileUtil->getFileAsString( osilFileName.c_str());
00451 cout << "IPOPT Solver created for OSiL string solution" << endl;
00452 ipoptSolver->osol = osol;
00453 osilreader = new OSiLReader();
00454 ipoptSolver->osinstance = osilreader->readOSiL( osil);
00455 cout << "call the IPOPT Solver" << endl;
00456 ipoptSolver->buildSolverInstance();
00457 ipoptSolver->solve();
00458 check = 6.7279;
00459
00460 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00461 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on rosenbrock");
00462 delete osilreader;
00463 osilreader = NULL;
00464 unitTestResult << "Solved problem rosenbrockmod.osil with Ipopt" << std::endl;
00465 delete ipoptSolver;
00466 ipoptSolver = NULL;
00467 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00468 ipoptSolver = new IpoptSolver();
00469
00470
00471 osilFileName = dataDir + "osilFiles" + dirsep + "parincQuadratic.osil";
00472 osil = fileUtil->getFileAsString( osilFileName.c_str());
00473 cout << "IPOPT Solver created for OSiL string solution" << endl;
00474 ipoptSolver->osol = osol;
00475 osilreader = new OSiLReader();
00476 ipoptSolver->osinstance = osilreader->readOSiL( osil);
00477 cout << "call the IPOPT Solver" << endl;
00478 ipoptSolver->buildSolverInstance();
00479 ipoptSolver->solve();
00480 cout << "Here is the IPOPT solver solution for parincQuadratic" << endl;
00481 check = 49920.5;
00482
00483 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00484 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on parincQuadradic");
00485 delete osilreader;
00486 osilreader = NULL;
00487 unitTestResult << "Solved problem parincQuadratic.osil with Ipopt" << std::endl;
00488 delete ipoptSolver;
00489 ipoptSolver = NULL;
00490 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00491 ipoptSolver = new IpoptSolver();
00492
00493
00494 osilFileName = dataDir + "osilFiles" + dirsep + "parincLinear.osil";
00495 osil = fileUtil->getFileAsString( osilFileName.c_str());
00496 cout << "IPOPT Solver created for OSiL string solution" << endl;
00497 ipoptSolver->osol = osol;
00498 osilreader = new OSiLReader();
00499 ipoptSolver->osinstance = osilreader->readOSiL( osil);
00500 cout << "call the IPOPT Solver" << endl;
00501 ipoptSolver->buildSolverInstance();
00502 ipoptSolver->solve();
00503 cout << "Here is the IPOPT solver solution for parincLinear" << endl;
00504 check = 7668;
00505
00506 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00507 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on parincLinear");
00508 delete osilreader;
00509 osilreader = NULL;
00510 unitTestResult << "Solved problem parincLinear.osil with Ipopt" << std::endl;
00511 delete ipoptSolver;
00512 ipoptSolver = NULL;
00513 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00514 ipoptSolver = new IpoptSolver();
00515
00516
00517 osilFileName = dataDir + "osilFiles" + dirsep + "callBackTest.osil";
00518 osil = fileUtil->getFileAsString( osilFileName.c_str());
00519 cout << "IPOPT Solver created for OSiL string solution" << endl;
00520 ipoptSolver->osol = osol;
00521 osilreader = new OSiLReader();
00522 ipoptSolver->osinstance = osilreader->readOSiL( osil);
00523
00524
00525
00526 cout << "call the IPOPT Solver" << endl;
00527 ipoptSolver->buildSolverInstance();
00528 ipoptSolver->solve();
00529 cout << "Here is the IPOPT solver solution for callBackTest" << endl;
00530 check = 1.00045e+06;
00531
00532 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00533 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on parincLinear");
00534 delete osilreader;
00535 osilreader = NULL;
00536 unitTestResult << "Solved problem callBack.osil with Ipopt" << std::endl;
00537 delete ipoptSolver;
00538 ipoptSolver = NULL;
00539 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00540 ipoptSolver = new IpoptSolver();
00541
00542
00543 osilFileName = dataDir + "osilFiles" + dirsep + "callBackTestRowMajor.osil";
00544 osil = fileUtil->getFileAsString( osilFileName.c_str());
00545 cout << "IPOPT Solver created for OSiL string solution" << endl;
00546 ipoptSolver->osol = osol;
00547 osilreader = new OSiLReader();
00548 ipoptSolver->osinstance = osilreader->readOSiL( osil);
00549
00550
00551
00552 cout << "call the IPOPT Solver" << endl;
00553 ipoptSolver->buildSolverInstance();
00554 ipoptSolver->solve();
00555 cout << "Here is the IPOPT solver solution for callBackTestRowMajor" << endl;
00556 check = 1.00045e+06;
00557
00558 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00559 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on parincLinear");
00560 delete osilreader;
00561 osilreader = NULL;
00562 delete ipoptSolver;
00563 ipoptSolver = NULL;
00564 unitTestResult << "Solved problem callBackRowMajor.osil with Ipopt" << std::endl;
00565 }
00566 catch(const ErrorClass& eclass){
00567 unitTestResultFailure << "Sorry Unit Test Failed Testing the Ipopt Solver:" + eclass.errormsg<< endl;
00568 }
00569 #endif
00570 try{
00571 ok = true;
00572 std::cout << "create a new COIN Clp for OSiL string solution" << std::endl;
00573 osilFileName = dataDir + "osilFiles" + dirsep + "parincLinearByRow.osil";
00574 osil = fileUtil->getFileAsString( osilFileName.c_str());
00575 std::cout << "create a new Solver object" << std::endl;
00576 OSiLReader *osilreader = NULL;
00577 osilreader = new OSiLReader();
00578
00579 OSInstance *osinstance = osilreader->readOSiL( osil);
00580 std::cout << " Done reading the OSiL" << std::endl;
00581
00582 OSiLWriter *osilwriter;
00583 osilwriter = new OSiLWriter();
00584 osilwriter->m_bWhiteSpace = true;
00585 std::cout << " Write the OSiL" << std::endl;
00586 osil = osilwriter->writeOSiL( osinstance) ;
00587
00588 std::cout << " Done writing the OSiL" << std::endl;
00589 solver = new CoinSolver();
00590 solver->sSolverName = "clp";
00591 solver->osil = osil;
00592 solver->osol = osol;
00593 solver->osinstance = NULL;
00594 cout << "call the COIN - clp Solver for parincLinearbyRow" << endl;
00595
00596 solver->solve();
00597 cout << "Here is the COIN clp solver solution for parincLinearByRow" << endl;
00598 cout << solver->osrl << endl;
00599 check = 7668;
00600 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00601
00602 if(ok == false) throw ErrorClass(" Fail unit test with clp on parincLinear");
00603
00604 osrlreader = new OSrLReader();
00605 osrlreader->readOSrL( solver->osrl);
00606 delete osilreader;
00607 osilreader = NULL;
00608 delete solver;
00609 solver = NULL;
00610 delete osilwriter;
00611 osilwriter = NULL;
00612 delete osrlreader;
00613 osrlreader = NULL;
00614 unitTestResult << "Solved problem parincLinearByRow.osil with Clp" << std::endl;
00615
00616
00617 }
00618 catch(const ErrorClass& eclass){
00619 unitTestResultFailure << "Sorry Unit Test Failed Testing Clp Solver:" + eclass.errormsg<< endl;
00620 }
00621 try{
00622 std::cout << "create a new COIN Cbc for OSiL string solution" << std::endl;
00623 ok = true;
00624 osilFileName = dataDir + "osilFiles" + dirsep + "p0033.osil";
00625 osil = fileUtil->getFileAsString( osilFileName.c_str());
00626 solver = new CoinSolver();
00627 solver->sSolverName ="cbc";
00628 solver->osil = osil;
00629 solver->osol = osol;
00630 solver->osinstance = NULL;
00631 cout << "call the COIN - Cbc Solver for p0033" << endl;
00632 solver->buildSolverInstance();
00633 solver->solve();
00634 cout << "Here is the COIN Cbc solver solution for p0033" << endl;
00635
00636 check = 3089;
00637
00638 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00639 if(ok == false) throw ErrorClass(" Fail unit test with Cbc on p0033");
00640 delete solver;
00641 solver = NULL;
00642 unitTestResult << "Solved problem p0033.osil with Cbc" << std::endl;
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664 }
00665 catch(const ErrorClass& eclass){
00666 unitTestResultFailure << "Sorry Unit Test Failed Testing Cbc Solver:" + eclass.errormsg<< endl;
00667 }
00668
00669
00670
00671 #ifdef COIN_HAS_KNITRO
00672 try{
00673 ok = true;
00674 osilFileName = dataDir + "osilFiles" + dirsep + "rosenbrockmod.osil";
00675 osil = fileUtil->getFileAsString( osilFileName.c_str());
00676 solver = new KnitroSolver();
00677 solver->osrl = "";
00678 solver->osil = osil;
00679 solver->osol = osol;
00680 solver->osinstance = NULL;
00681 cout << "call the KNITRO Solver" << endl;
00682 solver->solve();
00683 cout << "Here is the KNITRO solver solution" << endl;
00684 check = 6.7279;
00685 cout << solver->osrl << endl;
00686
00687 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00688 if(ok == false) throw ErrorClass(" Fail unit test with Knitro on rosenbrockmod");
00689 delete solver;
00690 solver = NULL;
00691 unitTestResult << "Solved problem rosenbrockmod.osil with Knitro" << std::endl;
00692
00693
00694 osilFileName = dataDir + "osilFiles" + dirsep + "callBackTest.osil";
00695 osil = fileUtil->getFileAsString( osilFileName.c_str());
00696 solver = new KnitroSolver();
00697 solver->osrl = "";
00698 solver->osil = osil;
00699 solver->osol = osol;
00700 cout << "call the KNITRO Solver" << endl;
00701 solver->solve();
00702 cout << "Here is the KNITRO solver solution" << endl;
00703 check = 1.00045e+06;
00704 cout << solver->osrl << endl;
00705
00706 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00707 if(ok == false) throw ErrorClass(" Fail unit test with Knitro callBackTest.osil");
00708 delete solver;
00709 solver = NULL;
00710 unitTestResult << "Solved problem callBackTest.osil with Knitro" << std::endl;
00711
00712
00713 osilFileName = dataDir + "osilFiles" + dirsep + "parincQuadratic.osil";
00714 osil = fileUtil->getFileAsString( osilFileName.c_str());
00715 solver = new KnitroSolver();
00716 solver->osil = osil;
00717 solver->osol = osol;
00718 solver->osinstance = NULL;
00719 cout << "call the Knitro Solver" << endl;
00720 solver->solve();
00721 cout << "Here is the Knitro solver solution" << endl;
00722 cout << solver->osrl << endl;
00723 check = 49920.5;
00724
00725 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00726 if(ok == false) throw ErrorClass(" Fail unit test with Knitro on parincQuadratic");
00727 delete solver;
00728 solver = NULL;
00729 unitTestResult << "Solved problem parincQuadratic.osil with Knitro" << std::endl;
00730
00731
00732 osilFileName = dataDir + "osilFiles" + dirsep + "HS071_NLP.osil";
00733 osil = fileUtil->getFileAsString( osilFileName.c_str());
00734 solver = new KnitroSolver();
00735 solver->osil = osil;
00736 solver->osol = osol;
00737 solver->osinstance = NULL;
00738 cout << "call the Knitro Solver" << endl;
00739 solver->solve();
00740 cout << "Here is the Knitro solver solution" << endl;
00741 cout << solver->osrl << endl;
00742 check = 17.014;
00743
00744 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00745 if(ok == false) throw ErrorClass(" Fail unit test with Knitro on HS071_NLP");
00746 delete solver;
00747 solver = NULL;
00748 unitTestResult << "Solved problem HS071_NLP.osil with Knitro" << std::endl;
00749 }
00750 catch(const ErrorClass& eclass){
00751 cout << "OSrL = " << solver->osrl << endl;
00752 cout << endl << endl << endl;
00753 unitTestResultFailure << "Sorry Unit Test Failed Testing the Knitro Solver: " + eclass.errormsg << endl;
00754 }
00755 #endif
00756
00757
00758
00759
00760
00761 #ifdef COIN_HAS_SYMPHONY
00762 try{
00763 ok = true;
00764 osilFileName = dataDir + "osilFiles" + dirsep + "p0033.osil";
00765 osil = fileUtil->getFileAsString( osilFileName.c_str());
00766 solver = new CoinSolver();
00767 solver->sSolverName = "symphony";
00768 solver->osil = osil;
00769 solver->osol = osol;
00770 solver->osinstance = NULL;
00771 cout << "call the COIN - SYMPHONY Solver for p0033" << endl;
00772 solver->buildSolverInstance();
00773 solver->solve();
00774 cout << "Here is the COIN SYMPHONY solver solution for p0033" << endl;
00775 cout << solver->osrl << endl;
00776 check = 3089;
00777
00778 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00779 if(ok == false) throw ErrorClass(" Fail unit test with SYMPHONY on p0033.osil");
00780 delete solver;
00781 solver = NULL;
00782 unitTestResult << "Solved problem p0033.osil with SYMPHONY" << std::endl;
00783 }
00784 catch(const ErrorClass& eclass){
00785 cout << "OSrL = " << solver->osrl << endl;
00786 cout << endl << endl << endl;
00787 unitTestResultFailure << "Sorry Unit Test Failed Testing the SYMPHONY Solver:" + eclass.errormsg << endl;
00788 }
00789 #endif
00790
00791
00792
00793
00794 #ifdef COIN_HAS_DYLP
00795 try{
00796 ok = true;
00797 osilFileName = dataDir + "osilFiles" + dirsep + "parincLinear.osil";
00798 osil = fileUtil->getFileAsString( osilFileName.c_str());
00799 solver = new CoinSolver();
00800 solver->sSolverName = "dylp";
00801 solver->osil = osil;
00802 solver->osol = osol;
00803 solver->osinstance = NULL;
00804 cout << "call the COIN - DyLP solver for parincLinear" << endl;
00805 solver->buildSolverInstance();
00806 solver->solve();
00807 cout << "Here is the COIN - DyLP solver solution for parincLinear" << endl;
00808 cout << solver->osrl << endl;
00809 check = 7668;
00810
00811 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00812 if(ok == false) throw ErrorClass(" Fail unit test with DyLP on parincLinear.osil");
00813 delete solver;
00814 solver = NULL;
00815 unitTestResult << "Solved problem parincLinear.osil with DyLP" << std::endl;
00816 }
00817 catch(const ErrorClass& eclass){
00818 cout << "OSrL = " << solver->osrl << endl;
00819 cout << endl << endl << endl;
00820 unitTestResultFailure <<"Sorry Unit Test Failed Testing the DyLP Solver:" + eclass.errormsg << endl;
00821 }
00822 #endif
00823
00824
00825
00826
00827 #ifdef COIN_HAS_VOL
00828 try{
00829 ok = true;
00830 osilFileName = dataDir + "osilFiles" + dirsep + "volumeTest.osil";
00831 osil = fileUtil->getFileAsString( osilFileName.c_str());
00832 solver = new CoinSolver();
00833 solver->sSolverName = "vol";
00834 solver->osil = osil;
00835 solver->osol = osol;
00836 solver->osinstance = NULL;
00837 cout << "call the COIN - Vol solver for parincLinear" << endl;
00838 solver->buildSolverInstance();
00839 solver->solve();
00840 cout << "Here is the COIN - Vol solver solution for parincLinear" << endl;
00841 cout << solver->osrl << endl;
00842 check = 7;
00843
00844 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00845 if(ok == false) throw ErrorClass(" Fail unit test with Vol on volumeTest.osil");
00846 delete solver;
00847 solver = NULL;
00848 unitTestResult << "Solved problem volumeTest.osil with Vol" << std::endl;
00849 }
00850 catch(const ErrorClass& eclass){
00851 cout << "OSrL = " << solver->osrl << endl;
00852 cout << endl << endl << endl;
00853 unitTestResultFailure <<"Sorry Unit Test Failed Testing the Vol Solver:" + eclass.errormsg << endl;
00854 }
00855 #endif
00856
00857
00858
00859
00860 #ifdef COIN_HAS_GLPK
00861 try{
00862 ok = true;
00863 osilFileName = dataDir + "osilFiles" + dirsep + "p0033.osil";
00864 osil = fileUtil->getFileAsString( osilFileName.c_str());
00865 solver = new CoinSolver();
00866 solver->sSolverName = "glpk";
00867 solver->osil = osil;
00868 solver->osol = osol;
00869 solver->osinstance = NULL;
00870 cout << "call the GLPK Solver for p0033" << endl;
00871 solver->buildSolverInstance();
00872 solver->solve();
00873 cout << "Here is the GLPK solver solution for p0033" << endl;
00874 cout << solver->osrl << endl;
00875 check = 3089;
00876
00877 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00878 if(ok == false) throw ErrorClass(" Fail unit test with GLPK on p0033.osil");
00879 delete solver;
00880 solver = NULL;
00881 unitTestResult << "Solved problem p0033.osil with GLPK" << std::endl;
00882 }
00883 catch(const ErrorClass& eclass){
00884 cout << "OSrL = " << solver->osrl << endl;
00885 cout << endl << endl << endl;
00886 unitTestResultFailure <<"Sorry Unit Test Failed Testing the Glpk Solver:" + eclass.errormsg << endl;
00887 }
00888 #endif
00889
00890
00891
00892 #ifdef COIN_HAS_CPX
00893 try{
00894 ok = true;
00895 osilFileName = dataDir + "osilFiles" + dirsep + "p0033.osil";
00896 osil = fileUtil->getFileAsString( osilFileName.c_str());
00897 solver = new CoinSolver();
00898 solver->sSolverName = "cplex";
00899 solver->osil = osil;
00900 solver->osol = osol;
00901 solver->osinstance = NULL;
00902 cout << "call the CPLEX Solver for p0033" << endl;
00903 solver->buildSolverInstance();
00904 solver->solve();
00905 cout << "Here is the CPLEX solver solution for p0033" << endl;
00906 cout << solver->osrl << endl;
00907 check = 3089;
00908
00909 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00910 if(ok == false) throw ErrorClass(" Fail unit test with CPLEX on p0033.osil");
00911 delete solver;
00912 solver = NULL;
00913 unitTestResult << "Solved problem p0033.osil with CPLEX" << std::endl;
00914 }
00915 catch(const ErrorClass& eclass){
00916 cout << "OSrL = " << solver->osrl << endl;
00917 cout << endl << endl << endl;
00918 unitTestResultFailure <<"Sorry Unit Test Failed Testing the Cplex Solver:" + eclass.errormsg << endl;
00919 }
00920 #endif
00921
00922
00923 #ifdef COIN_HAS_LINDO
00924 try{
00925 ok = true;
00926 osilFileName = dataDir + "osilFiles" + dirsep + "lindoapiaddins.osil";
00927 osil = fileUtil->getFileAsString( osilFileName.c_str());
00928 cout << "create a new LINDO Solver for OSiL string solution" << endl;
00929 solver = new LindoSolver();
00930 solver->osil = osil;
00931 solver->osol = osol;
00932 solver->osinstance = NULL;
00933 cout << "call the LINDO Solver" << endl;
00934 solver->buildSolverInstance();
00935 solver->solve();
00936 cout << "Here is the LINDO solver solution" << endl;
00937 cout << solver->osrl << endl;
00938 check = 99;
00939
00940 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00941 if(ok == false) throw ErrorClass(" Fail unit test with LINDO on lindoapiaddins");
00942 solver->osinstance = NULL;
00943 delete solver;
00944 solver = NULL;
00945 unitTestResult << "Solved problem lindoapiaddins.osil with Lindo" << std::endl;
00946
00947 osilFileName = dataDir + "osilFiles" + dirsep + "rosenbrockmod.osil";
00948 osil = fileUtil->getFileAsString( osilFileName.c_str());
00949 solver = new LindoSolver();
00950 solver->osil = osil;
00951 solver->osol = osol;
00952 solver->osinstance = NULL;
00953 cout << "call the LINDO Solver" << endl;
00954 solver->buildSolverInstance();
00955 solver->solve();
00956 cout << "Here is the LINDO solver solution" << endl;
00957 cout << solver->osrl << endl;
00958 check = 6.7279;
00959
00960 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00961 if(ok == false) throw ErrorClass(" Fail unit test with LINDO on rosenbrockmod");
00962 solver->osinstance = NULL;
00963 delete solver;
00964 solver = NULL;
00965 unitTestResult << "Solved problem rosenbrockmod.osil with Lindo" << std::endl;
00966
00967 osilFileName = dataDir + "osilFiles" + dirsep + "parincQuadratic.osil";
00968 osil = fileUtil->getFileAsString( osilFileName.c_str());
00969 solver = new LindoSolver();
00970 solver->osil = osil;
00971 solver->osol = osol;
00972 solver->osinstance = NULL;
00973 cout << "call the LINDO Solver" << endl;
00974 solver->buildSolverInstance();
00975 solver->solve();
00976 cout << "Here is the LINDO solver solution" << endl;
00977 cout << solver->osrl << endl;
00978 check = 49920.5;
00979
00980 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00981 if(ok == false) throw ErrorClass(" Fail unit test with LINDO on parincQuadratic");
00982 delete solver;
00983 solver = NULL;
00984 unitTestResult << "Solved problem parincQuadratic.osil with Lindo" << std::endl;
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010 }
01011 catch(const ErrorClass& eclass){
01012
01013 cout << endl << endl << endl;
01014 unitTestResultFailure <<"Sorry Unit Test Failed Testing the LINDO Solver:" + eclass.errormsg << endl << endl;
01015 }
01016 #endif
01017
01018
01019 try{
01020 ok = true;
01021 cout << endl;
01022 cout << "START MPS TESTING" << endl << endl;
01023 cout << "create a COIN Solver for MPS - OSInstance solution" << endl;
01024 solver = new CoinSolver();
01025 solver->sSolverName = "cbc";
01026 mps2osil = new OSmps2osil( mpsFileName);
01027 mps2osil->createOSInstance() ;
01028 solver->osinstance = mps2osil->osinstance;
01029 solver->osol = osol;
01030 cout << "call COIN Solve" << endl;
01031 solver->buildSolverInstance();
01032 solver->solve();
01033 cout << "Here is the COIN solver solution" << endl;
01034 cout << solver->osrl << endl;
01035 check = -7668;
01036
01037 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01038 if(ok == false) throw ErrorClass(" Fail unit test with COIN Solver on MPS test problem parincLinear.mps");
01039 delete solver;
01040 solver = NULL;
01041 delete mps2osil;
01042 mps2osil = NULL;
01043 cout << endl;
01044 cout << "DONE WITH MPS TESTING" << endl;
01045 unitTestResult << "Test the MPS -> OSiL converter on parinc.mps using Cbc" << std::endl;
01046 }
01047 catch(const ErrorClass& eclass){
01048 cout << "OSrL = " << solver->osrl << endl;
01049 cout << endl << endl << endl;
01050 unitTestResultFailure <<"Sorry Unit Test Failed Testing the MPS converter:" + eclass.errormsg << endl;
01051 }
01052
01053 try{
01054 ok = true;
01055 cout << endl;
01056 cout << "START AMPL TESTING" << endl << endl;
01057 #ifdef COIN_HAS_ASL
01058 cout << "create a cbc Solver for AMPL nl - OSInstance solution" << endl;
01059 solver = new CoinSolver();
01060 solver->sSolverName = "cbc";
01061 nl2osil = new OSnl2osil( nlFileName);
01062 nl2osil->createOSInstance() ;
01063 solver->osinstance = nl2osil->osinstance;
01064 solver->osol = osol;
01065 cout << "call Cbc Solve" << endl;
01066 solver->buildSolverInstance();
01067 solver->solve();
01068 cout << "Here is the Cbc solver solution" << endl;
01069 cout << solver->osrl << endl;
01070 check = 7668;
01071
01072 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01073 if(ok == false) throw ErrorClass(" Fail unit test with OSnl2osil on problem parinc.nl");
01074 solver->osinstance = NULL;
01075 delete solver;
01076 solver = NULL;
01077 cout << "call delete nl2osil" << endl;
01078 delete nl2osil;
01079 nl2osil = NULL;
01080 unitTestResult << "Test the AMPL nl -> OSiL converter on parinc.nl using Cbc" << std::endl;
01081 #endif
01082 cout << "END AMPL TESTING" << endl << endl;
01083 }
01084 catch(const ErrorClass& eclass){
01085 cout << "OSrL = " << solver->osrl << endl;
01086 cout << endl << endl << endl;
01087 unitTestResultFailure <<"Sorry Unit Test Failed Testing AMPL:" + eclass.errormsg << endl;
01088 }
01089
01090
01091
01092 try{
01093 ok = true;
01094 cout << endl;
01095 cout << endl;
01096 cout << "TESTING BASE 64 WITH A COIN SOLVER"<< endl;
01097 cout << endl;
01098 OSiLWriter osilwriter;
01099 osilwriter.m_bWriteBase64 = true;
01100 solver = new CoinSolver();
01101 solver->sSolverName = "cbc";
01102 mps2osil = new OSmps2osil( mpsFileName);
01103 solver->osinstance = NULL;
01104 solver->osol = osol;
01105 mps2osil->createOSInstance() ;
01106 solver->osil = osilwriter.writeOSiL( mps2osil->osinstance) ;
01107 std::cout << solver->osil << std::endl;
01108 solver->buildSolverInstance();
01109 solver->solve();
01110 cout << endl << endl;
01111 cout << "COIN solution of a OSiL string in b64 format" << endl;
01112 cout << solver->osrl;
01113 check = -7668;
01114
01115 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01116 if(ok == false) throw ErrorClass(" Fail unit test with COIN Cbc cSolver on b64 test problem parincLinear.mps");
01117 solver->osinstance = NULL;
01118 delete solver;
01119 solver = NULL;
01120 delete mps2osil;
01121 mps2osil = NULL;
01122 unitTestResult << "Test a problem written in b64 and then converted to OSInstance" << std::endl;
01123 }
01124 catch(const ErrorClass& eclass){
01125 cout << endl << endl;
01126 cout << eclass.errormsg << endl << endl;
01127 cout << "OSrL = " << solver->osrl << endl;
01128 cout << endl << endl << endl;
01129 unitTestResultFailure << "Sorry Unit Test Failed Testing Use of Base 64" << endl;
01130
01131 }
01132
01133
01134 try{
01135 cout << endl;
01136 clock_t start, finish;
01137 double duration;
01138 OSiLWriter *osilwriter = NULL;
01139 osilwriter = new OSiLWriter();
01140
01141
01142
01143 cout << "TEST PARSING A MODEL" << endl;
01144 cout << "FIRST READ THE FILE INTO A STRING" << endl;
01145 start = clock();
01146 osilFileName = dataDir + "osilFiles" + dirsep + "parincLinear.osil";
01147 osil = fileUtil->getFileAsString( osilFileName.c_str());
01148 finish = clock();
01149 duration = (double) (finish - start) / CLOCKS_PER_SEC;
01150 cout << "Reading the file into a string took (seconds): "<< duration << endl;
01151 OSiLReader *osilreader = NULL;
01152 osilreader = new OSiLReader();
01153 start = clock();
01154 cout << "PARSE THE OSIL STRING INTO AN OSINSTANCE OBJECT" << endl;
01155 osilreader->readOSiL( osil);
01156
01157 delete osilreader;
01158 osilreader = 0;
01159 delete osilwriter;
01160 osilwriter = NULL;
01161 finish = clock();
01162 duration = (double) (finish - start) / CLOCKS_PER_SEC;
01163 cout << "Parsing took (seconds): "<< duration << endl;
01164 unitTestResult << "Successful test of OSiL parser on problem parincLinear.osil" << std::endl;
01165
01166 }
01167 catch(const ErrorClass& eclass){
01168 cout << endl << endl << endl;
01169 cout << eclass.errormsg << endl;
01170 unitTestResultFailure << "Sorry Unit Test Failed Testing An OSiL Parser" << endl;
01171
01172 }
01173
01174
01175
01176 try{
01177 cout << endl;
01178 clock_t start, finish;
01179 double duration;
01180 osrlwriter = new OSrLWriter();
01181 osrlreader = new OSrLReader();
01182 OSResult *osresult = NULL;
01183
01184 cout << "TEST PARSING AN OSrL FILE" << endl;
01185 cout << "FIRST READ THE OSrL FILE INTO A STRING" << endl;
01186 osrlFileName = dataDir + "osrlFiles" + dirsep + "parincLinear.osrl";
01187 start = clock();
01188 std::string osrl = fileUtil->getFileAsString( osrlFileName.c_str() );
01189 finish = clock();
01190 duration = (double) (finish - start) / CLOCKS_PER_SEC;
01191 cout << "Reading the file into a string took (seconds): "<< duration << endl;
01192 start = clock();
01193 cout << "PARSE THE OSRL STRING INTO AN OSRESULT OBJECT" << endl;
01194 osresult = osrlreader->readOSrL( osrl);
01195 cout << osrlwriter->writeOSrL( osresult) << endl;
01196 delete osrlwriter;
01197 osrlwriter = NULL;
01198 delete osrlreader;
01199 osrlreader = NULL;
01200 finish = clock();
01201 duration = (double) (finish - start) / CLOCKS_PER_SEC;
01202 cout << "Parsing took (seconds): "<< duration << endl;
01203 unitTestResult << "Successful test of OSrL parser on problem parincLinear.osrl" << std::endl;
01204
01205 }
01206 catch(const ErrorClass& eclass){
01207 cout << endl << endl << endl;
01208 if(osrlwriter != NULL) delete osrlwriter;
01209 if(osrlreader != NULL) delete osrlreader;
01210
01211 unitTestResultFailure << eclass.errormsg << endl;
01212 unitTestResultFailure << "There was a failure in the test for reading OSrL" << endl;
01213 }
01214
01215 try{
01216 std::string expTreeTest = dataDir + "osilFiles" + dirsep + "rosenbrockmod.osil";
01217 osil = fileUtil->getFileAsString( expTreeTest.c_str() ) ;
01218 OSInstance *osinstance = NULL;
01219
01220 OSiLReader *osilreader = NULL;
01221 osilreader = new OSiLReader();
01222
01223 osinstance = osilreader->readOSiL( osil);
01224 OSExpressionTree* expTree = osinstance->getNonlinearExpressionTree( -1);
01225 if(expTree == NULL) throw ErrorClass(" Null expression tree when testing prefix and postfix routines");
01226 std::vector<OSnLNode*> postfixVec;
01227
01228 postfixVec = osinstance->getNonlinearExpressionTreeInPostfix( -1);
01229
01230 unsigned int n = postfixVec.size();
01231 unsigned int i;
01232 std::string *nodeNames1 = new std::string[ n];
01233 std::string *nodeNames2 = new std::string[ n];
01234 for (i = 0 ; i < n; i++){
01235 std::cout << postfixVec[i]->snodeName << std::endl;
01236 nodeNames1[i] = postfixVec[i]->snodeName;
01237 }
01238
01239
01240 expTree->m_treeRoot = postfixVec[ n - 1]->createExpressionTreeFromPostfix( postfixVec);
01241
01242
01243 std::vector<OSnLNode*> prefixVec;
01244
01245 prefixVec = osinstance->getNonlinearExpressionTreeInPrefix( -1);
01246
01247
01248 expTree->m_treeRoot = prefixVec[ 0]->createExpressionTreeFromPrefix( prefixVec);
01249
01250
01251 postfixVec = expTree->m_treeRoot->getPostfixFromExpressionTree();
01252
01253 if(postfixVec.size() != n) throw ErrorClass(" Problem with creating expression trees");
01254 std::cout << std::endl << std::endl;
01255 for (i = 0 ; i < n; i++){
01256
01257 nodeNames2[i] = postfixVec[i]->snodeName;
01258 if( nodeNames1[i] != nodeNames2[ i]) throw ErrorClass(" Problem with creating expression trees");
01259 }
01260
01261
01262 delete[] nodeNames1;
01263 delete[] nodeNames2;
01264
01265 delete osilreader;
01266 osilreader = NULL;
01267 osinstance = NULL;
01268 unitTestResult << "Successful test of prefix and postfix conversion routines on problem rosenbrockmod.osil" << std::endl;
01269
01270 }
01271 catch(const ErrorClass& eclass){
01272 cout << endl << endl << endl;
01273 unitTestResultFailure << eclass.errormsg << endl;
01274 }
01275
01276 try{
01277 ok = true;
01278 std::cout << "Test nonlinear operators" << std::endl;
01279 std::string operatorTest = dataDir + "osilFiles" + dirsep + "testOperators.osil";
01280 osil = fileUtil->getFileAsString( operatorTest.c_str() );
01281 OSInstance *osinstance = NULL;
01282
01283 OSiLReader *osilreader = NULL;
01284 osilreader = new OSiLReader();
01285 OSiLWriter *osilwriter = NULL;
01286 osilwriter = new OSiLWriter();
01287 osinstance = osilreader->readOSiL( osil);
01288 OSExpressionTree* expTree = osinstance->getNonlinearExpressionTree( -1);
01289 std::vector<OSnLNode*> postfixVec;
01290 postfixVec = expTree->m_treeRoot->getPostfixFromExpressionTree();
01291 int n = postfixVec.size();
01292 std::string *nodeNames1 = new std::string[ n];
01293 for (int i = 0 ; i < n; i++){
01294 std::cout << postfixVec[i]->snodeName << std::endl;
01295 nodeNames1[i] = postfixVec[i]->snodeName;
01296 }
01297 std::cout << std::endl << std::endl;
01298 std::cout << osilwriter->writeOSiL( osinstance) << std::endl;
01299
01300 double *x = NULL;
01301 x = new double[2];
01302 x[0] = 1;
01303 x[1] = 2;
01304 double parserTestVal = expTree->m_treeRoot->calculateFunction( x);
01305 std::cout << "ParserTest Val = " << parserTestVal << std::endl;
01306 check = 11;
01307
01308 ok = ( fabs(check - expTree->m_treeRoot->calculateFunction( x))/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01309 if(ok == false) throw ErrorClass(" Problem evaluating expression tree");
01310 delete[] x;
01311 delete[] nodeNames1;
01312 delete osilreader;
01313 osilreader = NULL;
01314 delete osilwriter;
01315 osilwriter = NULL;
01316 osinstance = NULL;
01317
01318 unitTestResult << "Successful test of all of the nonlinear operators on file testOperators.osil" << std::endl;
01319 }
01320 catch(const ErrorClass& eclass){
01321 cout << endl << endl << endl;
01322 unitTestResultFailure << eclass.errormsg << endl;
01323 }
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335
01336
01337
01338
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348
01349
01350
01351
01352
01353
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366 try{
01367 std::cout << std::endl << std::endl;
01368 std::cout << "Testing AD Features " << std::endl;
01369 std::string expTreeTest = dataDir + "osilFiles" + dirsep + "CppADTestLag.osil";
01370
01371
01372
01373
01374
01375
01376
01377
01378 osil = fileUtil->getFileAsString( expTreeTest.c_str() );
01379 OSInstance *osinstance = NULL;
01380
01381 OSiLReader *osilreader = NULL;
01382 osilreader = new OSiLReader();
01383
01384 osinstance = osilreader->readOSiL( osil);
01385 double *x;
01386 x = new double[ 4];
01387 x[0] = 1;
01388 x[1] = 5;
01389 x[2] = 10;
01390 x[3] = 5;
01391 SparseVector *sp;
01392
01393 osinstance->getJacobianSparsityPattern();
01394 sp = osinstance->calculateConstraintFunctionGradient(x, 1, true);
01395 int i;
01396 for(i = 0; i < sp->number; i++){
01397 std::cout << "gradient value " << sp->values[i] << std::endl;
01398 }
01399 ok = true;
01400
01401 double checkPartial2Con1 = 7.0 ;
01402
01403 ok = ( fabs(checkPartial2Con1 - sp->values[ 0] )/(fabs( checkPartial2Con1) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01404 if(ok == false) throw ErrorClass(" Fail testing gradient calculation");
01405 double checkPartial0Con1 = (1./x[0]) ;
01406
01407 ok = ( fabs(checkPartial0Con1 - sp->values[ 1] )/(fabs( checkPartial0Con1) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01408 if(ok == false) throw ErrorClass(" Fail testing gradient calculation");
01409 double checkPartial3Con1 = (1./x[3]) ;
01410
01411 ok = ( fabs(checkPartial3Con1 - sp->values[ 2] )/(fabs( checkPartial3Con1) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01412 if(ok == false) throw ErrorClass(" Fail testing gradient calculation");
01413 delete sp;
01414 SparseHessianMatrix *sh;
01415
01416 osinstance->getLagrangianHessianSparsityPattern( );
01417 sh = osinstance->calculateHessian(x, -1, true);
01418 for(i = 0; i < sh->hessDimension; i++){
01419 std::cout << "Hessian value " << sh->hessValues[i] << std::endl;
01420 }
01421
01422 ok = ( fabs(2. - sh->hessValues[0] )/(2. + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01423 if(ok == false) throw ErrorClass(" Fail testing Hessian calculation");
01424
01425 ok = ( fabs(0. - sh->hessValues[ 1] )/(0. + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01426 if(ok == false) throw ErrorClass(" Fail testing Hessian calculation");
01427
01428 ok = ( fabs(0. - sh->hessValues[2] )/(0. + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01429 if(ok == false) throw ErrorClass(" Fail testing Hessian calculation");
01430 unitTestResult << "Successful test of AD gradient and Hessian calculations on problem CppADTestLag.osil" << std::endl;
01431 delete[] x;
01432 delete osilreader;
01433 osilreader = NULL;
01434 }
01435 catch(const ErrorClass& eclass){
01436 cout << endl << endl << endl;
01437 unitTestResultFailure << eclass.errormsg << endl;
01438 }
01439 delete fileUtil;
01440 fileUtil = NULL;
01441
01442 if(unitTestResultFailure.str().length() > 0){
01443 cout << "The unitTest passed the following" << endl << endl;
01444 cout << unitTestResult.str() << endl << endl;
01445 cout << "Unfortunately, you failed on the following:" << endl << endl;
01446 cout << unitTestResultFailure.str() << endl << endl;
01447 cout << "Conclusion: FAILURE" << endl;
01448 return 1;
01449 }
01450 else{
01451 cout << "The unitTest passed the following" << endl << endl;
01452 cout << unitTestResult.str() << endl << endl;
01453 cout << "All tests completed successfully" << endl << endl;
01454 return 0;
01455 }
01456 }
01457
01458 double getObjVal( std::string osrl){
01459 std::string sObjVal;
01460 double dObjVal;
01461 string::size_type pos2;
01462 string::size_type pos1 = osrl.find( "<obj ");
01463 if(pos1 != std::string::npos){
01464
01465 pos1 = osrl.find(">", pos1 + 1);
01466 if(pos1 != std::string::npos){
01467
01468 pos2 = osrl.find( "</obj", pos1 + 1);
01469 if( pos2 != std::string::npos){
01470
01471 sObjVal = osrl.substr( pos1 + 1, pos2 - pos1 - 1);
01472
01473
01474
01475 return dObjVal = os_strtod( sObjVal.c_str(), NULL);
01476 }
01477 else return OSNAN;
01478 }
01479 else return OSNAN;
01480 }
01481 else return OSNAN;
01482 }