Changeset 734 for branches


Ignore:
Timestamp:
Aug 9, 2007 4:52:04 PM (12 years ago)
Author:
ladanyi
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/BSP/trunk/Cbc/src/unitTestClp.cpp

    r708 r734  
    187187  return solveOptions;
    188188}
     189
    189190//----------------------------------------------------------------
    190 // unitTest [-mpsDir=V1] [-netlibDir=V2] [-test]
    191 //
    192 // where:
    193 //   -mpsDir: directory containing mps test files
    194 //       Default value V1="../../Data/Sample"   
    195 //   -netlibDir: directory containing netlib files
    196 //       Default value V2="../../Data/Netlib"
    197 //   -test
    198 //       If specified, then netlib test set run
    199 //
    200 // All parameters are optional.
     191static void usage()
     192{
     193  std::cerr <<"Correct usage for running clp in testing mode: \n"
     194            <<"  clp <-unitTest | -netlib> -directory DIR"
     195            <<"    where:\n"
     196            <<"      -unitTest or -netlib specifies whether a small sample should be run\n"
     197            <<"          or the full set pf netlib problems.\n"
     198            <<"          One of them must be specified.\n"
     199            <<"      -directory: directory containing mps test files\n"
     200            <<"                  Must be specified.n";
     201}
     202
    201203//----------------------------------------------------------------
    202204int mainTest (int argc, const char *argv[],int algorithm,
    203205              ClpSimplex empty, bool doPresolve, int switchOffValue,bool doVector)
    204206{
    205   int i;
    206 
    207207  if (switchOffValue>0) {
    208208    // switch off some
     
    216216  }
    217217
    218   // define valid parameter keywords
    219   std::set<std::string> definedKeyWords;
    220   definedKeyWords.insert("-mpsDir");
    221   definedKeyWords.insert("-netlibDir");
    222   definedKeyWords.insert("-netlib");
    223 
    224   // Create a map of parameter keys and associated data
    225   std::map<std::string,std::string> parms;
    226   for ( i=1; i<argc; i++ ) {
    227     std::string parm(argv[i]);
    228     std::string key,value;
    229     unsigned int  eqPos = parm.find('=');
    230 
    231     // Does parm contain and '='
    232     if ( eqPos==std::string::npos ) {
    233       //Parm does not contain '='
    234       key = parm;
    235     }
    236     else {
    237       key=parm.substr(0,eqPos);
    238       value=parm.substr(eqPos+1);
    239     }
    240 
    241     // Is specifed key valid?
    242     if ( definedKeyWords.find(key) == definedKeyWords.end() ) {
    243       // invalid key word.
    244       // Write help text
    245       std::cerr <<"Undefined parameter \"" <<key <<"\".\n";
    246       std::cerr <<"Correct usage: \n";
    247       std::cerr <<"  unitTest [-mpsDir=V1] [-netlibDir=V2] [-test[=V3]]\n";
    248       std::cerr <<"  where:\n";
    249       std::cerr <<"    -mpsDir: directory containing mps test files\n";
    250       std::cerr <<"        Default value V1=\"../../Data/Sample\"\n";
    251       std::cerr <<"    -netlibDir: directory containing netlib files\n";
    252       std::cerr <<"        Default value V2=\"../../Data/Netlib\"\n";
    253       std::cerr <<"    -test\n";
    254       std::cerr <<"        If specified, then netlib testset run.\n";
    255       std::cerr <<"        If V3 then taken as single file\n";
    256       return 1;
    257     }
    258     parms[key]=value;
     218  bool netlib = false;
     219  bool singleprob = empty.numberRows() > 0;
     220
     221  if (argc != 4) {
     222    usage();
     223    return 1;
    259224  }
    260225 
     226  if (strncmp(argv[1], "-unitTest", 9) == 0) {
     227    netlib = false;
     228  } else if (strncmp(argv[1], "-netlib", 7) == 0) {
     229    netlib = true;
     230  } else {
     231    usage();
     232    return 1;
     233  }
     234 
     235  if (strncmp(argv[2], "-directory", 9) != 0) {
     236    usage();
     237    return 1;
     238  }
    261239  const char dirsep =  CoinFindDirSeparator();
    262240  // Set directory containing mps data files.
    263   std::string mpsDir;
    264   if (parms.find("-mpsDir") != parms.end())
    265     mpsDir=parms["-mpsDir"] + dirsep;
    266   else
    267     mpsDir = dirsep == '/' ? "../../Data/Sample/" : "..\\..\\Data\\Sample\\";
    268  
    269   // Set directory containing netlib data files.
    270   std::string netlibDir;
    271   if (parms.find("-netlibDir") != parms.end())
    272     netlibDir=parms["-netlibDir"] + dirsep;
    273   else
    274     netlibDir = dirsep == '/' ? "../../Data/Netlib/" : "..\\..\\Data\\Netlib\\";
    275   if (!empty.numberRows()) {
    276     testingMessage( "Testing ClpSimplex\n" );
    277     ClpSimplexUnitTest(mpsDir,netlibDir);
    278   }
    279   if (parms.find("-netlib") != parms.end()||empty.numberRows())
    280   {
     241  std::string directory(argv[3]);
     242  directory += dirsep;
     243
     244  if (!netlib) {
     245    testingMessage( "Testing clp -unitTest\n" );
     246    ClpSimplexUnitTest(directory);
     247  }
     248
     249  if (netlib) {
    281250    unsigned int m;
    282251   
     
    294263    // 100 added means no presolve
    295264    std::vector<int> bestStrategy;
    296     if(empty.numberRows()) {
     265
     266    if (singleprob) {
     267      testingMessage( "Testing clp on a single netlib problemx\n" );
     268      // Just testing one
     269      mpsName.push_back(empty.problemName());min.push_back(true);nRows.push_back(-1);
     270      nCols.push_back(-1);objValueTol.push_back(1.e-10);
     271      objValue.push_back(0.0);bestStrategy.push_back(0);
     272      int iTest;
    297273      std::string alg;
    298       for (int iTest=0;iTest<NUMBER_ALGORITHMS;iTest++) {
     274      for (iTest=0;iTest<NUMBER_ALGORITHMS;iTest++) {
    299275        ClpSolve solveOptions=setupForSolve(iTest,alg,0);
    300276        printf("%d %s ",iTest,alg.c_str());
     
    306282          printf("will be tested\n");
    307283      }
    308     }
    309     if (!empty.numberRows()) {
     284    } else {
     285      testingMessage( "Testing clp -netlibx\n" );
    310286      mpsName.push_back("25fv47");
    311287      min.push_back(true);
     
    409385      mpsName.push_back("wood1p");min.push_back(true);nRows.push_back(245);nCols.push_back(2594);objValueTol.push_back(5.e-5);objValue.push_back(1.4429024116e+00);bestStrategy.push_back(3);
    410386      mpsName.push_back("woodw");min.push_back(true);nRows.push_back(1099);nCols.push_back(8405);objValueTol.push_back(1.e-10);objValue.push_back(1.3044763331E+00);bestStrategy.push_back(3);
    411     } else {
    412       // Just testing one
    413       mpsName.push_back(empty.problemName());min.push_back(true);nRows.push_back(-1);
    414       nCols.push_back(-1);objValueTol.push_back(1.e-10);
    415       objValue.push_back(0.0);bestStrategy.push_back(0);
    416       int iTest;
    417       std::string alg;
    418       for (iTest=0;iTest<NUMBER_ALGORITHMS;iTest++) {
    419         ClpSolve solveOptions=setupForSolve(iTest,alg,0);
    420         printf("%d %s ",iTest,alg.c_str());
    421         if (switchOff[iTest])
    422           printf("skipped by user\n");
    423         else if(solveOptions.getSolveType()==ClpSolve::notImplemented)
    424           printf("skipped as not available\n");
    425         else
    426           printf("will be tested\n");
    427       }
    428387    }
    429388
     
    437396
    438397      ClpSimplex solutionBase=empty;
    439       std::string fn = netlibDir+mpsName[m];
     398      std::string fn = directory+mpsName[m];
    440399      if (!empty.numberRows()||algorithm<6) {
    441400        // Read data mps file,
     
    582541    printf("Total time %g seconds\n",timeTaken);
    583542  }
    584   else {
    585     testingMessage( "***Skipped Testing on netlib    ***\n" );
    586     testingMessage( "***use -netlib to test class***\n" );
    587   }
    588543 
    589544  testingMessage( "All tests completed successfully\n" );
     
    603558// test factorization methods and simplex method and simple barrier
    604559void
    605 ClpSimplexUnitTest(const std::string & mpsDir,
    606                    const std::string & netlibDir)
     560ClpSimplexUnitTest(const std::string & directory)
    607561{
    608562 
     
    725679  {   
    726680    CoinMpsIO m;
    727     std::string fn = mpsDir+"exmip1";
     681    std::string fn = directory+"exmip1";
    728682    m.readMps(fn.c_str(),"mps");
    729683    ClpSimplex solution;
     
    745699  {   
    746700    CoinMpsIO m;
    747     std::string fn = mpsDir+"exmip1";
     701    std::string fn = directory+"exmip1";
    748702    //fn = "Test/subGams4";
    749703    m.readMps(fn.c_str(),"mps");
     
    794748  {   
    795749    CoinMpsIO m;
    796     std::string fn = mpsDir+"exmip1";
     750    std::string fn = directory+"exmip1";
    797751    m.readMps(fn.c_str(),"mps");
    798752    ClpSimplex model;
     
    853807  {   
    854808    CoinMpsIO m;
    855     std::string fn = mpsDir+"exmip1";
     809    std::string fn = directory+"exmip1";
    856810    m.readMps(fn.c_str(),"mps");
    857811    ClpSimplex model;
     
    956910  {   
    957911    CoinMpsIO m;
    958     std::string fn = netlibDir+"finnis";
     912    std::string fn = directory+"finnis";
    959913    int returnCode = m.readMps(fn.c_str(),"mps");
    960914    if (returnCode) {
    961915      // probable cause is that gz not there
    962       fprintf(stderr,"Unable to open finnis.mps in Data/Netlib!\n");
     916      fprintf(stderr,"Unable to open finnis.mps in %s!\n", directory.c_str());
    963917      fprintf(stderr,"Most probable cause is finnis.mps is gzipped i.e. finnis.mps.gz and libz has not been activated\n");
    964918      fprintf(stderr,"Either gunzip files or edit Makefiles/Makefile.location to get libz\n");
     
    986940  {   
    987941    CoinMpsIO m;
    988     std::string fn = netlibDir+"afiro";
     942    std::string fn = directory+"afiro";
    989943    m.readMps(fn.c_str(),"mps");
    990944    ClpSimplex solution;
     
    10731027  {   
    10741028    CoinMpsIO m;
    1075     std::string fn = netlibDir+"brandy";
     1029    std::string fn = directory+"brandy";
    10761030    m.readMps(fn.c_str(),"mps");
    10771031    ClpSimplex solution;
     
    11451099  {   
    11461100    CoinMpsIO m;
    1147     std::string fn = netlibDir+"brandy";
     1101    std::string fn = directory+"brandy";
    11481102    m.readMps(fn.c_str(),"mps");
    11491103    ClpSimplex solution;
     
    12341188  {   
    12351189    CoinMpsIO m;
    1236     std::string fn = netlibDir+"brandy";
     1190    std::string fn = directory+"brandy";
    12371191    m.readMps(fn.c_str(),"mps");
    12381192    ClpSimplex solution;
     
    14131367  {
    14141368    CoinMpsIO m;
    1415     std::string fn = mpsDir+"exmip1";
     1369    std::string fn = directory+"exmip1";
    14161370    m.readMps(fn.c_str(),"mps");
    14171371    ClpInterior solution;
     
    14251379#define QUADRATIC
    14261380  if (1) {   
    1427     std::string fn = mpsDir+"input.130";
     1381    std::string fn = directory+"input.130";
    14281382    int numberColumns;
    14291383    int numberRows;
     
    14311385    FILE * fp = fopen(fn.c_str(),"r");
    14321386    if (!fp) {
    1433       // Try in Data
    1434       fn = "Data/Sample/input.130";
    1435       fp = fopen(fn.c_str(),"r");
    1436     }
    1437     if (!fp) {
    1438       fprintf(stderr,"Unable to open file input.130 in mpsDir or Data/Sample directory\n");
     1387      fprintf(stderr,"Unable to open file input.130 in directory %s\n",
     1388              directory.c_str());
    14391389    } else {
    14401390      int problem;
     
    16021552  if (1) {   
    16031553    CoinMpsIO m;
    1604     std::string fn = mpsDir+"exmip1";
     1554    std::string fn = directory+"exmip1";
    16051555    m.readMps(fn.c_str(),"mps");
    16061556    ClpSimplex solution;
     
    16731623  if (1) {   
    16741624    CoinMpsIO m;
    1675     std::string fn = mpsDir+"share2qp";
     1625    std::string fn = directory+"share2qp";
    16761626    //fn = "share2qpb";
    16771627    m.readMps(fn.c_str(),"mps");
Note: See TracChangeset for help on using the changeset viewer.