Changeset 477 for branches


Ignore:
Timestamp:
Nov 3, 2006 3:48:00 PM (13 years ago)
Author:
forrest
Message:

for nonlinear and start moving to OsiTree?
afor n

Location:
branches/devel/Cbc/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/devel/Cbc/src/CbcBranchActual.cpp

    r471 r477  
    985985  int iColumn = originalCbcObject_->columnNumber();
    986986  assert (variable_==iColumn);
     987  double olb,oub ;
     988  olb = model_->solver()->getColLower()[iColumn] ;
     989  oub = model_->solver()->getColUpper()[iColumn] ;
    987990  if (way_<0) {
    988991#ifdef CBC_DEBUG
     
    10081011    way_=-1;      // Swap direction
    10091012  }
     1013  double nlb = model_->solver()->getColLower()[iColumn];
     1014  if (nlb<olb) {
     1015#ifndef NDEBUG
     1016    printf("bad lb change for column %d from %g to %g\n",iColumn,olb,nlb);
     1017#endif
     1018    model_->solver()->setColLower(iColumn,olb);
     1019  }
     1020  double nub = model_->solver()->getColUpper()[iColumn];
     1021  if (nub>oub) {
     1022#ifndef NDEBUG
     1023    printf("bad ub change for column %d from %g to %g\n",iColumn,oub,nub);
     1024#endif
     1025    model_->solver()->setColUpper(iColumn,oub);
     1026  }
     1027#ifndef NDEBUG
     1028  if (nlb<olb+1.0e-8&&nub>oub-1.0e-8)
     1029    printf("bad null change for column %d - bounds %g,%g\n",iColumn,olb,oub);
     1030#endif
    10101031  return 0.0;
    10111032}
  • branches/devel/Cbc/src/CbcModel.cpp

    r473 r477  
    281281
    282282
    283 
     283static double trueIncrement=0.0;
    284284void
    285285CbcModel::analyzeObjective ()
     
    311311*/
    312312  double maximumCost = 0.0 ;
     313  trueIncrement=0.0;
    313314  bool possibleMultiple = true ;
    314315  int iColumn ;
     
    335336      while (10.0*multiplier*maximumCost < 1.0e8)
    336337        multiplier *= 10.0 ;
    337 
    338       for (iColumn = 0 ; iColumn < numberColumns ; iColumn++)
    339       { if (upper[iColumn] > lower[iColumn]+1.0e-8)
    340         { if (isInteger(iColumn)&&objective[iColumn])
    341           { double value = fabs(objective[iColumn])*multiplier ;
     338    int bigIntegers = 0; // Count of large costs which are integer
     339    for (iColumn = 0 ; iColumn < numberColumns ; iColumn++) {
     340      if (upper[iColumn] > lower[iColumn]+1.0e-8) {
     341        if (isInteger(iColumn)&&objective[iColumn]) {
     342          double value = fabs(objective[iColumn])*multiplier ;
     343          if (value <2.1e9) {
    342344            int nearest = (int) floor(value+0.5) ;
    343345            if (fabs(value-floor(value+0.5)) > 1.0e-8)
    344             { increment = 0 ;
     346              { increment = 0 ;
    345347              break ; }
    346348            else if (!increment)
    347             { increment = nearest ; }
     349              { increment = nearest ; }
    348350            else
    349             { increment = gcd(increment,nearest) ; } } } }
     351              { increment = gcd(increment,nearest) ; }
     352          } else {
     353            // large value - may still be multiple of 1.0
     354            value = fabs(objective[iColumn]);
     355            if (fabs(value-floor(value+0.5)) > 1.0e-8) {
     356              increment=0;
     357              break;
     358            } else {
     359              bigIntegers++;
     360            }
     361          }
     362        }
     363      }
     364    }
     365
    350366/*
    351367  If the increment beats the current value for objective change, install it.
     
    354370      { double value = increment ;
    355371        double cutoff = getDblParam(CbcModel::CbcCutoffIncrement) ;
     372        if (bigIntegers) {
     373          // allow for 1.0
     374          increment = gcd(increment,(int) multiplier);
     375          value = increment;
     376        }
    356377        value /= multiplier ;
     378        trueIncrement=CoinMax(cutoff,value);;
    357379        if (value*0.999 > cutoff)
    358380        { messageHandler()->message(CBC_INTEGERINCREMENT,
     
    748770      solver_->findIntegersAndSOS(false);
    749771      numberObjects_=solver_->numberObjects();
    750       object_ = new OsiObject * [numberObjects_];
    751       for (int iObject = 0 ; iObject < numberObjects_ ; iObject++) {
    752         object_[iObject]=solver_->object(iObject)->clone();
    753       }
     772      object_ = solver_->objects();
     773      ownObjects_ = false;
    754774    }
    755775    branchingMethod_->chooseMethod()->setSolver(solver_);
     
    21962216    if (originalObject) {
    21972217      int iColumn;
     2218      assert (ownObjects_);
    21982219      for (iColumn=0;iColumn<numberObjects_;iColumn++)
    21992220        delete object_[iColumn];
     
    23532374  numberObjects_(0),
    23542375  object_(NULL),
     2376  ownObjects_(true),
    23552377  originalColumns_(NULL),
    23562378  howOftenGlobalScan_(1),
     
    24812503  numberObjects_(0),
    24822504  object_(NULL),
     2505  ownObjects_(true),
    24832506  originalColumns_(NULL),
    24842507  howOftenGlobalScan_(1),
     
    27672790  else
    27682791  { eventHandler_ = NULL ; }
    2769   numberObjects_=rhs.numberObjects_;
    2770   if (numberObjects_) {
    2771     object_ = new OsiObject * [numberObjects_];
    2772     int i;
    2773     for (i=0;i<numberObjects_;i++)
    2774       object_[i]=(rhs.object_[i])->clone();
     2792  ownObjects_ = rhs.ownObjects_;
     2793  if (ownObjects_) {
     2794    numberObjects_=rhs.numberObjects_;
     2795    if (numberObjects_) {
     2796      object_ = new OsiObject * [numberObjects_];
     2797      int i;
     2798      for (i=0;i<numberObjects_;i++)
     2799        object_[i]=(rhs.object_[i])->clone();
     2800    } else {
     2801      object_=NULL;
     2802    }
    27752803  } else {
     2804    // assume will be redone
     2805    numberObjects_=0;
    27762806    object_=NULL;
    27772807  }
     
    30473077    else
    30483078    { eventHandler_ = NULL ; }
    3049     for (i=0;i<numberObjects_;i++)
    3050       delete object_[i];
    3051     delete [] object_;
    3052     numberObjects_=rhs.numberObjects_;
    3053     if (numberObjects_) {
    3054       object_ = new OsiObject * [numberObjects_];
    3055       int i;
    3056       for (i=0;i<numberObjects_;i++)
    3057         object_[i]=(rhs.object_[i])->clone();
     3079    if (ownObjects_) {
     3080      for (i=0;i<numberObjects_;i++)
     3081        delete object_[i];
     3082      delete [] object_;
     3083      numberObjects_=rhs.numberObjects_;
     3084      if (numberObjects_) {
     3085        object_ = new OsiObject * [numberObjects_];
     3086        int i;
     3087        for (i=0;i<numberObjects_;i++)
     3088          object_[i]=(rhs.object_[i])->clone();
     3089      } else {
     3090        object_=NULL;
     3091    }
    30583092    } else {
     3093      // assume will be redone
     3094      numberObjects_=0;
    30593095      object_=NULL;
    30603096    }
     
    31853221  integerVariable_=NULL;
    31863222  int i;
    3187   for (i=0;i<numberObjects_;i++)
    3188     delete object_[i];
    3189   delete [] object_;
     3223  if (ownObjects_) {
     3224    for (i=0;i<numberObjects_;i++)
     3225      delete object_[i];
     3226    delete [] object_;
     3227  }
     3228  ownObjects_=true;
    31903229  object_=NULL;
    31913230  numberIntegers_=0;
     
    38593898    objectiveValue= node->objectiveValue();
    38603899  int returnCode = resolve(node ? node->nodeInfo() : NULL,1);
     3900#ifdef COIN_DEVELOP
     3901  //if (!solver_->getIterationCount()&&solver_->isProvenOptimal())
     3902  //printf("zero iterations on first solve of branch\n");
     3903#endif
    38613904  if (node&&!node->nodeInfo()->numberBranchesLeft())
    38623905    node->nodeInfo()->allBranchesGone(); // can clean up
     
    52135256    }
    52145257  }
    5215   if (!feasible&& continuousObjective_ <-1.0e30) {
     5258  if (false&&!feasible&& continuousObjective_ <-1.0e30) {
    52165259    // at root node - double double check
    52175260    bool saveTakeHint;
     
    52275270    }
    52285271  }
     5272  if (feasible&&!solverCharacteristics_->solutionAddsCuts()) {
     5273    //double increment = getDblParam(CbcModel::CbcCutoffIncrement) ;
     5274    double cutoff ;
     5275    solver_->getDblParam(OsiDualObjectiveLimit,cutoff) ;
     5276    double distance = fabs(cutoff-solver_->getObjValue());
     5277    if (distance<10.0*trueIncrement) {
     5278      double offset;
     5279      solver_->getDblParam(OsiObjOffset,offset);
     5280      double objFixedValue = -offset;
     5281      double objValue=0.0;
     5282      double direction = solver_->getObjSense();
     5283      const double * solution = solver_->getColSolution();
     5284      const double * objective = solver_->getObjCoefficients();
     5285      const double * columnLower = solver_->getColLower();
     5286      const double * columnUpper = solver_->getColUpper();
     5287      int numberColumns = solver_->getNumCols();
     5288      int increment = 0 ;
     5289      double multiplier = 1.0/trueIncrement;
     5290      int bigIntegers = 0; // Count of large costs which are integer
     5291      for (int iColumn=0;iColumn<numberColumns;iColumn++) {
     5292        double value = solution[iColumn];
     5293        // make sure clean
     5294        value = CoinMin(value,columnUpper[iColumn]);
     5295        value = CoinMax(value,columnLower[iColumn]);
     5296        double cost = direction * objective[iColumn];
     5297        if (cost) {
     5298          if (columnLower[iColumn]<columnUpper[iColumn]) {
     5299            objValue += value*cost;
     5300            value = fabs(cost)*multiplier ;
     5301            if (value <2.1e9) {
     5302              int nearest = (int) floor(value+0.5) ;
     5303              assert (fabs(value-floor(value+0.5)) < 1.0e-8);
     5304              if (!increment)
     5305                increment = nearest ;
     5306              else
     5307                increment = gcd(increment,nearest) ;
     5308            } else {
     5309              // large value - may still be multiple of 1.0
     5310              value = fabs(objective[iColumn]);
     5311              assert(fabs(value-floor(value+0.5)) < 1.0e-8);
     5312              bigIntegers++;
     5313            }
     5314          } else {
     5315            // fixed
     5316            objFixedValue += value*cost;
     5317          }
     5318        }
     5319      }
     5320      if (increment) {
     5321        double value = increment ;
     5322        value /= multiplier ;
     5323        if (value>trueIncrement) {
     5324          double x = objValue/value;
     5325          x = ceil(x-1.0e-5);
     5326          x *= value;
     5327          //printf("fixed %g, variable %g -> %g, sum %g - cutoff %g\n",
     5328          // objFixedValue,objValue,x,x+objFixedValue,cutoff);
     5329          x += objFixedValue;
     5330          if (x>cutoff + 1.0e-5*fabs(cutoff)+1.0e-5) {
     5331            //printf("Node cutoff\n");
     5332            feasible=false;
     5333          }
     5334        } else {
     5335          value = trueIncrement;
     5336          double x = objValue/value;
     5337          x = ceil(x-1.0e-5);
     5338          x *= value;
     5339          x += objFixedValue;
     5340          if (x>cutoff + 1.0e-5*fabs(cutoff)+1.0e-5) {
     5341            //printf("Node cutoff\n");
     5342            feasible=false;
     5343          }
     5344        }
     5345      }
     5346    }
     5347  }
     5348
    52295349  setPointers(solver_);
    52305350  int returnStatus = feasible ? 1 : 0;
     
    55045624    delete [] element;
    55055625    newModel->addObjects(numberCliques,object);
     5626    assert (ownObjects_);
    55065627    for (;i<numberCliques;i++)
    55075628      delete object[i];
     
    55105631    return newModel;
    55115632  } else {
     5633    assert (ownObjects_);
    55125634    if (numberCliques>0) {
    55135635      addObjects(numberCliques,object);
     
    56515773CbcModel::deleteObjects(bool getIntegers)
    56525774{
    5653   int i;
    5654   for (i=0;i<numberObjects_;i++)
    5655     delete object_[i];
    5656   delete [] object_;
     5775  if (ownObjects_) {
     5776    int i;
     5777    for (i=0;i<numberObjects_;i++)
     5778      delete object_[i];
     5779    delete [] object_;
     5780  }
    56575781  object_ = NULL;
    56585782  numberObjects_=0;
    5659   if (getIntegers)
     5783  if (getIntegers&&ownObjects_)
    56605784    findIntegers(true);
    56615785}
     
    59436067  }
    59446068  delete [] mark;
     6069  assert (ownObjects_);
    59456070  delete [] object_;
    59466071  object_ = temp;
     
    60566181  }
    60576182  delete [] mark;
     6183  assert (ownObjects_);
    60586184  delete [] object_;
    60596185  object_ = temp;
     
    70977223                                   bool weak)
    70987224{
     7225  printf("DEPRECATED\n");
    70997226  status_ = 0;
    71007227  // solve LP
     
    72227349              double value = fabs(objective[iColumn])*multiplier;
    72237350              int nearest = (int) floor(value+0.5);
    7224               if (fabs(value-floor(value+0.5))>1.0e-8) {
     7351              if (fabs(value-floor(value+0.5))>1.0e-8||value>2.1e9) {
    72257352                increment=0;
    72267353                break; // no good
  • branches/devel/Cbc/src/CbcModel.hpp

    r473 r477  
    13571357  inline bool normalSolver() const
    13581358  { return (specialOptions_&16)==0;};
     1359  /// Now we may not own objects - just point to solver's objects
     1360  inline bool ownObjects() const
     1361  { return ownObjects_;};
    13591362  //@}
    13601363  //---------------------------------------------------------------------------
     
    18281831  */
    18291832  OsiObject ** object_;
    1830 
     1833  /// Now we may not own objects - just point to solver's objects
     1834  bool ownObjects_;
    18311835 
    18321836  /// Original columns as created by integerPresolve
  • branches/devel/Cbc/src/CbcNode.cpp

    r473 r477  
    624624  for (i=0;i<numberChangedBounds_;i++) {
    625625    int variable = variables_[i];
     626    int k = variable&0x7fffffff;
    626627    if ((variable&0x80000000)==0) {
    627628      // lower bound changing
    628       solver->setColLower(variable,newBounds_[i]);
     629#ifndef NDEBUG
     630      double oldValue = solver->getColLower()[k];
     631      assert (newBounds_[i]>oldValue-1.0e-8);
     632      if (newBounds_[i]<oldValue+1.0e-8)
     633        printf("bad null lower change for column %d - bound %g\n",k,oldValue);
     634#endif
     635      solver->setColLower(k,newBounds_[i]);
    629636    } else {
    630637      // upper bound changing
    631       solver->setColUpper(variable&0x7fffffff,newBounds_[i]);
     638#ifndef NDEBUG
     639      double oldValue = solver->getColUpper()[k];
     640      assert (newBounds_[i]<oldValue+1.0e-8);
     641      if (newBounds_[i]>oldValue-1.0e-8)
     642        printf("bad null upper change for column %d - bound %g\n",k,oldValue);
     643#endif
     644      solver->setColUpper(k,newBounds_[i]);
    632645    }
    633646  }
     
    31673180                  dynamic_cast <CbcBranchingObject *>(branch_) ;
    31683181                assert (branchObj);
    3169                 branchObj->way(preferredWay);
     3182                //branchObj->way(preferredWay);
     3183                branchObj->way(betterWay);
    31703184              }
    31713185              if (couldChooseFirst)
  • branches/devel/Cbc/src/CbcNode.hpp

    r473 r477  
    88
    99#include "CoinWarmStartBasis.hpp"
     10#include "CoinSearchTree.hpp"
    1011#include "CbcBranchBase.hpp"
    1112
     
    388389*/
    389390
    390 class CbcNode {
     391class CbcNode : public CoinTreeNode {
    391392 
    392393public:
  • branches/devel/Cbc/src/CbcStrategy.cpp

    r439 r477  
    285285    model.solver()->messageHandler()->setLogLevel(0);
    286286  } else {
    287     model.messageHandler()->setLogLevel(2);
    288     model.solver()->messageHandler()->setLogLevel(1);
    289     model.setPrintFrequency(50);
     287    model.messageHandler()->setLogLevel(CoinMax(2,model.messageHandler()->logLevel()));
     288    model.solver()->messageHandler()->setLogLevel(CoinMax(1,model.solver()->messageHandler()->logLevel()));
     289    model.setPrintFrequency(CoinMin(50,model.printFrequency()));
    290290  }
    291291}
  • branches/devel/Cbc/src/CbcTree.hpp

    r441 r477  
    9696
    9797};
     98
     99/// New style
     100#include "CoinSearchTree.hpp"
     101/*! \class tree
     102    \brief Implementation of live set as a heap.
     103
     104    This class is used to hold the set of live nodes in the search tree.
     105*/
     106
     107class CbcNewTree : public CbcTree, public CoinSearchTreeManager {
     108
     109public:
     110
     111  // Default Constructor
     112  CbcNewTree ();
     113
     114  // Copy constructor
     115  CbcNewTree ( const CbcNewTree & rhs);
     116  // = operator
     117  CbcNewTree & operator=(const CbcNewTree & rhs);
     118   
     119  virtual ~CbcNewTree();
     120
     121  /// Clone
     122  virtual CbcNewTree * clone() const;
     123  /// Create C++ lines to get to current state
     124  virtual void generateCpp( FILE * fp) {};
     125
     126/*! \name Heap access and maintenance methods */
     127//@{
     128
     129  /// Set comparison function and resort heap
     130  void setComparison(CbcCompareBase  &compare);
     131
     132  /// Return the top node of the heap
     133  virtual CbcNode * top() const;
     134
     135  /// Add a node to the heap
     136  virtual void push(CbcNode * x);
     137
     138  /// Remove the top node from the heap
     139  virtual void pop() ;
     140  /// Gets best node and takes off heap
     141  virtual CbcNode * bestNode(double cutoff);
     142
     143//@}
     144/*! \name vector methods */
     145//@{
     146
     147  /// Test if empty *** note may be overridden
     148  virtual bool empty() ;
     149
     150  /// Return size
     151  inline int size() const
     152  { return nodes_.size();}
     153
     154  /// [] operator
     155  inline CbcNode * operator [] (int i) const
     156  { return nodes_[i];}
     157
     158  /// Return a node pointer
     159  inline CbcNode * nodePointer (int i) const
     160  { return nodes_[i];}
     161
     162//@}
     163
     164/*! \name Search tree maintenance */
     165//@{
     166
     167/*! \brief Prune the tree using an objective function cutoff
     168
     169  This routine removes all nodes with objective worst than the
     170  specified cutoff value.
     171  It also sets bestPossibleObjective to best
     172  of all on tree before deleting.
     173*/
     174
     175  void cleanTree(CbcModel * model, double cutoff, double & bestPossibleObjective);
     176
     177  /// Get best on list using alternate method
     178  CbcNode * bestAlternate();
     179
     180  /// We may have got an intelligent tree so give it one more chance
     181  virtual void endSearch() {}
     182//@}
     183protected:
     184
     185
     186};
    98187#endif
    99188
  • branches/devel/Cbc/src/CoinSolve.cpp

    r473 r477  
    475475{
    476476#ifdef COIN_DEVELOP
     477  if (!babModel->ownObjects())
     478    return;
    477479  //const double *objective = solver->getObjCoefficients() ;
    478480  const double *columnLower = solver->getColLower() ;
Note: See TracChangeset for help on using the changeset viewer.