Changeset 13


Ignore:
Timestamp:
Nov 17, 2004 11:26:56 AM (17 years ago)
Author:
forrest
Message:

CbcCompareActual?.cpp added + cut stuff for subtrees

Location:
trunk
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/CbcBranchActual.cpp

    r11 r13  
    666666
    667667  double nearest = floor(value+0.5);
    668   double integerTolerance =
    669     model_->getDblParam(CbcModel::CbcIntegerTolerance);
     668  //double integerTolerance =
     669  //model_->getDblParam(CbcModel::CbcIntegerTolerance);
    670670  // Scaling may have moved it a bit
    671   assert (fabs(value-nearest)<=100.0*integerTolerance);
     671  //assert (fabs(value-nearest)<=100.0*integerTolerance);
     672  assert (fabs(value-nearest)<=0.01);
    672673  solver->setColLower(columnNumber_,nearest);
    673674  solver->setColUpper(columnNumber_,nearest);
     
    19331934// As some computation is needed in more than one place - returns row
    19341935int
    1935 CbcFollowOn::gutsOfFollowOn(int & otherRow) const
     1936CbcFollowOn::gutsOfFollowOn(int & otherRow, int & preferredWay) const
    19361937{
    19371938  int whichRow=-1;
     
    19981999    CoinSort_2(isort,isort+nSort,sort);
    19992000    CoinZeroN(isort,numberRows);
     2001    double * other = new double[numberRows];
     2002    CoinZeroN(other,numberRows);
    20002003    int * which = new int[numberRows];
     2004    //#define COUNT
     2005#ifndef COUNT
     2006    bool beforeSolution = model_->getSolutionCount()==0;
     2007#endif
    20012008    for (int k=0;k<nSort-1;k++) {
    20022009      i=sort[k];
     
    20072014        int iColumn = column[j];
    20082015        if (columnLower[iColumn]!=columnUpper[iColumn]) {
    2009           double solValue = solution[iColumn];
     2016          double solValue = solution[iColumn]-columnLower[iColumn];
    20102017          if (solValue<1.0-integerTolerance&&solValue>integerTolerance) {
    20112018            numberUnsatisfied++;
     
    20132020              int iRow = row[jj];
    20142021              if (rhs_[iRow]) {
     2022                other[iRow]+=solValue;
    20152023                if (isort[iRow]) {
    20162024                  isort[iRow]++;
     
    20242032        }
    20252033      }
     2034      double total=0.0;
    20262035      assert (numberUnsatisfied==isort[i]);
    2027       // find one nearest half
     2036      // find one nearest half if solution, one if before solution
    20282037      int iBest=-1;
     2038      double dtarget=0.5*total;
     2039#ifdef COUNT
    20292040      int target = (numberUnsatisfied+1)>>1;
    20302041      int best=numberUnsatisfied;
     2042#else
     2043      double best;
     2044      if (beforeSolution)
     2045        best=dtarget;
     2046      else
     2047        best=1.0e30;
     2048#endif
    20312049      for (j=0;j<n;j++) {
    20322050        int iRow = which[j];
     2051        double dvalue=other[iRow];
     2052        other[iRow]=0.0;
     2053#ifdef COUNT
    20332054        int value = isort[iRow];
     2055#endif
    20342056        isort[iRow]=0;
     2057        if (dvalue<integerTolerance||dvalue>1.0-integerTolerance)
     2058          continue;
     2059#ifdef COUNT
    20352060        if (abs(value-target)<best&&value!=numberUnsatisfied) {
    20362061          best=abs(value-target);
    20372062          iBest=iRow;
     2063          if (dvalue<dtarget)
     2064            preferredWay=1;
     2065          else
     2066            preferredWay=-1;
    20382067        }
     2068#else
     2069        if (beforeSolution) {
     2070          if (fabs(dvalue-dtarget)>best) {
     2071            best = fabs(dvalue-dtarget);
     2072            iBest=iRow;
     2073            if (dvalue<dtarget)
     2074              preferredWay=1;
     2075            else
     2076              preferredWay=-1;
     2077          }
     2078        } else {
     2079          if (fabs(dvalue-dtarget)<best) {
     2080            best = fabs(dvalue-dtarget);
     2081            iBest=iRow;
     2082            if (dvalue<dtarget)
     2083              preferredWay=1;
     2084            else
     2085              preferredWay=-1;
     2086          }
     2087        }
     2088#endif
    20392089      }
    20402090      if (iBest>=0) {
     
    20452095    }
    20462096    delete [] which;
     2097    delete [] other;
    20472098  }
    20482099  delete [] sort;
     
    20562107{
    20572108  int otherRow=0;
    2058   int whichRow = gutsOfFollowOn(otherRow);
    2059   preferredWay=-1;
     2109  int whichRow = gutsOfFollowOn(otherRow,preferredWay);
    20602110  if (whichRow<0)
    20612111    return 0.0;
     
    20762126{
    20772127  int otherRow=0;
    2078   int whichRow = gutsOfFollowOn(otherRow);
    2079   assert(way==-1);
     2128  int preferredWay;
     2129  int whichRow = gutsOfFollowOn(otherRow,preferredWay);
     2130  assert(way==preferredWay);
    20802131  assert (whichRow>=0);
    20812132  int numberColumns = matrix_.getNumCols();
  • trunk/CbcBranchCut.cpp

    r11 r13  
    505505  CbcCutBranchingObject * newObject =
    506506    new CbcCutBranchingObject(model_,down,up);
    507   printf("creating cut in CbcBranchCut\n");
     507  if (model_->messageHandler()->logLevel()>1)
     508    printf("creating cut in CbcBranchCut\n");
    508509  return newObject;
    509510}
     
    516517  int returnCode=0;
    517518  OsiSolverInterface * solver = model_->solver();
     519  int numberRows = solver->getNumRows();
     520  if (numberRows!=matrixByRow_.getNumRows())
     521    return 0;
    518522  const double * solution = model_->currentSolution();
    519523  const double * lower = solver->getColLower();
     
    574578    bool someToDoYet=false;
    575579    int numberColumns = solver->getNumCols();
    576     int numberRows = solver->getNumRows();
    577580    char * mark = new char[numberColumns];
    578581    int numberFixed=0;
  • trunk/CbcCutGenerator.cpp

    r6 r13  
    2121    whenCutGenerator_(-1),
    2222    whenCutGeneratorInSub_(-100),
     23    depthCutGenerator_(-1),
     24    depthCutGeneratorInSub_(-1),
    2325    generatorName_(NULL),
    2426    normal_(true),
     
    3234// Normal constructor
    3335CbcCutGenerator::CbcCutGenerator(CbcModel * model,CglCutGenerator * generator,
    34                   int howOften, const char * name,
    35                   bool normal, bool atSolution,
    36                   bool infeasible, int howOftenInSub)
    37   :  numberTimes_(0),
    38      numberCuts_(0),
    39      numberCutsActive_(0)
     36                                 int howOften, const char * name,
     37                                 bool normal, bool atSolution,
     38                                 bool infeasible, int howOftenInSub,
     39                                 int whatDepth, int whatDepthInSub)
     40  :
     41    depthCutGenerator_(whatDepth),
     42    depthCutGeneratorInSub_(whatDepthInSub),
     43    numberTimes_(0),
     44    numberCuts_(0),
     45    numberCutsActive_(0)
    4046{
    4147  model_ = model;
     
    6167  whenCutGenerator_=rhs.whenCutGenerator_;
    6268  whenCutGeneratorInSub_ = rhs.whenCutGeneratorInSub_;
     69  depthCutGenerator_=rhs.depthCutGenerator_;
     70  depthCutGeneratorInSub_ = rhs.depthCutGeneratorInSub_;
    6371  generatorName_=strdup(rhs.generatorName_);
    6472  normal_=rhs.normal_;
     
    8290    whenCutGenerator_=rhs.whenCutGenerator_;
    8391    whenCutGeneratorInSub_ = rhs.whenCutGeneratorInSub_;
     92    depthCutGenerator_=rhs.depthCutGenerator_;
     93    depthCutGeneratorInSub_ = rhs.depthCutGeneratorInSub_;
    8494    generatorName_=strdup(rhs.generatorName_);
    8595    normal_=rhs.normal_;
     
    134144    depth=0;
    135145  int pass=model_->getCurrentPassNumber()-1;
    136   if (fullScan||(model_->getNodeCount()%howOften)==0) {
     146  bool doThis=(model_->getNodeCount()%howOften)==0;
     147  if (depthCutGenerator_>0)
     148    doThis = (depth % depthCutGenerator_) ==0;
     149  // But turn off if 100
     150  if (howOften==100)
     151    doThis=false;
     152  if (fullScan||doThis) {
    137153    incrementNumberTimesEntered();
    138154    CglProbing* generator =
     
    192208  whenCutGenerator_ = howOften;
    193209}
     210void
     211CbcCutGenerator::setWhatDepth(int value)
     212{
     213  depthCutGenerator_ = value;
     214}
     215void
     216CbcCutGenerator::setWhatDepthInSub(int value)
     217{
     218  depthCutGeneratorInSub_ = value;
     219}
  • trunk/CbcModel.cpp

    r11 r13  
    386386*/
    387387  status_ = 0 ;
     388  phase_=0;
    388389/*
    389390  Scan the variables, noting the integer variables. Create an
     
    517518  TODO: If numberUnsatisfied == 0, don't we have a solution?
    518519*/
     520  phase_=1;
    519521  int iCutGenerator;
    520522  for (iCutGenerator = 0;iCutGenerator<numberCutGenerators_;iCutGenerator++) {
     
    577579      currentNode_=&fakeNode;
    578580    }
     581    phase_=3;
    579582    while (anyAction == -1)
    580583    { anyAction = newNode->chooseBranch(this,NULL) ;
     
    848851  in which case solveWithCuts() will make the adjustment.
    849852*/
     853      phase_=2;
    850854      cuts = OsiCuts() ;
    851855      currentNumberCuts = solver_->getNumRows()-numberRowsAtContinuous_ ;
     
    11071111  if (bestSolution_)
    11081112  { setCutoff(1.0e50) ; // As best solution should be worse than cutoff
     1113    phase_=5;
    11091114    setBestSolution(CBC_SOLUTION,bestObjective_,bestSolution_,true) ;
    11101115    continuousSolver_->resolve() ;
     
    12101215  numberRowsAtContinuous_(0),
    12111216  maximumNumberCuts_(0),
     1217  phase_(0),
    12121218  currentNumberCuts_(0),
    12131219  maximumDepth_(0),
     
    12811287  numberRowsAtContinuous_(0),
    12821288  maximumNumberCuts_(0),
     1289  phase_(0),
    12831290  currentNumberCuts_(0),
    12841291  maximumDepth_(0),
     
    15511558  numberRowsAtContinuous_ = rhs.numberRowsAtContinuous_;
    15521559  maximumNumberCuts_=rhs.maximumNumberCuts_;
     1560  phase_ = rhs.phase_;
    15531561  currentNumberCuts_=rhs.currentNumberCuts_;
    15541562  maximumDepth_= rhs.maximumDepth_;
     
    17291737    numberRowsAtContinuous_ = rhs.numberRowsAtContinuous_;
    17301738    maximumNumberCuts_=rhs.maximumNumberCuts_;
     1739    phase_ = rhs.phase_;
    17311740    currentNumberCuts_=rhs.currentNumberCuts_;
    17321741    maximumDepth_= rhs.maximumDepth_;
     
    18691878                          int howOften, const char * name,
    18701879                          bool normal, bool atSolution,
    1871                           bool whenInfeasible,int howOftenInSub)
     1880                          bool whenInfeasible,int howOftenInSub,
     1881                          int whatDepth, int whatDepthInSub)
    18721882{
    18731883  CbcCutGenerator ** temp = generator_;
     
    18771887  generator_[numberCutGenerators_]=
    18781888    new CbcCutGenerator(this,generator, howOften, name,
    1879                         normal,atSolution,whenInfeasible,howOftenInSub);
     1889                        normal,atSolution,whenInfeasible,howOftenInSub,
     1890                        whatDepth, whatDepthInSub);
    18801891  // and before any cahnges
    18811892  temp = virginGenerator_;
     
    18851896  virginGenerator_[numberCutGenerators_++]=
    18861897    new CbcCutGenerator(this,generator, howOften, name,
    1887                         normal,atSolution,whenInfeasible,howOftenInSub);
     1898                        normal,atSolution,whenInfeasible,howOftenInSub,
     1899                        whatDepth, whatDepthInSub);
    18881900                                                         
    18891901}
     
    22352247*/
    22362248  if (onOptimalPath && !solver_->isDualObjectiveLimitReached()) {
    2237     if (!feasible)
     2249    if (!feasible) {
    22382250      solver_->writeMps("infeas");
     2251      CoinWarmStartBasis *slack =
     2252        dynamic_cast<CoinWarmStartBasis *>(solver_->getEmptyWarmStart()) ;
     2253      solver_->setWarmStart(slack);
     2254      delete slack ;
     2255      solver_->setHintParam(OsiDoReducePrint,false,OsiHintDo,0) ;
     2256      solver_->initialSolve();
     2257    }
    22392258    assert(feasible) ;
    22402259  }
     
    23662385      delete nextRowCut_;
    23672386      nextRowCut_=NULL;
    2368       printf("applying branch cut, sum is %g, bounds %g %g\n",sum,lb,ub);
     2387      if (handler_->logLevel()>1)
     2388        printf("applying branch cut, sum is %g, bounds %g %g\n",sum,lb,ub);
    23692389      // set whichgenerator (also serves as marker to say don't delete0
    23702390      whichGenerator[numberViolated++]=-2;
     
    24782498*/
    24792499    if (found >= 0)
    2480     { setBestSolution(CBC_ROUNDING,heuristicValue,newSolution) ; }
     2500    {
     2501      phase_=4;
     2502      setBestSolution(CBC_ROUNDING,heuristicValue,newSolution) ; }
    24812503    delete [] newSolution ;
    24822504
     
    29382960      { // save which generator did it
    29392961        whichGenerator[k++] = whichGenerator[i] ; } }
     2962    delete ws ;
    29402963    for (i = numberNewToDelete-1 ; i >= 0 ; i--)
    29412964    { int iCut = newCutIndices[i] ;
     
    29572980#     endif
    29582981      if (allowResolve)
    2959       { solver_->resolve() ;
     2982      {
     2983        phase_=3;
     2984        solver_->resolve() ;
    29602985        if (solver_->getIterationCount() == 0)
    29612986        { needPurge = false ; }
     
    29742999  Clean up and return.
    29753000*/
    2976   delete ws ;
    29773001  delete [] solverCutIndices ;
    29783002  delete [] newCutIndices ;
     
    43914415        const int * originalColumns = pinfo.originalColumns();
    43924416        // just slot in new solver
    4393         OsiClpSolverInterface * temp = new OsiClpSolverInterface(model2);
     4417        OsiClpSolverInterface * temp = new OsiClpSolverInterface(model2,true);
    43944418        numberColumns = temp->getNumCols();
    43954419        for (iColumn=0;iColumn<originalNumberColumns;iColumn++)
     
    44034427        setCutoff(cutoff);
    44044428        deleteObjects();
     4429        if (!numberObjects_) {
     4430          // Nothing left
     4431          doIntegerPresolve=false;
     4432          weak=true;
     4433          break;
     4434        }
    44054435        synchronizeModel(); // make sure everything that needs solver has it
    44064436        // just point to solver_
     
    45354565    int numberColumns = getNumCols();
    45364566    int numberOtherColumns = presolvedModel->getNumCols();
    4537     bestSolution_ = new double[numberColumns];
     4567    //bestSolution_ = new double[numberColumns];
    45384568    // set up map
    45394569    int * back = new int[numberColumns];
     
    45464576    // set ones in presolved model to values
    45474577    double * otherSolution = presolvedModel->bestSolution_;
    4548     const double * lower = getColLower();
     4578    //const double * lower = getColLower();
    45494579    for (i=0;i<numberIntegers_;i++) {
    45504580      iColumn = integerVariable_[i];
    45514581      int jColumn = back[iColumn];
    4552       bestSolution_[iColumn]=lower[iColumn];
     4582      //bestSolution_[iColumn]=lower[iColumn];
    45534583      if (jColumn >= 0) {
    45544584        double value=floor(otherSolution[jColumn]+0.5);
    45554585        solver_->setColLower(iColumn,value);
    45564586        solver_->setColUpper(iColumn,value);
    4557         bestSolution_[iColumn]=value;
     4587        //bestSolution_[iColumn]=value;
    45584588      }
    45594589    }
     4590    delete [] back;
    45604591#if 0
    45614592    // ** looks as if presolve needs more intelligence
     
    45864617    }
    45874618#endif
    4588     // solve problem
    4589     resolve();
    4590     // should be feasible
    4591     int numberIntegerInfeasibilities;
    4592     int numberObjectInfeasibilities;
    4593     if (!currentSolution_)
    4594       currentSolution_ = new double[numberColumns] ;
    4595     assert(feasibleSolution(numberIntegerInfeasibilities,
    4596                             numberObjectInfeasibilities));
     4619    if (bestSolution_) {
     4620      // solve problem
     4621      resolve();
     4622      // should be feasible
     4623      int numberIntegerInfeasibilities;
     4624      int numberObjectInfeasibilities;
     4625      if (!currentSolution_)
     4626        currentSolution_ = new double[numberColumns] ;
     4627      assert(feasibleSolution(numberIntegerInfeasibilities,
     4628                              numberObjectInfeasibilities));
     4629    }
    45974630  } else {
    45984631    bestSolution_=NULL;
     
    46984731  }
    46994732  CbcModel model(*solver);
     4733  // off some messages
     4734  if (handler_->logLevel()<=1) {
     4735    model.messagesPointer()->setDetailMessage(3,9);
     4736    model.messagesPointer()->setDetailMessage(3,6);
     4737    model.messagesPointer()->setDetailMessage(3,4);
     4738    model.messagesPointer()->setDetailMessage(3,1);
     4739    model.messagesPointer()->setDetailMessage(3,3007);
     4740  }
    47004741  double cutoff = getCutoff();
    47014742  model.setCutoff(cutoff);
    47024743  // integer presolve
    47034744  CbcModel * model2 = model.integerPresolve(false);
    4704   if (!model2) {
     4745  if (!model2||!model2->getNumRows()) {
     4746    delete model2;
    47054747    delete solver;
    47064748    return 2;
    47074749  }
    4708   printf("Reduced model has %d rows and %d columns\n",
    4709          model2->getNumRows(),model2->getNumCols());
     4750  if (handler_->logLevel()>1)
     4751    printf("Reduced model has %d rows and %d columns\n",
     4752           model2->getNumRows(),model2->getNumCols());
    47104753  // Do complete search
    47114754 
     
    47154758    if (howOften>-100) {
    47164759      CbcCutGenerator * generator = virginGenerator_[i];
    4717       CglCutGenerator * cglGenerator = generator->generator()->clone();
     4760      CglCutGenerator * cglGenerator = generator->generator();
    47184761      model2->addCutGenerator(cglGenerator,howOften,
    47194762                              generator->cutGeneratorName(),
     
    47214764                              generator->atSolution(),
    47224765                              generator->whenInfeasible(),
    4723                               -100);
     4766                              -100, generator->whatDepthInSub(),-1);
    47244767    }
    47254768  }
     
    47384781  model2->branchAndBound();
    47394782  delete model2->nodeComparison();
     4783  if (model2->getMinimizationObjValue()>cutoff) {
     4784    // no good
     4785    delete model2;
     4786    delete solver;
     4787    return 2;
     4788  }
    47404789  // get back solution
    47414790  model.originalModel(model2,false);
    47424791  delete model2;
    47434792  int status;
    4744   if (model.getMinimizationObjValue()<cutoff) {
     4793  if (model.getMinimizationObjValue()<cutoff&&model.bestSolution()) {
    47454794    double objValue = model.getObjValue();
    47464795    const double * solution = model.bestSolution();
  • trunk/CbcNode.cpp

    r11 r13  
    737737    for (;iFull>=nPartial;iFull--) {
    738738      CoinWarmStartBasis::Status status = ws->getArtifStatus(--iCompact);
    739       assert (status != CoinWarmStartBasis::basic);
     739      //assert (status != CoinWarmStartBasis::basic); // may be permanent cut
    740740      expanded->setArtifStatus(iFull,status);
    741741    }
  • trunk/Makefile.Cbc

    r2 r13  
    2020LIBSRC += CbcBranchActual.cpp
    2121LIBSRC += CbcBranchLotsize.cpp
     22LIBSRC += CbcBranchCut.cpp
     23LIBSRC += CbcCompareActual.cpp
    2224LIBSRC += CbcCutGenerator.cpp
    2325LIBSRC += Cbc_C_Interface.cpp
  • trunk/include/CbcBranchActual.hpp

    r11 r13  
    728728  virtual CbcBranchingObject * createBranch(int way) const;
    729729  /// As some computation is needed in more than one place - returns row
    730   int gutsOfFollowOn(int & otherRow) const;
     730  int gutsOfFollowOn(int & otherRow, int & preferredWay) const;
    731731
    732732protected:
  • trunk/include/CbcCompareActual.hpp

    r6 r13  
    1515#include "CbcNode.hpp"
    1616#include "CbcCompareBase.hpp"
    17 
     17class CbcModel;
    1818// This is default before first solution
    1919class CbcCompareDepth : public CbcCompareBase{
    2020public:
    2121  // Default Constructor
    22   CbcCompareDepth () {test_=this;};
     22  CbcCompareDepth () ;
    2323
    24   ~CbcCompareDepth() {};
     24  ~CbcCompareDepth();
    2525  // Copy constructor
    26   CbcCompareDepth ( const CbcCompareDepth &rhs)
    27     : CbcCompareBase(rhs)
    28   {};
     26  CbcCompareDepth ( const CbcCompareDepth &rhs);
    2927   
    3028  // Assignment operator
    31   CbcCompareDepth & operator=( const CbcCompareDepth& rhs)
    32   {  if (this!=&rhs) { CbcCompareBase::operator=(rhs);}
    33   return *this;
    34   };
     29  CbcCompareDepth & operator=( const CbcCompareDepth& rhs);
    3530
    3631  /// Clone
    37   virtual CbcCompareBase * clone() const
    38   { return new CbcCompareDepth (*this);
    39   }
     32  virtual CbcCompareBase * clone() const;
    4033
    4134  // This returns true if the depth of node y is greater than depth of node x
    42   virtual bool test (CbcNode * x, CbcNode * y) {
    43     return x->depth() < y->depth();
    44   }
     35  virtual bool test (CbcNode * x, CbcNode * y);
    4536};
    4637class CbcCompareObjective  : public CbcCompareBase {
    4738public:
    4839  // Default Constructor
    49   CbcCompareObjective () {test_=this;};
     40  CbcCompareObjective ();
    5041
    51   virtual ~CbcCompareObjective() {};
     42  virtual ~CbcCompareObjective();
    5243  // Copy constructor
    53   CbcCompareObjective ( const CbcCompareObjective &rhs)
    54     : CbcCompareBase(rhs)
    55   {};
     44  CbcCompareObjective ( const CbcCompareObjective &rhs);
    5645   
    5746  // Assignment operator
    58   CbcCompareObjective & operator=( const CbcCompareObjective& rhs)
    59   {  if (this!=&rhs) { CbcCompareBase::operator=(rhs);
    60   }
    61   return *this;
    62   };
     47  CbcCompareObjective & operator=( const CbcCompareObjective& rhs);
    6348
    6449  /// Clone
    65   virtual CbcCompareBase * clone() const
    66   { return new CbcCompareObjective (*this);
    67   }
    68 
     50  virtual CbcCompareBase * clone() const;
    6951
    7052  /* This returns true if objective value of node y is less than
    7153     objective value of node x */
    72   virtual bool test (CbcNode * x, CbcNode * y) {
    73     return x->objectiveValue() > y->objectiveValue();
    74   }
     54  virtual bool test (CbcNode * x, CbcNode * y);
    7555};
    7656/* This is an example of a more complex rule with data
     
    8161class CbcCompareDefault  : public CbcCompareBase {
    8262public:
     63  // Default Constructor
     64  CbcCompareDefault () ;
     65  // Constructor with weight
     66  CbcCompareDefault (double weight);
     67
     68  // Copy constructor
     69  CbcCompareDefault ( const CbcCompareDefault &rhs);
     70   
     71  // Assignment operator
     72  CbcCompareDefault & operator=( const CbcCompareDefault& rhs);
     73
     74  /// Clone
     75  virtual CbcCompareBase * clone() const;
     76
     77  ~CbcCompareDefault() ;
     78  /* This returns true if weighted value of node y is less than
     79     weighted value of node x */
     80  virtual bool test (CbcNode * x, CbcNode * y) ;
     81  // This allows method to change behavior as it is called
     82  // after each solution
     83  virtual void newSolution(CbcModel * model,
     84                           double objectiveAtContinuous,
     85                           int numberInfeasibilitiesAtContinuous) ;
     86  // This allows method to change behavior
     87  virtual void every1000Nodes(CbcModel * model, int numberNodes);
     88
     89  inline double getWeight() const
     90  { return weight_;};
     91  inline void setWeight(double weight)
     92  { weight_ = weight;};
     93protected:
    8394  // Weight for each infeasibility
    8495  double weight_;
    85   // Default Constructor
    86   CbcCompareDefault () : weight_(0.0) {test_=this;};
    87   // Constructor with weight
    88   CbcCompareDefault (double weight) : weight_(weight) {test_=this;};
    89 
    90   // Copy constructor
    91   CbcCompareDefault ( const CbcCompareDefault &rhs)
    92     : CbcCompareBase(rhs)
    93   {};
    94    
    95   // Assignment operator
    96   CbcCompareDefault & operator=( const CbcCompareDefault& rhs)
    97   {  if (this!=&rhs) { CbcCompareBase::operator=(rhs);
    98 }
    99   return *this;
    100   };
    101 
    102   /// Clone
    103   virtual CbcCompareBase * clone() const
    104   { return new CbcCompareDefault (*this);
    105   }
    106 
    107   ~CbcCompareDefault() {};
    108   /* This returns true if weighted value of node y is less than
    109      weighted value of node x */
    110   virtual bool test (CbcNode * x, CbcNode * y) {
    111     return x->objectiveValue()+ weight_*x->numberUnsatisfied() >
    112       y->objectiveValue() + weight_*y->numberUnsatisfied();
    113   }
    114   double getWeight() const
    115   { return weight_;};
    116   void setWeight(double weight)
    117   { weight_ = weight;};
     96  // Number of solutions
     97  int numberSolutions_;
    11898};
    11999
     
    123103public:
    124104  // Default Constructor
    125   CbcCompareEstimate () {test_=this;};
    126   ~CbcCompareEstimate() {};
     105  CbcCompareEstimate () ;
     106  ~CbcCompareEstimate() ;
    127107  // Copy constructor
    128   CbcCompareEstimate ( const CbcCompareEstimate &rhs)
    129     : CbcCompareBase(rhs)
    130   {};
     108  CbcCompareEstimate ( const CbcCompareEstimate &rhs);
    131109   
    132110  // Assignment operator
    133   CbcCompareEstimate & operator=( const CbcCompareEstimate& rhs)
    134   {  if (this!=&rhs) { CbcCompareBase::operator=(rhs);
    135 }
    136   return *this;
    137   };
     111  CbcCompareEstimate & operator=( const CbcCompareEstimate& rhs);
    138112
    139113  /// Clone
    140   virtual CbcCompareBase * clone() const
    141   { return new CbcCompareEstimate (*this);
    142   }
     114  virtual CbcCompareBase * clone() const;
    143115
    144   virtual bool test (CbcNode * x, CbcNode * y) {
    145     return x->guessedObjectiveValue() >  y->guessedObjectiveValue() ;
    146   }
     116  virtual bool test (CbcNode * x, CbcNode * y) ;
    147117};
    148118
  • trunk/include/CbcCompareBase.hpp

    r6 r13  
    1919class CbcCompareBase {
    2020public:
    21   CbcCompareBase * test_;
    2221  // Default Constructor
    2322  CbcCompareBase () {test_=NULL;};
     
    5857    return test(x,y);
    5958  }
     59protected:
     60  CbcCompareBase * test_;
    6061};
    6162class CbcCompare {
  • trunk/include/CbcCutGenerator.hpp

    r5 r13  
    7777                  int howOften=1, const char * name=NULL,
    7878                  bool normal=true, bool atSolution=false,
    79                   bool infeasible=false,int howOftenInsub=-100);
     79                  bool infeasible=false,int howOftenInsub=-100,
     80                  int whatDepth=-1, int whatDepthInSub=-1);
    8081 
    8182  /// Copy constructor
     
    124125  inline int howOftenInSub() const
    125126  { return whenCutGeneratorInSub_;};
     127
     128  /** Set the cut generation depth
     129
     130    Set the depth criterion for calls to the Cgl object's
     131    \p generateCuts routine.  Only active if > 0.
     132
     133    If whenCutGenerator is positive and this is positive then this overrides. 
     134    If whenCutGenerator is -1 then this is used as criterion if any cuts
     135    were generated at root node.
     136    If whenCutGenerator is anything else this is ignored.
     137  */
     138  void setWhatDepth(int value) ;
     139  /// Set the cut generation depth in sub tree
     140  void setWhatDepthInSub(int value) ;
     141  /// Get the cut generation depth criterion.
     142  inline int whatDepth() const
     143  { return depthCutGenerator_;};
     144  /// Get the cut generation depth criterion.in sub tree
     145  inline int whatDepthInSub() const
     146  { return depthCutGeneratorInSub_;};
    126147
    127148  /// Get whether the cut generator should be called in the normal place
     
    189210  int whenCutGeneratorInSub_;
    190211
     212  /** Depth at which to call the CglCutGenerator::generateCuts
     213     routine (If >0 then overrides when and is called if depth%depthCutGenerator==0).
     214  */
     215  int depthCutGenerator_;
     216
     217  /** Depth at which to call the CglCutGenerator::generateCuts
     218     routine (If >0 then overrides when and is called if depth%depthCutGenerator==0).
     219     In sub tree.
     220  */
     221  int depthCutGeneratorInSub_;
     222
    191223  /// Name of generator
    192224  char * generatorName_;
  • trunk/include/CbcModel.hpp

    r6 r13  
    748748  void setSolutionCount(int value)
    749749  { numberSolutions_=value;};
     750  /** Current phase (so heuristics etc etc can find out).
     751      0 - initial solve
     752      1 - solve with cuts at root
     753      2 - solve with cuts
     754      3 - other e.g. strong branching
     755      4 - trying to validate a solution
     756      5 - at end of search
     757  */
     758  inline int phase() const
     759  { return phase_;};
    750760 
    751761  /// Get number of heuristic solutions
     
    936946      meaning as positive but they may be switched off (-> -100) by code if
    937947      not many cuts generated at continuous.  -99 is just done at root.
    938       Name is just for printout
     948      Name is just for printout.
     949      If depth >0 overrides how often generator is called (if howOften==-1 or >0).
    939950  */
    940951  void addCutGenerator(CglCutGenerator * generator,
    941                   int howOften=1, const char * name=NULL,
    942                   bool normal=true, bool atSolution=false,
    943                   bool infeasible=false,int howOftenInSub=-100);
    944   //@}
     952                       int howOften=1, const char * name=NULL,
     953                       bool normal=true, bool atSolution=false,
     954                       bool infeasible=false,int howOftenInSub=-100,
     955                       int whatDepth=-1, int whatDepthInSub=-1);
     956//@}
    945957
    946958  /** \name Heuristics and priorities */
     
    11451157  /// Maximum number of cuts
    11461158  int maximumNumberCuts_;
     1159  /** Current phase (so heuristics etc etc can find out).
     1160      0 - initial solve
     1161      1 - solve with cuts at root
     1162      2 - solve with cuts
     1163      3 - other e.g. strong branching
     1164      4 - trying to validate a solution
     1165      5 - at end of search
     1166  */
     1167  int phase_;
    11471168
    11481169  /// Number of entries in #addedCuts_
Note: See TracChangeset for help on using the changeset viewer.