212int main(
int argC,
char* argV[])
217 WindowsErrorPopupBlocker();
224 cout <<
"START UNIT TEST" << endl;
229 OSnl2osil *nl2osil = NULL;
239 std::string osilFileName;
240 std::string osolFileName;
241 std::string osrlFileName;
242 std::string nlFileName;
243 std::string mpsFileName;
246 ostringstream unitTestResult;
247 ostringstream unitTestResultFailure;
249 const char dirsep = CoinFindDirSeparator();
252 dataDir = dirsep ==
'/' ?
"../data/" :
"..\\data\\";
253 nlFileName = dataDir +
"amplFiles" + dirsep +
"parinc.nl";
254 mpsFileName = dataDir +
"mpsFiles" + dirsep +
"parinc.mps";
258#ifdef INSTALLATION_TEST
262 std::cout << endl <<
"TEST " << ++nOfTest <<
": Try to read a sample file" << endl << endl;
263 osilFileName = dataDir +
"osilFiles" + dirsep +
"parincLinearByRow.osil";
265 std::cout <<
"The file is: " ;
266 std::cout << osilFileName << std::endl;
267 osil = fileUtil->getFileAsString( osilFileName.c_str() );
268 std::cout <<
"Done reading the test file" << std::endl;
272 unitTestResult <<
"Reading files successfully" << std::endl;
273 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
313 cout << endl <<
"TEST " << ++nOfTest <<
": Lossless I/O" << endl << endl;
315 mpsFileName = dataDir +
"mpsFiles" + dirsep +
"parinc.mps";
318 mps2osil->createOSInstance() ;
320 OSInstance *osinstance1 = mps2osil->osinstance;
321 std::string sOSiL = osilwriter.writeOSiL( osinstance1 );
326 OSInstance *osinstance2 = osilreader->readOSiL( sOSiL);
329 double theDiff, theMax;
332 for(
int i = 0; i < nvals; i++){
333 theDiff = fabs(osinstance1->instanceData->linearConstraintCoefficients->value->el[ i] -
334 osinstance2->instanceData->linearConstraintCoefficients->value->el[ i])/ fabs(osinstance1->instanceData->linearConstraintCoefficients->value->el[ i]);
335 if(theDiff > theMax){
341 std::cout <<
"MAXIMUM DIFF = " << theMax << std::endl;
342 std::cout <<
"MAXIMUM DIFF INDEX = " << theIndex << std::endl;
343 if(theMax > 0) unitTestResult <<
"WARNING: you do not have lossless IO" << std::endl;
345 { unitTestResult <<
"Passed lossless IO test" << std::endl;
346 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
411 unitTestResultFailure <<
"Sorry Unit Test Failed Reading a file: " + eclass.errormsg<< endl;
413 unitTestResultFailure <<
"Since we can't read files we are terminating" << endl;
414 cout << unitTestResultFailure.str() << endl << endl;
415 cout <<
"Conclusion: FAILURE" << endl;
420 cout << endl <<
"TEST " << ++nOfTest <<
": Clp solver on parincLinearByRow.osil" << endl << endl;
422 std::cout <<
"create a new COIN Clp for OSiL string solution" << std::endl;
423 osilFileName = dataDir +
"osilFiles" + dirsep +
"parincLinearByRow.osil";
424 osolFileName = dataDir +
"osolFiles" + dirsep +
"parincLinearByRow_clp.osol";
425 osil = fileUtil->getFileAsString( osilFileName.c_str());
426 osol = fileUtil->getFileAsString( osolFileName.c_str());
428 std::cout <<
"create a new Solver object" << std::endl;
433 solver->
osinstance = osilreader->readOSiL( osil);
434 std::cout <<
" Done reading the OSiL" << std::endl;
438 osilwriter->m_bWhiteSpace =
true;
439 std::cout <<
" Write the OSiL" << std::endl;
440 osil = osilwriter->writeOSiL( solver->
osinstance) ;
442 std::cout <<
" Done writing the OSiL" << std::endl;
444 cout <<
"call the COIN - clp Solver for parincLinearbyRow" << endl;
447 cout <<
"Here is the COIN clp solver solution for parincLinearByRow" << endl;
448 cout << solver->
osrl << endl;
452 if(ok ==
false)
throw ErrorClass(
" Fail unit test with clp on parincLinearByRow.osil");
455 cout <<
"First osrl file\n" << solver->
osrl << endl;
456 osrlreader->readOSrL( solver->
osrl);
457 cout <<
"read successfully" << endl;
459 cout <<
"osilreader successfully deleted" << endl;
462 cout <<
"osolreader successfully deleted" << endl;
465 cout <<
"solver successfully deleted" << endl;
468 cout <<
"osilwriter successfully deleted" << endl;
471 cout <<
"osrlreader successfully deleted" << endl;
473 unitTestResult <<
"Solved problem parincLinearByRow.osil with Clp" << std::endl;
474 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
477 unitTestResultFailure <<
"Sorry Unit Test Failed Testing Clp Solver:" + eclass.errormsg<< endl;
482 cout << endl <<
"TEST " << ++nOfTest <<
": Cbc solver on p0033.osil" << endl << endl;
483 std::cout <<
"create a new COIN Cbc for OSiL string solution" << std::endl;
485 osilFileName = dataDir +
"osilFiles" + dirsep +
"p0033.osil";
486 osolFileName = dataDir +
"osolFiles" + dirsep +
"p0033_cbc.osol";
487 osil = fileUtil->getFileAsString( osilFileName.c_str());
488 osol = fileUtil->getFileAsString( osolFileName.c_str());
497 cout <<
"call the COIN - Cbc Solver for p0033" << endl;
500 cout <<
"Here is the COIN Cbc solver solution for p0033" << endl;
505 if(ok ==
false)
throw ErrorClass(
" Fail unit test with Cbc on p0033.osil");
512 unitTestResult <<
"Solved problem p0033.osil with Cbc" << std::endl;
513 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
516 unitTestResultFailure <<
"Sorry Unit Test Failed Testing Cbc Solver:" + eclass.errormsg<< endl;
522 cout << endl <<
"TEST " << ++nOfTest <<
": Cbc solver on p0201.osil" << endl << endl;
524 osilFileName = dataDir +
"osilFiles" + dirsep +
"p0201.osil";
525 osolFileName = dataDir +
"osolFiles" + dirsep +
"p0201_cbc.osol";
526 osil = fileUtil->getFileAsString( osilFileName.c_str());
527 osol = fileUtil->getFileAsString( osolFileName.c_str());
536 cout <<
"call the COIN - Cbc Solver for p0201" << endl;
538 cout <<
"Here is the COIN Cbc solver solution for p0201" << endl;
542 if(ok ==
false)
throw ErrorClass(
" Fail unit test with Cbc on p0201.osil");
549 unitTestResult <<
"Solved problem p0201.osil with Cbc" << std::endl;
550 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
553 unitTestResultFailure <<
"Sorry Unit Test Failed Testing Cbc Solver:" + eclass.errormsg<< endl;
556 cout << endl <<
"TEST " << ++nOfTest <<
": Cbc solver on parincInteger.osil" << endl << endl;
558 osilFileName = dataDir +
"osilFiles" + dirsep +
"parincInteger.osil";
559 osolFileName = dataDir +
"osolFiles" + dirsep +
"parincInteger_cbc.osol";
560 osil = fileUtil->getFileAsString( osilFileName.c_str());
561 osol = fileUtil->getFileAsString( osolFileName.c_str());
567 solver->
osinstance = osilreader->readOSiL( osil);
569 cout <<
"call the COIN - Cbc Solver for parincInteger" << endl;
572 cout <<
"Here is the Cbc solver solution for parincInteger" << endl;
576 if(ok ==
false)
throw ErrorClass(
" Fail unit test with Cbc on parincInteger.osil");
577 unitTestResult <<
"Solved problem parincInteger.osil with Cbc" << std::endl;
584 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
592 cout << endl <<
"TEST " << ++nOfTest <<
": Ipopt solver with avion2.osil" << endl << endl;
594 cout <<
"create a new IPOPT Solver for OSiL string solution" << endl;
600 osilFileName = dataDir +
"osilFiles" + dirsep +
"avion2.osil";
601 osolFileName = dataDir +
"osolFiles" + dirsep +
"avion2_ipopt.osol";
602 osil = fileUtil->getFileAsString( osilFileName.c_str());
603 osol = fileUtil->getFileAsString( osolFileName.c_str());
604 cout <<
"IPOPT Solver created for OSiL string solution" << endl;
605 ipoptSolver->osol = osol;
608 ipoptSolver->osinstance = osilreader->readOSiL( osil);
609 ipoptSolver->osol = osol;
610 cout <<
"call the IPOPT Solver" << endl;
611 ipoptSolver->buildSolverInstance();
612 ipoptSolver->solve();
613 cout <<
"Here is the IPOPT solver solution for avion2" << endl;
617 if(ok ==
false)
throw ErrorClass(
" Fail unit test with Ipopt on avion2.osil");
624 unitTestResult <<
"Solved problem avion2.osil with Ipopt" << std::endl;
625 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
630 cout << endl <<
"TEST " << ++nOfTest <<
": Ipopt solver with HS071_NLPMod.osil" << endl << endl;
631 cout <<
"create a new IPOPT Solver for OSiL string solution" << endl;
634 osilFileName = dataDir +
"osilFiles" + dirsep +
"HS071_NLPMod.osil";
635 osolFileName = dataDir +
"osolFiles" + dirsep +
"HS071_NLPMod_ipopt.osol";
636 osil = fileUtil->getFileAsString( osilFileName.c_str());
637 osol = fileUtil->getFileAsString( osolFileName.c_str());
638 cout <<
"IPOPT Solver created for OSiL string solution" << endl;
642 ipoptSolver->osinstance = osilreader->readOSiL( osil);
643 ipoptSolver->osoption = osolreader->
readOSoL( osol);
644 ipoptSolver->osol = osol;
645 ipoptSolver->buildSolverInstance();
646 ipoptSolver->solve();
647 cout <<
"Here is the IPOPT solver solution for HS071_NLP" << endl;
657 if(ok ==
false)
throw ErrorClass(
" Fail unit test with Ipopt on HS071_NLP.osil");
658 unitTestResult <<
"Solved problem HS071.osil with Ipopt" << std::endl;
659 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
661 cout << endl <<
"TEST " << ++nOfTest <<
": Ipopt solver on rosenbrockmod.osil" << endl << endl;
662 cout <<
"create a new IPOPT Solver for OSiL string solution" << endl;
666 osilFileName = dataDir +
"osilFiles" + dirsep +
"rosenbrockmod.osil";
667 osolFileName = dataDir +
"osolFiles" + dirsep +
"rosenbrockmod_ipopt.osol";
668 osil = fileUtil->getFileAsString( osilFileName.c_str());
669 osol = fileUtil->getFileAsString( osolFileName.c_str());
670 cout <<
"IPOPT Solver created for OSiL string solution" << endl;
673 ipoptSolver->osil = osil;
674 ipoptSolver->osoption = osolreader->
readOSoL( osol);
675 cout <<
"call the IPOPT Solver" << endl;
676 ipoptSolver->buildSolverInstance();
677 ipoptSolver->solve();
682 throw ErrorClass(
" Fail unit test with Ipopt on rosenbrockmod.osil");
687 unitTestResult <<
"Solved problem rosenbrockmod.osil with Ipopt" << std::endl;
690 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
692 cout << endl <<
"TEST " << ++nOfTest <<
": Ipopt solver on parincQuadratic.osil" << endl << endl;
693 cout <<
"create a new IPOPT Solver for OSiL string solution" << endl;
697 osilFileName = dataDir +
"osilFiles" + dirsep +
"parincQuadratic.osil";
698 osolFileName = dataDir +
"osolFiles" + dirsep +
"parincQuadratic_ipopt.osol";
699 osil = fileUtil->getFileAsString( osilFileName.c_str());
700 osol = fileUtil->getFileAsString( osolFileName.c_str());
701 cout <<
"IPOPT Solver created for OSiL string solution" << endl;
704 ipoptSolver->osinstance = osilreader->readOSiL( osil);
705 ipoptSolver->osil = osil;
706 ipoptSolver->osol = osol;
707 cout <<
"call the IPOPT Solver" << endl;
708 ipoptSolver->buildSolverInstance();
709 ipoptSolver->solve();
710 cout <<
"Here is the IPOPT solver solution for parincQuadratic" << endl;
714 if(ok ==
false)
throw ErrorClass(
" Fail unit test with Ipopt on parincQuadradic.osil");
719 unitTestResult <<
"Solved problem parincQuadratic.osil with Ipopt" << std::endl;
722 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
724 cout << endl <<
"TEST " << ++nOfTest <<
": Ipopt solver on parincLinear.osil" << endl << endl;
725 cout <<
"create a new IPOPT Solver for OSiL string solution" << endl;
729 osilFileName = dataDir +
"osilFiles" + dirsep +
"parincLinear.osil";
730 osolFileName = dataDir +
"osolFiles" + dirsep +
"parincLinear_ipopt.osol";
731 osil = fileUtil->getFileAsString( osilFileName.c_str());
732 osol = fileUtil->getFileAsString( osolFileName.c_str());
733 cout <<
"IPOPT Solver created for OSiL string solution" << endl;
736 ipoptSolver->osinstance = osilreader->readOSiL( osil);
737 ipoptSolver->osoption = NULL;
738 ipoptSolver->osol =
"";
739 cout <<
"call the IPOPT Solver" << endl;
740 ipoptSolver->buildSolverInstance();
741 ipoptSolver->solve();
742 cout <<
"Here is the IPOPT solver solution for parincLinear" << endl;
746 if(ok ==
false)
throw ErrorClass(
" Fail unit test with Ipopt on parincLinear.osil");
747 unitTestResult <<
"Solved problem parincLinear.osil with Ipopt" << std::endl;
754 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
756 cout << endl <<
"TEST " << ++nOfTest <<
": Ipopt solver on callBackTest.osil" << endl << endl;
757 cout <<
"create a new IPOPT Solver for OSiL string solution" << endl;
761 osilFileName = dataDir +
"osilFiles" + dirsep +
"callBackTest.osil";
762 osolFileName = dataDir +
"osolFiles" + dirsep +
"callBackTest_ipopt.osol";
763 osil = fileUtil->getFileAsString( osilFileName.c_str());
764 osol = fileUtil->getFileAsString( osolFileName.c_str());
765 cout <<
"IPOPT Solver created for OSiL string solution" << endl;
768 ipoptSolver->osinstance = osilreader->readOSiL( osil);
769 ipoptSolver->osoption = osolreader->
readOSoL( osol);
770 ipoptSolver->osol = osol;
771 cout <<
"call the IPOPT Solver" << endl;
772 ipoptSolver->buildSolverInstance();
773 ipoptSolver->solve();
774 cout <<
"Here is the IPOPT solver solution for callBackTest" << endl;
778 if(ok ==
false)
throw ErrorClass(
" Fail unit test with Ipopt on callBackTest.osil");
779 unitTestResult <<
"Solved problem callBackTest.osil with Ipopt" << std::endl;
786 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
788 cout << endl <<
"TEST " << ++nOfTest <<
": Ipopt solver on callBackTestRowMajor.osil" << endl << endl;
789 cout <<
"create a new IPOPT Solver for OSiL string solution" << endl;
793 osilFileName = dataDir +
"osilFiles" + dirsep +
"callBackTestRowMajor.osil";
794 osolFileName = dataDir +
"osolFiles" + dirsep +
"callBackTestRowMajor_ipopt.osol";
795 osil = fileUtil->getFileAsString( osilFileName.c_str());
796 osol = fileUtil->getFileAsString( osolFileName.c_str());
797 cout <<
"IPOPT Solver created for OSiL string solution" << endl;
800 ipoptSolver->osinstance = NULL;
801 ipoptSolver->osoption = NULL;
802 ipoptSolver->osil = osil;
803 ipoptSolver->osol = osol;
804 cout <<
"call the IPOPT Solver" << endl;
806 ipoptSolver->solve();
807 cout <<
"Here is the IPOPT solver solution for callBackTestRowMajor" << endl;
811 if(ok ==
false)
throw ErrorClass(
" Fail unit test with Ipopt on callBackTestRowMajor.osil");
818 unitTestResult <<
"Solved problem callBackRowMajor.osil with Ipopt" << std::endl;
819 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
821 cout << endl <<
"TEST " << ++nOfTest <<
": Ipopt solver on nonconvex.osil" << endl << endl;
826 osilFileName = dataDir +
"osilFiles" + dirsep +
"nonconvex.osil";
828 osil = fileUtil->getFileAsString( osilFileName.c_str());
837 cout <<
"call the COIN - Ipopt Solver for nonconvex.osil" << endl;
840 std::cout <<
" CALL SOLVE " << std::endl;
843 cout <<
"Here is the Ipopt solver solution for nonconvex.osil" << endl;
851 cout << solver->
osrl << endl << endl;
860 unitTestResult <<
"Solved problem nonconvex.osil with Ipopt" << std::endl;
867 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
869 cout << endl <<
"TEST " << ++nOfTest <<
": Ipopt solver on rosenbrockorig.osil" << endl << endl;
874 osilFileName = dataDir +
"osilFiles" + dirsep +
"rosenbrockorig.osil";
876 osil = fileUtil->getFileAsString( osilFileName.c_str());
885 cout <<
"call the COIN - Ipopt Solver for rosenbrockorig" << endl;
888 std::cout <<
" CALL SOLVE " << std::endl;
891 cout <<
"Here is the Ipopt solver solution for rosenbrockorig" << endl;
899 cout << solver->
osrl << endl << endl;
908 unitTestResult <<
"Solved problem rosenbrockorig.osil with Ipopt" << std::endl;
915 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
917 cout << endl <<
"TEST " << ++nOfTest <<
": Ipopt solver on HS071_feas.osil" << endl << endl;
922 osilFileName = dataDir +
"osilFiles" + dirsep +
"HS071_feas.osil";
924 osil = fileUtil->getFileAsString( osilFileName.c_str());
933 cout <<
"call the COIN - Ipopt Solver for HS071_feas.osil" << endl;
936 std::cout <<
" CALL SOLVE " << std::endl;
942 if(ok ==
false)
throw ErrorClass(
" Fail unit test with Ipopt on HS071_feas.osil");
945 cout <<
"Received error message from Ipopt: \"Ipopt NEEDS AN OBJECTIVE FUNCTION\"" << endl;
946 unitTestResult <<
"Correctly diagnosed problem HS071_feas with Ipopt" << std::endl;
955 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
960 unitTestResultFailure <<
"Sorry Unit Test Failed Testing the Ipopt Solver:" + eclass.errormsg<< endl;
965#ifdef COIN_HAS_BONMIN
967 cout << endl <<
"TEST " << ++nOfTest <<
": Bonmin solver on bonminEx1.osil" << endl << endl;
972 osilFileName = dataDir +
"osilFiles" + dirsep +
"bonminEx1.osil";
973 osolFileName = dataDir +
"osolFiles" + dirsep +
"bonminEx1_Bonmin.osol";
974 osil = fileUtil->getFileAsString( osilFileName.c_str());
975 osol = fileUtil->getFileAsString( osolFileName.c_str());
981 cout <<
"call the COIN - Bonmin Solver for bonminEx1" << endl;
984 cout <<
"Here is the Bonmin solver solution for bonminEx1" << endl;
985 cout << solver->
osrl << endl;
989 if(ok ==
false)
throw ErrorClass(
" Fail unit test with Bonmin on bonminEx1.osil");
992 unitTestResult <<
"Solved problem bonminEx1.osil with Bonmin" << std::endl;
997 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1000 cout << endl <<
"TEST " << ++nOfTest <<
": Bonmin solver on wayneQuadratic.osil" << endl << endl;
1002 osilFileName = dataDir +
"osilFiles" + dirsep +
"wayneQuadratic.osil";
1003 osolFileName = dataDir +
"osolFiles" + dirsep +
"wayneQuadratic_Bonmin1.osol";
1004 osil = fileUtil->getFileAsString( osilFileName.c_str());
1005 osol = fileUtil->getFileAsString( osolFileName.c_str());
1008 solver->
osol = osol;
1009 solver->
osinstance = osilreader->readOSiL( osil);
1010 cout <<
"call the Bonmin Solver for wayneQuadratic" << endl;
1014 cout <<
"Here is the Bonmin solver solution" << endl;
1015 cout << solver->
osrl << endl;
1017 std::cout <<
"CALL NEAR_EQUAL" << std::endl;
1020 std::cout <<
"CALL NEAR_EQUAL" << std::endl;
1021 if(ok ==
false)
throw ErrorClass(
" Fail unit test with Bonmin on wayneQuadratic.osil");
1026 unitTestResult <<
"Solved problem wayneQuadratic.osil with Bonmin" << std::endl;
1027 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1029 cout << endl <<
"TEST " << ++nOfTest <<
": Bonmin solver on wayneQuadratic.osil" << endl << endl;
1031 osilFileName = dataDir +
"osilFiles" + dirsep +
"wayneQuadratic.osil";
1032 osolFileName = dataDir +
"osolFiles" + dirsep +
"wayneQuadratic_Bonmin2.osol";
1033 osil = fileUtil->getFileAsString( osilFileName.c_str());
1034 osol = fileUtil->getFileAsString( osolFileName.c_str());
1038 solver->
osol = osol;
1039 solver->
osinstance = osilreader->readOSiL( osil);
1041 cout <<
"call the Bonmin Solver for wayneQuadratic" << endl;
1045 cout <<
"Here is the Bonmin solver solution" << endl;
1046 cout << solver->
osrl << endl;
1048 std::cout <<
"CALL NEAR_EQUAL" << std::endl;
1051 std::cout <<
"CALL NEAR_EQUAL" << std::endl;
1052 if(ok ==
false)
throw ErrorClass(
" Fail unit test with Bonmin on wayneQuadratic.osil");
1059 unitTestResult <<
"Solved problem wayneQuadratic.osil with Bonmin" << std::endl;
1060 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1065 cout << endl <<
"TEST " << ++nOfTest <<
": Bonmin solver on rosenbrockorig.osil" << endl << endl;
1067 osilFileName = dataDir +
"osilFiles" + dirsep +
"rosenbrockorig.osil";
1069 osil = fileUtil->getFileAsString( osilFileName.c_str());
1075 solver->
osinstance = osilreader->readOSiL( osil);
1077 cout <<
"call the Bonmin Solver for rosenbrockorig" << endl;
1080 cout <<
"Here is the Bonmin solver solution" << endl;
1081 cout << solver->
osrl << endl;
1083 std::cout <<
"CALL NEAR_EQUAL" << std::endl;
1086 std::cout <<
"CALL NEAR_EQUAL" << std::endl;
1087 if(ok ==
false)
throw ErrorClass(
" Fail unit test with Bonmin on rosenbrockorig.osil");
1094 unitTestResult <<
"Solved problem rosenbrockorig.osil with Bonmin" << std::endl;
1095 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1099 cout << endl <<
"TEST " << ++nOfTest <<
": Bonmin solver on rosenbrockinteger.osil" << endl << endl;
1101 osilFileName = dataDir +
"osilFiles" + dirsep +
"rosenbrockinteger.osil";
1103 osil = fileUtil->getFileAsString( osilFileName.c_str());
1109 solver->
osinstance = osilreader->readOSiL( osil);
1111 cout <<
"call the Bonmin Solver for rosenbrockinteger" << endl;
1114 cout <<
"Here is the Bonmin solver solution" << endl;
1115 cout << solver->
osrl << endl;
1117 std::cout <<
"CALL NEAR_EQUAL" << std::endl;
1120 std::cout <<
"CALL NEAR_EQUAL" << std::endl;
1121 if(ok ==
false)
throw ErrorClass(
" Fail unit test with Bonmin on rosenbrockinteger.osil");
1128 unitTestResult <<
"Solved problem rosenbrockinteger.osil with Bonmin" << std::endl;
1129 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1134 cout <<
"OSrL = " << solver->
osrl << endl;
1135 cout << endl << endl << endl;
1136 unitTestResultFailure <<
"Sorry Unit Test Failed Testing the Bonmin Solver:" + eclass.errormsg << endl;
1141#ifdef COIN_HAS_COUENNE
1143 cout << endl <<
"TEST " << ++nOfTest <<
": Couenne solver on bonminEx1.osil" << endl << endl;
1150 osilFileName = dataDir +
"osilFiles" + dirsep +
"bonminEx1.osil";
1151 osolFileName = dataDir +
"osolFiles" + dirsep +
"bonminEx1_Couenne.osol";
1152 osil = fileUtil->getFileAsString( osilFileName.c_str());
1153 osol = fileUtil->getFileAsString( osolFileName.c_str());
1156 solver->
osil = osil;
1157 solver->
osol = osol;
1160 cout <<
"call the COIN - Couenne Solver for bonminEx1" << endl;
1163 std::cout <<
" CALL SOLVE " << std::endl;
1166 cout <<
"Here is the Couenne solver solution for bonminEx1" << endl;
1169 solver->
osrl = tmp_writer->writeOSrL(solver->
osresult);
1176 if(ok ==
false)
throw ErrorClass(
" Fail unit test with Couenne on bonminEx1.osil");
1180 unitTestResult <<
"Solved problem bonminEx1.osil with Couenne" << std::endl;
1187 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1190 cout << endl <<
"TEST " << ++nOfTest <<
": Couenne solver on bonminEx1_Nonlinear.osil" << endl << endl;
1195 osilFileName = dataDir +
"osilFiles" + dirsep +
"bonminEx1_Nonlinear.osil";
1197 osil = fileUtil->getFileAsString( osilFileName.c_str());
1202 solver->
osil = osil;
1203 solver->
osol = osol;
1206 cout <<
"call the COIN - Couenne Solver for bonminEx1_Nonlinear" << endl;
1209 std::cout <<
" CALL SOLVE " << std::endl;
1212 cout <<
"Here is the Couenne solver solution for bonminEx1_Nonlinear.osil" << endl;
1216 solver->
osrl = tmp_writer->writeOSrL(solver->
osresult);
1220 cout << solver->
osrl << endl << endl;
1229 unitTestResult <<
"Solved problem bonminEx1_Nonlinear with Couenne" << std::endl;
1236 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1239 cout << endl <<
"TEST " << ++nOfTest <<
": Couenne solver on nonconvex.osil" << endl << endl;
1244 osilFileName = dataDir +
"osilFiles" + dirsep +
"nonconvex.osil";
1246 osil = fileUtil->getFileAsString( osilFileName.c_str());
1251 solver->
osil = osil;
1252 solver->
osol = osol;
1255 cout <<
"call the COIN - Couenne Solver for nonconvex.osil" << endl;
1258 std::cout <<
" CALL SOLVE " << std::endl;
1261 cout <<
"Here is the Couenne solver solution for nonconvex.osil" << endl;
1265 solver->
osrl = tmp_writer->writeOSrL(solver->
osresult);
1269 cout << solver->
osrl << endl << endl;
1278 unitTestResult <<
"Solved problem nonconvex.osil with Couenne" << std::endl;
1285 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1287 cout << endl <<
"TEST " << ++nOfTest <<
": Couenne solver on rosenbrockorig.osil" << endl << endl;
1292 osilFileName = dataDir +
"osilFiles" + dirsep +
"rosenbrockorig.osil";
1294 osil = fileUtil->getFileAsString( osilFileName.c_str());
1299 solver->
osil = osil;
1300 solver->
osol = osol;
1303 cout <<
"call the COIN - Couenne Solver for rosenbrockorig" << endl;
1306 std::cout <<
" CALL SOLVE " << std::endl;
1309 cout <<
"Here is the Couenne solver solution for rosenbrockorig" << endl;
1313 solver->
osrl = tmp_writer->writeOSrL(solver->
osresult);
1317 cout << solver->
osrl << endl << endl;
1326 unitTestResult <<
"Solved problem rosenbrockorig.osil with Couenne" << std::endl;
1333 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1337 cout << endl <<
"TEST " << ++nOfTest <<
": Couenne solver on rosenbrockinteger.osil" << endl << endl;
1342 osilFileName = dataDir +
"osilFiles" + dirsep +
"rosenbrockinteger.osil";
1344 osil = fileUtil->getFileAsString( osilFileName.c_str());
1349 solver->
osil = osil;
1350 solver->
osol = osol;
1353 cout <<
"call the COIN - Couenne Solver for rosenbrockinteger" << endl;
1356 std::cout <<
" CALL SOLVE " << std::endl;
1359 cout <<
"Here is the Couenne solver solution for rosenbrockinteger" << endl;
1363 solver->
osrl = tmp_writer->writeOSrL(solver->
osresult);
1367 cout << solver->
osrl << endl << endl;
1376 unitTestResult <<
"Solved problem rosenbrockinteger.osil with Couenne" << std::endl;
1383 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1386 cout << endl <<
"TEST " << ++nOfTest <<
": Couenne solver on HS071_feas.osil" << endl << endl;
1391 osilFileName = dataDir +
"osilFiles" + dirsep +
"HS071_feas.osil";
1393 osil = fileUtil->getFileAsString( osilFileName.c_str());
1398 solver->
osil = osil;
1399 solver->
osol = osol;
1402 cout <<
"call the COIN - Couenne Solver for HS071_feas.osil" << endl;
1405 std::cout <<
" CALL SOLVE " << std::endl;
1408 cout <<
"Here is the Couenne solver solution for HS071_feas" << endl;
1412 solver->
osrl = tmp_writer->writeOSrL(solver->
osresult);
1416 cout << solver->
osrl << endl << endl;
1425 unitTestResult <<
"Solved problem HS071_feas with Couenne" << std::endl;
1432 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1438 cout <<
"OSrL = " << solver->
osrl << endl;
1439 cout << endl << endl << endl;
1440 unitTestResultFailure <<
"Sorry Unit Test Failed Testing the Couenne Solver:" + eclass.errormsg << endl;
1447#ifdef COIN_HAS_SYMPHONY
1449 cout << endl <<
"TEST " << ++nOfTest <<
": SYMPHONY solver on p0033.osil" << endl << endl;
1451 osilFileName = dataDir +
"osilFiles" + dirsep +
"p0033.osil";
1452 osolFileName = dataDir +
"osolFiles" + dirsep +
"p0033_sym.osol";
1453 osil = fileUtil->getFileAsString( osilFileName.c_str());
1454 osol = fileUtil->getFileAsString( osolFileName.c_str());
1458 solver->
osil = osil;
1461 cout <<
"build the solver instance for COIN - SYMPHONY" << endl;
1465 cout <<
"Here is the COIN SYMPHONY solver solution for p0033" << endl;
1466 cout << solver->
osrl << endl;
1470 if(ok ==
false)
throw ErrorClass(
" Fail unit test with SYMPHONY on p0033.osil");
1475 unitTestResult <<
"Solved problem p0033.osil with SYMPHONY" << std::endl;
1476 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1479 cout <<
"OSrL = " << solver->
osrl << endl;
1480 cout << endl << endl << endl;
1481 unitTestResultFailure <<
"Sorry Unit Test Failed Testing the SYMPHONY Solver:" + eclass.errormsg << endl;
1489 cout << endl <<
"TEST " << ++nOfTest <<
": DyLP solver on parincLinear.osil" << endl << endl;
1491 osilFileName = dataDir +
"osilFiles" + dirsep +
"parincLinear.osil";
1492 osolFileName = dataDir +
"osolFiles" + dirsep +
"parincLinear_dylp.osol";
1493 osil = fileUtil->getFileAsString( osilFileName.c_str());
1494 osol = fileUtil->getFileAsString( osolFileName.c_str());
1498 solver->
osol = osol;
1499 solver->
osinstance = osilreader->readOSiL( osil);
1500 cout <<
"call the COIN - DyLP solver for parincLinear" << endl;
1503 cout <<
"Here is the COIN - DyLP solver solution for parincLinear" << endl;
1504 cout << solver->
osrl << endl;
1508 if(ok ==
false)
throw ErrorClass(
" Fail unit test with DyLP on parincLinear.osil");
1513 unitTestResult <<
"Solved problem parincLinear.osil with DyLP" << std::endl;
1514 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1517 cout <<
"OSrL = " << solver->
osrl << endl;
1518 cout << endl << endl << endl;
1519 unitTestResultFailure <<
"Sorry Unit Test Failed Testing the DyLP Solver:" + eclass.errormsg << endl;
1526 cout << endl <<
"TEST " << ++nOfTest <<
": Vol solver on volumeTest.osil" << endl << endl;
1528 osilFileName = dataDir +
"osilFiles" + dirsep +
"volumeTest.osil";
1529 osolFileName = dataDir +
"osolFiles" + dirsep +
"volumeTest_vol.osol";
1530 osil = fileUtil->getFileAsString( osilFileName.c_str());
1531 osol = fileUtil->getFileAsString( osolFileName.c_str());
1535 solver->
osil = osil;
1538 cout <<
"call the COIN - Vol solver for volumeTest" << endl;
1541 cout <<
"Here is the COIN - Vol solver solution for parincLinear" << endl;
1542 cout << solver->
osrl << endl;
1546 if(ok ==
false)
throw ErrorClass(
" Fail unit test with Vol on volumeTest.osil");
1551 unitTestResult <<
"Solved problem volumeTest.osil with Vol" << std::endl;
1552 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1555 cout <<
"OSrL = " << solver->
osrl << endl;
1556 cout << endl << endl << endl;
1557 unitTestResultFailure <<
"Sorry Unit Test Failed Testing the Vol Solver:" + eclass.errormsg << endl;
1563 cout << endl <<
"TEST " << ++nOfTest <<
": GLPK solver on p0033.osil" << endl << endl;
1565 osilFileName = dataDir +
"osilFiles" + dirsep +
"p0033.osil";
1566 osolFileName = dataDir +
"osolFiles" + dirsep +
"p0033_glpk.osol";
1567 osil = fileUtil->getFileAsString( osilFileName.c_str());
1568 osol = fileUtil->getFileAsString( osolFileName.c_str());
1573 solver->
osinstance = osilreader->readOSiL( osil);
1575 cout <<
"call the GLPK Solver for p0033" << endl;
1578 cout <<
"Here is the GLPK solver solution for p0033" << endl;
1579 cout << solver->
osrl << endl;
1583 if(ok ==
false)
throw ErrorClass(
" Fail unit test with GLPK on p0033.osil");
1590 unitTestResult <<
"Solved problem p0033.osil with GLPK" << std::endl;
1591 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1594 cout <<
"OSrL = " << solver->
osrl << endl;
1595 cout << endl << endl << endl;
1596 unitTestResultFailure <<
"Sorry Unit Test Failed Testing the Glpk Solver:" + eclass.errormsg << endl;
1604 cout << endl <<
"TEST " << ++nOfTest <<
": Cplex solver on p0033.osil" << endl << endl;
1606 osilFileName = dataDir +
"osilFiles" + dirsep +
"p0033.osil";
1607 osolFileName = dataDir +
"osolFiles" + dirsep +
"p0033_cpx.osol";
1608 osil = fileUtil->getFileAsString( osilFileName.c_str());
1609 osol = fileUtil->getFileAsString( osolFileName.c_str());
1612 solver->
osil = osil;
1613 solver->
osol = osol;
1615 cout <<
"call the CPLEX Solver for p0033" << endl;
1618 cout <<
"Here is the CPLEX solver solution for p0033" << endl;
1619 cout << solver->
osrl << endl;
1623 if(ok ==
false)
throw ErrorClass(
" Fail unit test with CPLEX on p0033.osil");
1626 unitTestResult <<
"Solved problem p0033.osil with CPLEX" << std::endl;
1627 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1630 cout <<
"OSrL = " << solver->
osrl << endl;
1631 cout << endl << endl << endl;
1632 unitTestResultFailure <<
"Sorry Unit Test Failed Testing the Cplex Solver:" + eclass.errormsg << endl;
1637#ifdef COIN_HAS_LINDO
1639 cout << endl <<
"TEST " << ++nOfTest <<
": Lindo solver on lindoapiaddins.osil" << endl << endl;
1641 osilFileName = dataDir +
"osilFiles" + dirsep +
"lindoapiaddins.osil";
1642 osolFileName = dataDir +
"osolFiles" + dirsep +
"lindoapiaddins_lindo.osol";
1643 osil = fileUtil->getFileAsString( osilFileName.c_str());
1644 osol = fileUtil->getFileAsString( osolFileName.c_str());
1646 cout <<
"create a new LINDO Solver for OSiL string solution" << endl;
1648 solver->
osinstance = osilreader->readOSiL( osil);
1649 solver->
osol = osol;
1650 cout <<
"call the LINDO Solver" << endl;
1653 cout <<
"Here is the LINDO solver solution" << endl;
1654 cout << solver->
osrl << endl;
1658 if(ok ==
false)
throw ErrorClass(
" Fail unit test with LINDO on lindoapiaddins.osil");
1664 unitTestResult <<
"Solved problem lindoapiaddins.osil with Lindo" << std::endl;
1665 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1669 cout << endl <<
"TEST " << ++nOfTest <<
": Lindo solver on rosenbrockmod.osil" << endl << endl;
1670 osilFileName = dataDir +
"osilFiles" + dirsep +
"rosenbrockmod.osil";
1671 osolFileName = dataDir +
"osolFiles" + dirsep +
"rosenbrockmod_lindo.osol";
1672 osil = fileUtil->getFileAsString( osilFileName.c_str());
1673 osol = fileUtil->getFileAsString( osolFileName.c_str());
1675 solver->
osil = osil;
1676 solver->
osol = osol;
1678 cout <<
"call the LINDO Solver" << endl;
1681 cout <<
"Here is the LINDO solver solution" << endl;
1682 cout << solver->
osrl << endl;
1686 if(ok ==
false)
throw ErrorClass(
" Fail unit test with LINDO on rosenbrockmod.osil");
1690 unitTestResult <<
"Solved problem rosenbrockmod.osil with Lindo" << std::endl;
1691 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1694 cout << endl <<
"TEST " << ++nOfTest <<
": Lindo solver on parincQuadratic.osil" << endl << endl;
1695 osilFileName = dataDir +
"osilFiles" + dirsep +
"parincQuadratic.osil";
1696 osolFileName = dataDir +
"osolFiles" + dirsep +
"parincQuadratic_lindo.osol";
1697 osil = fileUtil->getFileAsString( osilFileName.c_str());
1698 osol = fileUtil->getFileAsString( osolFileName.c_str());
1701 solver->
osil = osil;
1702 solver->
osol = osol;
1705 cout <<
"call the LINDO Solver" << endl;
1708 cout <<
"Here is the LINDO solver solution" << endl;
1709 cout << solver->
osrl << endl;
1713 if(ok ==
false)
throw ErrorClass(
" Fail unit test with LINDO on parincQuadratic.osil");
1718 unitTestResult <<
"Solved problem parincQuadratic.osil with Lindo" << std::endl;
1719 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1756 cout << endl << endl << endl;
1757 unitTestResultFailure <<
"Sorry Unit Test Failed Testing the LINDO Solver:" + eclass.errormsg << endl << endl;
1766 cout << endl <<
"TEST " << ++nOfTest <<
": Cbc solver using MPS file" << endl << endl;
1770 cout <<
"create a COIN Solver for MPS - OSInstance solution" << endl;
1774 mps2osil->createOSInstance() ;
1776 osol =
"<osol t></osol>";
1777 solver->
osol = osol;
1778 cout <<
"call COIN Solve" << endl;
1781 cout <<
"Here is the COIN solver solution" << endl;
1782 cout << solver->
osrl << endl;
1786 if(ok ==
false)
throw ErrorClass(
" Fail unit test with COIN Solver on MPS test problem parincLinear.mps");
1793 unitTestResult <<
"Test the MPS -> OSiL converter on parinc.mps using Cbc" << std::endl;
1794 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1797 cout <<
"OSrL = " << solver->
osrl << endl;
1798 cout << endl << endl << endl;
1799 unitTestResultFailure <<
"Sorry Unit Test Failed Testing the MPS converter:" + eclass.errormsg << endl;
1805 cout << endl <<
"TEST " << ++nOfTest <<
": AMPL solver interface" << endl << endl;
1807 cout <<
"create a cbc Solver for AMPL nl - OSInstance solution" << endl;
1810 nl2osil =
new OSnl2osil( nlFileName);
1811 nl2osil->createOSInstance() ;
1814 solver->
osol = osol;
1815 cout <<
"call Cbc Solve" << endl;
1818 cout <<
"Here is the Cbc solver solution" << endl;
1819 cout << solver->
osrl << endl;
1823 if(ok ==
false)
throw ErrorClass(
" Fail unit test with OSnl2osil on problem parinc.nl");
1827 cout <<
"call delete nl2osil" << endl;
1830 unitTestResult <<
"Test the AMPL nl -> OSiL converter on parinc.nl using Cbc" << std::endl;
1831 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1835 cout <<
"OSrL = " << solver->
osrl << endl;
1836 cout << endl << endl << endl;
1837 unitTestResultFailure <<
"Sorry Unit Test Failed Testing AMPL:" + eclass.errormsg << endl;
1844 cout << endl <<
"TEST " << ++nOfTest <<
": b64 operations" << endl << endl;
1852 osol =
"<osol></osol>";
1853 solver->
osol = osol;
1854 mps2osil->createOSInstance() ;
1855 solver->
osil = osilwriter.writeOSiL( mps2osil->osinstance) ;
1856 std::cout << solver->
osil << std::endl;
1859 cout << endl << endl;
1860 cout <<
"COIN solution of a OSiL string in b64 format" << endl;
1861 cout << solver->
osrl;
1865 if(ok ==
false)
throw ErrorClass(
" Fail unit test with COIN Cbc cSolver on b64 test problem parincLinear.mps");
1871 unitTestResult <<
"Test a problem written in b64 and then converted to OSInstance" << std::endl;
1872 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1875 cout << endl << endl;
1876 cout << eclass.errormsg << endl << endl;
1877 cout <<
"OSrL = " << solver->
osrl << endl;
1878 cout << endl << endl << endl;
1879 unitTestResultFailure <<
"Sorry Unit Test Failed Testing Use of Base 64" << endl;
1885#ifdef COMPONENT_DEBUG
1889 cout << endl <<
"TEST " << ++nOfTest <<
": postfix and prefix routines" << endl << endl;
1890 std::string expTreeTest = dataDir +
"osilFiles" + dirsep +
"rosenbrockmod.osil";
1891 osil = fileUtil->getFileAsString( expTreeTest.c_str() ) ;
1897 osinstance = osilreader->readOSiL( osil);
1899 if(expTree == NULL)
throw ErrorClass(
" Null expression tree when testing prefix and postfix routines");
1900 std::vector<OSnLNode*> postfixVec;
1904 unsigned int n = postfixVec.size();
1906 std::string *nodeNames1 =
new std::string[ n];
1907 std::string *nodeNames2 =
new std::string[ n];
1908 for (
int i = 0 ; i < n; i++){
1909 std::cout << postfixVec[i]->snodeName << std::endl;
1910 nodeNames1[i] = postfixVec[i]->snodeName;
1914 expTree->m_treeRoot = postfixVec[ n - 1]->createExpressionTreeFromPostfix( postfixVec);
1917 std::vector<OSnLNode*> prefixVec;
1922 expTree->m_treeRoot = prefixVec[ 0]->createExpressionTreeFromPrefix( prefixVec);
1925 postfixVec = expTree->m_treeRoot->getPostfixFromExpressionTree();
1927 if(postfixVec.size() != n)
throw ErrorClass(
" Problem with creating expression trees");
1928 std::cout << std::endl << std::endl;
1929 for (
int i = 0 ; i < n; i++){
1931 nodeNames2[i] = postfixVec[i]->snodeName;
1932 if( nodeNames1[i] != nodeNames2[ i])
throw ErrorClass(
" Problem with creating expression trees");
1936 delete[] nodeNames1;
1937 delete[] nodeNames2;
1942 unitTestResult <<
"Successful test of prefix and postfix conversion routines" << std::endl;
1943 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1947 cout << endl << endl << endl;
1948 unitTestResultFailure << eclass.errormsg << endl;
1952 cout << endl <<
"TEST " << ++nOfTest <<
": nonlinear operators" << endl << endl;
1954 std::string operatorTest = dataDir +
"osilFiles" + dirsep +
"testOperators.osil";
1955 osil = fileUtil->getFileAsString( operatorTest.c_str() );
1963 osinstance = osilreader->readOSiL( osil);
1966 std::vector<OSnLNode*> postfixVec;
1968 int n = postfixVec.size();
1969 std::string *nodeNames1 =
new std::string[ n];
1970 for (
int i = 0 ; i < n; i++){
1971 std::cout << postfixVec[i]->snodeName << std::endl;
1972 nodeNames1[i] = postfixVec[i]->snodeName;
1974 std::cout << std::endl << std::endl;
1975 std::cout << osilwriter->writeOSiL( osinstance) << std::endl;
1981 double parserTestVal = expTree->m_treeRoot->calculateFunction( x);
1982 std::cout <<
"ParserTest Val = " << parserTestVal << std::endl;
1985 ok = ( fabs(check - expTree->m_treeRoot->calculateFunction( x))/(fabs( check) +
OS_NEAR_EQUAL) <=
OS_NEAR_EQUAL) ? true :
false;
1986 if(ok ==
false)
throw ErrorClass(
" Problem evaluating expression tree");
1988 delete[] nodeNames1;
1995 unitTestResult <<
"Successful test of nonlinear operators using file testOperators.osil" << std::endl;
1996 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
1999 cout << endl << endl << endl;
2000 unitTestResultFailure << eclass.errormsg << endl;
2004 cout << endl <<
"TEST " << ++nOfTest <<
": Automatic differentiation" << endl << endl;
2007 std::string expTreeTest = dataDir +
"osilFiles" + dirsep +
"CppADTestLag.osil";
2016 osil = fileUtil->getFileAsString( expTreeTest.c_str() );
2022 osinstance = osilreader->readOSiL( osil);
2033 for(
int i = 0; i < sp->number; i++){
2034 std::cout <<
"gradient value " << sp->
values[i] << std::endl;
2038 double checkPartial2Con1 = 7.0 ;
2040 ok = ( fabs(checkPartial2Con1 - sp->values[ 0] )/(fabs( checkPartial2Con1) +
OS_NEAR_EQUAL) <=
OS_NEAR_EQUAL) ? true :
false;
2041 if(ok ==
false)
throw ErrorClass(
" Fail testing gradient calculation");
2042 double checkPartial0Con1 = (1./x[0]) ;
2044 ok = ( fabs(checkPartial0Con1 - sp->values[ 1] )/(fabs( checkPartial0Con1) +
OS_NEAR_EQUAL) <=
OS_NEAR_EQUAL) ? true :
false;
2045 if(ok ==
false)
throw ErrorClass(
" Fail testing gradient calculation");
2046 double checkPartial3Con1 = (1./x[3]) ;
2048 ok = ( fabs(checkPartial3Con1 - sp->values[ 2] )/(fabs( checkPartial3Con1) +
OS_NEAR_EQUAL) <=
OS_NEAR_EQUAL) ? true :
false;
2049 if(ok ==
false)
throw ErrorClass(
" Fail testing gradient calculation");
2055 for(
int i = 0; i < sh->hessDimension; i++){
2056 std::cout <<
"Hessian value " << sh->
hessValues[i] << std::endl;
2060 if(ok ==
false)
throw ErrorClass(
" Fail testing Hessian calculation");
2063 if(ok ==
false)
throw ErrorClass(
" Fail testing Hessian calculation");
2066 if(ok ==
false)
throw ErrorClass(
" Fail testing Hessian calculation");
2067 unitTestResult <<
"Successful test of AD gradient and Hessian calculations" << std::endl;
2071 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
2074 cout << endl << endl << endl;
2075 unitTestResultFailure << eclass.errormsg << endl;
2080 cout << endl <<
"TEST " << ++nOfTest <<
": OSiL parser" << endl << endl;
2081 clock_t start, finish;
2088 cout <<
"TEST PARSING A MODEL" << endl;
2089 cout <<
"FIRST READ THE FILE INTO A STRING" << endl;
2091 osilFileName = dataDir +
"osilFiles" + dirsep +
"parincLinear.osil";
2092 osil = fileUtil->getFileAsString( osilFileName.c_str());
2094 duration = (double) (finish - start) / CLOCKS_PER_SEC;
2095 cout <<
"Reading the file into a string took (seconds): "<< duration << endl;
2099 cout <<
"PARSE THE OSIL STRING INTO AN OSINSTANCE OBJECT" << endl;
2100 osilreader->readOSiL( osil);
2107 duration = (double) (finish - start) / CLOCKS_PER_SEC;
2108 cout <<
"Parsing took (seconds): "<< duration << endl;
2109 unitTestResult <<
"Successful test of OSiL parser on problem parincLinear.osil" << std::endl;
2110 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
2113 cout << endl << endl << endl;
2114 cout << eclass.errormsg << endl;
2115 unitTestResultFailure <<
"Sorry Unit Test Failed Testing An OSiL Parser" << endl;
2123 cout << endl <<
"TEST " << ++nOfTest <<
": Stochastic extensions to OSiL" << endl << endl;
2124 clock_t start, finish;
2131 cout <<
"\nTEST PARSING A STOCHASTIC MODEL" << endl;
2132 cout <<
"FIRST READ THE FILE INTO A STRING" << endl;
2134 osilFileName = dataDir +
"osilFiles" + dirsep +
"finplan1.osil";
2135 osil = fileUtil->getFileAsString( &osilFileName[0]);
2137 duration = (double) (finish - start) / CLOCKS_PER_SEC;
2138 cout <<
"Reading the file into a string took (seconds): "<< duration << endl;
2142 cout <<
"PARSE THE OSIL STRING INTO AN OSINSTANCE OBJECT" << endl;
2143 osilreader->readOSiL( osil);
2150 duration = (double) (finish - start) / CLOCKS_PER_SEC;
2151 cout <<
"Parsing took (seconds): "<< duration << endl;
2152 unitTestResult <<
"Successful test of OSiL parser on problem finplan1.osil" << std::endl;
2153 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
2156 cout << endl << endl << endl;
2157 cout << eclass.errormsg << endl;
2158 unitTestResultFailure <<
"Error parsing an osil file with time domain information" << endl;
2164 cout << endl <<
"TEST " << ++nOfTest <<
": GET() AND SET() METHODS FOR TimeDomain OBJECT" << endl << endl;
2170 osinstance = osilreader->readOSiL( osil);
2172 ok = (f ==
"stages");
2176 std::string* sncheck =
new std::string[6];
2180 sncheck[3] =
"test";
2181 sncheck[4] =
"Wha'zzup?";
2186 for (
int i = 0; i < 6; i++)
2187 ok &= (sn[i] == sncheck[i]);
2191 int* nvcheck =
new int[6];
2199 for (
int i = 0; i < 6; i++)
2200 ok &= (nv[i] == nvcheck[i]);
2204 int* nccheck =
new int[6];
2212 for (
int i = 0; i < 6; i++)
2213 ok &= (nc[i] == nccheck[i]);
2217 int* nocheck =
new int[6];
2225 for (
int i = 0; i < 6; i++)
2226 ok &= (no[i] == nocheck[i]);
2232 int** lvcheck =
new int*[6];
2233 int** lccheck =
new int*[6];
2234 int** locheck =
new int*[6];
2235 for (
int i = 0; i < 6; i++) {
2236 lvcheck[i] =
new int[2];
2237 lccheck[i] =
new int[2];
2238 locheck[i] =
new int[2];
2258 for (
int i = 0; i < 6; i++) {
2259 for (
int j = 0; j < nv[i]; j++)
2260 ok &= (lvcheck[i][j] == lv[i][j]);
2261 for (
int j = 0; j < nc[i]; j++)
2262 ok &= (lccheck[i][j] == lc[i][j]);
2263 for (
int j = 0; j < no[i]; j++)
2264 ok &= (locheck[i][j] == lo[i][j]);
2267 std::string* sn1 =
new std::string[6];
2268 int* nv1 =
new int[6];
2269 int* nc1 =
new int[6];
2270 int* no1 =
new int[6];
2271 int** lv1 =
new int*[6];
2272 int** lc1 =
new int*[6];
2273 int** lo1 =
new int*[6];
2274 for (
int i = 0; i < 6; i++) {
2275 lv1[i] =
new int[2];
2276 lc1[i] =
new int[2];
2277 lo1[i] =
new int[2];
2279 for (
int i = 0; i < 6; i++) {
2284 for (
int j = 0; j < nv[i]; j++) {
2285 lv1[i][j] = lv[i][j];
2287 for (
int j = 0; j < nc[i]; j++) {
2288 lc1[i][j] = lc[i][j];
2290 for (
int j = 0; j < no[i]; j++) {
2291 lo1[i][j] = lo[i][j];
2303 int *nelem, *startIdx, **VI;
2305 startIdx =
new int[4];
2307 for (
int i = 0; i < 4; i++)
2316 for (
int i = 0; i < 4; i++)
2322 for (
int i = 0; i < 4; i++)
2334 ok &= (lower == 0.0);
2336 ok &= (upper == 1.0);
2353 for (
int i = 0; i < n2; i++)
2354 { ok &= (sn2[i] == sncheck[i]);
2355 ok &= (nv2[i] == nvcheck[i]);
2356 ok &= (nc2[i] == nccheck[i]);
2357 ok &= (no2[i] == nocheck[i]);
2358 for (
int j = 0; j < nv2[i]; j++)
2359 ok &= (lv2[i][j] == lvcheck[i][j]);
2360 for (
int j = 0; j < nc2[i]; j++)
2361 ok &= (lc2[i][j] == lccheck[i][j]);
2362 for (
int j = 0; j < no2[i]; j++)
2363 ok &= (lo2[i][j] == locheck[i][j]);
2373 for (
int i = 0; i < 6; i++) {
2374 delete [] lvcheck[i];
2375 delete [] lccheck[i];
2376 delete [] locheck[i];
2405 for (
int i = 0; i < 4; i++) {
2411 unitTestResult <<
"Successful test of osinstance get() and set() methods" << std::endl;
2412 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
2415 cout << endl << endl << endl;
2416 cout << eclass.errormsg << endl;
2417 unitTestResultFailure <<
"Sorry Unit Test Failed osinstance get() and set() Methods" << endl;
2441 cout << endl <<
"TEST " << ++nOfTest <<
": OSoL parser" << endl << endl;
2442 std::string tmpOSoL;
2443 clock_t start, finish;
2449 cout <<
"TEST PARSING AN OSoL FILE" << endl;
2450 cout <<
"FIRST READ THE OSoL FILE INTO A STRING" << endl;
2451 osolFileName = dataDir +
"osolFiles" + dirsep +
"parsertest.osol";
2453 std::string osol = fileUtil->getFileAsString( osolFileName.c_str() );
2455 duration = (double) (finish - start) / CLOCKS_PER_SEC;
2456 cout <<
"Reading the file into a string took (seconds): "<< duration << endl;
2458 cout <<
"PARSE THE OSOL STRING INTO AN OSOPTION OBJECT" << endl;
2462 cout << endl <<
"Test the add() methods" << endl;
2500 cout << endl <<
"another SOS has been added" << endl << endl;
2505 varopt->name =
"testVarOpt";
2506 varopt->numberOfVar = 0;
2513 objopt->name =
"testObjOpt";
2514 objopt->numberOfObj = 0;
2524 conopt->name =
"testObjOpt";
2525 conopt->numberOfCon = 2;
2528 conopt->con[0]->idx = 0;
2529 conopt->con[0]->value =
"3.0";
2531 conopt->con[1]->idx = 1;
2532 conopt->con[1]->lbValue =
"0.0";
2533 conopt->con[1]->ubValue =
"10.0";
2541 throw ErrorClass(
" Could not add to osoption data structure");
2544 std::string optionstring;
2549 cout << endl <<
"transfer osoption to another OSOption object" << endl;
2552 ok = osoption2->setServiceURI(optionstring);
2555 throw ErrorClass(
" error in get/set ServiceURI");
2559 ok = osoption2->setServiceName(optionstring) && ok;
2562 throw ErrorClass(
" error in get/set ServiceName");
2566 ok = osoption2->setInstanceName(optionstring) && ok;
2569 throw ErrorClass(
" error in get/set InstanceName");
2573 ok = osoption2->setInstanceLocation(optionstring) && ok;
2576 throw ErrorClass(
" error in get/set InstanceLocation");
2580 ok = osoption2->setInstanceLocationType(optionstring) && ok;
2583 throw ErrorClass(
" error in get/set InstanceLocationtype");
2587 ok = osoption2->setJobID(optionstring) && ok;
2594 ok = osoption2->setSolverToInvoke(optionstring) && ok;
2597 throw ErrorClass(
" error in get/set SolverToInvoke");
2601 ok = osoption2->setInstanceLocationType(optionstring) && ok;
2604 throw ErrorClass(
" error in get/set InstanceLocationType");
2608 ok = osoption2->setUserName(optionstring) && ok;
2611 throw ErrorClass(
" error in get/set UserName");
2617 throw ErrorClass(
" error in get/set Password");
2619 ok = osoption2->setPassword(optionstring) && ok;
2622 ok = osoption2->setContact(optionstring) && ok;
2625 throw ErrorClass(
" error in get/set Contact");
2629 ok = osoption2->setContactTransportType(optionstring) && ok;
2632 throw ErrorClass(
" error in get/set TransportType");
2639 ok = osoption2->setOtherGeneralOptions(nopt, otherOpt) && ok;
2642 throw ErrorClass(
" error in get/set OtherGeneralOption");
2646 ok = osoption2->setMinDiskSpace(option_d) && ok;
2649 throw ErrorClass(
" error in get/set MinDiskSpace");
2653 ok = osoption2->setMinDiskSpaceUnit(optionstring) && ok;
2656 throw ErrorClass(
" error in get/set MinDiskSpaceUnit");
2660 ok = osoption2->setMinMemorySize(option_d) && ok;
2663 throw ErrorClass(
" error in get/set MinMemorySize");
2667 ok = osoption2->setMinMemoryUnit(optionstring) && ok;
2670 throw ErrorClass(
" error in get/set MinMemoryUnit");
2674 ok = osoption2->setMinCPUSpeed(option_d) && ok;
2677 throw ErrorClass(
" error in get/set MinCPUSpeed");
2681 ok = osoption2->setMinCPUSpeedUnit(optionstring) && ok;
2684 throw ErrorClass(
" error in get/set MinCPUSpeedUnit");
2688 ok = osoption2->setMinCPUNumber(option_i) && ok;
2691 throw ErrorClass(
" error in get/set MinCPUNumber");
2697 ok = osoption2->setOtherSystemOptions(nopt, otherOpt2) && ok;
2700 throw ErrorClass(
" error in get/set OtherSystemOptions");
2705 ok = osoption2->setServiceType(optionstring) && ok;
2708 throw ErrorClass(
" error in get/set ServiceType");
2714 ok = osoption2->setOtherServiceOptions(nopt, otherOpt3) && ok;
2717 throw ErrorClass(
" error in get/set OtherServiceOptions");
2722 ok = osoption2->setMaxTime(option_d) && ok;
2725 throw ErrorClass(
" error in get/set MaxTime");
2729 ok = osoption2->setMaxTimeUnit(optionstring) && ok;
2732 throw ErrorClass(
" error in get/set MaxTimeUnit");
2736 ok = osoption2->setRequestedStartTime(optionstring) && ok;
2739 throw ErrorClass(
" error in get/set RequestedStartTime");
2744 ok = osoption2->setJobDependencies(nopt, tJobID) && ok;
2747 throw ErrorClass(
" error in get/set JobDependencies");
2752 ok = osoption2->setRequiredDirectories(nopt, reqDir) && ok;
2755 throw ErrorClass(
" error in get/set RequiredDirectories");
2760 ok = osoption2->setRequiredFiles(nopt, reqFil) && ok;
2763 throw ErrorClass(
" error in get/set RequiredFiles");
2768 ok = osoption2->setDirectoriesToMake(nopt, mkDir) && ok;
2771 throw ErrorClass(
" error in get/set DirectoriesToMake");
2776 ok = osoption2->setFilesToMake(nopt, mkFil) && ok;
2779 throw ErrorClass(
" error in get/set FilesToMake");
2784 ok = osoption2->setInputDirectoriesToMove(nopt, inDMv) && ok;
2787 throw ErrorClass(
" error in get/set InputDirectoriesToMove");
2792 ok = osoption2->setInputFilesToMove(nopt, inFMv) && ok;
2795 throw ErrorClass(
" error in get/set InputFilesToMove");
2800 ok = osoption2->setOutputFilesToMove(nopt, outFMv) && ok;
2803 throw ErrorClass(
" error in get/set OutputFilesToMove");
2808 ok = osoption2->setOutputDirectoriesToMove(nopt, outDMv) && ok;
2811 throw ErrorClass(
" error in get/set OutputDirectoriesToMove");
2816 ok = osoption2->setFilesToDelete(nopt, rmFil) && ok;
2819 throw ErrorClass(
" error in get/set FilesToDelete");
2824 ok = osoption2->setDirectoriesToDelete(nopt, rmDir) && ok;
2827 throw ErrorClass(
" error in get/set DirectoriesToDelete");
2832 ok = osoption2->setProcessesToKill(nopt, rmProc) && ok;
2835 throw ErrorClass(
" error in get/set ProcessesToKill");
2841 ok = osoption2->setOtherJobOptions(nopt, otherOpt4) && ok;
2844 throw ErrorClass(
" error in get/set OtherJobOptions");
2847 int nvar, nobj, ncon;
2849 ok = osoption2->setNumberOfVariables(nvar) && ok;
2851 ok = osoption2->setNumberOfObjectives(nobj) && ok;
2853 ok = osoption2->setNumberOfConstraints(ncon) && ok;
2856 throw ErrorClass(
" error in get/set problem dimensions");
2862 ok = osoption2->setInitVarValuesDense(nvar, IVV) && ok;
2865 throw ErrorClass(
" error in get/set InitVarValues");
2871 ok = osoption2->setInitVarValuesStringSparse(nopt, IVV2) && ok;
2874 throw ErrorClass(
" error in get/set InitVarValuesString");
2879 ok = osoption2->setInitBasisStatusDense(nvar, IBS) && ok;
2882 throw ErrorClass(
" error in get/set InitBasisStatus");
2887 ok = osoption2->setIntegerVariableBranchingWeightsDense(nvar, IVBW) && ok;
2890 throw ErrorClass(
" error in get/set IntegerVariableBranchingWeights");
2896 ok = osoption2->setSOSVariableBranchingWeights(nopt, sos) && ok;
2899 throw ErrorClass(
" error in get/set SOSVariableBranchingWeights");
2905 ok = osoption2->setOtherVariableOptions(nopt, otherV) && ok;
2908 throw ErrorClass(
" error in get/set OtherVariableOptions");
2913 ok = osoption2->setInitObjValuesDense(nobj, IOV) && ok;
2916 throw ErrorClass(
" error in get/set InitObjValues");
2922 ok = osoption2->setInitObjBoundsSparse(nopt, IOB) && ok;
2925 throw ErrorClass(
" error in get/set InitObjBounds");
2931 ok = osoption2->setOtherObjectiveOptions(nopt, otherO) && ok;
2934 throw ErrorClass(
" error in get/set OtherObjectiveOptions");
2940 ok = osoption2->setInitConValuesDense(ncon, ICV) && ok;
2943 throw ErrorClass(
" error in get/set InitConValues");
2949 ok = osoption2->setInitDualVarValuesSparse(nopt, IDV) && ok;
2952 throw ErrorClass(
" error in get/set InitDualVarValues");
2958 ok = osoption2->setOtherConstraintOptions(nopt, otherC) && ok;
2961 throw ErrorClass(
" error in get/set OtherConstraintOptions");
2967 ok = osoption2->setSolverOptions(nopt, SO) && ok;
2970 throw ErrorClass(
" error in get/set SolverOptions");
2975 throw ErrorClass(
" OSOption get() and set() methods do not work correctly");
2977 cout << endl <<
"delete osoption2" << endl;
2980 cout <<
"osoption2 deleted" << endl << endl;
2982 cout <<
"Write the content to a new file" <<endl;
2983 tmpOSoL = osolwriter->writeOSoL(
osoption);
2984 cout << endl <<
"Here is tmpOSoL:" <<endl;
2985 cout << endl << endl << tmpOSoL << endl;
2986 cout <<
"-----------------------------------------" << endl << endl;
2993 cout <<
"Read the string back" << endl;
2996 osoption3 = osolreader2->readOSoL( tmpOSoL);
3000 throw ErrorClass(
" Loss of information in OSoL write/read");
3009 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
3013 cout << endl <<
"TEST " << ++nOfTest <<
": Parse another .osol file" << endl << endl;
3016 cout <<
"First read the OSoL file into a string" << endl;
3017 osolFileName = dataDir +
"osolFiles" + dirsep +
"parsertest2.osol";
3018 osol = fileUtil->getFileAsString( osolFileName.c_str() );
3020 duration = (double) (finish - start) / CLOCKS_PER_SEC;
3021 cout <<
"Reading the file into a string took (seconds): "<< duration << endl;
3022 cout <<
"Parse the OSoL string into an OSOption object" << endl;
3024 tmpOSoL = osolwriter->writeOSoL(
osoption) ;
3035 cout <<
"Test parsing another OSoL file" << endl;
3038 cout <<
"First read the OSoL file into a string" << endl;
3039 osolFileName = dataDir +
"osolFiles" + dirsep +
"parsertest3.osol";
3040 osol = fileUtil->getFileAsString( osolFileName.c_str() );
3042 duration = (double) (finish - start) / CLOCKS_PER_SEC;
3043 cout <<
"Reading the file into a string took (seconds): "<< duration << endl;
3044 cout <<
"Parse the OSoL string into an OSOption object" << endl;
3046 tmpOSoL = osolwriter->writeOSoL(
osoption) ;
3058 cout <<
"Test parsing a trivial string" << endl;
3060 osol =
"<osol></osol>";
3061 cout <<
"Parse the OSoL string into an OSOption object" << endl;
3068 "Successful test of OSoL parser on file parsertest.osol"
3070 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
3076 cout << endl << endl << endl;
3077 if(osolwriter != NULL)
delete osolwriter;
3078 if(osolreader != NULL)
delete osolreader;
3080 unitTestResultFailure << eclass.errormsg << endl;
3081 unitTestResultFailure <<
"There was a failure in the test for reading OSoL" << endl;
3097 cout << endl <<
"TEST " << ++nOfTest <<
": OSrL parser" << endl << endl;
3098 std::string tmpOSrL;
3099 clock_t start, finish;
3105 cout <<
"TEST PARSING AN OSrL FILE" << endl;
3106 cout <<
"FIRST READ THE OSrL FILE INTO A STRING" << endl;
3108 osrlFileName = dataDir +
"osrlFiles" + dirsep +
"parserTest.osrl";
3110 std::string osrl = fileUtil->getFileAsString( osrlFileName.c_str() );
3112 duration = (double) (finish - start) / CLOCKS_PER_SEC;
3113 cout <<
"Reading the file into a string took (seconds): "<< duration << endl;
3114 cout << osrl << endl;
3116 cout <<
"PARSE THE OSRL STRING INTO AN OSRESULT OBJECT" << endl;
3117 osresult = osrlreader->readOSrL( osrl);
3118 cout <<
"Finished read; write OSResult object to temporary string" << endl;
3120 cout << tmpOSrL << endl;
3125 cout <<
"Parse temporary string" << endl;
3126 osrlreader->readOSrL( tmpOSrL);
3156 "Successful test of OSrL parser on problems parincLinear.osrl and errorExample.osrl"
3158 cout << endl <<
"TEST " << nOfTest <<
": Completed successfully" << endl << endl;
3161 cout << endl << endl << endl;
3162 if(osrlwriter != NULL)
delete osrlwriter;
3163 if(osrlreader != NULL)
delete osrlreader;
3165 unitTestResultFailure << eclass.errormsg << endl;
3166 unitTestResultFailure <<
"There was a failure in the test for reading OSrL" << endl;
3183 if(unitTestResultFailure.str().length() > 0){
3184 cout << endl <<
"THE UNIT TEST PASSED THE FOLLOWING:" << endl << endl;
3185 cout << unitTestResult.str() << endl << endl;
3186 cout <<
"UNFORTUNATELY, YOU FAILED ON THE FOLLOWING:" << endl << endl;
3187 cout << unitTestResultFailure.str() << endl << endl;
3188 cout <<
"Conclusion: FAILURE" << endl;
3192 cout << endl <<
"THE UNIT TEST PASSED THE FOLLOWING:" << endl << endl;
3193 cout << unitTestResult.str() << endl << endl;
3194 cout <<
"All tests completed successfully" << endl << endl;