/home/coin/SVN-release/OS-1.1.1/OS/test/unitTest.cpp

Go to the documentation of this file.
00001 
00101 #include <cppad/cppad.hpp> 
00102 //#include "CoinUtilsConfig.h"
00103 #include "OSCoinSolver.h"
00104 #include "OSConfig.h"
00105 #include "OSmps2osil.h" 
00106 #include "OSResult.h" 
00107 #include "OSiLReader.h"        
00108 #include "OSiLWriter.h" 
00109 #include "OSrLReader.h"          
00110 #include "OSrLWriter.h"      
00111 #include "OSInstance.h"  
00112 #include "OSFileUtil.h"  
00113 #include "OSConfig.h" 
00114 #include "CoinError.hpp"
00115 
00116 #include "OSDefaultSolver.h"  
00117 #include "OSWSUtil.h" 
00118 #include "OSSolverAgent.h"   
00119 #include "OShL.h"     
00120 #include "OSErrorClass.h"
00121 #include "OSmps2osil.h"   
00122 #include "OSBase64.h"
00123 #include "OSCommonUtil.h"
00124 
00125 
00126 #include <CoinMpsIO.hpp>
00127 #include <CoinPackedMatrix.hpp>
00128     
00129  
00130 #ifdef COIN_HAS_KNITRO    
00131 #include "OSKnitroSolver.h"
00132 #endif 
00133 
00134 #include "OSMathUtil.h"
00135 
00136 #ifdef COIN_HAS_GLPK
00137 #include <OsiGlpkSolverInterface.hpp>
00138 #endif
00139 
00140 
00141 #ifdef COIN_HAS_ASL
00142 #include "OSnl2osil.h"
00143 #endif
00144 #ifdef COIN_HAS_LINDO    
00145 #include "OSLindoSolver.h"
00146 #endif  
00147 #ifdef COIN_HAS_IPOPT    
00148 #include "OSIpoptSolver.h"
00149 #endif 
00150 
00151 #ifdef COIN_HAS_BONMIN    
00152 #include "OSBonminSolver.h"
00153 #endif 
00154  
00155 
00156 
00157 #ifdef HAVE_CTIME
00158 # include <ctime>
00159 #else
00160 # ifdef HAVE_TIME_H
00161 #  include <time.h>
00162 # else
00163 #  error "don't have header file for time"
00164 # endif
00165 #endif
00166 
00167 
00168 #ifdef HAVE_CMATH
00169 # include <cmath>
00170 #else
00171 # ifdef HAVE_CMATH_H
00172 #  include <cmath.h>
00173 # endif
00174 #endif
00175 
00176 
00177 
00178 #ifdef HAVE_CSTDIO
00179 # include <cstdio>
00180 #else
00181 # ifdef HAVE_STDIO_H
00182 #  include <stdio.h>
00183 # else
00184 #  error "don't have header file for stdio"
00185 # endif
00186 #endif
00187 
00188 //#ifdef HAVE_WINDOWS_H
00189 //#include <windows.h>
00190 //#endif
00191 
00192 using std::cout;   
00193 using std::endl;
00194 using std::ostringstream; 
00195 
00196 int main(int argC, char* argV[])
00197 {
00198 //#ifdef HAVE_WINDOWS_H
00199 //   SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
00200 //#endif 
00201         WindowsErrorPopupBlocker();
00202         double getObjVal(std::string osrl);
00203         //using CppAD::NearEqual;
00204         bool ok;
00205         double check;
00206         
00207         
00208         //return 0;
00209         cout << "START UNIT TEST" << endl;
00210         // define the classes
00211         FileUtil *fileUtil = NULL;  
00212         #ifdef COIN_HAS_ASL
00213         OSnl2osil *nl2osil = NULL;
00214         #endif 
00215         OSmps2osil *mps2osil = NULL;
00216         DefaultSolver *solver  = NULL;
00217         OSrLWriter *osrlwriter = NULL;
00218         OSrLReader *osrlreader = NULL;
00219         // end classes    
00220         std::string osilFileName;
00221         std::string osrlFileName;
00222         std::string nlFileName; 
00223         std::string mpsFileName;     
00224         std::string osil;
00225         ostringstream unitTestResult;
00226         ostringstream unitTestResultFailure;
00227         // get the input files
00228          const char dirsep =  CoinFindDirSeparator();
00229         // Set directory containing mps data files.
00230         std::string dataDir;
00231     dataDir = dirsep == '/' ? "../data/" : "..\\data\\";
00232         std::string osol = "<osol></osol>";
00233         nlFileName =  dataDir  + "amplFiles" + dirsep + "parinc.nl";
00234         mpsFileName =  dataDir + "mpsFiles" + dirsep + "parinc.mps";
00235         fileUtil = new FileUtil();
00236         // 
00237         unitTestResult << "HERE ARE THE UNIT TEST RESULTS:" << std::endl << std::endl;
00238         
00239         //first make sure we can read files
00240         try{
00241                 osilFileName =  dataDir  + "osilFiles" + dirsep +  "parincLinearByRow.osil";
00242                 //osilFileName =  dataDir  + "osilFiles" + dirsep +  "parincLinear.osil";
00243                 std::cout << "Try to read a sample file" << std::endl;
00244                 std::cout << "The file is: " ;
00245                 std::cout <<  osilFileName << std::endl;
00246                 osil = fileUtil->getFileAsString( osilFileName.c_str() );
00247                 std::cout << "Done reading the test file" << std::endl;
00248                 OSiLReader *osilreader = NULL;
00249                 osilreader = new OSiLReader(); 
00250                 //OSInstance *osinstance = osilreader->readOSiL( osil);
00251                 //osinstance->initForAlgDiff();
00252                 unitTestResult << "Reading files successfully" << std::endl;
00253                 OSiLWriter osilwriter;
00254                 osilwriter.m_bWhiteSpace = true;
00255                 //std::cout << osilwriter.writeOSiL( osinstance) << std::endl;
00256                 delete osilreader;
00257                 osilreader = NULL;
00258                 //cout << "The unitTest passed the following" << endl << endl;
00259                 //cout << unitTestResult.str() << endl << endl;
00260                 /*
00261                 // below is just a bunch of misc. stuff kipp is testing
00262                 //
00263                 // Create a problem pointer.  We use the base class here.
00264                 OsiSolverInterface *si, *si2;
00265                 // When we instantiate the object, we need a specific derived class.
00266                 si = new OsiCbcSolverInterface;
00267                 // Read in an mps file.  This one's from the MIPLIB library.
00268                 si->readMps( mpsFileName.c_str());
00269                 // get the problem
00270                 // variable upper and lower bounds
00271                  const double *collb = si->getColLower();
00272                  const double *colub = si->getColUpper();               
00273                 // constraint upper and lower bound     
00274                 const  double *rowlb = si->getRowLower();
00275                 const  double *rowub = si->getRowUpper();               
00276                 //the Coin packed matrix
00277                 const CoinPackedMatrix *m_CoinPackedMatrix =  si->getMatrixByCol();             
00278                 //finally the objective function coefficients           
00279                 const double *objcoef = si->getObjCoefficients();
00280                 //delete si;
00281                 si2 = new OsiCbcSolverInterface;
00282                 std::cout << objcoef[ 0] << std::endl;
00283                 // now load the problem
00284                 si2->loadProblem(*m_CoinPackedMatrix, collb, colub,  objcoef, rowlb, rowub);            
00285                 // Solve the (relaxation of the) problem
00286                 //si2->branchAndBound();        
00287                 delete si;
00288                 delete si2;
00289                 */
00290                 
00291                 
00292                 
00293                 //mpsFileName =  dataDir + "mpsFiles" + dirsep + "testfile2.mps";
00294                 mpsFileName =  dataDir + "mpsFiles" + dirsep + "parinc.mps";
00295                 mps2osil = new OSmps2osil( mpsFileName);
00296                 // create the first in-memory OSInstance
00297                 mps2osil->createOSInstance() ;
00298                 // write the instance to a string
00299                 OSInstance *osinstance1 = mps2osil->osinstance;
00300                 std::string sOSiL = osilwriter.writeOSiL( osinstance1  );
00301                 //cout << sOSiL << endl;
00302                 //fileUtil->writeFileFromString("p0201.osil", sOSiL);
00303                 // now create a second object
00304                 osilreader = new OSiLReader();
00305                 OSInstance *osinstance2 = osilreader->readOSiL( sOSiL);
00306                 // now compare the elements in the A matrix for the two intances
00307                 int nvals = osinstance1->instanceData->linearConstraintCoefficients->numberOfValues;
00308                 double theDiff, theMax;
00309                 int theIndex = -1;
00310                 theMax = 0;
00311                 for(int i = 0; i < nvals; i++){
00312                         theDiff = fabs(osinstance1->instanceData->linearConstraintCoefficients->value->el[ i] -
00313                                 osinstance2->instanceData->linearConstraintCoefficients->value->el[ i])/ fabs(osinstance1->instanceData->linearConstraintCoefficients->value->el[ i]);
00314                         if(theDiff > theMax){
00315                                 theMax = theDiff;
00316                                 theIndex = i;
00317                         }
00318                         //std::cout << theDiff << std::endl;
00319                 }
00320                 std::cout << "MAXIMUM DIFF = " << theMax << std::endl;
00321                 std::cout << "MAXIMUM DIFF INDEX  = " << theIndex << std::endl;
00322                 if(theMax > 0) unitTestResult << "WARNING:  you do not have lossless IO" << std::endl;
00323                 else unitTestResult << "passed lossless IO test" << std::endl;
00324                 delete mps2osil;
00325                 delete osilreader;
00326                 //nl2osil = new OSnl2osil( nlFileName);
00327             //return 0; 
00328                 /*
00329                 //using os_dtoa_format
00330                 MathUtil *mathUtil = new MathUtil();
00331             int decimalPoint; // where the decimal point goes
00332             int sign; // 1 if negative, 0 if positive
00333             double d ;
00334             d = -2./3.;
00335             //d = 123.4567;
00336             d = 1.23456589e-2;
00337             d = .00001123;
00338             char *result = os_dtoa(d, 0, 0, &decimalPoint, &sign, NULL);
00339             for(int kj = 5; kj < 9; kj++){
00340                 d = pow(10. ,kj) + pow(10., (kj-1));
00341                 //d = 57.7;
00342                 result =os_dtoa(d, 0, 0, &decimalPoint, &sign, NULL);
00343                 printf("HERE IS THE RESULT  %s\n\n", result);
00344                 printf("HERE IS THE RESULT of sign  %d\n\n", sign);
00345                 printf("HERE IS THE RESULT decimal point  %i\n\n", decimalPoint);
00346                 printf("HERE IS THE LENGTH OF THE RESULT  %d\n\n",  strlen(result));
00347                 std::cout << "HERE IS THE RESULT OF OS os_dtoa_format: " << os_dtoa_format( d) << std::endl;
00348             }
00349             d = .00001123;
00350             d = -2./3.;
00351             d = 100;
00352             result = os_dtoa(DBL_MAX, 0, 0, &decimalPoint, &sign, NULL);
00353         printf("HERE IS THE RESULT  %s\n\n", result);
00354         printf("HERE IS THE RESULT of sign  %d\n\n", sign);
00355         printf("HERE IS THE RESULT decimal point  %i\n\n", decimalPoint);
00356         printf("HERE IS THE LENGTH OF THE RESULT  %d\n\n",  strlen(result));
00357         std::cout << "HERE IS THE RESULT OF OS os_dtoa_format: " << os_dtoa_format( OSDBL_MAX) << std::endl;    
00358         d = .000234;
00359             result = os_dtoa(d, 0, 0, &decimalPoint, &sign, NULL);
00360         printf("HERE IS THE RESULT  %s\n\n", result);
00361         printf("HERE IS THE RESULT of sign  %d\n\n", sign);
00362         printf("HERE IS THE RESULT decimal point  %i\n\n", decimalPoint);
00363         printf("HERE IS THE LENGTH OF THE RESULT  %d\n\n",  strlen(result));
00364         std::cout << "HERE IS THE RESULT OF OS os_dtoa_format: " << os_dtoa_format( d) << std::endl;
00365         //
00366         char sInput[] = "77.77 99.99";
00367         char *pEnd;
00368         double d1, d2;
00369         d1 = os_strtod (sInput,  &pEnd);
00370         d2 = os_strtod (pEnd,NULL);
00371         std::cout << d1 << std::endl;
00372         std::cout << d2 << std::endl;
00373         
00374         std::cout << "HERE IS THE RESULT OF OS os_dtoa_format OSDBL_MAX: " << os_dtoa_format( OSDBL_MAX) << std::endl;
00375         std::cout << "HERE IS THE RESULT OF OS os_dtoa_format OSDBL_MAX: " << OSDBL_MAX << std::endl;
00376         std::cout << "HERE IS THE RESULT OF OS os_dtoa_format DBL_MAX: " << os_dtoa_format( DBL_MAX) << std::endl;
00377         std::cout << "HERE IS THE RESULT OF OS os_dtoa_format DBL_MAX: " <<  DBL_MAX << std::endl;
00378         d1 = os_strtod(os_dtoa_format( OSDBL_MAX).c_str(),     NULL);
00379         if(d1 == DBL_MAX )std::cout <<  "SUCCESS" << endl;
00380         else std::cout <<  "FAILURE" << endl;
00381         */
00382         //nl2osil = new OSnl2osil( nlFileName);
00383                 //cout << "All tests completed successfully" <<  endl <<  endl;
00384             //return 0;
00385     
00386         }
00387         catch(const ErrorClass& eclass){
00388                 unitTestResultFailure << "Sorry Unit Test Failed Reading a file: "  + eclass.errormsg<< endl; 
00389                 //no point continuing we can't even read a file
00390                 unitTestResultFailure << "Since we can't read files we are terminating"  << endl; 
00391                 cout << unitTestResultFailure.str() << endl << endl;
00392                 cout << "Conclusion: FAILURE" << endl;
00393                 return 1;
00394         }       
00395         // solve using using the osil file
00396         #ifdef COIN_HAS_IPOPT
00397         IpoptSolver *ipoptSolver  =  NULL;      
00398         try{
00399             ipoptSolver  = new IpoptSolver();
00400                 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00401                 ok = true;
00402                 OSiLReader *osilreader = NULL;
00403                 // avion does not work with Mumps on AIX xlC compiler
00404 #ifndef XLC_
00405                 osilFileName =  dataDir  + "osilFiles" + dirsep +  "avion2.osil";
00406                 osil = fileUtil->getFileAsString(  osilFileName.c_str() );
00407                 cout << "IPOPT Solver created for OSiL string solution" << endl;
00408                 ipoptSolver->osol = osol;
00409                 osilreader = new OSiLReader(); 
00410                 ipoptSolver->osinstance = osilreader->readOSiL( osil);
00411                 cout << "call the IPOPT Solver" << endl;        
00412                 ipoptSolver->buildSolverInstance();
00413                 ipoptSolver->solve();
00414                 cout << "Here is the IPOPT solver solution for avion2" << endl;
00415                 check = 9.46801e+07;
00416                 //ok &= NearEqual(getObjVal( ipoptSolver->osrl) , check,  1e-10 , 1e-10);
00417                 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00418                 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on avion2");
00419                 delete osilreader;
00420                 osilreader = NULL;
00421                 delete ipoptSolver;
00422                 ipoptSolver = NULL;
00423                 unitTestResult << "Solved problem avion2.osil with Ipopt" << std::endl;
00424 #endif
00425                 // solve another problem
00426                 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00427                 ipoptSolver  = new IpoptSolver();
00428                 // a problem with all nonlinear terms no linear terms
00429                 osilFileName =  dataDir  + "osilFiles" + dirsep + "HS071_NLPMod.osil";
00430                 osil = fileUtil->getFileAsString( osilFileName.c_str());
00431                 cout << "IPOPT Solver created for OSiL string solution" << endl;
00432                 ipoptSolver->osol = osol;
00433                 osilreader = new OSiLReader(); 
00434                 ipoptSolver->osinstance = osilreader->readOSiL( osil);
00435                 ipoptSolver->buildSolverInstance();
00436                 ipoptSolver->solve();
00437                 cout << "Here is the IPOPT solver solution for HS071_NLP" << endl;
00438                 check = 17.014;
00439                 //ok &= NearEqual(getObjVal( ipoptSolver->osrl) , check,  1e-10 , 1e-10);
00440                 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00441                 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on HS071_NLP");
00442                 delete osilreader;
00443                 osilreader = NULL;
00444                 unitTestResult << "Solved problem HS071.osil with Ipopt" << std::endl;
00445                 delete ipoptSolver;
00446                 ipoptSolver = NULL;
00447                 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00448                 ipoptSolver  = new IpoptSolver();
00449                 // solve another problem
00450                 // a problem with both quadratic terms and general nonlinear terms
00451                 osilFileName =  dataDir  + "osilFiles" + dirsep + "rosenbrockmod.osil";
00452                 osil = fileUtil->getFileAsString( osilFileName.c_str());
00453                 cout << "IPOPT Solver created for OSiL string solution" << endl;
00454                 ipoptSolver->osol = osol;
00455                 osilreader = new OSiLReader(); 
00456                 ipoptSolver->osinstance = osilreader->readOSiL( osil);
00457                 cout << "call the IPOPT Solver" << endl;
00458                 ipoptSolver->buildSolverInstance();
00459                 ipoptSolver->solve();
00460                 check = 6.7279;
00461                 //ok &= NearEqual(getObjVal( ipoptSolver->osrl) , check,  1e-10 , 1e-10);
00462                 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00463                 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on rosenbrock");
00464                 delete osilreader;
00465                 osilreader = NULL;
00466                 unitTestResult << "Solved problem rosenbrockmod.osil with Ipopt" << std::endl;
00467                 delete ipoptSolver;
00468                 ipoptSolver = NULL;
00469                 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00470                 ipoptSolver  = new IpoptSolver();
00471                 // solve another problem
00472                 // a problem that is a pure quadratic
00473                 osilFileName =  dataDir  + "osilFiles" + dirsep + "parincQuadratic.osil";
00474                 osil = fileUtil->getFileAsString( osilFileName.c_str());
00475                 cout << "IPOPT Solver created for OSiL string solution" << endl;
00476                 ipoptSolver->osol = osol;
00477                 osilreader = new OSiLReader(); 
00478                 ipoptSolver->osinstance = osilreader->readOSiL( osil);
00479                 cout << "call the IPOPT Solver" << endl;
00480                 ipoptSolver->buildSolverInstance();
00481                 ipoptSolver->solve();
00482                 cout << "Here is the IPOPT solver solution for parincQuadratic" << endl;
00483                 check = 49920.5;
00484                 //ok &= NearEqual(getObjVal( ipoptSolver->osrl) , check,  1e-10 , 1e-10);
00485                 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00486                 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on parincQuadradic");
00487                 delete osilreader;
00488                 osilreader = NULL;      
00489                 unitTestResult << "Solved problem parincQuadratic.osil with Ipopt" << std::endl;
00490                 delete ipoptSolver;
00491                 ipoptSolver = NULL;
00492                 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00493                 ipoptSolver  = new IpoptSolver();
00494                 // solve another problem
00495                 // try a pure linear program
00496                 osilFileName =  dataDir  + "osilFiles" + dirsep + "parincLinear.osil";
00497                 osil = fileUtil->getFileAsString( osilFileName.c_str());
00498                 cout << "IPOPT Solver created for OSiL string solution" << endl;
00499                 ipoptSolver->osol = osol; 
00500                 osilreader = new OSiLReader(); 
00501                 ipoptSolver->osinstance = osilreader->readOSiL( osil);
00502                 cout << "call the IPOPT Solver" << endl;
00503                 ipoptSolver->buildSolverInstance();
00504                 ipoptSolver->solve();
00505                 cout << "Here is the IPOPT solver solution for parincLinear" << endl;
00506                 check = 7668;
00507                 //ok &= NearEqual(getObjVal( ipoptSolver->osrl) , check,  1e-1 , 1e-1);
00508                 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00509                 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on parincLinear");
00510                 delete osilreader;
00511                 osilreader = NULL;      
00512                 unitTestResult << "Solved problem parincLinear.osil with Ipopt" << std::endl;
00513                 delete ipoptSolver;
00514                 ipoptSolver = NULL;
00515                 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00516                 ipoptSolver  = new IpoptSolver();
00517                 // solve another problem
00518                 // callBackTest.osil
00519                 osilFileName =  dataDir  + "osilFiles" + dirsep + "callBackTest.osil";
00520                 osil = fileUtil->getFileAsString( osilFileName.c_str());
00521                 cout << "IPOPT Solver created for OSiL string solution" << endl;
00522                 ipoptSolver->osol = osol;
00523                 osilreader = new OSiLReader(); 
00524                 ipoptSolver->osinstance = osilreader->readOSiL( osil);
00525                 //OSiLWriter osilwriter;
00526                 //cout << osilwriter.writeOSiL( ipoptSolver->osinstance) << endl;
00527                 //return 0;
00528                 cout << "call the IPOPT Solver" << endl;
00529                 ipoptSolver->buildSolverInstance();
00530                 ipoptSolver->solve();
00531                 cout << "Here is the IPOPT solver solution for callBackTest" << endl;
00532                 check = 1.00045e+06;
00533                 //ok &= NearEqual(getObjVal( ipoptSolver->osrl) , check,  1e-10 , 1e-10);
00534                 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00535                 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on callBackTest");
00536                 delete osilreader;
00537                 osilreader = NULL;      
00538                 unitTestResult << "Solved problem callBack.osil with Ipopt" << std::endl;       
00539                 delete ipoptSolver;
00540                 ipoptSolver = NULL;
00541                 cout << "create a new IPOPT Solver for OSiL string solution" << endl;
00542                 ipoptSolver  = new IpoptSolver();
00543                 // solve another problem
00544                 // callBackTest.osil
00545                 osilFileName =  dataDir  + "osilFiles" + dirsep + "callBackTestRowMajor.osil";
00546                 osil = fileUtil->getFileAsString( osilFileName.c_str());
00547                 cout << "IPOPT Solver created for OSiL string solution" << endl;
00548                 ipoptSolver->osol = osol;
00549                 osilreader = new OSiLReader(); 
00550                 ipoptSolver->osinstance = osilreader->readOSiL( osil);
00551                 //OSiLWriter osilwriter;
00552                 //cout << osilwriter.writeOSiL( ipoptSolver->osinstance) << endl;
00553                 //return 0;
00554                 cout << "call the IPOPT Solver" << endl;
00555                 ipoptSolver->buildSolverInstance();
00556                 ipoptSolver->solve();
00557                 cout << "Here is the IPOPT solver solution for callBackTestRowMajor" << endl;
00558                 check = 1.00045e+06;
00559                 //ok &= NearEqual(getObjVal( ipoptSolver->osrl) , check,  1e-10 , 1e-10);
00560                 ok = ( fabs(check - getObjVal( ipoptSolver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00561                 if(ok == false) throw ErrorClass(" Fail unit test with Ipopt on callBackTestRowMajor");
00562                 delete osilreader;
00563                 osilreader = NULL;      
00564                 delete ipoptSolver;
00565                 ipoptSolver = NULL;     
00566                 unitTestResult << "Solved problem callBackRowMajor.osil with Ipopt" << std::endl;
00567         }
00568         catch(const ErrorClass& eclass){
00569                 unitTestResultFailure << "Sorry Unit Test Failed Testing the Ipopt Solver:"  + eclass.errormsg<< endl; 
00570         }
00571         #endif
00572         try{
00573                 ok = true; 
00574                 std::cout << "create a new COIN Clp for OSiL string solution" << std::endl;
00575                 osilFileName = dataDir  + "osilFiles" + dirsep + "parincLinearByRow.osil";
00576                 osil = fileUtil->getFileAsString( osilFileName.c_str());
00577                 std::cout << "create a new Solver object" << std::endl;
00578                 OSiLReader *osilreader = NULL;
00579                 osilreader = new OSiLReader(); 
00580                 //std::cout <<  osil  << std::endl;
00581                 OSInstance *osinstance = osilreader->readOSiL( osil);
00582                 std::cout << " Done reading the OSiL" << std::endl;
00583                 // now write it again as a string
00584                 OSiLWriter *osilwriter;
00585                 osilwriter = new OSiLWriter();
00586                 osilwriter->m_bWhiteSpace = true;
00587                 std::cout << " Write the OSiL" << std::endl;
00588                 osil = osilwriter->writeOSiL( osinstance) ;
00589                 //std::cout <<  osil  << std::endl;
00590                 std::cout << " Done writing the OSiL" << std::endl;
00591                 solver = new CoinSolver();
00592                 solver->sSolverName = "clp";
00593                 solver->osil = osil;
00594                 solver->osol = osol;  
00595                 solver->osinstance = NULL; 
00596                 cout << "call the COIN - clp Solver for parincLinearbyRow" << endl;
00597                 //solver->buildSolverInstance();
00598                 solver->solve();
00599                 cout << "Here is the COIN clp solver solution for parincLinearByRow" << endl;
00600                 cout << solver->osrl << endl;
00601                 check = 7668;
00602                 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00603                 //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-1 , 1e-1);
00604                 if(ok == false) throw ErrorClass(" Fail unit test with clp on parincLinear");
00605                 // parse the osrl file
00606                 osrlreader =  new OSrLReader();
00607                 osrlreader->readOSrL( solver->osrl);
00608                 delete osilreader;
00609                 osilreader = NULL;      
00610                 delete solver;
00611                 solver = NULL;
00612                 delete osilwriter;
00613                 osilwriter = NULL;
00614                 delete osrlreader;
00615                 osrlreader = NULL;
00616                 unitTestResult << "Solved problem parincLinearByRow.osil with Clp" << std::endl;
00617                 // now solve another problem -- try an integer program
00618         }
00619         catch(const ErrorClass& eclass){
00620                 unitTestResultFailure << "Sorry Unit Test Failed Testing Clp Solver:"  + eclass.errormsg<< endl;
00621         }
00622         try{
00623                 std::cout << "create a new COIN Cbc for OSiL string solution" << std::endl;
00624                 ok = true;
00625                 osilFileName = dataDir  + "osilFiles" + dirsep + "p0033.osil";
00626                 osil = fileUtil->getFileAsString( osilFileName.c_str());
00627                 solver = new CoinSolver();
00628                 solver->sSolverName ="cbc";
00629                 solver->osil = osil;
00630                 solver->osol = osol;  
00631                 solver->osinstance = NULL; 
00632                 cout << "call the COIN - Cbc Solver for p0033" << endl;
00633                 solver->buildSolverInstance();
00634                 solver->solve();
00635                 cout << "Here is the COIN Cbc solver solution for p0033" << endl;
00636                 //cout << solver->osrl << endl;
00637                 check = 3089;
00638                 //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-10 , 1e-10);
00639                 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00640                 if(ok == false) throw ErrorClass(" Fail unit test with Cbc on p0033");
00641                 delete solver;
00642                 solver = NULL;
00643                 unitTestResult << "Solved problem p0033.osil with Cbc" << std::endl;
00644                 // now test p0201.osil
00645                 /*
00646                 ok = true;
00647                 osilFileName = dataDir  + "osilFiles" + dirsep + "p0201.osil";
00648                 osil = fileUtil->getFileAsString( osilFileName.c_str());
00649                 solver = new CoinSolver();
00650                 solver->sSolverName ="cbc";
00651                 solver->osil = osil;
00652                 solver->osol = osol;  
00653                 solver->osinstance = NULL; 
00654                 cout << "call the COIN - Cbc Solver for p0201" << endl;
00655                 solver->solve();
00656                 cout << "Here is the COIN Cbc solver solution for p0201" << endl;
00657                 check = 7615;
00658                 //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-10 , 1e-10);
00659                 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00660                 if(ok == false) throw ErrorClass(" Fail unit test with Cbc on p0548");
00661                 delete solver;
00662                 solver = NULL;
00663                 unitTestResult << "Solved problem p0201.osil with Cbc" << std::endl;
00664                 */
00665         }
00666         catch(const ErrorClass& eclass){
00667                 unitTestResultFailure << "Sorry Unit Test Failed Testing Cbc Solver:"  + eclass.errormsg<< endl;
00668         }
00669         
00670         //
00671         //
00672         #ifdef COIN_HAS_KNITRO
00673         try{
00674                 ok = true; 
00675                 osilFileName = dataDir  + "osilFiles" + dirsep + "rosenbrockmod.osil";
00676                 osil = fileUtil->getFileAsString( osilFileName.c_str());
00677                 solver = new KnitroSolver();
00678                 solver->osrl = "";      
00679                 solver->osil = osil;
00680                 solver->osol = osol;
00681                 solver->osinstance = NULL;
00682                 cout << "call the KNITRO Solver" << endl;
00683                 solver->solve();
00684                 cout << "Here is the KNITRO solver solution" << endl;   
00685                 check = 6.7279;
00686                 cout << solver->osrl << endl;
00687                 //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-10 , 1e-10);
00688                 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00689                 if(ok == false) throw ErrorClass(" Fail unit test with Knitro on rosenbrockmod");
00690                 delete solver;
00691                 solver = NULL;
00692                 unitTestResult << "Solved problem rosenbrockmod.osil with Knitro" << std::endl;
00693                 //
00694                 // now solve callBackTest.osil
00695                 osilFileName = dataDir  + "osilFiles" + dirsep + "callBackTest.osil";
00696                 osil = fileUtil->getFileAsString( osilFileName.c_str());
00697                 solver = new KnitroSolver();
00698                 solver->osrl = "";              
00699                 solver->osil = osil;            
00700                 solver->osol = osol;
00701                 cout << "call the KNITRO Solver" << endl;
00702                 solver->solve();
00703                 cout << "Here is the KNITRO solver solution" << endl;
00704                 check = 1.00045e+06; 
00705                 cout << solver->osrl << endl;
00706                 //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-10 , 1e-10);
00707                 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00708                 if(ok == false) throw ErrorClass(" Fail unit test with Knitro callBackTest.osil");
00709                 delete solver;
00710                 solver = NULL;  
00711                 unitTestResult << "Solved problem callBackTest.osil with Knitro" << std::endl;          
00712                 //
00713                 // now solve a pure quadratic
00714                 osilFileName = dataDir  + "osilFiles" + dirsep + "parincQuadratic.osil";
00715                 osil = fileUtil->getFileAsString( osilFileName.c_str());
00716                 solver = new KnitroSolver();    
00717                 solver->osil = osil;
00718                 solver->osol = osol;
00719                 solver->osinstance = NULL;
00720                 cout << "call the Knitro Solver" << endl;
00721                 solver->solve();
00722                 cout << "Here is the Knitro solver solution" << endl;
00723                 cout << solver->osrl << endl;
00724                 check = 49920.5;
00725                 //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-10 , 1e-10);
00726                 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00727                 if(ok == false) throw ErrorClass(" Fail unit test with Knitro on parincQuadratic");
00728                 delete solver;
00729                 solver = NULL;
00730                 unitTestResult << "Solved problem parincQuadratic.osil with Knitro" << std::endl;
00731                 //
00732                 // now solve a HS071_NLP.osil
00733                 osilFileName = dataDir  + "osilFiles" + dirsep + "HS071_NLP.osil";
00734                 osil = fileUtil->getFileAsString( osilFileName.c_str());
00735                 solver = new KnitroSolver();    
00736                 solver->osil = osil;
00737                 solver->osol = osol;
00738                 solver->osinstance = NULL;
00739                 cout << "call the Knitro Solver" << endl;
00740                 solver->solve();                
00741                 cout << "Here is the Knitro solver solution" << endl;
00742                 cout << solver->osrl << endl;
00743                 check = 17.014;
00744                 //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-10 , 1e-10);
00745                 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00746                 if(ok == false) throw ErrorClass(" Fail unit test with Knitro on HS071_NLP");
00747                 delete solver;
00748                 solver = NULL;
00749                 unitTestResult << "Solved problem HS071_NLP.osil with Knitro" << std::endl;
00750         }
00751         catch(const ErrorClass& eclass){
00752                 cout << "OSrL =  " <<  solver->osrl <<  endl;           
00753                 cout << endl << endl << endl;
00754                 unitTestResultFailure  << "Sorry Unit Test Failed Testing the Knitro Solver: "  + eclass.errormsg << endl;
00755         }       
00756         #endif
00757         //
00758         //
00759         
00760         //
00761         //
00762         #ifdef COIN_HAS_SYMPHONY
00763         try{
00764                 ok = true; 
00765                 osilFileName = dataDir  + "osilFiles" + dirsep + "p0033.osil";
00766                 osil = fileUtil->getFileAsString( osilFileName.c_str());
00767                 solver = new CoinSolver();
00768                 solver->sSolverName = "symphony";
00769                 solver->osil = osil;
00770                 solver->osol = osol;  
00771                 solver->osinstance = NULL; 
00772                 cout << "call the COIN - SYMPHONY Solver for p0033" << endl;
00773                 solver->buildSolverInstance();
00774                 solver->solve();
00775                 cout << "Here is the COIN SYMPHONY solver solution for p0033" << endl;
00776                 cout << solver->osrl << endl;
00777                 check = 3089;
00778                 //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-10 , 1e-10);
00779                 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00780                 if(ok == false) throw ErrorClass(" Fail unit test with SYMPHONY on p0033.osil");
00781                 delete solver;
00782                 solver = NULL;
00783                 unitTestResult << "Solved problem p0033.osil with SYMPHONY" << std::endl;
00784         }
00785         catch(const ErrorClass& eclass){
00786                 cout << "OSrL =  " <<  solver->osrl <<  endl;
00787                 cout << endl << endl << endl;
00788                 unitTestResultFailure  << "Sorry Unit Test Failed Testing the SYMPHONY Solver:"  + eclass.errormsg << endl;
00789         }       
00790         #endif
00791         //
00792         //
00793         //
00794         //
00795 #ifdef COIN_HAS_BONMIN
00796 try{
00797         OSiLReader *osilreader = NULL;
00798         osilreader = new OSiLReader(); 
00799         ok = true; 
00800         osilFileName = dataDir  + "osilFiles" + dirsep + "bonminEx1.osil";
00801         osil = fileUtil->getFileAsString( osilFileName.c_str());
00802         solver = new BonminSolver();
00803         //solver->sSolverName = "bonmin";
00804         solver->osinstance = osilreader->readOSiL( osil);
00805         //solver->osil = osil;
00806         solver->osol = osol;  
00807         cout << "call the COIN - Bonmin Solver for bonminEx1" << endl;
00808         solver->buildSolverInstance();
00809         solver->solve();
00810         cout << "Here is the COIN SYMPHONY solver solution for bonminEx1" << endl;
00811         cout << solver->osrl << endl;
00812         check = -1.70711;
00813         //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-10 , 1e-10);
00814         ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00815         if(ok == false) throw ErrorClass(" Fail unit test with Bonmin on bonminEx1.osil");
00816         delete solver;
00817         solver = NULL;
00818         unitTestResult << "Solved problem bonminEx1.osil with Bonmin" << std::endl;
00819         delete osilreader;
00820         osilreader = NULL;
00821         ok = true;
00822         osilFileName = dataDir  + "osilFiles" + dirsep + "wayneQuadratic.osil";
00823         osil = fileUtil->getFileAsString( osilFileName.c_str());
00824         solver = new BonminSolver();    
00825         solver->osil = osil;
00826         solver->osol = osol;
00827         solver->osinstance = NULL;
00828         cout << "call the Bonmin Solver for wayneQuadratic" << endl;
00829         solver->buildSolverInstance();
00830         solver->solve();
00831         cout << "Here is the Bonmin solver solution" << endl;
00832         cout << solver->osrl << endl;
00833         check = 2.925;
00834         std::cout << "CALL NEAR_EQUAL" << std::endl;
00835         //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-10 , 1e-10);
00836         ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00837         std::cout << "CALL NEAR_EQUAL" << std::endl;
00838         if(ok == false) throw ErrorClass(" Fail unit test with Bonmin on wayneQuadratic");
00839         delete solver;
00840         solver = NULL;
00841         unitTestResult << "Solved problem wayneQuadratic.osil with Bonmin" << std::endl;
00842 }
00843 catch(const ErrorClass& eclass){
00844         cout << "OSrL =  " <<  solver->osrl <<  endl;
00845         cout << endl << endl << endl;
00846         unitTestResultFailure  << "Sorry Unit Test Failed Testing the Bonmin Solver:"  + eclass.errormsg << endl;
00847 }       
00848 #endif
00849 //
00850 //
00851 //
00852 //
00853         #ifdef COIN_HAS_DYLP
00854         try{
00855                 ok = true; 
00856                 osilFileName = dataDir  + "osilFiles" + dirsep + "parincLinear.osil";
00857                 osil = fileUtil->getFileAsString( osilFileName.c_str());
00858                 solver = new CoinSolver();
00859                 solver->sSolverName = "dylp";
00860                 solver->osil = osil;
00861                 solver->osol = osol;   
00862                 solver->osinstance = NULL; 
00863                 cout << "call the COIN - DyLP solver for parincLinear" << endl;
00864                 solver->buildSolverInstance();
00865                 solver->solve();
00866                 cout << "Here is the COIN - DyLP solver solution for parincLinear" << endl;
00867                 cout << solver->osrl << endl;
00868                 check = 7668;
00869                 //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-1 , 1e-1);
00870                 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00871                 if(ok == false) throw ErrorClass(" Fail unit test with DyLP on parincLinear.osil");
00872                 delete solver;
00873                 solver = NULL;
00874                 unitTestResult << "Solved problem parincLinear.osil with DyLP" << std::endl;
00875         }
00876         catch(const ErrorClass& eclass){
00877                 cout << "OSrL =  " <<  solver->osrl <<  endl;
00878                 cout << endl << endl << endl;
00879                 unitTestResultFailure  <<"Sorry Unit Test Failed Testing the DyLP Solver:"  + eclass.errormsg << endl;
00880         }       
00881         #endif
00882         //
00883         //
00884         //
00885         
00886         #ifdef COIN_HAS_VOL
00887         try{
00888                 ok = true; 
00889                 osilFileName = dataDir  + "osilFiles" + dirsep + "volumeTest.osil";
00890                 osil = fileUtil->getFileAsString( osilFileName.c_str());
00891                 solver = new CoinSolver();
00892                 solver->sSolverName = "vol";
00893                 solver->osil = osil;
00894                 solver->osol = osol;  
00895                 solver->osinstance = NULL; 
00896                 cout << "call the COIN - Vol solver for parincLinear" << endl;
00897                 solver->buildSolverInstance();
00898                 solver->solve();
00899                 cout << "Here is the COIN - Vol solver solution for parincLinear" << endl;
00900                 cout << solver->osrl << endl;
00901                 check = 7;
00902                 //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-1 , 1e-1);
00903                 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00904                 if(ok == false) throw ErrorClass(" Fail unit test with Vol on volumeTest.osil");
00905                 delete solver;
00906                 solver = NULL;
00907                 unitTestResult << "Solved problem volumeTest.osil with Vol" << std::endl;
00908         }
00909         catch(const ErrorClass& eclass){
00910                 cout << "OSrL =  " <<  solver->osrl <<  endl;
00911                 cout << endl << endl << endl;
00912                 unitTestResultFailure  <<"Sorry Unit Test Failed Testing the Vol Solver:"  + eclass.errormsg << endl;
00913         }       
00914         #endif
00915         //
00916         //
00917         //
00918         //
00919         #ifdef COIN_HAS_GLPK
00920         try{
00921                 ok = true; 
00922                 osilFileName = dataDir  + "osilFiles" + dirsep + "p0033.osil";
00923                 osil = fileUtil->getFileAsString( osilFileName.c_str());
00924                 solver = new CoinSolver();
00925                 solver->sSolverName = "glpk";
00926                 solver->osil = osil;
00927                 solver->osol = osol;  
00928                 solver->osinstance = NULL; 
00929                 cout << "call the GLPK Solver for p0033" << endl;
00930                 solver->buildSolverInstance();
00931                 solver->solve();
00932                 cout << "Here is the GLPK solver solution for p0033" << endl;
00933                 cout << solver->osrl << endl;
00934                 check = 3089;
00935                 //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-10 , 1e-10);
00936                 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00937                 if(ok == false) throw ErrorClass(" Fail unit test with GLPK on p0033.osil");
00938                 delete solver;
00939                 solver = NULL;
00940                 unitTestResult << "Solved problem p0033.osil with GLPK" << std::endl;
00941         }
00942         catch(const ErrorClass& eclass){
00943                 cout << "OSrL =  " <<  solver->osrl <<  endl;
00944                 cout << endl << endl << endl;
00945                 unitTestResultFailure  <<"Sorry Unit Test Failed Testing the Glpk Solver:"  + eclass.errormsg << endl;
00946         }       
00947         #endif
00948         //
00949         //
00950         //
00951         #ifdef COIN_HAS_CPX
00952         try{
00953                 ok = true; 
00954                 osilFileName = dataDir  + "osilFiles" + dirsep + "p0033.osil";
00955                 osil = fileUtil->getFileAsString( osilFileName.c_str());
00956                 solver = new CoinSolver();
00957                 solver->sSolverName = "cplex";
00958                 solver->osil = osil;
00959                 solver->osol = osol;  
00960                 solver->osinstance = NULL; 
00961                 cout << "call the CPLEX Solver for p0033" << endl;
00962                 solver->buildSolverInstance();
00963                 solver->solve();
00964                 cout << "Here is the CPLEX solver solution for p0033" << endl;
00965                 cout << solver->osrl << endl;
00966                 check = 3089;
00967                 //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-10 , 1e-10);
00968                 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
00969                 if(ok == false) throw ErrorClass(" Fail unit test with CPLEX on p0033.osil");
00970                 delete solver;
00971                 solver = NULL;
00972                 unitTestResult << "Solved problem p0033.osil with CPLEX" << std::endl;
00973         }
00974         catch(const ErrorClass& eclass){
00975                 cout << "OSrL =  " <<  solver->osrl <<  endl;
00976                 cout << endl << endl << endl;
00977                 unitTestResultFailure  <<"Sorry Unit Test Failed Testing the Cplex Solver:"  + eclass.errormsg << endl;
00978         }       
00979         #endif
00980         
00981         //
00982         #ifdef COIN_HAS_LINDO
00983         try{
00984                 ok = true;
00985                 osilFileName = dataDir  + "osilFiles" + dirsep + "lindoapiaddins.osil";
00986                 osil = fileUtil->getFileAsString( osilFileName.c_str());
00987                 cout << "create a new LINDO Solver for OSiL string solution" << endl;
00988                 solver = new LindoSolver();     
00989                 solver->osil = osil;
00990                 solver->osol = osol;
00991                 solver->osinstance = NULL;
00992                 cout << "call the LINDO Solver" << endl;
00993                 solver->buildSolverInstance();
00994                 solver->solve();
00995                 cout << "Here is the LINDO solver solution" << endl;
00996                 cout << solver->osrl << endl;
00997                 check = 99;
00998                 //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-10 , 1e-10);
00999                 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01000                 if(ok == false) throw ErrorClass(" Fail unit test with LINDO on lindoapiaddins");
01001                 solver->osinstance = NULL;
01002                 delete solver;
01003                 solver = NULL;
01004                 unitTestResult << "Solved problem lindoapiaddins.osil with Lindo" << std::endl;
01005                 // now solve the rosenbrock problem from the OSiL paper
01006                 osilFileName = dataDir  + "osilFiles" + dirsep + "rosenbrockmod.osil";
01007                 osil = fileUtil->getFileAsString( osilFileName.c_str());
01008                 solver = new LindoSolver();     
01009                 solver->osil = osil;
01010                 solver->osol = osol;
01011                 solver->osinstance = NULL;
01012                 cout << "call the LINDO Solver" << endl;
01013                 solver->buildSolverInstance();
01014                 solver->solve();
01015                 cout << "Here is the LINDO solver solution" << endl;
01016                 cout << solver->osrl << endl;
01017                 check = 6.7279;
01018                 //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-10 , 1e-10);
01019                 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01020                 if(ok == false) throw ErrorClass(" Fail unit test with LINDO on rosenbrockmod");
01021                 solver->osinstance = NULL;
01022                 delete solver;
01023                 solver = NULL;
01024                 unitTestResult << "Solved problem rosenbrockmod.osil with Lindo" << std::endl;
01025                 // now solve a pure quadratic
01026                 osilFileName = dataDir  + "osilFiles" + dirsep + "parincQuadratic.osil";
01027                 osil = fileUtil->getFileAsString( osilFileName.c_str());
01028                 solver = new LindoSolver();     
01029                 solver->osil = osil;
01030                 solver->osol = osol;
01031                 solver->osinstance = NULL;
01032                 cout << "call the LINDO Solver" << endl;
01033                 solver->buildSolverInstance();
01034                 solver->solve();
01035                 cout << "Here is the LINDO solver solution" << endl;
01036                 cout << solver->osrl << endl;
01037                 check = 49920.5;
01038                 //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-10 , 1e-10);
01039                 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01040                 if(ok == false) throw ErrorClass(" Fail unit test with LINDO on parincQuadratic");
01041                 delete solver;
01042                 solver = NULL;
01043                 unitTestResult << "Solved problem parincQuadratic.osil with Lindo" << std::endl;
01044                 // now solve a quadratic binary problem
01045                 // wayneQuadratic.osil
01046                 /*
01047                 osilFileName = dataDir  + "osilFiles" + dirsep + "wayneQuadratic.osil";
01048                 osil = fileUtil->getFileAsString( osilFileName.c_str());
01049                 solver = new LindoSolver();     
01050                 solver->osil = osil;
01051                 solver->osol = osol;
01052                 solver->osinstance = NULL;
01053                 cout << "call the LINDO Solver" << endl;
01054                 solver->buildSolverInstance();
01055                 solver->solve();
01056                 cout << "Here is the LINDO solver solution" << endl;
01057                 cout << solver->osrl << endl;
01058                 check = 2.925;
01059                 std::cout << "CALL NEAR_EQUAL" << std::endl;
01060                 //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-10 , 1e-10);
01061                 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01062                 std::cout << "CALL NEAR_EQUAL" << std::endl;
01063                 if(ok == false) throw ErrorClass(" Fail unit test with LINDO on wayneQuadratic");
01064                 delete solver;
01065                 solver = NULL;
01066                 unitTestResult << "Solved problem wayneQuadratic.osil with Lindo" << std::endl;
01067                 */
01068                 
01069         }
01070         catch(const ErrorClass& eclass){
01071                 //cout << "OSrL =  " <<  solver->osrl <<  endl;
01072                 cout << endl << endl << endl;
01073                 unitTestResultFailure  <<"Sorry Unit Test Failed Testing the LINDO Solver:"  + eclass.errormsg << endl << endl;
01074         }
01075         #endif
01076         // end solving using the osil file
01077         // now solve with an OSInstance created from an MPS file
01078         try{
01079                 ok = true;
01080                 cout << endl;
01081                 cout << "START MPS TESTING" << endl << endl;
01082                 cout << "create a COIN Solver for MPS - OSInstance solution" << endl;
01083                 solver = new CoinSolver();
01084                 solver->sSolverName = "cbc";
01085                 mps2osil = new OSmps2osil( mpsFileName);
01086                 mps2osil->createOSInstance() ;
01087                 solver->osinstance = mps2osil->osinstance;
01088                 solver->osol = osol;
01089                 cout << "call COIN Solve" << endl;
01090                 solver->buildSolverInstance();
01091                 solver->solve();
01092                 cout << "Here is the COIN solver solution" << endl;
01093                 cout << solver->osrl << endl;
01094                 check = -7668;
01095                 //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-1 , 1e-1);
01096                 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01097                 if(ok == false) throw ErrorClass(" Fail unit test with COIN Solver on MPS test problem parincLinear.mps");
01098                 delete solver;
01099                 solver = NULL;
01100                 delete mps2osil; 
01101                 mps2osil = NULL;
01102                 cout << endl;
01103                 cout << "DONE WITH MPS TESTING" << endl;
01104                 unitTestResult << "Test the MPS -> OSiL converter on parinc.mps using Cbc" << std::endl;
01105         }
01106         catch(const ErrorClass& eclass){
01107                 cout << "OSrL =  " <<  solver->osrl <<  endl;
01108                 cout << endl << endl << endl;
01109                 unitTestResultFailure  <<"Sorry Unit Test Failed Testing the MPS converter:"  + eclass.errormsg << endl;
01110         }
01111         // now solve with an OSInstance created from an AMPL nl file
01112         try{
01113                 ok = true;
01114                 cout << endl;
01115                 cout << "START AMPL TESTING" << endl << endl;
01116 #ifdef COIN_HAS_ASL
01117                 cout << "create a cbc Solver for AMPL nl - OSInstance solution" << endl;
01118                 solver = new CoinSolver();
01119                 solver->sSolverName = "cbc";
01120                 nl2osil = new OSnl2osil( nlFileName); 
01121                 nl2osil->createOSInstance() ;
01122                 solver->osinstance = nl2osil->osinstance;       
01123                 solver->osol = osol;
01124                 cout << "call Cbc Solve" << endl;
01125                 solver->buildSolverInstance();
01126                 solver->solve();
01127                 cout << "Here is the Cbc solver solution" << endl;
01128                 cout << solver->osrl << endl;
01129                 check = 7668;
01130                 //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-1 , 1e-1);
01131                 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01132                 if(ok == false) throw ErrorClass(" Fail unit test with OSnl2osil on problem parinc.nl");
01133                 solver->osinstance = NULL;
01134                 delete solver;
01135                 solver = NULL;
01136                 cout << "call delete nl2osil" << endl;
01137                 delete nl2osil;
01138                 nl2osil = NULL; 
01139                 unitTestResult << "Test the AMPL nl -> OSiL converter on parinc.nl using Cbc" << std::endl; 
01140 #endif
01141                 cout << "END AMPL TESTING" << endl << endl;
01142         }       
01143                 catch(const ErrorClass& eclass){
01144                 cout << "OSrL =  " <<  solver->osrl <<  endl;
01145                 cout << endl << endl << endl;
01146                 unitTestResultFailure  <<"Sorry Unit Test Failed Testing AMPL:"  + eclass.errormsg << endl;
01147         }
01148         //
01149         // Now test the mps feature
01150         //
01151         try{
01152                 ok = true;
01153                 cout << endl;
01154                 cout << endl;
01155                 cout << "TESTING b64 OPERATIONS WITH A COIN SOLVER"<< endl;
01156                 cout << endl;
01157                 OSiLWriter osilwriter;
01158                 osilwriter.m_bWriteBase64 = true;
01159                 solver = new CoinSolver();
01160                 solver->sSolverName = "cbc";
01161                 mps2osil = new OSmps2osil( mpsFileName);
01162                 solver->osinstance = NULL;
01163                 solver->osol = osol;
01164                 mps2osil->createOSInstance() ;
01165                 solver->osil = osilwriter.writeOSiL( mps2osil->osinstance) ;
01166                 std::cout << solver->osil << std::endl;
01167                 solver->buildSolverInstance();
01168                 //return 0;
01169                 solver->solve();
01170                 cout << endl << endl;
01171                 cout << "COIN solution of a OSiL string in b64 format" << endl;
01172                 cout << solver->osrl;
01173                 check = -7668;
01174                 //ok &= NearEqual(getObjVal( solver->osrl) , check,  1e-1 , 1e-1);
01175                 ok = ( fabs(check - getObjVal( solver->osrl) )/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01176                 if(ok == false) throw ErrorClass(" Fail unit test with COIN Cbc cSolver on b64 test problem parincLinear.mps");
01177                 solver->osinstance = NULL;
01178                 delete solver;
01179                 solver = NULL;
01180                 delete mps2osil;
01181                 mps2osil = NULL;
01182                 unitTestResult << "Test a problem written in b64 and then converted to OSInstance" << std::endl;
01183         }       
01184         catch(const ErrorClass& eclass){
01185                 cout << endl << endl;
01186                 cout << eclass.errormsg <<  endl << endl;
01187                 cout << "OSrL =  " <<  solver->osrl <<  endl;
01188                 cout << endl << endl << endl;
01189                 unitTestResultFailure   << "Sorry Unit Test Failed Testing Use of Base 64" << endl;
01190 
01191         }  
01192         //
01193         // Now just test the OSiL parser
01194         try{ 
01195                 cout << endl;
01196                 clock_t start, finish;
01197                 double duration;
01198                 OSiLWriter *osilwriter = NULL;
01199                 osilwriter = new OSiLWriter();
01200                 //delete fileUtil;
01201                 //fileUtil = NULL;
01202                 //fileUtil = new FileUtil();
01203                 cout << "TEST PARSING A MODEL" << endl;
01204                 cout << "FIRST READ THE FILE INTO A STRING" << endl;
01205                 start = clock();
01206                 osilFileName = dataDir  + "osilFiles" + dirsep + "parincLinear.osil";
01207                 osil = fileUtil->getFileAsString( osilFileName.c_str());
01208                 finish = clock();
01209                 duration = (double) (finish - start) / CLOCKS_PER_SEC;
01210                 cout << "Reading the file into a string took (seconds): "<< duration << endl;
01211                 OSiLReader *osilreader = NULL;
01212                 osilreader = new OSiLReader(); 
01213                 start = clock();
01214                 cout << "PARSE THE OSIL STRING INTO AN OSINSTANCE OBJECT" << endl;
01215                 osilreader->readOSiL( osil);
01216                 //cout << osilwriter->writeOSiL( osilreader->readOSiL( osil)) << endl;
01217                 delete osilreader;
01218                 osilreader = 0;
01219                 delete osilwriter;
01220                 osilwriter = NULL;
01221                 finish = clock();
01222                 duration = (double) (finish - start) / CLOCKS_PER_SEC;
01223                 cout << "Parsing took (seconds): "<< duration << endl;
01224                 unitTestResult << "Successful test of OSiL parser on problem parincLinear.osil" << std::endl;
01225 
01226         }       
01227                 catch(const ErrorClass& eclass){
01228                 cout << endl << endl << endl;
01229                 cout << eclass.errormsg << endl;
01230                 unitTestResultFailure << "Sorry Unit Test Failed Testing An OSiL Parser" << endl;
01231                 
01232         }       
01233 
01234         //
01235         // Now test the extensions to the OSiL format: <timeDomain>, etc.
01236 
01237 #ifdef STRESSTEST
01238         try{ 
01239                 cout << endl;
01240                 clock_t start, finish;
01241                 double duration;
01242                 OSiLWriter *osilwriter = NULL;
01243                 osilwriter = new OSiLWriter();
01244                 //delete fileUtil;
01245                 //fileUtil = NULL;
01246                 //fileUtil = new FileUtil();
01247                 cout << "\nTEST PARSING A STOCHASTIC MODEL" << endl;
01248                 cout << "FIRST READ THE FILE INTO A STRING" << endl;
01249                 start = clock();
01250                 osilFileName = dataDir  + "osilFiles" + dirsep + "finplan1.osil";
01251                 osil = fileUtil->getFileAsString( &osilFileName[0]);
01252                 finish = clock();
01253                 duration = (double) (finish - start) / CLOCKS_PER_SEC;
01254                 cout << "Reading the file into a string took (seconds): "<< duration << endl;
01255                 OSiLReader *osilreader = NULL;
01256                 osilreader = new OSiLReader(); 
01257                 start = clock();
01258                 cout << "PARSE THE OSIL STRING INTO AN OSINSTANCE OBJECT" << endl;
01259                 osilreader->readOSiL( osil);
01260                 //cout << osilwriter->writeOSiL( osilreader->readOSiL( &osil)) << endl;
01261                 delete osilreader;
01262                 osilreader = 0;
01263                 finish = clock();
01264                 duration = (double) (finish - start) / CLOCKS_PER_SEC;
01265                 cout << "Parsing took (seconds): "<< duration << endl;
01266                 unitTestResult << "Successful test of OSiL parser on problem finplan1.osil" << std::endl;
01270                 cout << "\nTEST THE GET() AND SET() METHODS FOR TimeDomain OBJECT" << endl;
01271                 OSInstance *osinstance = NULL;
01272                 //osinstance = new OSInstance();
01273                 //OSiLReader *osilreader = NULL;
01274                 osilreader = new OSiLReader();
01275                 //create an osinstance
01276                 osinstance = osilreader->readOSiL( osil);
01277                 std::string f = osinstance->getTimeDomainFormat();
01278                 ok = (f == "stages");
01279                 int n = osinstance->getTimeDomainStageNumber();
01280                 ok &= (n == 6);
01281 
01282                 std::string* sncheck = new std::string[6];
01283                 sncheck[0] = "";
01284                 sncheck[1] = "";
01285                 sncheck[2] = "";
01286                 sncheck[3] = "test";
01287                 sncheck[4] = "Wha'zzup?";
01288                 sncheck[5] = "";
01289 
01290                 std::string* sn = osinstance->getTimeDomainStageNames();
01291 
01292                 for (int i = 0; i < 6; i++)
01293                         ok &= (sn[i] == sncheck[i]);
01294 
01295                 int* nv = osinstance->getTimeDomainStageNumberOfVariables();
01296 
01297                 int* nvcheck = new int[6];
01298                 nvcheck[0] = 2;
01299                 nvcheck[1] = 2;
01300                 nvcheck[2] = 0;
01301                 nvcheck[3] = 0;
01302                 nvcheck[4] = 2;
01303                 nvcheck[5] = 2;
01304 
01305                 for (int i = 0; i < 6; i++)
01306                         ok &= (nv[i] == nvcheck[i]);
01307 
01308                 int* nc = osinstance->getTimeDomainStageNumberOfConstraints();
01309 
01310                 int* nccheck = new int[6];
01311                 nccheck[0] = 1;
01312                 nccheck[1] = 1;
01313                 nccheck[2] = 0;
01314                 nccheck[3] = 0;
01315                 nccheck[4] = 1;
01316                 nccheck[5] = 1;
01317 
01318                 for (int i = 0; i < 6; i++)
01319                         ok &= (nc[i] == nccheck[i]);
01320 
01321                 int* no = osinstance->getTimeDomainStageNumberOfObjectives();
01322 
01323                 int* nocheck = new int[6];
01324                 nocheck[0] = 1;
01325                 nocheck[1] = 1;
01326                 nocheck[2] = 1;
01327                 nocheck[3] = 0;
01328                 nocheck[4] = 1;
01329                 nocheck[5] = 1;
01330 
01331                 for (int i = 0; i < 6; i++)
01332                         ok &= (no[i] == nocheck[i]);
01333 
01334                 int** lv = osinstance->getTimeDomainStageVarList();
01335                 int** lc = osinstance->getTimeDomainStageConList();
01336                 int** lo = osinstance->getTimeDomainStageObjList();
01337 
01338                 int** lvcheck = new int*[6];
01339                 int** lccheck = new int*[6];
01340                 int** locheck = new int*[6];
01341                 for (int i = 0; i < 6; i++) {
01342                         lvcheck[i] = new int[2];
01343                         lccheck[i] = new int[2];
01344                         locheck[i] = new int[2];
01345                 };
01346                 lvcheck[0][0] = 0;
01347                 lvcheck[0][1] = 1;
01348                 lvcheck[1][0] = 2;
01349                 lvcheck[1][1] = 3;
01350                 lvcheck[4][0] = 4;
01351                 lvcheck[4][1] = 5;
01352                 lvcheck[5][0] = 6;
01353                 lvcheck[5][1] = 7;
01354                 lccheck[0][0] = 0;
01355                 lccheck[1][0] = 1;
01356                 lccheck[4][0] = 2;
01357                 lccheck[5][0] = 3;
01358                 locheck[0][0] = -1;
01359                 locheck[1][0] = -1;
01360                 locheck[2][0] = -1;
01361                 locheck[4][0] = -1;
01362                 locheck[5][0] = -1;
01363 
01364                 for (int i = 0; i < 6; i++) {
01365                         for (int j = 0; j < nv[i]; j++) 
01366                                 ok &= (lvcheck[i][j] == lv[i][j]);
01367                         for (int j = 0; j < nc[i]; j++) 
01368                                 ok &= (lccheck[i][j] == lc[i][j]);
01369                         for (int j = 0; j < no[i]; j++) 
01370                                 ok &= (locheck[i][j] == lo[i][j]);
01371                 };
01372 
01373                 std::string* sn1 = new std::string[6];
01374                 int* nv1 = new int[6];
01375                 int* nc1 = new int[6];
01376                 int* no1 = new int[6];
01377                 int** lv1 = new int*[6];
01378                 int** lc1 = new int*[6];
01379                 int** lo1 = new int*[6];
01380                 for (int i = 0; i < 6; i++) {
01381                         lv1[i] = new int[2];
01382                         lc1[i] = new int[2];
01383                         lo1[i] = new int[2];
01384                 };
01385                 for (int i = 0; i < 6; i++) {
01386                         sn1[i] = sn[i];
01387                         nv1[i] = nv[i];
01388                         nc1[i] = nc[i];
01389                         no1[i] = no[i];
01390                         for (int j = 0; j < nv[i]; j++) {
01391                                 lv1[i][j] = lv[i][j];
01392                         };
01393                         for (int j = 0; j < nc[i]; j++) {
01394                                 lc1[i][j] = lc[i][j];
01395                         };
01396                         for (int j = 0; j < no[i]; j++) {
01397                                 lo1[i][j] = lo[i][j];
01398                         };
01399                 };
01400 
01401                 ok &= osinstance->setTimeDomain("none");
01402                 n = 0;
01403                 ok &= osinstance->setTimeDomainStages(n,NULL);
01404                 ok &= osinstance->setTimeDomainStages(4,NULL);
01405 
01406                 n = osinstance->getTimeDomainStageNumber();
01407                 ok &= (n == 4);
01408 
01409                 int *nelem, *startIdx, **VI;
01410                 nelem = new int[4];
01411                 startIdx = new int[4];
01412                 VI = new int*[4];
01413                 for (i = 0; i < 4; i++)
01414                 {       nelem[i] = 2;
01415                         startIdx[i] = 2*i;
01416                         VI[i] = new int[2];
01417                         VI[i][0] = 2*i;
01418                         VI[i][1] = 2*i + 1;
01419                 };
01420                 ok &= osinstance->setTimeDomainStageVariablesUnordered(4,nelem,VI);
01421 
01422                 for (i = 0; i < 4; i++)
01423                 {       nelem[i] = 1;
01424                         startIdx[i] = i;
01425                 };
01426                 ok &= osinstance->setTimeDomainStageConstraintsOrdered(4,nelem,startIdx);
01427 
01428                 for (i = 0; i < 4; i++)
01429                 {       nelem[i] = 1;
01430                         startIdx[i] = -1;
01431                 };
01432                 ok &= osinstance->setTimeDomainStageObjectivesOrdered(4,nelem,startIdx);
01433 
01434                 ok &= osinstance->setTimeDomain("none");
01435 
01436                 ok &= osinstance->setTimeDomain("interval");
01437 
01438                 ok &= osinstance->setTimeDomainInterval(0.0, 1.0);
01439                 double lower = osinstance->getTimeDomainIntervalStart();
01440                 ok &= (lower == 0.0);
01441                 double upper = osinstance->getTimeDomainIntervalHorizon();
01442                 ok &= (upper == 1.0);
01443 
01444                 ok &= osinstance->setTimeDomain("none");
01445 
01446                 ok &= osinstance->setTimeDomainStages(6,sncheck);
01447                 ok &= osinstance->setTimeDomainStageVariablesUnordered(6,nvcheck,lvcheck);
01448                 ok &= osinstance->setTimeDomainStageObjectivesUnordered(6,nocheck,locheck);
01449                 ok &= osinstance->setTimeDomainStageConstraintsUnordered(6,nccheck,lccheck);
01450                 int n2 = osinstance->getTimeDomainStageNumber();
01451                 ok &= (n2 == 6);
01452                 std::string* sn2 = osinstance->getTimeDomainStageNames();
01453                 int* nv2 = osinstance->getTimeDomainStageNumberOfVariables();
01454                 int* nc2 = osinstance->getTimeDomainStageNumberOfConstraints();
01455                 int* no2 = osinstance->getTimeDomainStageNumberOfObjectives();
01456                 int** lv2 = osinstance->getTimeDomainStageVarList();
01457                 int** lc2 = osinstance->getTimeDomainStageConList();
01458                 int** lo2 = osinstance->getTimeDomainStageObjList();
01459                 for (int i = 0; i < n2; i++)
01460                 {       ok &= (sn2[i] == sncheck[i]);
01461                         ok &= (nv2[i] == nvcheck[i]);
01462                         ok &= (nc2[i] == nccheck[i]);
01463                         ok &= (no2[i] == nocheck[i]);
01464                         for (int j = 0; j < nv2[i]; j++)
01465                                 ok &= (lv2[i][j] == lvcheck[i][j]);
01466                         for (int j = 0; j < nc2[i]; j++)
01467                                 ok &= (lc2[i][j] == lccheck[i][j]);
01468                         for (int j = 0; j < no2[i]; j++)
01469                                 ok &= (lo2[i][j] == locheck[i][j]);
01470                 };
01471                 delete [] sncheck;
01472                 sncheck = NULL;
01473                 delete [] nvcheck;
01474                 nvcheck = NULL;
01475                 delete [] nccheck;
01476                 nccheck = NULL;
01477                 delete [] nocheck;
01478                 nocheck = NULL;
01479                 for (int i = 0; i < 6; i++) {
01480                         delete [] lvcheck[i];
01481                         delete [] lccheck[i];
01482                         delete [] locheck[i];
01483                         delete [] lv1[i];
01484                         delete [] lc1[i];
01485                         delete [] lo1[i];
01486                 };
01487                 delete [] lvcheck;
01488                 lvcheck = NULL;
01489                 delete [] lccheck;
01490                 lccheck = NULL;
01491                 delete [] locheck;
01492                 locheck = NULL;
01493                 delete [] lv1;
01494                 lv1 = NULL;
01495                 delete [] lc1;
01496                 lc1 = NULL;
01497                 delete [] lo1;
01498                 lo1 = NULL;
01499                 delete [] sn1;
01500                 sn1 = NULL;
01501                 delete nv1;
01502                 nv1 = NULL;
01503                 delete nc1;
01504                 nc1 = NULL;
01505                 delete no1;
01506                 no1 = NULL;
01507                 delete [] nelem;
01508                 nelem = NULL;
01509                 delete [] startIdx;
01510                 startIdx = NULL;
01511                 for (int i = 0; i < 4; i++) {
01512                         delete [] VI[i];
01513                 };
01514                 delete [] VI;
01515                 VI = NULL;
01516                 unitTestResult << "Successful test of osinstance get() and set() methods" << std::endl;
01517         }       
01518         catch(const ErrorClass& eclass){
01519                 cout << endl << endl << endl;
01520                 cout << eclass.errormsg << endl;
01521                 unitTestResultFailure << "Sorry Unit Test Failed osinstance get() and set() Methods" << endl;           
01522         }       
01523 #endif
01524 
01525 
01526         //
01527         // Now just test the OSrL parser
01528         try{ 
01537                 cout << endl;
01538                 std::string tmpOSrL;
01539                 clock_t start, finish;
01540                 double duration;
01541                 osrlwriter = new OSrLWriter();
01542                 osrlreader = new OSrLReader();
01543                 OSResult *osresult = NULL;
01544                 //osresult = new OSResult(); 
01545                 cout << "TEST PARSING AN OSrL FILE" << endl;
01546                 cout << "FIRST READ THE OSrL FILE INTO A STRING" << endl;
01547                 osrlFileName = dataDir  + "osrlFiles" + dirsep + "parincLinear.osrl"; 
01548                 start = clock();
01549                 std::string osrl = fileUtil->getFileAsString( osrlFileName.c_str() );
01550                 finish = clock();
01551                 duration = (double) (finish - start) / CLOCKS_PER_SEC;
01552                 cout << "Reading the file into a string took (seconds): "<< duration << endl;
01553                 start = clock();
01554                 cout << "PARSE THE OSRL STRING INTO AN OSRESULT OBJECT" << endl;
01555                 osresult = osrlreader->readOSrL( osrl);
01556                 tmpOSrL = osrlwriter->writeOSrL( osresult) ;
01557                 // make ssure we can parse without error
01558                 delete osrlreader;
01559                 osrlreader = NULL;
01560                 osrlreader = new OSrLReader();
01561                 osrlreader->readOSrL( tmpOSrL);
01562                 delete osrlwriter;
01563                 osrlwriter = NULL;
01564                 delete osrlreader;
01565                 osrlreader = NULL;
01566                 // now a second example
01567                 cout << "TEST PARSING AN OSrL FILE" << endl;
01568                 osrlwriter = new OSrLWriter();
01569                 osrlreader = new OSrLReader();
01570                 cout << "FIRST READ THE OSrL FILE INTO A STRING" << endl;
01571                 //errorExample.osrl -- check to see if we read an error message correct;
01572                 osrlFileName = dataDir  + "osrlFiles" + dirsep + "errorExample.osrl"; 
01573                 osrl = fileUtil->getFileAsString( osrlFileName.c_str() );
01574                 finish = clock();
01575                 duration = (double) (finish - start) / CLOCKS_PER_SEC;
01576                 cout << "Reading the file into a string took (seconds): "<< duration << endl;
01577                 cout << "PARSE THE OSRL STRING INTO AN OSRESULT OBJECT" << endl;
01578                 osresult = osrlreader->readOSrL( osrl);
01579                 tmpOSrL = osrlwriter->writeOSrL( osresult) ;
01580                 delete osrlreader;
01581                 osrlreader = NULL;
01582                 osrlreader = new OSrLReader();
01583                 osrlreader->readOSrL( tmpOSrL);
01584                 delete osrlwriter;
01585                 osrlwriter = NULL;
01586                 delete osrlreader;
01587                 osrlreader = NULL;
01588                 unitTestResult << 
01589                      "Successful test of OSrL parser on problems parincLinear.osrl and errorExample.osrl" 
01590                       << std::endl;
01591 
01592         }       
01593                 catch(const ErrorClass& eclass){
01594                 cout << endl << endl << endl;
01595                 if(osrlwriter != NULL) delete osrlwriter;
01596                 if(osrlreader != NULL) delete osrlreader;
01597                 // " Problem with the test reading OSrL data";
01598                 unitTestResultFailure << eclass.errormsg << endl;
01599                 unitTestResultFailure << "There was a failure in the test for reading OSrL" << endl;
01600         }
01601         // now test postfix and prefix routines
01602         try{
01603                 std::string expTreeTest =  dataDir  + "osilFiles" + dirsep + "rosenbrockmod.osil";
01604                 osil = fileUtil->getFileAsString( expTreeTest.c_str() ) ;
01605                 OSInstance *osinstance = NULL;
01606                 //osinstance = new OSInstance();
01607                 OSiLReader *osilreader = NULL;
01608                 osilreader = new OSiLReader();
01609                 //create an osinstance
01610                 osinstance = osilreader->readOSiL( osil);
01611                 OSExpressionTree* expTree = osinstance->getNonlinearExpressionTree( -1);
01612                 if(expTree == NULL) throw ErrorClass(" Null expression tree when testing prefix and postfix routines");
01613                 std::vector<OSnLNode*> postfixVec;
01614                 //postfixVec = expTree->m_treeRoot->getPostfixFromExpressionTree();
01615                 postfixVec = osinstance->getNonlinearExpressionTreeInPostfix( -1);
01616         
01617                 unsigned int n = postfixVec.size();
01618                 unsigned int i;
01619                 std::string *nodeNames1 = new std::string[ n];
01620                 std::string *nodeNames2 = new std::string[ n];
01621                 for (i = 0 ; i < n; i++){
01622                         std::cout << postfixVec[i]->snodeName << std::endl;
01623                         nodeNames1[i] = postfixVec[i]->snodeName;
01624                 }
01625                 
01626                 // now create back the expression tree 
01627                 expTree->m_treeRoot = postfixVec[ n - 1]->createExpressionTreeFromPostfix( postfixVec);
01628         
01629                 // now get in prefix
01630                 std::vector<OSnLNode*> prefixVec;
01631                 //prefixVec = expTree->m_treeRoot->getPrefixFromExpressionTree();
01632                 prefixVec = osinstance->getNonlinearExpressionTreeInPrefix( -1);
01633                 
01634                 // now create back the expression tree
01635                 expTree->m_treeRoot = prefixVec[ 0]->createExpressionTreeFromPrefix( prefixVec);
01636                 
01637                 // now get postfix vector again and compare with original
01638                 postfixVec = expTree->m_treeRoot->getPostfixFromExpressionTree();
01639                 //postfixVec = osinstance->getNonlinearExpressionTreeInPostfix( -1);
01640                 if(postfixVec.size() != n) throw ErrorClass(" Problem with creating expression trees");
01641                 std::cout << std::endl << std::endl;
01642                 for (i = 0 ; i < n; i++){
01643                         //std::cout << postfixVec[i]->snodeName << std::endl;
01644                         nodeNames2[i] = postfixVec[i]->snodeName;
01645                         if( nodeNames1[i] != nodeNames2[ i]) throw ErrorClass(" Problem with creating expression trees");
01646                 }       
01647                 
01648                 //delete osinstance;
01649                 delete[] nodeNames1;
01650                 delete[] nodeNames2; 
01651 
01652                 delete osilreader;
01653                 osilreader = NULL;
01654                 osinstance = NULL;              
01655                 unitTestResult << "Successful test of prefix and postfix conversion routines on problem rosenbrockmod.osil" << std::endl;
01656                 
01657         }
01658         catch(const ErrorClass& eclass){
01659                 cout << endl << endl << endl;
01660                 unitTestResultFailure << eclass.errormsg << endl;
01661         }
01662         // now test the nonlinear operators     
01663         try{
01664                 ok = true;
01665                 std::cout << "Test nonlinear operators" << std::endl;
01666                 std::string operatorTest =  dataDir  + "osilFiles" + dirsep + "testOperators.osil";
01667                 osil = fileUtil->getFileAsString( operatorTest.c_str() );
01668                 OSInstance *osinstance = NULL;
01669                 //osinstance = new OSInstance();
01670                 OSiLReader *osilreader = NULL;
01671                 osilreader = new OSiLReader();
01672                 OSiLWriter *osilwriter = NULL;
01673                 osilwriter = new OSiLWriter();
01674                 osinstance = osilreader->readOSiL( osil);
01675                 OSExpressionTree* expTree = osinstance->getNonlinearExpressionTree( -1);
01676                 std::vector<OSnLNode*> postfixVec;
01677                 postfixVec = expTree->m_treeRoot->getPostfixFromExpressionTree();
01678                 int n = postfixVec.size();
01679                 std::string *nodeNames1 = new std::string[ n];
01680                 for (int i = 0 ; i < n; i++){
01681                         std::cout << postfixVec[i]->snodeName << std::endl;
01682                         nodeNames1[i] = postfixVec[i]->snodeName;
01683                 }
01684                 std::cout << std::endl << std::endl;
01685                 std::cout << osilwriter->writeOSiL( osinstance) << std::endl;
01686                 // now test value
01687                 double *x = NULL;
01688                 x = new double[2];
01689                 x[0] = 1;
01690                 x[1] = 2;
01691                 double parserTestVal = expTree->m_treeRoot->calculateFunction( x);
01692                 std::cout << "ParserTest Val = " << parserTestVal << std::endl;
01693                 check = 11;
01694                 //ok &= NearEqual(expTree->m_treeRoot->calculateFunction( x) , check,  1e-10 , 1e-10);
01695                 ok = ( fabs(check -  expTree->m_treeRoot->calculateFunction( x))/(fabs( check) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01696                 if(ok == false) throw ErrorClass(" Problem evaluating expression tree");
01697                 delete[] x;
01698                 delete[] nodeNames1;
01699                 delete osilreader;
01700                 osilreader = NULL;
01701                 delete osilwriter;
01702                 osilwriter = NULL;
01703                 osinstance = NULL;
01704                 //create an osinstance
01705                 unitTestResult << "Successful test of all of the nonlinear operators on file testOperators.osil" << std::endl;
01706         }
01707         catch(const ErrorClass& eclass){
01708                 cout << endl << endl << endl;
01709                 unitTestResultFailure << eclass.errormsg << endl;
01710         }
01711         // 
01712         // now solve on a remote server
01713         /*
01714         try{
01715                 //return 0;
01716                 OSSolverAgent* osagent = NULL;
01717                 //osagent = new OSSolverAgent("128.135.130.17/axis/OSSolverService");
01718                 //osagent = new OSSolverAgent("gsbkip.chicagogsb.edu:80/os/ossolver/COINSolverService.jws");
01719                 //osagent = new OSSolverAgent("localhost/os/ossolver/COINSolverService.jws");
01720                 //osagent = new OSSolverAgent("localhost/axis/OSSolverService");
01721                 osagent = new OSSolverAgent("http://127.0.0.1:8080/os/ossolver/CoinSolverService.jws");
01722                 //osagent = new OSSolverAgent("128.135.130.17:8080/os/ossolver/CoinSolverService.jws");
01723                 //osagent = new OSSolverAgent("127.0.0.1:8080/web-services-examples/ted/VrptsSolverService.jws");
01724                 cout << "Place remote synchronous call" << endl;
01725                 nl2osil = new OSnl2osil( nlFileName);
01726                 nl2osil->createOSInstance() ;
01727                 OSiLWriter *osilwriter = NULL;
01728                 osilwriter = new OSiLWriter();
01729                 osil = osilwriter->writeOSiL( nl2osil->osinstance) ;
01730                 string osrl = osagent->solve(osil, osol);
01731                 cout << "READ THE OSrL and WRITE IT AGAIN" << endl;
01732                 cout << osrl  << endl;
01733                 OSrLReader *osrlreader = NULL;
01734                 OSResult *osresult = NULL;
01735                 osrlreader = new OSrLReader();
01736                 osresult = osrlreader->readOSrL( osrl);
01737                 OSrLWriter *osrlwriter;
01738                 if(osresult != NULL){
01739                         osrlwriter = new OSrLWriter();
01740                         osrl = osrlwriter->writeOSrL( osresult);
01741                 }
01742                 cout << osrl << endl;
01743                 //
01744                 delete nl2osil;
01745                 nl2osil = NULL;
01746                 delete osilwriter;
01747                 osilwriter = NULL;
01748         }       
01749                 catch(const ErrorClass& eclass){
01750                 cout <<  eclass.errormsg <<  endl;
01751         }       
01752         */
01753         try{
01754                 std::cout << std::endl << std::endl;
01755                 std::cout << "Testing AD Features " << std::endl;
01756                 std::string expTreeTest =  dataDir  + "osilFiles" + dirsep + "CppADTestLag.osil";
01757                 /*
01758                 min x0^2 + 9*x1   -- w[0]
01759                 s.t. 
01760                 33 - 105 + 1.37*x1 + 2*x3 + 5*x1 <= 10  -- y[0]
01761                 ln(x0*x3)  + 7*x2 >= 10  -- y[1]
01762                 Note: in the first constraint 33 is a constant term and 105 
01763                 is part of the nl node
01764                 */
01765                 osil = fileUtil->getFileAsString( expTreeTest.c_str() );
01766                 OSInstance *osinstance = NULL;
01767                 //osinstance = new OSInstance();
01768                 OSiLReader *osilreader = NULL;
01769                 osilreader = new OSiLReader();
01770                 //create an osinstance
01771                 osinstance = osilreader->readOSiL( osil);
01772                 double *x;
01773                 x = new double[ 4];
01774                 x[0] = 1;
01775                 x[1] = 5;
01776                 x[2] = 10;
01777                 x[3] = 5;
01778                 SparseVector *sp;
01779                 // get the gradient for constraint 1
01780                 osinstance->getJacobianSparsityPattern();
01781                 sp = osinstance->calculateConstraintFunctionGradient(x, 1, true);
01782                 int i;
01783                 for(i = 0; i < sp->number; i++){
01784                         std::cout << "gradient value " << sp->values[i] << std::endl;
01785                 }
01786                 ok = true;
01787                 //check gradient for constraint with index 1
01788                 double checkPartial2Con1 = 7.0 ;
01789                 //ok &= NearEqual( sp->values[ 0], checkPartial2Con1, 1e-10, 1e-10); 
01790                 ok = ( fabs(checkPartial2Con1 - sp->values[ 0] )/(fabs( checkPartial2Con1) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01791                 if(ok == false) throw ErrorClass(" Fail testing gradient calculation");
01792                 double checkPartial0Con1 = (1./x[0])  ;
01793                 //ok &= NearEqual(sp->values[ 1], checkPartial0Con1, 1e-10, 1e-10); 
01794                 ok = ( fabs(checkPartial0Con1 - sp->values[ 1] )/(fabs( checkPartial0Con1) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01795                 if(ok == false) throw ErrorClass(" Fail testing gradient calculation");
01796                 double checkPartial3Con1 = (1./x[3]) ;
01797                 //ok &= NearEqual( sp->values[ 2], checkPartial3Con1, 1e-10, 1e-10); 
01798                 ok = ( fabs(checkPartial3Con1 - sp->values[ 2] )/(fabs( checkPartial3Con1) + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01799                 if(ok == false) throw ErrorClass(" Fail testing gradient calculation");
01800                 delete sp;
01801                 SparseHessianMatrix *sh;
01802                 // calcuate Hessian of objective function (index = -1)
01803                 osinstance->getLagrangianHessianSparsityPattern( );
01804                 sh = osinstance->calculateHessian(x, -1, true);
01805                 for(i = 0; i < sh->hessDimension; i++){
01806                         std::cout << "Hessian value " << sh->hessValues[i] << std::endl;
01807                 }
01808                 //ok &= NearEqual( sh->hessValues[ 0], 2., 1e-10, 1e-10);
01809                 ok = ( fabs(2. - sh->hessValues[0] )/(2. + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01810                 if(ok == false) throw ErrorClass(" Fail testing Hessian calculation"); 
01811                 //ok &= NearEqual( sh->hessValues[ 1], 0., 1e-10, 1e-10);
01812                 ok = ( fabs(0. - sh->hessValues[ 1] )/(0. + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01813                 if(ok == false) throw ErrorClass(" Fail testing Hessian calculation");
01814                 //ok &= NearEqual( sh->hessValues[ 2], 0., 1e-10, 1e-10);
01815                 ok = ( fabs(0. - sh->hessValues[2] )/(0. + OS_NEAR_EQUAL) <= OS_NEAR_EQUAL) ? true : false;
01816                 if(ok == false) throw ErrorClass(" Fail testing Hessian calculation");
01817                 unitTestResult << "Successful test of AD gradient and Hessian calculations on problem CppADTestLag.osil" << std::endl;
01818                 delete[] x;
01819                 delete osilreader;
01820                 osilreader = NULL;
01821         }       
01822         catch(const ErrorClass& eclass){
01823                 cout << endl << endl << endl;
01824                 unitTestResultFailure << eclass.errormsg << endl;
01825         }
01826         delete fileUtil;
01827         fileUtil = NULL;
01828             
01829         if(unitTestResultFailure.str().length() > 0){
01830                 cout << "The unitTest passed the following" << endl << endl;
01831                 cout << unitTestResult.str() << endl << endl;
01832                 cout << "Unfortunately, you failed on the following:" << endl << endl;
01833                 cout << unitTestResultFailure.str() << endl << endl;
01834                 cout << "Conclusion: FAILURE" << endl;
01835                 return 1;
01836         }
01837         else{
01838                 cout << "The unitTest passed the following" << endl << endl;
01839                 cout << unitTestResult.str() << endl << endl;
01840                 cout << "All tests completed successfully" <<  endl <<  endl;
01841                 return 0;
01842         }
01843 }//end main
01844 
01845 double getObjVal( std::string osrl){
01846         std::string sObjVal;
01847         double dObjVal;
01848         string::size_type pos2;
01849         string::size_type pos1 = osrl.find( "<obj ");
01850         if(pos1 != std::string::npos){
01851                 // get the end of the obj start tag
01852                 pos1 = osrl.find(">", pos1 + 1);
01853                 if(pos1 != std::string::npos){
01854                         // get the start of obj end tag
01855                         pos2 = osrl.find( "</obj", pos1 + 1);
01856                         if( pos2 != std::string::npos){
01857                                 // get the substring
01858                                 sObjVal = osrl.substr( pos1 + 1, pos2 - pos1 - 1);
01859                                 //std::cout << "HERE IS THE OBJECTIVE FUNCTION VALUE SUBSTRING  " << sObjVal<< std::endl; 
01860                                 // return dObjVal = strtod(sObjVal.c_str(), NULL);
01861                                 return dObjVal = os_strtod(sObjVal.c_str(), NULL); 
01862                         }
01863                         else return OSNAN;
01864                 }
01865                 else return OSNAN;
01866         }
01867         else return OSNAN;
01868 }

Generated on Tue Sep 30 03:01:25 2008 by  doxygen 1.4.7