Ignore:
Timestamp:
May 14, 2008 7:55:20 AM (11 years ago)
Author:
forrest
Message:

for my experiments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cbc/src/CbcTree.cpp

    r931 r940  
    77#include "CbcCountRowCut.hpp"
    88#include "CbcCompareActual.hpp"
     9#include "CbcBranchActual.hpp"
    910
    1011CbcTree::CbcTree()
    1112{
    1213  maximumNodeNumber_=0;
     14  numberBranching_=0;
     15  maximumBranching_=0;
     16  branched_=NULL;
     17  newBound_=NULL;
    1318}
    1419CbcTree::~CbcTree()
    1520{
     21  delete [] branched_;
     22  delete [] newBound_;
    1623}
    1724// Copy constructor
     
    2027  nodes_=rhs.nodes_;
    2128  maximumNodeNumber_=rhs.maximumNodeNumber_;
     29  numberBranching_=rhs.numberBranching_;
     30  maximumBranching_=rhs.maximumBranching_;
     31  if (maximumBranching_>0) {
     32    branched_=CoinCopyOfArray(rhs.branched_,maximumBranching_);
     33    newBound_=CoinCopyOfArray(rhs.newBound_,maximumBranching_);
     34  } else {
     35    branched_=NULL;
     36    newBound_=NULL;
     37  }
    2238}
    2339// Assignment operator
     
    2844    nodes_=rhs.nodes_;
    2945    maximumNodeNumber_=rhs.maximumNodeNumber_;
     46    delete [] branched_;
     47    delete [] newBound_;
     48    numberBranching_=rhs.numberBranching_;
     49    maximumBranching_=rhs.maximumBranching_;
     50    if (maximumBranching_>0) {
     51      branched_=CoinCopyOfArray(rhs.branched_,maximumBranching_);
     52      newBound_=CoinCopyOfArray(rhs.newBound_,maximumBranching_);
     53    } else {
     54      branched_=NULL;
     55      newBound_=NULL;
     56    }
    3057  }
    3158  return *this;
     59}
     60// Adds branching information to complete state
     61void
     62CbcTree::addBranchingInformation(const CbcModel * model, const CbcNodeInfo * nodeInfo,
     63                                 const double * currentLower,
     64                                 const double * currentUpper)
     65{
     66  const OsiBranchingObject * objA  = nodeInfo->owner()->branchingObject();
     67  const CbcIntegerBranchingObject * objBranch  = dynamic_cast<const CbcIntegerBranchingObject *> (objA);
     68  if (objBranch) {
     69    const CbcObject * objB = objBranch->object();
     70    const CbcSimpleInteger * obj = dynamic_cast<const CbcSimpleInteger *> (objB);
     71    assert (obj);
     72    int iColumn = obj->columnNumber();
     73    const double * down = objBranch->downBounds();
     74    const double * up = objBranch->upBounds();
     75    assert (currentLower[iColumn]==down[0]);
     76    assert (currentUpper[iColumn]==up[1]);
     77    if (dynamic_cast<const CbcPartialNodeInfo *> (nodeInfo)) {
     78      const CbcPartialNodeInfo * info = dynamic_cast<const CbcPartialNodeInfo *> (nodeInfo);
     79      const double * newBounds = info->newBounds();
     80      const int * variables = info->variables();
     81      int numberChanged = info->numberChangedBounds();
     82      for (int i=0;i<numberChanged;i++) {
     83        int jColumn = variables[i];
     84        int kColumn = jColumn&(~0x80000000);
     85        if (iColumn==kColumn) {
     86          jColumn |= 0x40000000;
     87          double value = newBounds[i];
     88          if ((jColumn&0x80000000)==0) {
     89            assert (value==up[0]);
     90          } else {
     91            assert (value==down[1]);
     92          }
     93        }
     94        if (numberBranching_==maximumBranching_)
     95          increaseSpace();
     96        newBound_[numberBranching_]=(int) newBounds[i];
     97        branched_[numberBranching_++]=jColumn;
     98      }
     99    } else {
     100      const CbcFullNodeInfo * info = dynamic_cast<const CbcFullNodeInfo *> (nodeInfo);
     101      int numberIntegers = model->numberIntegers();
     102      const int * which = model->integerVariable();
     103      const double * newLower = info->lower();
     104      const double * newUpper = info->upper();
     105      if (numberBranching_==maximumBranching_)
     106        increaseSpace();
     107      assert (newLower[iColumn]==up[0]||
     108              newUpper[iColumn]==down[1]);
     109      int jColumn=iColumn|0x40000000;
     110      if (newLower[iColumn]==up[0]) {
     111        newBound_[numberBranching_]=(int) up[0];
     112      } else {
     113        newBound_[numberBranching_]=(int) down[1];
     114        jColumn|= 0x80000000;
     115      }
     116      branched_[numberBranching_++]=jColumn;
     117      for (int i=0;i<numberIntegers;i++) {
     118        int jColumn=which[i];
     119        assert (currentLower[jColumn]==newLower[jColumn]||
     120                currentUpper[jColumn]==newUpper[jColumn]);
     121        if (jColumn!=iColumn) {
     122          bool changed=false;
     123          double value;
     124          if (newLower[jColumn]>currentLower[jColumn]) {
     125            value=newLower[jColumn];
     126            changed=true;
     127          } else if (newUpper[jColumn]<currentUpper[jColumn]) {
     128            value=newUpper[jColumn];
     129            jColumn|= 0x80000000;
     130            changed=true;
     131          }
     132          if (changed) {
     133            if (numberBranching_==maximumBranching_)
     134              increaseSpace();
     135            newBound_[numberBranching_]=(int) value;
     136            branched_[numberBranching_++]=jColumn;
     137          }
     138        }
     139      }
     140    }
     141  } else {
     142    // switch off
     143    delete [] branched_;
     144    delete [] newBound_;
     145    maximumBranching_=-1;
     146    branched_=NULL;
     147    newBound_=NULL;
     148  }
     149}
     150// Increase space for data
     151void
     152CbcTree::increaseSpace()
     153{
     154  assert (numberBranching_==maximumBranching_);
     155  maximumBranching_ = (3*maximumBranching_+10)>>1;
     156  unsigned int * temp1 = CoinCopyOfArrayPartial(branched_,maximumBranching_,numberBranching_);
     157  delete [] branched_;
     158  branched_ = temp1;
     159  int * temp2 = CoinCopyOfArrayPartial(newBound_,maximumBranching_,numberBranching_);
     160  delete [] newBound_;
     161  newBound_ = temp2;
    32162}
    33163// Clone
Note: See TracChangeset for help on using the changeset viewer.