Changeset 1900


Ignore:
Timestamp:
Apr 10, 2013 9:30:07 AM (6 years ago)
Author:
forrest
Message:

fix some examples and a bug on repeated use of same CbcModel?

Location:
trunk/Cbc
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cbc/examples/CbcBranchLink.cpp

    r1898 r1900  
    458458// Creates a branching object
    459459CbcBranchingObject *
    460 CbcLink::createBranch(int way)
     460CbcLink::createCbcBranch(OsiSolverInterface * /*solver*/, const OsiBranchingInformation * /*info*/, int way)
    461461{
    462462  int j;
  • trunk/Cbc/examples/CbcBranchLink.hpp

    r1574 r1900  
    5858  virtual void feasibleRegion();
    5959  /// Creates a branching object
    60   virtual CbcBranchingObject * createBranch(int way) ;
     60  virtual CbcBranchingObject * createCbcBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) ;
    6161
    6262  /// Number of members
  • trunk/Cbc/examples/sample4.cpp

    r1898 r1900  
    2626/************************************************************************
    2727
    28 This main program reads in an SOSr model (ltw) from an mps file.
     28This main program reads in an SOS model (rgn) from an mps file.
    2929
    3030It then solves it three ways :-
     
    3232a) As normal
    3333b) SOS 1
    34 c) SOS 2(so answer will be different)
     34c) SOS 2 (so answer will be different)
    3535
    3636************************************************************************/
     
    4646  model.solver()->setHintParam(OsiDoReducePrint,true,OsiHintTry);
    4747
    48   // Read in ltw.mps
    49   // and assert that it is a clean model
    50   int numMpsReadErrors = model.solver()->readMps("./ltw.mps","");
     48  // Read in rgn.mps
     49  std::string mpsFileName;
     50#if defined(MIPLIB3DIR)
     51  mpsFileName = MIPLIB3DIR "/rgn";
     52#else
     53  if (argc < 2) {
     54    fprintf(stderr, "Do not know where to find miplib3 MPS files.\n");
     55    exit(1);
     56  }
     57#endif
     58  if (argc>=2) mpsFileName = argv[1];
     59  int numMpsReadErrors = model.solver()->readMps(mpsFileName.c_str(),"");
    5160  if( numMpsReadErrors != 0 )
    5261  {
     
    7988  }
    8089
    81  
     90  if (numberColumns!=180 || numberIntegers!=100) {
     91    printf("Incorrect model for example\n");
     92    exit(1);
     93  }
     94
    8295  double time1 = CoinCpuTime() ;
    8396
    8497  model.branchAndBound();
    8598
    86   std::cout<<"ltw.mps"<<" took "<<CoinCpuTime()-time1<<" seconds, "
     99  std::cout<<"rgn.mps"<<" took "<<CoinCpuTime()-time1<<" seconds, "
    87100           <<model.getNodeCount()<<" nodes with objective "
    88101           <<model.getObjValue()
     
    108121  model = model2;
    109122
     123  // Convert slacks to variables
     124  CoinBigIndex start[5]={0,1,2,3,4};
     125  int row[4]={0,1,2,3};
     126  double element[4]={1.0,1.0,1.0,1.0};
     127  double up[4]={1.0,1.0,1.0,1.0};
     128  model.solver()->addCols(4,start,row,element,NULL,up,NULL);
    110129  // Now use SOS1
    111   int numberSets=8;
    112   int which[28]={20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,
    113                  39,40,41,42,43,44,45,46,47};
    114   double weights[]={1.0,2.0,3.0,4.0,5.0};
    115   int starts[]={0,2,4,6,8,13,18,23,28};
    116   CbcObject ** objects = new CbcObject * [numberSets];
     130  int numberSets=4;
     131  int which[104];
     132  double weights[104];
     133  int starts[5];
     134  // load
     135  int n=0;
     136  starts[0]=0;
     137  for (int iSet=0;iSet<4;iSet++) {
     138    for (int i=0;i<25;i++) {
     139      weights[n]=i+1.0;
     140      which[n]=iSet*25+i;
     141      n++;
     142    }
     143    // slack - make sure first branch is on slack
     144    weights[n]=1000.0;
     145    which[n]=180+iSet;
     146    n++;
     147    starts[iSet+1]=n;
     148  }
    117149  for (i=0;i<numberIntegers;i++) {
    118150    int iColumn = integerVariable[i];
     
    120152    model.solver()->setContinuous(iColumn);
    121153  }
     154  // save model in this state
     155  CbcModel modelSOS = model;
     156  CbcObject ** objects = new CbcObject * [numberSets];
    122157  for (i=0;i<numberSets;i++) {
    123158    objects[i]= new CbcSOS(&model,starts[i+1]-starts[i],which+starts[i],
     
    133168  model.branchAndBound();
    134169
    135   std::cout<<"ltw.mps"<<" took "<<CoinCpuTime()-time1<<" seconds, "
     170  std::cout<<"rgn.mps"<<" took "<<CoinCpuTime()-time1<<" seconds, "
    136171           <<model.getNodeCount()<<" nodes with objective "
    137172           <<model.getObjValue()
     
    155190
    156191
    157   // Restore model
    158   model = model2;
     192  // Restore SOS model
     193  model = modelSOS;
    159194
    160195// Now use SOS2
    161196  objects = new CbcObject * [numberSets];
    162   for (i=0;i<numberIntegers;i++) {
    163     int iColumn = integerVariable[i];
    164     // Stop being integer
    165     model.solver()->setContinuous(iColumn);
    166   }
    167197  for (i=0;i<numberSets;i++) {
    168198    objects[i]= new CbcSOS(&model,starts[i+1]-starts[i],which+starts[i],
     
    178208  model.branchAndBound();
    179209
    180   std::cout<<"ltw.mps"<<" took "<<CoinCpuTime()-time1<<" seconds, "
     210  std::cout<<"rgn.mps"<<" took "<<CoinCpuTime()-time1<<" seconds, "
    181211           <<model.getNodeCount()<<" nodes with objective "
    182212           <<model.getObjValue()
  • trunk/Cbc/src/CbcModel.cpp

    r1889 r1900  
    62656265    maximumDepthActual_ = 0;
    62666266    numberDJFixed_ = 0.0;
    6267     delete probingInfo_;
    6268     probingInfo_ = NULL;
     6267    if (probingInfo_) {
     6268      delete probingInfo_;
     6269      probingInfo_ = NULL;
     6270      // also get rid of cut generator
     6271      int n=0;
     6272      for (int i = 0; i < numberCutGenerators_; i++) {
     6273        CglImplication * cutGen;
     6274        cutGen = dynamic_cast<CglImplication *>(generator_[i]->generator());
     6275        if (!cutGen) {
     6276          generator_[n]=generator_[i];
     6277          virginGenerator_[n]=virginGenerator_[i];
     6278          n++;
     6279        } else {
     6280          cutGen->setProbingInfo(NULL);
     6281          delete generator_[i];
     6282          cutGen = dynamic_cast<CglImplication *>(virginGenerator_[i]->generator());
     6283          assert (cutGen);
     6284          cutGen->setProbingInfo(NULL);
     6285          delete virginGenerator_[i];
     6286        }
     6287      }
     6288      numberCutGenerators_=n;
     6289    }
    62696290    maximumStatistics_ = 0;
    62706291    delete [] analyzeResults_;
  • trunk/Cbc/src/CbcSOS.cpp

    r1899 r1900  
    222222                // Could change to #ifdef CBC_DEBUG
    223223#ifndef NDEBUG
    224                 if (model_->messageHandler()->logLevel() > 2)
     224                if (model_->messageHandler()->logLevel() > 2 &&
     225                    value > upper[iColumn] + integerTolerance)
    225226                    printf("** Variable %d (%d) has value %g and upper bound of %g\n",
    226227                           iColumn, j, value, upper[iColumn]);
Note: See TracChangeset for help on using the changeset viewer.