Changeset 463 for branches/devel/Cbc/src


Ignore:
Timestamp:
Oct 20, 2006 3:59:21 PM (13 years ago)
Author:
forrest
Message:

for osi methods

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

Legend:

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

    r441 r463  
    686686  return branch;
    687687}
    688 
     688// Construct an OsiSOS object
     689OsiSOS *
     690CbcSOS::osiObject(const OsiSolverInterface * solver) const
     691{
     692  OsiSOS * obj = new OsiSOS(solver,numberMembers_,members_,weights_,sosType_);
     693  obj->setPriority(priority());
     694  return obj;
     695}
    689696
    690697/** Default Constructor
     
    856863{
    857864  return columnNumber_;
     865}
     866/* Reset variable bounds to their original values.
     867 
     868    Bounds may be tightened, so it may be good to be able to set this info in object.
     869*/
     870void
     871CbcSimpleInteger::resetBounds(const OsiSolverInterface * solver)
     872{
     873  originalLower_ = solver->getColLower()[columnNumber_] ;
     874  originalUpper_ = solver->getColUpper()[columnNumber_] ;
    858875}
    859876
  • branches/devel/Cbc/src/CbcBranchActual.hpp

    r439 r463  
    138138  virtual void redoSequenceEtc(CbcModel * model, int numberColumns, const int * originalColumns);
    139139 
     140  /// Construct an OsiSOS object
     141  OsiSOS * osiObject(const OsiSolverInterface * solver) const;
    140142  /// Number of members
    141143  inline int numberMembers() const
     
    251253  virtual int columnNumber() const;
    252254
     255  /** Reset variable bounds to their original values.
     256 
     257    Bounds may be tightened, so it may be good to be able to set this info in object.
     258   */
     259  virtual void resetBounds(const OsiSolverInterface * solver) ;
    253260  /// Original bounds
    254261  inline double originalLowerBound() const
  • branches/devel/Cbc/src/CbcBranchBase.hpp

    r445 r463  
    181181  /** Reset variable bounds to their original values.
    182182 
    183     Bounds may be tightened, so it may be good to be able to reset them to
    184     their original values.
     183    Bounds may be tightened, so it may be good to be able to set this info in object.
    185184   */
    186185  virtual void resetBounds(const OsiSolverInterface * solver) {};
     
    280279  */
    281280  virtual double branch()=0;
     281  /** \brief Execute the actions required to branch, as specified by the
     282             current state of the branching object, and advance the object's
     283             state.  Mainly for diagnostics, whether it is true branch or
     284             strong branching is also passed.
     285             Returns change in guessed objective on next branch
     286  */
     287  virtual double branch(OsiSolverInterface * solver)
     288  { return branch();};
    282289
    283290  /** \brief Print something about branch - only if log level high
  • branches/devel/Cbc/src/CbcHeuristicFPump.cpp

    r444 r463  
    2727   absoluteIncrement_(0.0),
    2828   relativeIncrement_(0.0),
     29   initialWeight_(0.0),
     30   weightFactor_(0.1),
    2931   maximumPasses_(100),
    3032   maximumRetries_(1),
     
    4547   absoluteIncrement_(0.0),
    4648   relativeIncrement_(0.0),
     49   initialWeight_(0.0),
     50   weightFactor_(0.1),
    4751   maximumPasses_(100),
    4852   maximumRetries_(1),
     
    104108    fprintf(fp,"4  heuristicFPump.setRelativeIncrement(%g);\n",relativeIncrement_);
    105109  fprintf(fp,"3  cbcModel->addHeuristic(&heuristicFPump);\n");
     110  if (initialWeight_!=other.initialWeight_)
     111    fprintf(fp,"3  heuristicFPump.setInitialWeight(%g);\n",initialWeight_);
     112  else
     113    fprintf(fp,"4  heuristicFPump.setInitialWeight(%g);\n",initialWeight_);
     114  if (weightFactor_!=other.weightFactor_)
     115    fprintf(fp,"3  heuristicFPump.setWeightFactor(%g);\n",weightFactor_);
     116  else
     117    fprintf(fp,"4  heuristicFPump.setWeightFactor(%g);\n",weightFactor_);
    106118}
    107119
     
    116128  absoluteIncrement_(rhs.absoluteIncrement_),
    117129  relativeIncrement_(rhs.relativeIncrement_),
     130  initialWeight_(rhs.initialWeight_),
     131  weightFactor_(rhs.weightFactor_),
    118132  maximumPasses_(rhs.maximumPasses_),
    119133  maximumRetries_(rhs.maximumRetries_),
     
    154168  cutoff *= direction;
    155169  cutoff = CoinMin(cutoff,solutionValue);
    156   // space for rounded solution
     170  // check plausible and space for rounded solution
    157171  int numberColumns = model_->getNumCols();
     172  int numberIntegers = model_->numberIntegers();
     173  const int * integerVariableOrig = model_->integerVariable();
     174
     175  // 1. initially check 0-1
     176  int i,j;
     177  int general=0;
     178  int * integerVariable = new int[numberIntegers];
     179  const double * lower = model_->solver()->getColLower();
     180  const double * upper = model_->solver()->getColUpper();
     181  bool doGeneral = (accumulate_&4)!=0;
     182  j=0;
     183  for (i=0;i<numberIntegers;i++) {
     184    int iColumn = integerVariableOrig[i];
     185#ifndef NDEBUG
     186    const OsiObject * object = model_->object(i);
     187    const CbcSimpleInteger * integerObject =
     188      dynamic_cast<const  CbcSimpleInteger *> (object);
     189    const OsiSimpleInteger * integerObject2 =
     190      dynamic_cast<const  OsiSimpleInteger *> (object);
     191    assert(integerObject||integerObject2);
     192#endif
     193    if (upper[iColumn]-lower[iColumn]>1.000001) {
     194      general++;
     195      if (doGeneral)
     196        integerVariable[j++]=iColumn;
     197    } else {
     198      integerVariable[j++]=iColumn;
     199    }
     200  }
     201  if (general*3>numberIntegers&&!doGeneral) {
     202    delete [] integerVariable;
     203    return 0;
     204  }
     205  int numberIntegersOrig = numberIntegers;
     206  numberIntegers = j;
     207  if (!doGeneral)
     208    general=0;
    158209  double * newSolution = new double [numberColumns];
    159210  double newSolutionValue=COIN_DBL_MAX;
     
    219270    solver->getDblParam(OsiPrimalTolerance,primalTolerance);
    220271   
    221     int numberIntegers = model_->numberIntegers();
    222     const int * integerVariable = model_->integerVariable();
    223 
    224     // 1. initially check 0-1
    225     int i,j;
    226     int general=0;
    227     for (i=0;i<numberIntegers;i++) {
    228       int iColumn = integerVariable[i];
    229 #ifndef NDEBUG
    230       const OsiObject * object = model_->object(i);
    231       const CbcSimpleInteger * integerObject =
    232         dynamic_cast<const  CbcSimpleInteger *> (object);
    233       const OsiSimpleInteger * integerObject2 =
    234         dynamic_cast<const  OsiSimpleInteger *> (object);
    235       assert(integerObject||integerObject2);
    236 #endif
    237       if (upper[iColumn]-lower[iColumn]>1.000001) {
    238         general++;
    239         break;
    240       }
    241     }
    242     if (general*3>numberIntegers) {
    243       delete solver;
    244       return 0;
    245     }
    246272   
    247273    // 2 space for last rounded solutions
     
    271297    double saveOffset;
    272298    solver->getDblParam(OsiObjOffset,saveOffset);
    273    
     299    // Get amount for original objective
     300    double scaleFactor = 0.0;
     301    for (i=0;i<numberColumns;i++)
     302      scaleFactor += saveObjective[i]*saveObjective[i];
     303    if (scaleFactor)
     304      scaleFactor = (initialWeight_*sqrt((double) numberIntegers))/sqrt(scaleFactor);
    274305    // 5. MAIN WHILE LOOP
    275306    bool newLineNeeded=false;
     
    291322      memcpy(newSolution,solution,numberColumns*sizeof(double));
    292323      int flip;
    293       returnCode = rounds(newSolution,saveObjective,roundExpensive_,downValue_,&flip);
     324      returnCode = rounds(newSolution,saveObjective,numberIntegers,integerVariable,
     325                          roundExpensive_,downValue_,&flip);
    294326      if (returnCode) {
    295327        // SOLUTION IS INTEGER
     
    312344          if (general) {
    313345            int numberLeft=0;
    314             for (i=0;i<numberIntegers;i++) {
    315               int iColumn = integerVariable[i];
     346            for (i=0;i<numberIntegersOrig;i++) {
     347              int iColumn = integerVariableOrig[i];
    316348              double value = floor(newSolution[iColumn]+0.5);
    317               if(solver->isBinary(iColumn)) {
     349              if(solver->isBinary(iColumn)||general) {
    318350                solver->setColLower(iColumn,value);
    319351                solver->setColUpper(iColumn,value);
     
    358390          for (i = 0; i <numberIntegers; i++) {
    359391            int iColumn = integerVariable[i];
    360             if(!solver->isBinary(iColumn))
    361               continue;
    362392            if (newSolution[iColumn]!=b[iColumn]) {
    363393              matched=false;
     
    374404          for (i=0;i<numberIntegers;i++) {
    375405            int iColumn = integerVariable[i];
    376             if(!solver->isBinary(iColumn))
    377               continue;
    378406            double value = max(0.0,CoinDrand48()-0.3);
    379407            double difference = fabs(solution[iColumn]-newSolution[iColumn]);
    380408            if (difference+value>0.5) {
    381               if (newSolution[iColumn]<lower[iColumn]+primalTolerance) newSolution[iColumn] += 1.0;
    382               else if (newSolution[iColumn]>upper[iColumn]-primalTolerance) newSolution[iColumn] -= 1.0;
    383               else abort();
     409              if (newSolution[iColumn]<lower[iColumn]+primalTolerance) {
     410                newSolution[iColumn] += 1.0;
     411              } else if (newSolution[iColumn]>upper[iColumn]-primalTolerance) {
     412                newSolution[iColumn] -= 1.0;
     413              } else {
     414                // general integer
     415                if (difference+value>0.75)
     416                  newSolution[iColumn] += 1.0;
     417                else
     418                  newSolution[iColumn] -= 1.0;
     419              }
    384420            }
    385421          }
     
    393429        // 2. update the objective function based on the new rounded solution
    394430        double offset=0.0;
    395         for (i=0;i<numberIntegers;i++) {
    396           int iColumn = integerVariable[i];
    397           if(!solver->isBinary(iColumn))
     431        double costValue = (1.0-scaleFactor)*solver->getObjSense();
     432       
     433        for (i=0;i<numberColumns;i++) {
     434          // below so we can keep original code and allow for objective
     435          int iColumn = i;
     436          if(!solver->isBinary(iColumn)&&!general)
    398437            continue;
    399           double costValue = 1.0;
    400438          // deal with fixed variables (i.e., upper=lower)
    401439          if (fabs(lower[iColumn]-upper[iColumn]) < primalTolerance) {
    402             if (lower[iColumn] > 1. - primalTolerance) solver->setObjCoeff(iColumn,-costValue);
    403             else                                       solver->setObjCoeff(iColumn,costValue);
     440            //if (lower[iColumn] > 1. - primalTolerance) solver->setObjCoeff(iColumn,-costValue);
     441            //else                                       solver->setObjCoeff(iColumn,costValue);
    404442            continue;
    405443          }
    406444          if (newSolution[iColumn]<lower[iColumn]+primalTolerance) {
    407             solver->setObjCoeff(iColumn,costValue);
     445            solver->setObjCoeff(iColumn,costValue+scaleFactor*saveObjective[iColumn]);
    408446          } else {
    409447            if (newSolution[iColumn]>upper[iColumn]-primalTolerance) {
    410               solver->setObjCoeff(iColumn,-costValue);
     448              solver->setObjCoeff(iColumn,-costValue+scaleFactor*saveObjective[iColumn]);
    411449            } else {
    412450              abort();
     
    416454        }
    417455        solver->setDblParam(OsiObjOffset,-offset);
    418         if (!general&false) {
     456        if (!general&&false) {
    419457          // Solve in two goes - first keep satisfied ones fixed
    420458          double * saveLower = new double [numberIntegers];
     
    444482          memcpy(newSolution,solution,numberColumns*sizeof(double));
    445483          int flip;
    446           returnCode = rounds(newSolution,saveObjective,roundExpensive_,downValue_,&flip);
     484          returnCode = rounds(newSolution,saveObjective,numberIntegers,integerVariable,
     485                              roundExpensive_,downValue_,&flip);
    447486          if (returnCode) {
    448487            // solution - but may not be better
     
    465504          }     
    466505        }
    467         solver->resolve();
    468         assert (solver->isProvenOptimal());
     506        if (!general) {
     507          solver->resolve();
     508          assert (solver->isProvenOptimal());
     509        } else {
     510          int * addStart = new int[2*general+1];
     511          int * addIndex = new int[4*general];
     512          double * addElement = new double[4*general];
     513          double * addLower = new double[2*general];
     514          double * addUpper = new double[2*general];
     515          double * obj = new double[general];
     516          int nAdd=0;
     517          for (i=0;i<numberIntegers;i++) {
     518            int iColumn = integerVariable[i];
     519            if (newSolution[iColumn]>lower[iColumn]+primalTolerance&&
     520                newSolution[iColumn]<upper[iColumn]-primalTolerance) {
     521              obj[nAdd]=1.0;
     522              addLower[nAdd]=0.0;
     523              addUpper[nAdd]=COIN_DBL_MAX;
     524              nAdd++;
     525            }
     526          }
     527          OsiSolverInterface * solver2 = solver;
     528          if (nAdd) {
     529            CoinZeroN(addStart,nAdd+1);
     530            solver2 = solver->clone();
     531            solver2->addCols(nAdd,addStart,NULL,NULL,addLower,addUpper,obj);
     532            // feasible solution
     533            double * sol = new double[nAdd+numberColumns];
     534            memcpy(sol,solution,numberColumns*sizeof(double));
     535            // now rows
     536            int nAdd=0;
     537            int nEl=0;
     538            int nAddRow=0;
     539            for (i=0;i<numberIntegers;i++) {
     540              int iColumn = integerVariable[i];
     541              if (newSolution[iColumn]>lower[iColumn]+primalTolerance&&
     542                  newSolution[iColumn]<upper[iColumn]-primalTolerance) {
     543                addLower[nAddRow]=-newSolution[iColumn];;
     544                addUpper[nAddRow]=COIN_DBL_MAX;
     545                addIndex[nEl] = iColumn;
     546                addElement[nEl++]=-1.0;
     547                addIndex[nEl] = numberColumns+nAdd;
     548                addElement[nEl++]=1.0;
     549                nAddRow++;
     550                addStart[nAddRow]=nEl;
     551                addLower[nAddRow]=newSolution[iColumn];;
     552                addUpper[nAddRow]=COIN_DBL_MAX;
     553                addIndex[nEl] = iColumn;
     554                addElement[nEl++]=1.0;
     555                addIndex[nEl] = numberColumns+nAdd;
     556                addElement[nEl++]=1.0;
     557                nAddRow++;
     558                addStart[nAddRow]=nEl;
     559                sol[nAdd+numberColumns] = fabs(sol[iColumn]-newSolution[iColumn]);
     560                nAdd++;
     561              }
     562            }
     563            solver2->setColSolution(sol);
     564            delete [] sol;
     565            solver2->addRows(nAddRow,addStart,addIndex,addElement,addLower,addUpper);
     566          }
     567          delete [] addStart;
     568          delete [] addIndex;
     569          delete [] addElement;
     570          delete [] addLower;
     571          delete [] addUpper;
     572          delete [] obj;
     573          solver2->resolve();
     574          assert (solver2->isProvenOptimal());
     575          if (nAdd) {
     576            solver->setColSolution(solver2->getColSolution());
     577            delete solver2;
     578          }
     579        }
    469580        if (model_->logLevel())
    470581          printf("\npass %3d: obj. %10.5f --> ", numberPasses+totalNumberPasses,solver->getObjValue());
     
    472583       
    473584      }
     585      // reduce scale factor
     586      scaleFactor *= weightFactor_;
    474587    } // END WHILE
    475588    if (newLineNeeded&&model_->logLevel())
     
    491604      for (i=0;i<numberIntegers;i++) {
    492605        int iColumn=integerVariable[i];
    493         const OsiObject * object = model_->object(i);
    494         double originalLower;
    495         double originalUpper;
    496         getIntegerInformation( object,originalLower, originalUpper);
    497         assert(colLower[iColumn]==originalLower);
    498         newSolver->setColLower(iColumn,CoinMax(colLower[iColumn],originalLower));
    499         assert(colUpper[iColumn]==originalUpper);
    500         newSolver->setColUpper(iColumn,CoinMin(colUpper[iColumn],originalUpper));
     606        //const OsiObject * object = model_->object(i);
     607        //double originalLower;
     608        //double originalUpper;
     609        //getIntegerInformation( object,originalLower, originalUpper);
     610        //assert(colLower[iColumn]==originalLower);
     611        //newSolver->setColLower(iColumn,CoinMax(colLower[iColumn],originalLower));
     612        newSolver->setColLower(iColumn,colLower[iColumn]);
     613        //assert(colUpper[iColumn]==originalUpper);
     614        //newSolver->setColUpper(iColumn,CoinMin(colUpper[iColumn],originalUpper));
     615        newSolver->setColUpper(iColumn,colUpper[iColumn]);
    501616        if (!usedColumn[iColumn]) {
    502617          double value=lastSolution[iColumn];
     
    598713      cutoff -= CoinMax(CoinMax(gap,absoluteIncrement_),model_->getCutoffIncrement());
    599714      printf("round again with cutoff of %g\n",cutoff);
    600       if (accumulate_<2&&usedColumn)
     715      if ((accumulate_&3)<2&&usedColumn)
    601716        memset(usedColumn,0,numberColumns);
    602717      totalNumberPasses += numberPasses;
     
    608723  delete [] lastSolution;
    609724  delete [] newSolution;
     725  delete [] integerVariable;
    610726  return finalReturnCode;
    611727}
     
    625741CbcHeuristicFPump::rounds(double * solution,
    626742                          const double * objective,
     743                          int numberIntegers, const int * integerVariable,
    627744                          bool roundExpensive, double downValue, int *flip)
    628745{
     
    631748  double primalTolerance ;
    632749  solver->getDblParam(OsiPrimalTolerance,primalTolerance) ;
    633   int numberIntegers = model_->numberIntegers();
    634   const int * integerVariable = model_->integerVariable();
    635750
    636751  int i;
     
    653768  for (i=0;i<numberIntegers;i++) {
    654769    int iColumn = integerVariable[i];
    655     if(!solver->isBinary(iColumn))
    656       continue;
    657 #ifndef NDEBUG
    658       const OsiObject * object = model_->object(i);
    659       const CbcSimpleInteger * integerObject =
    660         dynamic_cast<const  CbcSimpleInteger *> (object);
    661       const OsiSimpleInteger * integerObject2 =
    662         dynamic_cast<const  OsiSimpleInteger *> (object);
    663       assert(integerObject||integerObject2);
    664 #endif
    665770    double value=solution[iColumn];
    666771    double round = floor(value+primalTolerance);
     
    691796  delete [] tmp;
    692797
     798  const double * columnLower = solver->getColLower();
     799  const double * columnUpper = solver->getColUpper();
    693800  if (*flip == 0 && iter != 0) {
    694801    if(model_->logLevel())
    695802      printf(" -- rand = %4d (%4d) ", nnv, nn);
    696      for (i = 0; i < nnv; i++) solution[list[i]] = 1. - solution[list[i]];
     803     for (i = 0; i < nnv; i++) {
     804       // was solution[list[i]] = 1. - solution[list[i]]; but does that work for 7>=x>=6
     805       int index = list[i];
     806       double value = solution[index];
     807       if (value<=1.0) {
     808         solution[index] = 1.0-value;
     809       } else if (value<columnLower[index]+integerTolerance) {
     810         solution[index] = value+1.0;
     811       } else if (value>columnUpper[index]-integerTolerance) {
     812         solution[index] = value-1.0;
     813       } else {
     814         solution[index] = value-1.0;
     815       }
     816     }
    697817     *flip = nnv;
    698818  } else if (model_->logLevel()) {
  • branches/devel/Cbc/src/CbcHeuristicFPump.hpp

    r441 r463  
    7777  inline double relativeIncrement() const
    7878  { return relativeIncrement_;};
     79  /// Set initial weight (default 0.0 == off)
     80  inline void setInitialWeight(double value)
     81  { initialWeight_ = value;};
     82  /// Get initial weight (default 0.0 == off)
     83  inline double initialWeight() const
     84  { return initialWeight_;};
     85  /// Set weight factor (default 0.1)
     86  inline void setWeightFactor(double value)
     87  { weightFactor_ = value;};
     88  /// Get weight factor (default 0.1)
     89  inline double weightFactor() const
     90  { return weightFactor_;};
    7991  /// Set maximum passes (default 100)
    8092  inline void setMaximumPasses(int value)
     
    117129  /// If positive carry on after solution expecting gain of at least this times objective
    118130  double relativeIncrement_;
     131  /// Initial weight for true objective
     132  double initialWeight_;
     133  /// factor for decreasing weight
     134  double weightFactor_;
    119135  /// Maximum number of passes
    120136  int maximumPasses_;
     
    128144       2 - reuse solves, do not accumulate integer solutions for local search
    129145       3 - reuse solves, accumulate integer solutions for local search
     146       If we add 4 then use second form of problem (with extra rows and variables)
    130147  */
    131148  int accumulate_;
     
    141158  */
    142159  int rounds(double * solution, const double * objective,
     160             int numberIntegers, const int * integerVariable,
    143161             bool roundExpensive=false,
    144162             double downValue=0.5, int *flip=0);
  • branches/devel/Cbc/src/CbcModel.cpp

    r445 r463  
    713713  }
    714714  // Convert to Osi if wanted
    715   OsiBranchingInformation * persistentInfo = NULL;
     715  bool useOsiBranching=false;
     716  //OsiBranchingInformation * persistentInfo = NULL;
    716717  if (branchingMethod_&&branchingMethod_->chooseMethod()) {
    717     persistentInfo = new OsiBranchingInformation(solver_);
    718     for (int iObject = 0 ; iObject < numberObjects_ ; iObject++) {
    719       CbcObject * obj =
    720         dynamic_cast <CbcObject *>(object_[iObject]) ;
    721       if (obj) {
    722         CbcSimpleInteger * obj2 =
    723           dynamic_cast <CbcSimpleInteger *>(obj) ;
    724         if (obj2) {
    725           // back to Osi land
    726           object_[iObject]=obj2->osiObject();
    727           delete obj;
    728         } else {
    729           printf("Code up CbcObject type in Osi land\n");
    730           abort();
     718    useOsiBranching=true;
     719    //persistentInfo = new OsiBranchingInformation(solver_);
     720    if (numberOriginalObjects) {
     721      for (int iObject = 0 ; iObject < numberObjects_ ; iObject++) {
     722        CbcObject * obj =
     723          dynamic_cast <CbcObject *>(object_[iObject]) ;
     724        if (obj) {
     725          CbcSimpleInteger * obj2 =
     726            dynamic_cast <CbcSimpleInteger *>(obj) ;
     727          if (obj2) {
     728            // back to Osi land
     729            object_[iObject]=obj2->osiObject();
     730            delete obj;
     731          } else {
     732            OsiSimpleInteger * obj3 =
     733              dynamic_cast <OsiSimpleInteger *>(obj) ;
     734            if (!obj3) {
     735              OsiSOS * obj4 =
     736                dynamic_cast <OsiSOS *>(obj) ;
     737              if (!obj4) {
     738                CbcSOS * obj5 =
     739                  dynamic_cast <CbcSOS *>(obj) ;
     740                if (obj5) {
     741                  // back to Osi land
     742                  object_[iObject]=obj5->osiObject(solver_);
     743                } else {
     744                  printf("Code up CbcObject type in Osi land\n");
     745                  abort();
     746                }
     747              }
     748            }
     749          }
    731750        }
    732751      }
    733     }
    734     // and add to solver if none
    735     if (!solver_->numberObjects()) {
    736       solver_->addObjects(numberObjects_,object_);
     752      // and add to solver if none
     753      if (!solver_->numberObjects()) {
     754        solver_->addObjects(numberObjects_,object_);
     755      } else {
     756        printf("should have trapped that solver has objects before\n");
     757        abort();
     758      }
    737759    } else {
    738       printf("should have trapped that solver has objects before\n");
    739       abort();
     760      // do from solver
     761      deleteObjects();
     762      solver_->findIntegersAndSOS(false);
     763      numberObjects_=solver_->numberObjects();
     764      object_ = new OsiObject * [numberObjects_];
     765      for (int iObject = 0 ; iObject < numberObjects_ ; iObject++) {
     766        object_[iObject]=solver_->object(iObject)->clone();
     767      }
    740768    }
    741769    branchingMethod_->chooseMethod()->setSolver(solver_);
     
    10391067#else
    10401068  OsiSolverBranch * branches = NULL;
     1069  // point to useful information
     1070  OsiBranchingInformation usefulInfo=usefulInformation();
    10411071  anyAction = chooseBranch(newNode, numberPassesLeft, NULL, cuts,resolved,
    1042                            NULL,NULL,NULL,branches,persistentInfo);
     1072                           NULL,NULL,NULL,branches,&usefulInfo);
    10431073  if (anyAction == -2||newNode->objectiveValue() >= cutoff) {
    10441074    delete newNode ;
     
    13351365      if (messageHandler()->logLevel()>2)
    13361366        node->modifiableBranchingObject()->print();
    1337       if (node->branch())
     1367      int retCode;
     1368      if (!useOsiBranching)
     1369        retCode = node->branch(NULL); // old way
     1370      else
     1371        retCode = node->branch(solver_); // new way
     1372      if (retCode)
    13381373      {
    13391374        // set nodenumber correctly
     
    14891524          if (newNode->objectiveValue() >= getCutoff())
    14901525            anyAction=-2;
    1491           // only allow twenty passes
    1492           int numberPassesLeft=20;
     1526          // only allow at most a few passes
     1527          int numberPassesLeft=5;
    14931528          checkingNode=true;
    14941529#if 0
     
    16361671#else
    16371672        OsiSolverBranch * branches=NULL;
     1673        // point to useful information
     1674        OsiBranchingInformation usefulInfo=usefulInformation();
    16381675        anyAction = chooseBranch(newNode, numberPassesLeft,node, cuts,resolved,
    1639                                  lastws, lowerBefore, upperBefore, branches,persistentInfo);
     1676                                 lastws, lowerBefore, upperBefore, branches,&usefulInfo);
    16401677/*
    16411678  If we end up infeasible, we can delete the new node immediately. Since this
     
    21052142  delete [] addedCuts_ ;
    21062143  addedCuts_ = NULL ;
    2107   delete persistentInfo;
     2144  //delete persistentInfo;
    21082145  // Get rid of characteristics
    21092146  solverCharacteristics_=NULL;
     
    41644201      int saveNumberSolutions = numberSolutions_;
    41654202      int saveNumberHeuristicSolutions = numberHeuristicSolutions_;
     4203      // make sure bounds tight
     4204      {
     4205        for (int i = 0;i < numberObjects_;i++)
     4206          object_[i]->resetBounds(solver_) ;
     4207      }
    41664208      for (int i = 0;i<numberHeuristics_;i++) {
    41674209        // see if heuristic will do anything
     
    81988240    // Set objective value (not so obvious if NLP etc)
    81998241    setObjectiveValue(newNode,oldNode);
    8200     if (numberPassesLeft<=0)
    8201       branchingState=1;
     8242    //if (numberPassesLeft<=0)
     8243    //branchingState=1;
    82028244    if (!branchingMethod_||!branchingMethod_->chooseMethod()) {
    82038245      if (numberBeforeTrust_==0 ) {
     
    82108252    } else {
    82118253      anyAction = newNode->chooseOsiBranch(this,oldNode,usefulInfo,branchingState) ;; // Osi method
    8212       branchingState=0;
     8254      //branchingState=0;
    82138255    }
    82148256    if (solverCharacteristics_ &&
  • branches/devel/Cbc/src/CbcNode.cpp

    r445 r463  
    659659  objectiveValue_(1.0e100),
    660660  guessedObjectiveValue_(1.0e100),
     661  sumInfeasibilities_(0.0),
    661662  branch_(NULL),
    662663  depth_(-1),
     
    673674  objectiveValue_(1.0e100),
    674675  guessedObjectiveValue_(1.0e100),
     676  sumInfeasibilities_(0.0),
    675677  branch_(NULL),
    676678  depth_(-1),
     
    975977      estimatedDegradation=0.0;
    976978      numberUnsatisfied_ = 0;
     979      // initialize sum of "infeasibilities"
     980      sumInfeasibilities_ = 0.0;
    977981      int bestPriority=INT_MAX;
    978982      /*
     
    10651069          estimatedDegradation += CoinMin(object->upEstimate(),object->downEstimate());
    10661070          numberUnsatisfied_++;
     1071          sumInfeasibilities_ += infeasibility;
    10671072          // Better priority? Flush choices.
    10681073          if (priorityLevel<bestPriority) {
     
    21472152      estimatedDegradation=0.0;
    21482153      numberUnsatisfied_ = 0;
     2154      // initialize sum of "infeasibilities"
     2155      sumInfeasibilities_ = 0.0;
    21492156      int bestPriority=INT_MAX;
    21502157      int number01 = 0;
     
    22472254          upEstimate[i]=object->upEstimate();
    22482255          numberUnsatisfied_++;
     2256          sumInfeasibilities_ += infeasibility;
    22492257          // Better priority? Flush choices.
    22502258          if (priorityLevel<bestPriority) {
     
    38893897  objectiveValue_=rhs.objectiveValue_;
    38903898  guessedObjectiveValue_ = rhs.guessedObjectiveValue_;
     3899  sumInfeasibilities_ = rhs.sumInfeasibilities_;
    38913900  if (rhs.branch_)
    38923901    branch_=rhs.branch_->clone();
     
    39083917    objectiveValue_=rhs.objectiveValue_;
    39093918    guessedObjectiveValue_ = rhs.guessedObjectiveValue_;
     3919    sumInfeasibilities_ = rhs.sumInfeasibilities_;
    39103920    if (rhs.branch_)
    39113921      branch_=rhs.branch_->clone();
     
    39783988
    39793989int
    3980 CbcNode::branch()
     3990CbcNode::branch(OsiSolverInterface * solver)
    39813991{
    3982   double changeInGuessed=branch_->branch();
     3992  double changeInGuessed;
     3993  if (!solver)
     3994    changeInGuessed=branch_->branch();
     3995  else
     3996    changeInGuessed=branch_->branch(solver);
    39833997  guessedObjectiveValue_+= changeInGuessed;
    39843998  //#define PRINTIT
     
    40604074  else
    40614075    depth_ = 0;
    4062   objectiveValue_ = usefulInfo->solver_->getObjValue()*usefulInfo->solver_->getObjSense();
     4076  OsiSolverInterface * solver = model->solver();
     4077  objectiveValue_ = solver->getObjValue()*solver->getObjSense();
    40634078  usefulInfo->objectiveValue_ = objectiveValue_;
    40644079  usefulInfo->depth_ = depth_;
     4080  const double * saveInfoSol = usefulInfo->solution_;
     4081  double * saveSolution = new double[solver->getNumCols()];
     4082  memcpy(saveSolution,solver->getColSolution(),solver->getNumCols()*sizeof(double));
     4083  usefulInfo->solution_ = saveSolution;
    40654084  OsiChooseVariable * choose = model->branchingMethod()->chooseMethod();
    40664085  int numberUnsatisfied=-1;
    40674086  if (branchState<0) {
    40684087    // initialize
     4088    // initialize sum of "infeasibilities"
     4089    sumInfeasibilities_ = 0.0;
    40694090    numberUnsatisfied = choose->setupList(usefulInfo,true);
    40704091    numberUnsatisfied_ = numberUnsatisfied;
     
    40734094  // unset best
    40744095  int best=-1;
    4075   choose->setBestObject(-1);
     4096  choose->setBestObjectIndex(-1);
    40764097  if (numberUnsatisfied) {
    40774098    if (branchState>0||!choose->numberOnList()) {
     
    40794100      if (choose->numberOnList()||!choose->numberStrong()) {
    40804101        best = choose->candidates()[0];
    4081         choose->setBestObject(best);
    4082         choose->updateInformation(usefulInfo);
     4102        choose->setBestObjectIndex(best);
    40834103      } else {
    40844104        // nothing on list - need to try again - keep any solution
     
    40874107        if (numberUnsatisfied) {
    40884108          best = choose->candidates()[0];
    4089           choose->setBestObject(best);
    4090           choose->updateInformation(usefulInfo);
     4109          choose->setBestObjectIndex(best);
    40914110        }
    40924111      }
    40934112    } else {
    40944113      // carry on with strong branching or whatever
    4095       int returnCode = choose->chooseVariable(usefulInfo);
     4114      int returnCode = choose->chooseVariable(solver, usefulInfo,true);
     4115      // update number of strong iterations etc
     4116      model->incrementStrongInfo(choose->numberStrongDone(),choose->numberStrongIterations(),
     4117                                 returnCode==-1 ? 0:choose->numberStrongFixed(),returnCode==-1);
    40964118      if (returnCode>1) {
    4097         // can fix
     4119        // has fixed some
    40984120        returnStatus=-1;
    40994121      } else if (returnCode==-1) {
     
    41104132        if (numberUnsatisfied) {
    41114133          best = choose->candidates()[0];
    4112           choose->setBestObject(best);
    4113           choose->updateInformation( usefulInfo);
     4134          choose->setBestObjectIndex(best);
    41144135        }
    41154136      }
     
    41224143    if (numberUnsatisfied) {
    41234144      // create branching object
    4124       const OsiObject * obj = model->object(choose->bestObject());
     4145      const OsiObject * obj = model->object(choose->bestObjectIndex());
    41254146      //const OsiSolverInterface * solver = usefulInfo->solver_;
    41264147      branch_ = obj->createBranch(model->solver(),usefulInfo,obj->whichWay());
    41274148    }
    41284149  }
     4150  usefulInfo->solution_=saveInfoSol;
     4151  delete [] saveSolution;
     4152  // may have got solution
     4153  if (choose->goodSolution()
     4154      &&model->problemFeasibility()->feasible(model,-1)>=0) {
     4155    // yes
     4156    double objValue = choose->goodObjectiveValue();
     4157    model->setBestSolution(CBC_STRONGSOL,
     4158                                     objValue,
     4159                                     choose->goodSolution()) ;
     4160    model->setLastHeuristic(NULL);
     4161    model->incrementUsed(choose->goodSolution());
     4162    choose->clearGoodSolution();
     4163  }
    41294164  return returnStatus;
    41304165}
  • branches/devel/Cbc/src/CbcNode.hpp

    r439 r463  
    528528
    529529  /// Does next branch and updates state
    530   int branch();
     530  int branch(OsiSolverInterface * solver);
    531531
    532532  // Information to make basis and bounds
     
    559559  inline int numberUnsatisfied() const
    560560  {return numberUnsatisfied_;};
    561 
     561  /// Sum of "infeasibilities" reported by each object
     562  inline double sumInfeasibilities() const
     563  { return sumInfeasibilities_;};
    562564  // Guessed objective value (for solution)
    563565  inline double guessedObjectiveValue() const
     
    579581  /// Information to make basis and bounds
    580582  CbcNodeInfo * nodeInfo_;
    581   // Objective value
     583  /// Objective value
    582584  double objectiveValue_;
    583   // Guessed satisfied Objective value
     585  /// Guessed satisfied Objective value
    584586  double guessedObjectiveValue_;
     587  /// Sum of "infeasibilities" reported by each object
     588  double sumInfeasibilities_;
    585589  /// Branching object for this node
    586590  OsiBranchingObject * branch_;
  • branches/devel/Cbc/src/CoinSolve.cpp

    r452 r463  
    20702070                if (pumpTune>0) {
    20712071                  /*
     2072                    >=10000000 for using obj
    20722073                    >=1000000 use as accumulate switch
    20732074                    >=1000 use index+2 as number of large loops
     
    20862087                  int accumulate = r/1000;
    20872088                  r -= 1000*accumulate;
     2089                  if (accumulate>=10) {
     2090                    int which = accumulate/10;
     2091                    accumulate -= which;
     2092                    // weights and factors
     2093                    double weight[]={0.1,0.1,0.5,0.5,1.0,1.0,5.0,5.0};
     2094                    double factor[] = {0.1,0.5,0.1,0.5,0.1,0.5,0.1,0.5};
     2095                    heuristic4.setInitialWeight(weight[which]);
     2096                    heuristic4.setWeightFactor(factor[which]);
     2097                  }
    20882098                  // fake cutoff
    20892099                  printf("Setting ");
     
    24592469                        objects[iSOS]->setPriority(10);  // rather than 1000
    24602470                    }
     2471                    // delete any existing SOS objects
     2472                    int numberObjects=babModel->numberObjects();
     2473                    OsiObject ** oldObjects=babModel->objects();
     2474                    int nNew=0;
     2475                    for (int i=0;i<numberObjects;i++) {
     2476                      OsiObject * objThis = oldObjects[i];
     2477                      CbcSOS * obj1 =
     2478                        dynamic_cast <CbcSOS *>(objThis) ;
     2479                      OsiSOS * obj2 =
     2480                        dynamic_cast <OsiSOS *>(objThis) ;
     2481                      if (!obj1&&!obj2) {
     2482                        oldObjects[nNew++]=objThis;
     2483                      } else {
     2484                        delete objThis;
     2485                      }
     2486                    }
     2487                    babModel->setNumberObjects(nNew);
    24612488                    babModel->addObjects(numberSOS,objects);
    24622489                    for (iSOS=0;iSOS<numberSOS;iSOS++)
     
    25872614                  printf("Testing OsiObject options %d\n",testOsiOptions);
    25882615                  CbcBranchDefaultDecision decision;
    2589                   OsiChooseVariable choose(babModel->solver());
     2616                  babModel->solver()->findIntegersAndSOS(false);
     2617                  //OsiChooseVariable choose(babModel->solver());
     2618                  OsiChooseStrong choose(babModel->solver());
     2619                  choose.setNumberBeforeTrusted(babModel->numberBeforeTrust());
     2620                  choose.setNumberStrong(babModel->numberStrong());
    25902621                  decision.setChooseMethod(choose);
    25912622                  babModel->setBranchingMethod(decision);
Note: See TracChangeset for help on using the changeset viewer.