Changeset 97


Ignore:
Timestamp:
Mar 31, 2005 4:42:42 PM (15 years ago)
Author:
forrest
Message:

for OsiCbc?

Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/CbcBranchActual.cpp

    r74 r97  
    21892189  //printf("way %d\n",way);
    21902190  // create object
     2191  //printf("would fix %d down and %d up\n",nDown,nUp);
    21912192  CbcBranchingObject * branch
    21922193     = new CbcFixingBranchingObject(model_,way,
     
    22702271    printf("Down Fix ");
    22712272#endif
     2273    //printf("Down Fix %d\n",numberDown_);
    22722274    for (i=0;i<numberDown_;i++) {
    22732275      int iColumn = downList_[i];
     
    22822284    printf("Up Fix ");
    22832285#endif
     2286    //printf("Up Fix %d\n",numberUp_);
    22842287    for (i=0;i<numberUp_;i++) {
    22852288      int iColumn = upList_[i];
  • trunk/CbcCompareActual.cpp

    r27 r97  
    113113  : CbcCompareBase(),
    114114    weight_(-1.0),
     115    saveWeight_(0.0),
    115116    numberSolutions_(0),
    116117    treeSize_(0)
     
    123124  : CbcCompareBase(),
    124125    weight_(weight) ,
     126    saveWeight_(0.0),
    125127    numberSolutions_(0),
    126128    treeSize_(0)
     
    136138{
    137139  weight_=rhs.weight_;
     140  saveWeight_ = rhs.saveWeight_;
    138141  numberSolutions_=rhs.numberSolutions_;
    139142  treeSize_ = rhs.treeSize_;
     
    154157    CbcCompareBase::operator=(rhs);
    155158    weight_=rhs.weight_;
     159    saveWeight_ = rhs.saveWeight_;
    156160    numberSolutions_=rhs.numberSolutions_;
    157161    treeSize_ = rhs.treeSize_;
     
    169173CbcCompareDefault::test (CbcNode * x, CbcNode * y)
    170174{
     175#if 0
     176  // was
    171177  if (weight_<0.0||treeSize_>100000) {
    172178    // before solution
     
    185191      y->objectiveValue() + weight_*y->numberUnsatisfied();
    186192  }
     193#else
     194  if (weight_==-1.0) {
     195    // before solution
     196    /* printf("x %d %d %g, y %d %d %g\n",
     197       x->numberUnsatisfied(),x->depth(),x->objectiveValue(),
     198       y->numberUnsatisfied(),y->depth(),y->objectiveValue()); */
     199    if (x->numberUnsatisfied() > y->numberUnsatisfied())
     200      return true;
     201    else if (x->numberUnsatisfied() < y->numberUnsatisfied())
     202      return false;
     203    else
     204      return x->depth() < y->depth();
     205  } else {
     206    // after solution
     207    double weight = CoinMax(weight_,0.0);
     208    return x->objectiveValue()+ weight*x->numberUnsatisfied() >
     209      y->objectiveValue() + weight*y->numberUnsatisfied();
     210  }
     211#endif
    187212}
    188213// This allows method to change behavior as it is called
     
    208233CbcCompareDefault::every1000Nodes(CbcModel * model, int numberNodes)
    209234{
     235#if 0
     236  // was
    210237  if (numberNodes>10000)
    211238    weight_ =0.0; // this searches on objective
    212239  // get size of tree
    213240  treeSize_ = model->tree()->size();
     241#else
     242  if (numberNodes>10000)
     243    weight_ =0.0; // this searches on objective
     244  else if (numberNodes==1000&&weight_==-2.0)
     245    weight_=-1.0; // Go to depth first
     246  // get size of tree
     247  treeSize_ = model->tree()->size();
     248  if (treeSize_>10000) {
     249    // set weight to reduce size most of time
     250    if (treeSize_>20000)
     251      weight_=-1.0;
     252    else if ((numberNodes%4000)!=0)
     253      weight_=-1.0;
     254    else
     255      weight_=saveWeight_;
     256  }
     257#endif
    214258  return numberNodes==11000; // resort if first time
    215259}
  • trunk/CbcModel.cpp

    r96 r97  
    1919#include "CbcHeuristic.hpp"
    2020#include "CbcModel.hpp"
     21#include "CbcStrategy.hpp"
    2122#include "CbcMessage.hpp"
    2223#include "OsiRowCut.hpp"
     
    376377
    377378{
     379  // Set up strategies
     380  if (strategy_) {
     381    strategy_->setupCutGenerators(*this);
     382    strategy_->setupHeuristics(*this);
     383    strategy_->setupPrinting(*this);
     384    strategy_->setupOther(*this);
     385  }
    378386# ifdef CBC_DEBUG
    379387  std::string problemName ;
     
    489497  (problems which require further exploration).
    490498*/
    491   CbcCompareObjective compareObjective ;
    492   CbcCompareDepth compareDepth ;
    493   CbcCompareDefault compareDefault ;
    494   if (!nodeCompare_)
    495     tree_->setComparison(compareDefault) ;
    496   else
    497     tree_->setComparison(*nodeCompare_) ;
     499  tree_->setComparison(*nodeCompare_) ;
    498500/*
    499501  Used to record the path from a node to the root of the search tree, so that
     
    728730      // Do from deepest
    729731      tree_->cleanTree(this, getCutoff(),bestPossibleObjective_) ;
    730       if (!nodeCompare_) {
    731         if (!compareDefault.getWeight()) {
    732           // set to get close to this
    733           double costPerInteger =
    734             (bestObjective_-continuousObjective_)/
    735             ((double) continuousInfeasibilities_) ;
    736           compareDefault.setWeight(0.98*costPerInteger) ;
    737           /*printf("Setting weight per infeasibility to %g\n",
    738             0.98*costPerInteger);*/
    739         }
    740         tree_->setComparison(compareDefault) ;
    741         //tree_->setComparison(compareObjective) ;
    742       } else {
    743         nodeCompare_->newSolution(this) ;
    744         nodeCompare_->newSolution(this,continuousObjective_,
    745                                   continuousInfeasibilities_) ;
    746         tree_->setComparison(*nodeCompare_) ;
    747       }
     732      nodeCompare_->newSolution(this) ;
     733      nodeCompare_->newSolution(this,continuousObjective_,
     734                                continuousInfeasibilities_) ;
     735      tree_->setComparison(*nodeCompare_) ;
    748736      if (tree_->empty())
    749737        break; // finished
     
    756744    + print a summary line to let the user know we're working
    757745*/
    758     if ((numberNodes_%1000) == 0&&nodeCompare_) {
     746    if ((numberNodes_%1000) == 0) {
    759747      bool redoTree=nodeCompare_->every1000Nodes(this, numberNodes_) ;
    760748      // redo tree if wanted
     
    12971285  dblParam_[CbcMaximumSeconds] = 1.0e100;
    12981286  dblParam_[CbcStartSeconds] = 0.0;
    1299   nodeCompare_=NULL;
     1287  nodeCompare_=new CbcCompareDefault();;
    13001288  tree_= new CbcTree();
    13011289  branchingMethod_=NULL;
     1290  strategy_=NULL;
     1291  parentModel_=NULL;
    13021292  appData_=NULL;
    13031293  handler_ = new CoinMessageHandler();
     
    13711361  dblParam_[CbcStartSeconds] = 0.0;
    13721362
    1373   nodeCompare_=NULL;
     1363  nodeCompare_=new CbcCompareDefault();;
    13741364  tree_= new CbcTree();
    13751365  branchingMethod_=NULL;
     1366  strategy_=NULL;
     1367  parentModel_=NULL;
    13761368  appData_=NULL;
    13771369  handler_ = new CoinMessageHandler();
     
    15761568    originalColumns_=NULL;
    15771569  }
    1578   nodeCompare_=rhs.nodeCompare_;
     1570  nodeCompare_=rhs.nodeCompare_->clone();
    15791571  tree_= rhs.tree_->clone();
    15801572  branchingMethod_=rhs.branchingMethod_;
     1573  if (rhs.strategy_)
     1574    strategy_=rhs.strategy_->clone();
     1575  else
     1576    strategy_=NULL;
     1577  parentModel_=rhs.parentModel_;
    15811578  appData_=rhs.appData_;
    15821579  messages_ = rhs.messages_;
     
    17861783      originalColumns_=NULL;
    17871784    }
    1788     nodeCompare_=rhs.nodeCompare_;
     1785    nodeCompare_=rhs.nodeCompare_->clone();
    17891786    delete tree_;
    17901787    tree_= rhs.tree_->clone();
    17911788    branchingMethod_=rhs.branchingMethod_;
     1789    delete strategy_;
     1790    if (rhs.strategy_)
     1791      strategy_=rhs.strategy_->clone();
     1792    else
     1793      strategy_=NULL;
     1794    parentModel_=rhs.parentModel_;
    17921795    appData_=rhs.appData_;
    17931796
     
    18651868  delete [] heuristic_;
    18661869  heuristic_=NULL;
     1870  delete nodeCompare_;
     1871  nodeCompare_=NULL;
    18671872  delete [] addedCuts_;
    18681873  addedCuts_=NULL;
     
    18791884  delete [] originalColumns_;
    18801885  originalColumns_=NULL;
     1886  delete strategy_;
    18811887}
    18821888// Are there a numerical difficulties?
     
    53235329  return CoinMin(bestPossibleObjective_,bestObjective_) * solver_->getObjSense() ;
    53245330}
     5331// Make given rows (L or G) into global cuts and remove from lp
     5332void
     5333CbcModel::makeGlobalCuts(int number,const int * which)
     5334{
     5335  const double * rowLower = solver_->getRowLower();
     5336  const double * rowUpper = solver_->getRowUpper();
     5337
     5338  int numberRows = solver_->getNumRows();
     5339
     5340  // Row copy
     5341  const double * elementByRow = solver_->getMatrixByRow()->getElements();
     5342  const int * column = solver_->getMatrixByRow()->getIndices();
     5343  const CoinBigIndex * rowStart = solver_->getMatrixByRow()->getVectorStarts();
     5344  const int * rowLength = solver_->getMatrixByRow()->getVectorLengths();
     5345
     5346  // Not all rows may be good so we need new array
     5347  int * whichDelete = new int[numberRows];
     5348  int nDelete=0;
     5349  for (int i=0;i<number;i++) {
     5350    int iRow = which[i];
     5351    if (iRow>=0&&iRow<numberRows) {
     5352      if (rowLower[iRow]<-1.0e20||rowUpper[iRow]>1.0e20) {
     5353        whichDelete[nDelete++]=iRow;
     5354        OsiRowCut  thisCut;
     5355        thisCut.setLb(rowLower[iRow]);
     5356        thisCut.setUb(rowUpper[iRow]);
     5357        int start = rowStart[iRow];
     5358        thisCut.setRow(rowLength[iRow],column+start,elementByRow+start);
     5359        globalCuts_.insert(thisCut) ;
     5360      }
     5361    }
     5362  }
     5363  if (nDelete)
     5364    solver_->deleteRows(nDelete,whichDelete);
     5365  delete [] whichDelete;
     5366}
     5367void
     5368CbcModel::setNodeComparison(CbcCompareBase * compare)
     5369{
     5370  delete nodeCompare_;
     5371  nodeCompare_ = compare->clone();
     5372}
     5373void
     5374CbcModel::setNodeComparison(CbcCompareBase & compare)
     5375{
     5376  delete nodeCompare_;
     5377  nodeCompare_ = compare.clone();
     5378}
     5379// Set the strategy. Clones
     5380void
     5381CbcModel::setStrategy(CbcStrategy & strategy)
     5382{
     5383  delete strategy_;
     5384  strategy_ = strategy.clone();
     5385}
  • trunk/include/CbcCompareActual.hpp

    r27 r97  
    8888  virtual bool every1000Nodes(CbcModel * model,int numberNodes);
    8989
     90  /* if weight == -1.0 then depth first (before solution)
     91     if -2.0 then do breadth first just for first 1000 nodes
     92  */
    9093  inline double getWeight() const
    9194  { return weight_;};
     
    9598  // Weight for each infeasibility
    9699  double weight_;
     100  // Weight for each infeasibility - computed from solution
     101  double saveWeight_;
    97102  // Number of solutions
    98103  int numberSolutions_;
  • trunk/include/CbcModel.hpp

    r94 r97  
    2424class CbcObject;
    2525class CbcTree;
     26class CbcStrategy;
    2627
    2728//#############################################################################
     
    221222    */
    222223    bool resolve();
     224  /// Make given rows (L or G) into global cuts and remove from lp
     225  void makeGlobalCuts(int numberRows,const int * which);
    223226  //@}
    224227
     
    850853  inline CbcCompareBase * nodeComparison() const
    851854  { return nodeCompare_;};
    852   inline void setNodeComparison(CbcCompareBase * compare)
    853   { nodeCompare_ = compare;};
    854   inline void setNodeComparison(CbcCompareBase & compare)
    855   { nodeCompare_ = &compare;};
     855  void setNodeComparison(CbcCompareBase * compare);
     856  void setNodeComparison(CbcCompareBase & compare);
    856857  //@}
    857858
     
    10091010                       int whatDepth=-1, int whatDepthInSub=-1);
    10101011//@}
     1012  /** \name Strategy and sub models
     1013 
     1014    See the CbcStrategy class for additional information.
     1015  */
     1016  //@{
     1017
     1018  /// Get the current strategy
     1019  inline CbcStrategy * strategy() const
     1020  { return strategy_;};
     1021  /// Set the strategy. Clones
     1022  void setStrategy(CbcStrategy & strategy);
     1023  /// Get the current parent model
     1024  inline CbcModel * parentModel() const
     1025  { return parentModel_;};
     1026  /// Set the parent model
     1027  inline void setParentModel(CbcModel & parentModel)
     1028  { parentModel_ = &parentModel;};
     1029  //@}
     1030
    10111031
    10121032  /** \name Heuristics and priorities */
     
    12771297  /// Variable selection function
    12781298  CbcBranchDecision * branchingMethod_;
     1299  /// Strategy
     1300  CbcStrategy * strategy_;
     1301  /// Parent model
     1302  CbcModel * parentModel_;
    12791303  /** Whether to automatically do presolve before branch and bound.
    12801304      0 - no
Note: See TracChangeset for help on using the changeset viewer.