Changeset 737


Ignore:
Timestamp:
Aug 9, 2007 11:30:39 PM (12 years ago)
Author:
ladanyi
Message:

Got rid of dependency on Data/... except for Sample

Location:
branches/BSP/trunk/Cbc
Files:
4 edited

Legend:

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

    r388 r737  
    14781478              int nFields=1;
    14791479              fields[0]="fake main for miplib";
     1480              std::string dirfield="-miplibDir=";
    14801481              if (directory!="./") {
    1481                 fields[1]=("-miplibDir="+directory).c_str();
     1482                dirfield+=directory.c_str();
     1483                fields[1]=dirfield.c_str();
    14821484                nFields=2;
    14831485              }
  • branches/BSP/trunk/Cbc/src/unitTestClp.cpp

    r734 r737  
    187187  return solveOptions;
    188188}
    189 
    190189//----------------------------------------------------------------
    191 static 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 
     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.
    203201//----------------------------------------------------------------
    204202int mainTest (int argc, const char *argv[],int algorithm,
    205203              ClpSimplex empty, bool doPresolve, int switchOffValue,bool doVector)
    206204{
     205  int i;
     206
    207207  if (switchOffValue>0) {
    208208    // switch off some
     
    216216  }
    217217
    218   bool netlib = false;
    219   bool singleprob = empty.numberRows() > 0;
    220 
    221   if (argc != 4) {
    222     usage();
    223     return 1;
     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;
    224259  }
    225260 
    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   }
    239261  const char dirsep =  CoinFindDirSeparator();
    240262  // Set directory containing mps data files.
    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) {
     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  {
    250281    unsigned int m;
    251282   
     
    263294    // 100 added means no presolve
    264295    std::vector<int> bestStrategy;
    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;
     296    if(empty.numberRows()) {
    273297      std::string alg;
    274       for (iTest=0;iTest<NUMBER_ALGORITHMS;iTest++) {
     298      for (int iTest=0;iTest<NUMBER_ALGORITHMS;iTest++) {
    275299        ClpSolve solveOptions=setupForSolve(iTest,alg,0);
    276300        printf("%d %s ",iTest,alg.c_str());
     
    282306          printf("will be tested\n");
    283307      }
    284     } else {
    285       testingMessage( "Testing clp -netlibx\n" );
     308    }
     309    if (!empty.numberRows()) {
    286310      mpsName.push_back("25fv47");
    287311      min.push_back(true);
     
    385409      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);
    386410      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      }
    387428    }
    388429
     
    396437
    397438      ClpSimplex solutionBase=empty;
    398       std::string fn = directory+mpsName[m];
     439      std::string fn = netlibDir+mpsName[m];
    399440      if (!empty.numberRows()||algorithm<6) {
    400441        // Read data mps file,
     
    541582    printf("Total time %g seconds\n",timeTaken);
    542583  }
     584  else {
     585    testingMessage( "***Skipped Testing on netlib    ***\n" );
     586    testingMessage( "***use -netlib to test class***\n" );
     587  }
    543588 
    544589  testingMessage( "All tests completed successfully\n" );
     
    558603// test factorization methods and simplex method and simple barrier
    559604void
    560 ClpSimplexUnitTest(const std::string & directory)
     605ClpSimplexUnitTest(const std::string & mpsDir,
     606                   const std::string & netlibDir)
    561607{
    562608 
     
    679725  {   
    680726    CoinMpsIO m;
    681     std::string fn = directory+"exmip1";
     727    std::string fn = mpsDir+"exmip1";
    682728    m.readMps(fn.c_str(),"mps");
    683729    ClpSimplex solution;
     
    699745  {   
    700746    CoinMpsIO m;
    701     std::string fn = directory+"exmip1";
     747    std::string fn = mpsDir+"exmip1";
    702748    //fn = "Test/subGams4";
    703749    m.readMps(fn.c_str(),"mps");
     
    748794  {   
    749795    CoinMpsIO m;
    750     std::string fn = directory+"exmip1";
     796    std::string fn = mpsDir+"exmip1";
    751797    m.readMps(fn.c_str(),"mps");
    752798    ClpSimplex model;
     
    807853  {   
    808854    CoinMpsIO m;
    809     std::string fn = directory+"exmip1";
     855    std::string fn = mpsDir+"exmip1";
    810856    m.readMps(fn.c_str(),"mps");
    811857    ClpSimplex model;
     
    910956  {   
    911957    CoinMpsIO m;
    912     std::string fn = directory+"finnis";
     958    std::string fn = mpsDir+"finnis";
    913959    int returnCode = m.readMps(fn.c_str(),"mps");
    914960    if (returnCode) {
    915961      // probable cause is that gz not there
    916       fprintf(stderr,"Unable to open finnis.mps in %s!\n", directory.c_str());
     962      fprintf(stderr,"Unable to open finnis.mps in %s!\n", mpsDir.c_str());
    917963      fprintf(stderr,"Most probable cause is finnis.mps is gzipped i.e. finnis.mps.gz and libz has not been activated\n");
    918964      fprintf(stderr,"Either gunzip files or edit Makefiles/Makefile.location to get libz\n");
     
    940986  {   
    941987    CoinMpsIO m;
    942     std::string fn = directory+"afiro";
     988    std::string fn = mpsDir+"afiro";
    943989    m.readMps(fn.c_str(),"mps");
    944990    ClpSimplex solution;
     
    10271073  {   
    10281074    CoinMpsIO m;
    1029     std::string fn = directory+"brandy";
     1075    std::string fn = mpsDir+"brandy";
    10301076    m.readMps(fn.c_str(),"mps");
    10311077    ClpSimplex solution;
     
    10991145  {   
    11001146    CoinMpsIO m;
    1101     std::string fn = directory+"brandy";
     1147    std::string fn = mpsDir+"brandy";
    11021148    m.readMps(fn.c_str(),"mps");
    11031149    ClpSimplex solution;
     
    11881234  {   
    11891235    CoinMpsIO m;
    1190     std::string fn = directory+"brandy";
     1236    std::string fn = mpsDir+"brandy";
    11911237    m.readMps(fn.c_str(),"mps");
    11921238    ClpSimplex solution;
     
    13671413  {
    13681414    CoinMpsIO m;
    1369     std::string fn = directory+"exmip1";
     1415    std::string fn = mpsDir+"exmip1";
    13701416    m.readMps(fn.c_str(),"mps");
    13711417    ClpInterior solution;
     
    13791425#define QUADRATIC
    13801426  if (1) {   
    1381     std::string fn = directory+"input.130";
     1427    std::string fn = mpsDir+"input.130";
    13821428    int numberColumns;
    13831429    int numberRows;
     
    13851431    FILE * fp = fopen(fn.c_str(),"r");
    13861432    if (!fp) {
    1387       fprintf(stderr,"Unable to open file input.130 in directory %s\n",
    1388               directory.c_str());
     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");
    13891439    } else {
    13901440      int problem;
     
    15521602  if (1) {   
    15531603    CoinMpsIO m;
    1554     std::string fn = directory+"exmip1";
     1604    std::string fn = mpsDir+"exmip1";
    15551605    m.readMps(fn.c_str(),"mps");
    15561606    ClpSimplex solution;
     
    16231673  if (1) {   
    16241674    CoinMpsIO m;
    1625     std::string fn = directory+"share2qp";
     1675    std::string fn = mpsDir+"share2qp";
    16261676    //fn = "share2qpb";
    16271677    m.readMps(fn.c_str(),"mps");
  • branches/BSP/trunk/Cbc/test/Makefile.am

    r640 r737  
    2727
    2828test_cbc: ../src/cbc$(EXEEXT)
    29         cd ../../Data/Netlib; make uncompress
    30         cd ../../Data/miplib3; make uncompress
    31         ../src/cbc$(EXEEXT) -unitTest -netlib -miplib
     29        if test x"$(MIPLIBDIR)" != x; then \
     30                ../src/clp$(EXEEXT) -unitTest -directory $(MIPLIBDIR) -miplib; \
     31        else \
     32                ../src/clp$(EXEEXT) -unitTest; \
     33        fi
    3234
    3335test_cbc_generic: ../src/cbc-generic$(EXEEXT)
    3436        echo "A minimal test is all that cbc-generic can manage just yet."
    3537        ../src/cbc-generic$(EXEEXT) \
    36             -directory ../../Data/miplib3 -import p0033 -branch
     38            -directory ../../Data/Sample -import p0033 -branch
    3739
    3840.PHONY: test
  • branches/BSP/trunk/Cbc/test/Makefile.in

    r710 r737  
    437437
    438438test_cbc: ../src/cbc$(EXEEXT)
    439         cd ../../Data/Netlib; make uncompress
    440         cd ../../Data/miplib3; make uncompress
    441         ../src/cbc$(EXEEXT) -unitTest -netlib -miplib
     439        if test x"$(MIPLIBDIR)" != x; then \
     440                ../src/clp$(EXEEXT) -unitTest -directory $(MIPLIBDIR) -miplib; \
     441        else \
     442                ../src/clp$(EXEEXT) -unitTest; \
     443        fi
    442444
    443445test_cbc_generic: ../src/cbc-generic$(EXEEXT)
    444446        echo "A minimal test is all that cbc-generic can manage just yet."
    445447        ../src/cbc-generic$(EXEEXT) \
    446             -directory ../../Data/miplib3 -import p0033 -branch
     448            -directory ../../Data/Sample -import p0033 -branch
    447449
    448450.PHONY: test
Note: See TracChangeset for help on using the changeset viewer.