Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

unitTest.cpp

00001 // Copyright (C) 2000, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 // Test individual classes or groups of classes
00004 
00005 #if defined(_MSC_VER)
00006 // Turn off compiler warning about long names
00007 #  pragma warning(disable:4786)
00008 #endif
00009 
00010 #include <cassert>
00011 #include <iostream>
00012 
00013 #include "OsiRowCut.hpp"
00014 #include "OsiColCut.hpp"
00015 #include "OsiCuts.hpp"
00016 #include "CoinHelperFunctions.hpp"
00017 #include "CoinSort.hpp"
00018 #include "OsiSolverInterface.hpp"
00019 #include "OsiSimplexInterface.hpp"
00020 #include "OsiRowCutDebugger.hpp"
00021 #ifdef COIN_USE_OSL
00022 #include "OsiOslSolverInterface.hpp"
00023 #endif
00024 #ifdef COIN_USE_XPR
00025 #include "OsiXprSolverInterface.hpp"
00026 #endif
00027 #ifdef COIN_USE_CPX
00028 #include "OsiCpxSolverInterface.hpp"
00029 #endif
00030 #ifdef COIN_USE_SPX
00031 #include "OsiSpxSolverInterface.hpp"
00032 #endif
00033 #ifdef COIN_USE_VOL
00034 #include "OsiVolSolverInterface.hpp"
00035 #endif
00036 #ifdef COIN_USE_DYLP
00037 #include "OsiDylpSolverInterface.hpp"
00038 #endif
00039 #ifdef COIN_USE_GLPK
00040 #include "OsiGlpkSolverInterface.hpp"
00041 #endif
00042 #ifdef COIN_USE_CLP
00043 #include "OsiClpSolverInterface.hpp"
00044 #endif
00045 // Function Prototypes. Function definitions is in this file.
00046 void testingMessage( const char * const msg );
00047 
00048 //----------------------------------------------------------------
00049 // unitTest [-mpsDir=V1] [-netlibDir=V2] [-skipOsiSolverInterface]
00050 // 
00051 // where:
00052 //   -mpsDir: directory containing mps test files
00053 //       Default value V1="../Mps/Sample"    
00054 //   -netlibDir: directory containing netlib files
00055 //       Default value V2="../Mps/Netlib"
00056 //   -testOsiSolverInterface
00057 //       If specified, then OsiSolveInterface::unitTest
00058 //       is skipped over and not run.
00059 //
00060 // All parameters are optional.
00061 //----------------------------------------------------------------
00062 
00063 int main (int argc, const char *argv[])
00064 {
00065   int i;
00066 
00067 #ifdef COIN_USE_XPR
00068   OsiXprSolverInterface::setLogFileName("xprCallTrace.txt");
00069 #endif
00070 
00071   // define valid parameter keywords
00072   std::set<std::string> definedKeyWords;
00073   definedKeyWords.insert("-mpsDir");
00074   definedKeyWords.insert("-netlibDir");
00075   definedKeyWords.insert("-testOsiSolverInterface");
00076 
00077   // Create a map of parmater keys and associated data
00078   std::map<std::string,std::string> parms;
00079   for ( i=1; i<argc; i++ ) {
00080     std::string parm(argv[i]);
00081     std::string key,value;
00082     unsigned int  eqPos = parm.find('=');
00083 
00084     // Does parm contain and '='
00085     if ( eqPos==std::string::npos ) {
00086       //Parm does not contain '='
00087       key = parm;
00088     }
00089     else {
00090       key=parm.substr(0,eqPos);
00091       value=parm.substr(eqPos+1);
00092     }
00093 
00094     // Is specifed key valid?
00095     if ( definedKeyWords.find(key) == definedKeyWords.end() ) {
00096       // invalid key word.
00097       // Write help text
00098       std::cerr <<"Undefined parameter \"" <<key <<"\".\n";
00099       std::cerr <<"Correct usage: \n";
00100       std::cerr <<"  unitTest [-mpsDir=V1] [-netlibDir=V2] [-testOsiSolverInterface]\n";
00101       std::cerr <<"  where:\n";
00102       std::cerr <<"    -mpsDir: directory containing mps test files\n";
00103       std::cerr <<"        Default value V1=\"../Mps/Sample\"\n";
00104       std::cerr <<"    -netlibDir: directory containing netlib files\n";
00105       std::cerr <<"        Default value V2=\"../Mps/Netlib\"\n";
00106       std::cerr <<"    -testOsiSolverInterface\n";
00107       std::cerr <<"        If specified, then OsiSolveInterface::unitTest\n";
00108       std::cerr <<"        is run.\n";
00109       return 1;
00110     }
00111     parms[key]=value;
00112   }
00113   
00114   const char dirsep =  CoinFindDirSeparator();
00115   // Set directory containing mps data files.
00116   std::string mpsDir;
00117   if (parms.find("-mpsDir") != parms.end())
00118     mpsDir=parms["-mpsDir"] + dirsep;
00119   else 
00120     mpsDir = dirsep == '/' ? "../Mps/Sample/" : "..\\Mps\\Sample\\";
00121  
00122   // Set directory containing netlib data files.
00123   std::string netlibDir;
00124   if (parms.find("-netlibDir") != parms.end())
00125     netlibDir=parms["-netlibDir"] + dirsep;
00126   else 
00127     netlibDir = dirsep == '/' ? "../Mps/Netlib/" : "..\\Mps\\Netlib\\";
00128 
00129 #ifdef COIN_USE_OSL  
00130   {
00131     OsiOslSolverInterface oslSi;
00132     testingMessage( "Testing OsiRowCut with OsiOslSolverInterface\n" );
00133     OsiRowCutUnitTest(&oslSi,mpsDir);
00134   }
00135   {
00136     OsiOslSolverInterface oslSi;
00137     testingMessage( "Testing OsiColCut with OsiOslSolverInterface\n" );
00138     OsiColCutUnitTest(&oslSi,mpsDir);
00139   }
00140   {
00141     OsiOslSolverInterface oslSi;
00142     testingMessage( "Testing OsiRowCutDebugger with OsiOslSolverInterface\n" );
00143     OsiRowCutDebuggerUnitTest(&oslSi,mpsDir);
00144   }
00145   {
00146     OsiOslSolverInterface oslSi;
00147     testingMessage( "Testing OsiSimplexInterface with OsiOslSolverInterface\n" );
00148     OsiSimplexInterfaceCommonUnitTest(&oslSi,mpsDir);
00149   }
00150 
00151 #endif
00152 
00153 #ifdef COIN_USE_XPR  
00154   {
00155     OsiXprSolverInterface xprSi;
00156     testingMessage( "Testing OsiRowCut with OsiXprSolverInterface\n" );
00157     OsiRowCutUnitTest(&xprSi,mpsDir);
00158   }
00159   {
00160     OsiXprSolverInterface xprSi;
00161     testingMessage( "Testing OsiColCut with OsiXprSolverInterface\n" );
00162     OsiColCutUnitTest(&xprSi,mpsDir);
00163   }
00164   {
00165     OsiXprSolverInterface xprSi;
00166     testingMessage( "Testing OsiRowCutDebugger with OsiXprSolverInterface\n" );
00167     OsiRowCutDebuggerUnitTest(&xprSi,mpsDir);
00168   }
00169   {
00170     OsiXprSolverInterface xprSi;
00171     testingMessage( "Testing OsiSimplexInterface with OsiXprSolverInterface\n" );
00172     OsiSimplexInterfaceCommonUnitTest(&xprSi,mpsDir);
00173   }
00174 #endif
00175 
00176 #ifdef COIN_USE_CPX
00177   {
00178     OsiCpxSolverInterface cpxSi;
00179     testingMessage( "Testing OsiRowCut with OsiCpxSolverInterface\n" );
00180     OsiRowCutUnitTest(&cpxSi,mpsDir);
00181   }
00182   {
00183     OsiCpxSolverInterface cpxSi;
00184     testingMessage( "Testing OsiColCut with OsiCpxSolverInterface\n" );
00185     OsiColCutUnitTest(&cpxSi,mpsDir);
00186   }
00187   {
00188     OsiCpxSolverInterface cpxSi;
00189     testingMessage( "Testing OsiRowCutDebugger with OsiCpxSolverInterface\n" );
00190     OsiRowCutDebuggerUnitTest(&cpxSi,mpsDir);
00191   }
00192   {
00193     OsiCpxSolverInterface cpxSi;
00194     testingMessage( "Testing OsiSimplexInterface with OsiCpxSolverInterface\n" );
00195     OsiSimplexInterfaceCommonUnitTest(&cpxSi,mpsDir);
00196   }
00197 #endif
00198 
00199 #ifdef COIN_USE_SPX
00200   {
00201     OsiSpxSolverInterface spxSi;
00202     testingMessage( "Testing OsiRowCut with OsiSpxSolverInterface\n" );
00203     OsiRowCutUnitTest(&spxSi,mpsDir);
00204   }
00205   {
00206     OsiSpxSolverInterface spxSi;
00207     testingMessage( "Testing OsiColCut with OsiSpxSolverInterface\n" );
00208     OsiColCutUnitTest(&spxSi,mpsDir);
00209   }
00210   {
00211     OsiSpxSolverInterface spxSi;
00212     testingMessage( "Testing OsiRowCutDebugger with OsiSpxSolverInterface\n" );
00213     OsiRowCutDebuggerUnitTest(&spxSi,mpsDir);
00214   }
00215   {
00216     OsiSpxSolverInterface spxSi;
00217     testingMessage( "Testing OsiSimplexInterface with OsiSpxSolverInterface\n" );
00218     OsiSimplexInterfaceCommonUnitTest(&spxSi,mpsDir);
00219   }
00220 #endif
00221 
00222 #ifdef COIN_USE_VOL
00223   {
00224     OsiVolSolverInterface volSi;
00225     testingMessage( "Testing OsiRowCut with OsiVolSolverInterface\n" );
00226     OsiRowCutUnitTest(&volSi,mpsDir);
00227   }
00228   {
00229     OsiVolSolverInterface volSi;
00230     testingMessage( "Testing OsiColCut with OsiVolSolverInterface\n" );
00231     OsiColCutUnitTest(&volSi,mpsDir);
00232   }
00233 #endif
00234 
00235 #ifdef COIN_USE_DYLP
00236   {
00237     OsiDylpSolverInterface dylpSi;
00238     testingMessage( "Testing OsiRowCut with OsiDylpSolverInterface\n" );
00239     OsiRowCutUnitTest(&dylpSi,mpsDir);
00240   }
00241   {
00242     OsiDylpSolverInterface dylpSi;
00243     testingMessage( "Testing OsiColCut with OsiDylpSolverInterface\n" );
00244     OsiColCutUnitTest(&dylpSi,mpsDir);
00245   }
00246   {
00247     OsiDylpSolverInterface dylpSi;
00248     testingMessage( "Testing OsiRowCutDebugger with OsiDylpSolverInterface\n" );
00249     OsiRowCutDebuggerUnitTest(&dylpSi,mpsDir);
00250   }
00251   {
00252     OsiDylpSolverInterface dylpSi;
00253     testingMessage( "Testing OsiSimplexInterface with OsiDylpSolverInterface\n" );
00254     OsiSimplexInterfaceCommonUnitTest(&dylpSi,mpsDir);
00255   }
00256 #endif
00257 
00258 #ifdef COIN_USE_GLPK
00259   {
00260     OsiGlpkSolverInterface glpkSi;
00261     testingMessage( "Testing OsiRowCut with OsiGlpkSolverInterface\n" );
00262     OsiRowCutUnitTest(&glpkSi,mpsDir);
00263   }
00264   {
00265     OsiGlpkSolverInterface glpkSi;
00266     testingMessage( "Testing OsiColCut with OsiGlpkSolverInterface\n" );
00267     OsiColCutUnitTest(&glpkSi,mpsDir);
00268   }
00269   {
00270     OsiGlpkSolverInterface glpkSi;
00271     testingMessage( "Testing OsiRowCutDebugger with OsiGlpkSolverInterface\n" );
00272     OsiRowCutDebuggerUnitTest(&glpkSi,mpsDir);
00273   }
00274   {
00275     OsiGlpkSolverInterface glpkSi;
00276     testingMessage( "Testing OsiSimplexInterface with OsiGlpkSolverInterface\n" );
00277     OsiSimplexInterfaceCommonUnitTest(&glpkSi,mpsDir);
00278   }
00279 #endif
00280 
00281 #ifdef COIN_USE_CLP  
00282   {
00283     OsiClpSolverInterface clpSi;
00284     testingMessage( "Testing OsiRowCut with OsiClpSolverInterface\n" );
00285     OsiRowCutUnitTest(&clpSi,mpsDir);
00286   }
00287   {
00288     OsiClpSolverInterface clpSi;
00289     testingMessage( "Testing OsiColCut with OsiClpSolverInterface\n" );
00290     OsiColCutUnitTest(&clpSi,mpsDir);
00291   }
00292   {
00293     OsiClpSolverInterface clpSi;
00294     testingMessage( "Testing OsiRowCutDebugger with OsiClpSolverInterface\n" );
00295     OsiRowCutDebuggerUnitTest(&clpSi,mpsDir);
00296   }
00297   {
00298     OsiClpSolverInterface clpSi;
00299     testingMessage( "Testing OsiSimplexInterface with OsiClpSolverInterface\n" );
00300     OsiSimplexInterfaceCommonUnitTest(&clpSi,mpsDir);
00301   }
00302 #endif
00303 
00304   testingMessage( "Testing OsiCuts\n" );
00305   OsiCutsUnitTest();
00306 
00307 #ifdef COIN_USE_OSL
00308   testingMessage( "Testing OsiOslSolverInterface\n" );
00309   OsiOslSolverInterfaceUnitTest(mpsDir,netlibDir);
00310 #endif
00311 
00312 #ifdef COIN_USE_XPR
00313   testingMessage( "Testing OsiXprSolverInterface\n" );
00314   OsiXprSolverInterfaceUnitTest(mpsDir,netlibDir);
00315 #endif
00316 
00317 #ifdef COIN_USE_CPX
00318   testingMessage( "Testing OsiCpxSolverInterface\n" );
00319   OsiCpxSolverInterfaceUnitTest(mpsDir,netlibDir);
00320 #endif
00321 
00322 #ifdef COIN_USE_SPX
00323   testingMessage( "Testing OsiSpxSolverInterface\n" );
00324   OsiSpxSolverInterfaceUnitTest(mpsDir,netlibDir);
00325 #endif
00326 
00327 #ifdef COIN_USE_VOL
00328   testingMessage( "Testing OsiVolSolverInterface\n" );
00329   OsiVolSolverInterfaceUnitTest(mpsDir,netlibDir);
00330 #endif
00331 
00332 #ifdef COIN_USE_DYLP
00333   testingMessage( "Testing OsiDylpSolverInterface\n" );
00334   OsiDylpSolverInterfaceUnitTest(mpsDir,netlibDir);
00335 #endif
00336   
00337 #ifdef COIN_USE_GLPK
00338   testingMessage( "Testing OsiGlpkSolverInterface\n" );
00339   OsiGlpkSolverInterfaceUnitTest(mpsDir,netlibDir);
00340 #endif
00341   
00342 #ifdef COIN_USE_CLP
00343   testingMessage( "Testing OsiClpSolverInterface\n" );
00344   OsiClpSolverInterfaceUnitTest(mpsDir,netlibDir);
00345 #endif
00346 
00347   if (parms.find("-testOsiSolverInterface") != parms.end())
00348   {
00349     // Create vector of solver interfaces
00350     std::vector<OsiSolverInterface*> vecSi;
00351 #   if COIN_USE_OSL
00352     OsiSolverInterface * oslSi = new OsiOslSolverInterface;
00353     vecSi.push_back(oslSi);
00354 #endif
00355 #   if COIN_USE_XPR
00356     OsiSolverInterface * xprSi = new OsiXprSolverInterface;
00357     vecSi.push_back(xprSi);
00358 #endif
00359 #   if COIN_USE_CPX
00360     OsiSolverInterface * cpxSi = new OsiCpxSolverInterface;
00361     vecSi.push_back(cpxSi);
00362 #endif
00363 #   if COIN_USE_SPX
00364     OsiSolverInterface * spxSi = new OsiSpxSolverInterface;
00365     vecSi.push_back(spxSi);
00366 #endif
00367 #   if COIN_USE_CLP
00368     OsiSolverInterface * clpSi = new OsiClpSolverInterface;
00369     // Okay this is where John Forrest cheats by giving hints
00370     clpSi->setHintParam(OsiDoPresolveInInitial,true,OsiHintTry);
00371     vecSi.push_back(clpSi);
00372 #endif
00373 #   if COIN_USE_DYLP
00374     OsiSolverInterface * dylpSi = new OsiDylpSolverInterface;
00375     vecSi.push_back(dylpSi);
00376 #endif
00377 #   if COIN_USE_GLPK
00378     OsiSolverInterface * glpkSi = new OsiGlpkSolverInterface;
00379     vecSi.push_back(glpkSi);
00380 #endif
00381 #   if COIN_USE_VOL
00382     OsiSolverInterface * volSi = new OsiVolSolverInterface;
00383     vecSi.push_back(volSi);
00384 #endif
00385 
00386     testingMessage( "Testing OsiSolverInterface\n" );
00387     OsiSolverInterfaceMpsUnitTest(vecSi,netlibDir);
00388 
00389     unsigned int i;
00390     for (i=0; i<vecSi.size(); i++)
00391       delete vecSi[i];
00392   }
00393   else {
00394     testingMessage( "***Skipped Testing of OsiSolverInterface    ***\n" );
00395     testingMessage( "***use -testOsiSolverInterface to test class***\n" );
00396   }
00397 
00398   testingMessage( "All tests completed successfully\n" );
00399   return 0;
00400 }
00401 
00402  
00403 // Display message on stdout and stderr
00404 void testingMessage( const char * const msg )
00405 {
00406   std::cerr <<msg;
00407   //cout <<endl <<"*****************************************"
00408   //     <<endl <<msg <<endl;
00409 }
00410 

Generated on Wed Dec 3 14:35:36 2003 for Osi by doxygen 1.3.5