Changeset 231


Ignore:
Timestamp:
Jan 12, 2006 11:30:31 AM (13 years ago)
Author:
forrest
Message:

for hot start

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/CbcBranchActual.cpp

    r222 r231  
    553553}
    554554
     555/* Create an OsiSolverBranch object
     556   
     557This returns NULL if branch not represented by bound changes
     558*/
     559OsiSolverBranch *
     560CbcSOS::solverBranch() const
     561{
     562  int j;
     563  const double * solution = model_->testSolution();
     564  double integerTolerance =
     565      model_->getDblParam(CbcModel::CbcIntegerTolerance);
     566  OsiSolverInterface * solver = model_->solver();
     567  const double * upper = solver->getColUpper();
     568  int firstNonFixed=-1;
     569  int lastNonFixed=-1;
     570  int firstNonZero=-1;
     571  int lastNonZero = -1;
     572  double weight = 0.0;
     573  double sum =0.0;
     574  double * fix = new double[numberMembers_];
     575  int * which = new int[numberMembers_];
     576  for (j=0;j<numberMembers_;j++) {
     577    int iColumn = members_[j];
     578    // fix all on one side or other (even if fixed)
     579    fix[j]=0.0;
     580    which[j]=iColumn;
     581    if (upper[iColumn]) {
     582      double value = CoinMax(0.0,solution[iColumn]);
     583      sum += value;
     584      if (firstNonFixed<0)
     585        firstNonFixed=j;
     586      lastNonFixed=j;
     587      if (value>integerTolerance) {
     588        weight += weights_[j]*value;
     589        if (firstNonZero<0)
     590          firstNonZero=j;
     591        lastNonZero=j;
     592      }
     593    }
     594  }
     595  assert (lastNonZero-firstNonZero>=sosType_) ;
     596  // find where to branch
     597  assert (sum>0.0);
     598  weight /= sum;
     599  // down branch fixes ones above weight to 0
     600  int iWhere;
     601  int iDownStart=0;
     602  int iUpEnd=0;
     603  for (iWhere=firstNonZero;iWhere<lastNonZero;iWhere++)
     604    if (weight<weights_[iWhere+1])
     605      break;
     606  if (sosType_==1) {
     607    // SOS 1
     608    iUpEnd=iWhere+1;
     609    iDownStart=iUpEnd;
     610  } else {
     611    // SOS 2
     612    if (iWhere==firstNonFixed)
     613      iWhere++;;
     614    if (iWhere==lastNonFixed-1)
     615      iWhere = lastNonFixed-2;
     616    iUpEnd=iWhere+1;
     617    iDownStart=iUpEnd+1;
     618  }
     619  //
     620  OsiSolverBranch * branch = new OsiSolverBranch();
     621  branch->addBranch(-1,0,NULL,NULL,numberMembers_-iDownStart,which+iDownStart,fix);
     622  branch->addBranch(1,0,NULL,NULL,iUpEnd,which,fix);
     623  delete [] fix;
     624  delete [] which;
     625  return branch;
     626}
    555627
    556628
     
    701773  value = CoinMin(value, upper[columnNumber_]);
    702774  assert (upper[columnNumber_]>lower[columnNumber_]);
    703   int hotstartStrategy=model_->getHotstartStrategy();
    704   if (hotstartStrategy<=0) {
     775  if (!model_->hotstartSolution()) {
    705776#ifndef NDEBUG
    706777    double nearest = floor(value+0.5);
     
    710781#endif
    711782  } else {
    712     const double * bestSolution = model_->bestSolution();
    713     double targetValue = bestSolution[columnNumber_];
     783    const double * hotstartSolution = model_->hotstartSolution();
     784    double targetValue = hotstartSolution[columnNumber_];
    714785    if (way>0)
    715786      value = targetValue-0.1;
     
    9751046    downPseudoCost_(1.0e-5),
    9761047    upPseudoCost_(1.0e-5),
     1048    upDownSeparator_(-1.0),
    9771049    method_(0)
    9781050{
     
    9931065  // and balance at breakeven
    9941066  downPseudoCost_=((1.0-breakEven_)*upPseudoCost_)/breakEven_;
     1067  upDownSeparator_ = -1.0;
    9951068  method_=0;
    9961069}
     
    10081081  upPseudoCost_ = CoinMax(1.0e-10,upPseudoCost);
    10091082  breakEven_ = upPseudoCost_/(upPseudoCost_+downPseudoCost_);
     1083  upDownSeparator_ = -1.0;
    10101084  method_=0;
    10111085}
     
    10161090   downPseudoCost_(rhs.downPseudoCost_),
    10171091   upPseudoCost_(rhs.upPseudoCost_),
     1092   upDownSeparator_(rhs.upDownSeparator_),
    10181093   method_(rhs.method_)
    10191094
     
    10361111    downPseudoCost_=rhs.downPseudoCost_;
    10371112    upPseudoCost_=rhs.upPseudoCost_;
     1113    upDownSeparator_=rhs.upDownSeparator_;
    10381114    method_=rhs.method_;
    10391115  }
     
    10621138  assert (upper[columnNumber_]>lower[columnNumber_]);
    10631139#endif
    1064   int hotstartStrategy=model_->getHotstartStrategy();
    1065   if (hotstartStrategy<=0) {
     1140  if (!model_->hotstartSolution()) {
    10661141    assert (fabs(value-nearest)>integerTolerance);
    10671142  } else {
    1068     const double * bestSolution = model_->bestSolution();
    1069     double targetValue = bestSolution[columnNumber_];
     1143    const double * hotstartSolution = model_->hotstartSolution();
     1144    double targetValue = hotstartSolution[columnNumber_];
    10701145    if (way>0)
    10711146      value = targetValue-0.1;
     
    11201195  else
    11211196    preferredWay=-1;
     1197  // See if up down choice set
     1198  if (upDownSeparator_>0.0) {
     1199    preferredWay = (value-below>=upDownSeparator_) ? 1 : -1;
     1200  }
    11221201  if (fabs(value-nearest)<=integerTolerance) {
    11231202    return 0.0;
  • trunk/CbcBranchDynamic.cpp

    r222 r231  
    2626    downDynamicPseudoCost_(1.0e-5),
    2727    upDynamicPseudoCost_(1.0e-5),
     28    upDownSeparator_(-1.0),
    2829    sumDownCost_(0.0),
    2930    sumUpCost_(0.0),
     31    sumDownChange_(0.0),
     32    sumUpChange_(0.0),
    3033    sumDownCostSquared_(0.0),
    3134    sumUpCostSquared_(0.0),
     
    5255                                    int iColumn, double breakEven)
    5356  : CbcSimpleInteger(model,sequence,iColumn,breakEven),
     57    upDownSeparator_(-1.0),
    5458    sumDownCost_(0.0),
    5559    sumUpCost_(0.0),
     60    sumDownChange_(0.0),
     61    sumUpChange_(0.0),
    5662    sumDownCostSquared_(0.0),
    5763    sumUpCostSquared_(0.0),
     
    7581  // and balance at breakeven
    7682  downDynamicPseudoCost_=((1.0-breakEven_)*upDynamicPseudoCost_)/breakEven_;
     83  // so initial will have some effect
     84  sumUpCost_ = 2.0*upDynamicPseudoCost_;
     85  sumUpChange_ = 2.0;
     86  numberTimesUp_ = 2;
     87  sumDownCost_ = 2.0*downDynamicPseudoCost_;
     88  sumDownChange_ = 2.0;
     89  numberTimesDown_ = 2;
     90#if 0
     91  // No
     92  sumUpCost_ = 0.0;
     93  sumUpChange_ = 0.0;
     94  numberTimesUp_ = 0;
     95  sumDownCost_ = 0.0;
     96  sumDownChange_ = 0.0;
     97  numberTimesDown_ = 0;
     98#else
     99  sumUpCost_ = 1.0*upDynamicPseudoCost_;
     100  sumUpChange_ = 1.0;
     101  numberTimesUp_ = 1;
     102  sumDownCost_ = 1.0*downDynamicPseudoCost_;
     103  sumDownChange_ = 1.0;
     104  numberTimesDown_ = 1;
     105#endif
    77106}
    78107
     
    85114                                                        double upDynamicPseudoCost)
    86115  : CbcSimpleInteger(model,sequence,iColumn),
     116    upDownSeparator_(-1.0),
    87117    sumDownCost_(0.0),
    88118    sumUpCost_(0.0),
     119    sumDownChange_(0.0),
     120    sumUpChange_(0.0),
    89121    sumDownCostSquared_(0.0),
    90122    sumUpCostSquared_(0.0),
     
    105137  upDynamicPseudoCost_ = upDynamicPseudoCost;
    106138  breakEven_ = upDynamicPseudoCost_/(upDynamicPseudoCost_+downDynamicPseudoCost_);
     139  // so initial will have some effect
     140  sumUpCost_ = 2.0*upDynamicPseudoCost_;
     141  sumUpChange_ = 2.0;
     142  numberTimesUp_ = 2;
     143  sumDownCost_ = 2.0*downDynamicPseudoCost_;
     144  sumDownChange_ = 2.0;
     145  numberTimesDown_ = 2;
     146#if 0
     147  // No
     148  sumUpCost_ = 0.0;
     149  sumUpChange_ = 0.0;
     150  numberTimesUp_ = 0;
     151  sumDownCost_ = 0.0;
     152  sumDownChange_ = 0.0;
     153  numberTimesDown_ = 0;
     154#else
     155  sumUpCost_ = 1.0*upDynamicPseudoCost_;
     156  sumUpChange_ = 1.0;
     157  numberTimesUp_ = 1;
     158  sumDownCost_ = 1.0*downDynamicPseudoCost_;
     159  sumDownChange_ = 1.0;
     160  numberTimesDown_ = 1;
     161#endif
    107162}
    108163
     
    112167   downDynamicPseudoCost_(rhs.downDynamicPseudoCost_),
    113168   upDynamicPseudoCost_(rhs.upDynamicPseudoCost_),
     169   upDownSeparator_(rhs.upDownSeparator_),
    114170   sumDownCost_(rhs.sumDownCost_),
    115171   sumUpCost_(rhs.sumUpCost_),
     172   sumDownChange_(rhs.sumDownChange_),
     173   sumUpChange_(rhs.sumUpChange_),
    116174   sumDownCostSquared_(rhs.sumDownCostSquared_),
    117175   sumUpCostSquared_(rhs.sumUpCostSquared_),
     
    147205    downDynamicPseudoCost_=rhs.downDynamicPseudoCost_;
    148206    upDynamicPseudoCost_=rhs.upDynamicPseudoCost_;
     207    upDownSeparator_=rhs.upDownSeparator_;
    149208    sumDownCost_ = rhs.sumDownCost_;
    150209    sumUpCost_ = rhs.sumUpCost_;
     210    sumDownChange_ = rhs.sumDownChange_;
     211    sumUpChange_ = rhs.sumUpChange_;
    151212    sumDownCostSquared_ = rhs.sumDownCostSquared_;
    152213    sumUpCostSquared_ = rhs.sumUpCostSquared_;
     
    187248  assert (upper[columnNumber_]>lower[columnNumber_]);
    188249#endif
    189   int hotstartStrategy=model_->getHotstartStrategy();
    190   if (hotstartStrategy<=0) {
     250  if (!model_->hotstartSolution()) {
    191251    assert (fabs(value-nearest)>integerTolerance);
    192252  } else {
    193     const double * bestSolution = model_->bestSolution();
    194     double targetValue = bestSolution[columnNumber_];
     253    const double * hotstartSolution = model_->hotstartSolution();
     254    double targetValue = hotstartSolution[columnNumber_];
    195255    if (way>0)
    196256      value = targetValue-0.1;
     
    300360  else
    301361    preferredWay=-1;
     362  // See if up down choice set
     363  if (upDownSeparator_>0.0) {
     364    preferredWay = (value-below>=upDownSeparator_) ? 1 : -1;
     365  }
    302366  // weight at 1.0 is max min
    303367#define WEIGHT_AFTER 0.9
     
    326390        returnValue=1.0e50;
    327391    }
     392    //if (fabs(value-0.5)<1.0e-5) {
     393    //returnValue = 3.0*returnValue + 0.2;
     394    //} else if (value>0.9) {
     395    //returnValue = 2.0*returnValue + 0.1;
     396    //}
    328397    return CoinMax(returnValue,1.0e-15);
    329398  }
     
    667736  int way = object_->way();
    668737  double value = object_->value();
     738#define TYPE2
    669739  if (way<0) {
    670740    // down
    671     object->incrementNumberTimesDown();
    672741    if (feasible) {
     742      object->incrementNumberTimesDown();
     743      object->addToSumDownChange(1.0e-30+value-floor(value));
     744      object->addToSumDownDecrease(originalUnsatisfied-unsatisfied);
     745#ifndef TYPE2
    673746      object->addToSumDownCost(change/(1.0e-30+(value-floor(value))));
    674       object->addToSumDownDecrease(originalUnsatisfied-unsatisfied);
    675747      object->setDownDynamicPseudoCost(object->sumDownCost()/(double) object->numberTimesDown());
     748#else
     749      object->addToSumDownCost(change);
     750      object->setDownDynamicPseudoCost(object->sumDownCost()/object->sumDownChange());
     751#endif
    676752    } else {
    677753      object->incrementNumberTimesDownInfeasible();
     
    681757    if (feasible) {
    682758      object->incrementNumberTimesUp();
     759      object->addToSumUpChange(1.0e-30+ceil(value)-value);
     760      object->addToSumUpDecrease(unsatisfied-originalUnsatisfied);
     761#ifndef TYPE2
    683762      object->addToSumUpCost(change/(1.0e-30+(ceil(value)-value)));
    684       object->addToSumUpDecrease(unsatisfied-originalUnsatisfied);
    685763      object->setUpDynamicPseudoCost(object->sumUpCost()/(double) object->numberTimesUp());
     764#else
     765      object->addToSumUpCost(change);
     766      object->setUpDynamicPseudoCost(object->sumUpCost()/object->sumUpChange());
     767#endif
    686768    } else {
    687769      object->incrementNumberTimesUpInfeasible();
     
    786868  }
    787869  if (betterWay) {
     870    // maybe change better way
     871    CbcDynamicPseudoCostBranchingObject * branchingObject =
     872      dynamic_cast<CbcDynamicPseudoCostBranchingObject *>(thisOne);
     873    assert (branchingObject);
     874    CbcSimpleIntegerDynamicPseudoCost *  object = branchingObject->object();
     875    double separator = object->upDownSeparator();
     876    if (separator>0.0) {
     877      const double * solution = thisOne->model()->testSolution();
     878      double valueVariable = solution[object->columnNumber()];
     879      betterWay = (valueVariable-floor(valueVariable)>=separator) ? 1 : -1;
     880    }
    788881    bestCriterion_ = value;
    789882    bestChangeUp_ = changeUp;
  • trunk/CbcModel.cpp

    r227 r231  
    430430  if (!nodeCompare_)
    431431    nodeCompare_=new CbcCompareDefault();;
     432  // See if hot start wanted
     433  CbcCompareBase * saveCompare = NULL;
     434  if (hotstartSolution_) {
     435    if (strategy_&&strategy_->preProcessState()>0) {
     436      CglPreProcess * process = strategy_->process();
     437      assert (process);
     438      int n = solver_->getNumCols();
     439      const int * originalColumns = process->originalColumns();
     440      // columns should be in order ... but
     441      double * tempS = new double[n];
     442      for (int i=0;i<n;i++) {
     443        int iColumn = originalColumns[i];
     444        tempS[i]=hotstartSolution_[iColumn];
     445      }
     446      delete [] hotstartSolution_;
     447      hotstartSolution_=tempS;
     448      if (hotstartPriorities_) {
     449        int * tempP = new int [n];
     450        for (int i=0;i<n;i++) {
     451          int iColumn = originalColumns[i];
     452          tempP[i]=hotstartPriorities_[iColumn];
     453        }
     454        delete [] hotstartPriorities_;
     455        hotstartPriorities_=tempP;
     456      }
     457    }
     458    saveCompare = nodeCompare_;
     459    // depth first
     460    nodeCompare_ = new CbcCompareDepth();
     461  }
    432462  if (!problemFeasibility_)
    433463    problemFeasibility_=new CbcFeasibilityBase();
     
    919949      if (redoTree)
    920950        tree_->setComparison(*nodeCompare_) ;
     951    }
     952    if (saveCompare&&!hotstartSolution_) {
     953      // hotstart switched off
     954      delete nodeCompare_; // off depth first
     955      nodeCompare_=saveCompare;
     956      saveCompare=NULL;
     957      // redo tree
     958      tree_->setComparison(*nodeCompare_) ;
    921959    }
    922960    if ((numberNodes_%printFrequency_) == 0) {
     
    11951233          if (checkingNode)
    11961234            setSpecialOptions(specialOptions_|8);
    1197           // switch off any hot start
    1198           hotstartStrategy_=0;
    11991235          for (i = 0 ; i < currentNumberCuts_ ; i++)
    12001236          { if (addedCuts_[i])
     
    30483084        if (checkingNode)
    30493085          setSpecialOptions(specialOptions_|8);
    3050         // switch off any hot start
    3051         hotstartStrategy_=0;
    30523086        for (i = 0 ; i < currentNumberCuts_ ; i++) {
    30533087          if (addedCuts_[i]) {
     
    32753309  numberSolutions_(0),
    32763310  stateOfSearch_(0),
    3277   hotstartStrategy_(0),
     3311  hotstartSolution_(NULL),
     3312  hotstartPriorities_(NULL),
    32783313  numberHeuristicSolutions_(0),
    32793314  numberNodes_(0),
     
    33923427  numberSolutions_(0),
    33933428  stateOfSearch_(0),
    3394   hotstartStrategy_(0),
     3429  hotstartSolution_(NULL),
     3430  hotstartPriorities_(NULL),
    33953431  numberHeuristicSolutions_(0),
    33963432  numberNodes_(0),
     
    36003636  numberSolutions_(rhs.numberSolutions_),
    36013637  stateOfSearch_(rhs.stateOfSearch_),
    3602   hotstartStrategy_(rhs.hotstartStrategy_),
    36033638  numberHeuristicSolutions_(rhs.numberHeuristicSolutions_),
    36043639  numberNodes_(rhs.numberNodes_),
     
    37453780    integerInfo_=NULL;
    37463781  }
     3782  if (rhs.hotstartSolution_) {
     3783    int numberColumns = solver_->getNumCols();
     3784    hotstartSolution_ = CoinCopyOfArray(rhs.hotstartSolution_,numberColumns);
     3785    hotstartPriorities_ = CoinCopyOfArray(rhs.hotstartPriorities_,numberColumns);
     3786  } else {
     3787    hotstartSolution_ = NULL;
     3788    hotstartPriorities_ =NULL;
     3789  }
    37473790  if (rhs.bestSolution_&&!noTree) {
    37483791    int numberColumns = solver_->getNumCols();
     
    38623905    numberSolutions_=rhs.numberSolutions_;
    38633906    stateOfSearch_= rhs.stateOfSearch_;
    3864     hotstartStrategy_=rhs.hotstartStrategy_;
    38653907    numberHeuristicSolutions_=rhs.numberHeuristicSolutions_;
    38663908    numberNodes_ = rhs.numberNodes_;
     
    39984040      integerVariable_ = NULL;
    39994041      integerInfo_=NULL;
     4042    }
     4043    if (rhs.hotstartSolution_) {
     4044      int numberColumns = solver_->getNumCols();
     4045      hotstartSolution_ = CoinCopyOfArray(rhs.hotstartSolution_,numberColumns);
     4046      hotstartPriorities_ = CoinCopyOfArray(rhs.hotstartPriorities_,numberColumns);
     4047    } else {
     4048      hotstartSolution_ = NULL;
     4049      hotstartPriorities_ =NULL;
    40004050    }
    40014051    numberRowsAtContinuous_ = rhs.numberRowsAtContinuous_;
     
    41234173  numberSolutions_=0;
    41244174  stateOfSearch_=0;
    4125   hotstartStrategy_=0;
     4175  delete [] hotstartSolution_;
     4176  hotstartSolution_=NULL;
     4177  delete [] hotstartPriorities_;
     4178  hotstartPriorities_=NULL;
    41264179  numberHeuristicSolutions_=0;
    41274180  numberNodes_=0;
     
    82258278  }
    82268279}
     8280
     8281/* Pass in target solution and optional priorities.
     8282   If priorities then >0 means only branch if incorrect
     8283   while <0 means branch even if correct. +1 or -1 are
     8284   highest priority */
     8285void
     8286CbcModel::setHotstartSolution(const double * solution, const int * priorities)
     8287{
     8288  if (solution==NULL) {
     8289    delete [] hotstartSolution_;
     8290    hotstartSolution_=NULL;
     8291    delete [] hotstartPriorities_;
     8292    hotstartPriorities_=NULL;
     8293  } else {
     8294    int numberColumns = solver_->getNumCols();
     8295    hotstartSolution_ = CoinCopyOfArray(solution,numberColumns);
     8296    for (int i=0;i<numberColumns;i++) {
     8297      if (solver_->isInteger(i))
     8298        hotstartSolution_[i]=floor(hotstartSolution_[i]+0.5);
     8299    }
     8300    hotstartPriorities_ = CoinCopyOfArray(priorities,numberColumns);
     8301  }
     8302}
  • trunk/CbcNode.cpp

    r222 r231  
    880880  bool beforeSolution = model->getSolutionCount()==0;
    881881  int numberStrong=model->numberStrong();
     882  // switch off strong if hotstart
     883  if (model->hotstartSolution())
     884    numberStrong=0;
    882885  int saveNumberStrong=numberStrong;
    883886  int numberObjects = model->numberObjects();
     
    924927      //                      numberObjectInfeasibilities);
    925928      // If forcePriority > 0 then we want best solution
    926       const double * bestSolution = NULL;
    927       int hotstartStrategy=model->getHotstartStrategy();
    928       if (hotstartStrategy>0) {
    929         bestSolution = model->bestSolution();
    930       }
     929      const double * hotstartSolution = model->hotstartSolution();
     930      const int * hotstartPriorities = model->hotstartPriorities();
    931931     
    932932      // Some objects may compute an estimate of best solution from here
     
    959959        double infeasibility = object->infeasibility(preferredWay);
    960960        int priorityLevel = object->priority();
    961         if (bestSolution) {
     961        if (hotstartSolution) {
    962962          // we are doing hot start
    963963          const CbcSimpleInteger * thisOne = dynamic_cast <const CbcSimpleInteger *> (object);
    964964          if (thisOne) {
    965965            int iColumn = thisOne->modelSequence();
     966            double targetValue = hotstartSolution[iColumn];
    966967            if (saveUpper[iColumn]>saveLower[iColumn]) {
    967968              double value = saveSolution[iColumn];
    968               double targetValue = bestSolution[iColumn];
     969              if (hotstartPriorities)
     970                priorityLevel=hotstartPriorities[iColumn];
    969971              //double originalLower = thisOne->originalLower();
    970972              //double originalUpper = thisOne->originalUpper();
    971973              // switch off if not possible
    972974              if (targetValue>=saveLower[iColumn]&&targetValue<=saveUpper[iColumn]) {
    973                 /* priority outranks rest always if hotstartStrategy >1
     975                /* priority outranks rest always if negative
    974976                   otherwise can be downgraded if at correct level.
    975                    Infeasibility may be increased by targetValue to choose 1.0 values first.
     977                   Infeasibility may be increased to choose 1.0 values first.
     978                   choose one near wanted value
    976979                */
    977980                if (fabs(value-targetValue)>integerTolerance) {
     981                  infeasibility = 1.0-fabs(value-targetValue);
     982                  if (targetValue==1.0)
     983                    infeasibility += 1.0;
    978984                  if (value>targetValue) {
    979                     infeasibility += value;
    980985                    preferredWay=-1;
    981986                  } else {
    982                     infeasibility += targetValue;
    983987                    preferredWay=1;
    984988                  }
    985                 } else if (hotstartStrategy>1) {
     989                  priorityLevel = CoinAbs(priorityLevel);
     990                } else if (priorityLevel<0) {
     991                  priorityLevel = CoinAbs(priorityLevel);
    986992                  if (targetValue==saveLower[iColumn]) {
    987                     infeasibility += integerTolerance+1.0e-12;
     993                    infeasibility = integerTolerance+1.0e-12;
    988994                    preferredWay=-1;
    989995                  } else if (targetValue==saveUpper[iColumn]) {
    990                     infeasibility += integerTolerance+1.0e-12;
     996                    infeasibility = integerTolerance+1.0e-12;
    991997                    preferredWay=1;
    992998                  } else {
    993                     infeasibility += integerTolerance+1.0e-12;
    994                     preferredWay=1;
     999                    // can't
     1000                    priorityLevel += 10000000;
    9951001                  }
    9961002                } else {
     
    9991005              } else {
    10001006                // switch off if not possible
    1001                 bestSolution=NULL;
    1002                 model->setHotstartStrategy(0);
     1007                hotstartSolution=NULL;
     1008                model->setHotstartSolution(NULL,NULL);
    10031009              }
     1010            } else if (targetValue<saveLower[iColumn]||targetValue>saveUpper[iColumn]) {
     1011              // switch off as not possible
     1012              hotstartSolution=NULL;
     1013              model->setHotstartSolution(NULL,NULL);
    10041014            }
     1015          } else {
     1016            priorityLevel += 10000000;
    10051017          }
    10061018        }
     
    18171829    return -3;
    18181830  // Return if doing hot start (in BAB sense)
    1819   int hotstartStrategy=model->getHotstartStrategy();
    1820   if (hotstartStrategy>0)
     1831  if (model->hotstartSolution())
    18211832    return -3;
    18221833  // Pass number
  • trunk/include/CbcBranchActual.hpp

    r222 r231  
    128128  virtual CbcBranchingObject * createBranch(int way) ;
    129129
     130  /** Create an OsiSolverBranch object
     131
     132      This returns NULL if branch not represented by bound changes
     133  */
     134  virtual OsiSolverBranch * solverBranch() const;
     135 
    130136  /// Number of members
    131137  inline int numberMembers() const
     
    459465  { upPseudoCost_=value;};
    460466
     467  /// Up down separator
     468  inline double upDownSeparator() const
     469  { return upDownSeparator_;};
     470  /// Set up down separator
     471  inline void setUpDownSeparator(double value)
     472  { upDownSeparator_=value;};
     473
    461474  /// Return "up" estimate
    462475  virtual double upEstimate() const;
     
    478491  /// Up pseudo cost
    479492  double upPseudoCost_;
     493  /** Up/down separator
     494      If >0.0 then do first branch up if value-floor(value)
     495      >= this value
     496  */
     497  double upDownSeparator_;
    480498  /** Method -
    481499      0 - normal - return min (up,down)
  • trunk/include/CbcBranchDynamic.hpp

    r222 r231  
    6868  inline void setUpDynamicPseudoCost(double value)
    6969  { upDynamicPseudoCost_=value;};
     70
     71  /// Up down separator
     72  inline double upDownSeparator() const
     73  { return upDownSeparator_;};
     74  /// Set up down separator
     75  inline void setUpDownSeparator(double value)
     76  { upDownSeparator_=value;};
    7077
    7178  /// Down sum cost
     
    8996  { sumUpCost_+=value;lastUpCost_=value;sumUpCostSquared_ += value*value;};
    9097
     98  /// Down sum change
     99  inline double sumDownChange() const
     100  { return sumDownChange_;};
     101  /// Set down sum change
     102  inline void setSumDownChange(double value)
     103  { sumDownChange_=value;};
     104  /// Add to down sum change
     105  inline void addToSumDownChange(double value)
     106  { sumDownChange_+=value;};
     107
     108  /// Up sum change
     109  inline double sumUpChange() const
     110  { return sumUpChange_;};
     111  /// Set up sum change
     112  inline void setSumUpChange(double value)
     113  { sumUpChange_=value;};
     114  /// Add to up sum change and set last and square
     115  inline void addToSumUpChange(double value)
     116  { sumUpChange_+=value;};
     117
    91118  /// Sum down decrease number infeasibilities from strong or actual
    92119  inline double sumDownDecrease() const
     
    182209  /// Up pseudo cost
    183210  double upDynamicPseudoCost_;
     211  /** Up/down separator
     212      If >0.0 then do first branch up if value-floor(value)
     213      >= this value
     214  */
     215  double upDownSeparator_;
    184216  /// Sum down cost from strong or actual
    185217  double sumDownCost_;
    186218  /// Sum up cost from strong or actual
    187219  double sumUpCost_;
     220  /// Sum of all changes to x when going down
     221  double sumDownChange_;
     222  /// Sum of all changes to x when going up
     223  double sumUpChange_;
    188224  /// Sum down cost from strong or actual squared
    189225  double sumDownCostSquared_;
  • trunk/include/CbcModel.hpp

    r229 r231  
    537537  }
    538538
    539   /// Set the hotstart strategy
    540   inline void setHotstartStrategy(int value)
    541   { hotstartStrategy_=value;};
    542   /// Get the hotstart strategy
    543   inline int getHotstartStrategy() const
    544   { return hotstartStrategy_;};
     539  /** Pass in target solution and optional priorities.
     540      If priorities then >0 means only branch if incorrect
     541      while <0 means branch even if correct. +1 or -1 are
     542      highest priority */
     543  void setHotstartSolution(const double * solution, const int * priorities=NULL) ;
    545544 
    546545  /// Set the minimum drop to continue cuts
     
    11081107  //@{
    11091108
    1110   /** Perform reduced cost fixing
    1111 
    1112     Fixes integer variables at their current value based on reduced cost
    1113     penalties.  Returns number fixed
    1114   */
    1115   int reducedCostFix() ;
    1116 
    1117   /** Return an empty basis object of the specified size
    1118 
    1119     A useful utility when constructing a basis for a subproblem from scratch.
    1120     The object returned will be of the requested capacity and appropriate for
    1121     the solver attached to the model.
    1122   */
    1123   CoinWarmStartBasis *getEmptyBasis(int ns = 0, int na = 0) const ;
    1124 
    1125   /** Remove inactive cuts from the model
    1126 
    1127     An OsiSolverInterface is expected to maintain a valid basis, but not a
    1128     valid solution, when loose cuts are deleted. Restoring a valid solution
    1129     requires calling the solver to reoptimise. If it's certain the solution
    1130     will not be required, set allowResolve to false to suppress
    1131     reoptimisation.
    1132     If saveCuts then slack cuts will be saved
    1133   */
    1134   void takeOffCuts(OsiCuts &cuts,
    1135                      bool allowResolve,OsiCuts * saveCuts) ;
    1136 
    1137   /** Determine and install the active cuts that need to be added for
    1138     the current subproblem
    1139 
    1140     The whole truth is a bit more complicated. The first action is a call to
    1141     addCuts1(). addCuts() then sorts through the list, installs the tight
    1142     cuts in the model, and does bookkeeping (adjusts reference counts).
    1143     The basis returned from addCuts1() is adjusted accordingly.
    1144    
    1145     If it turns out that the node should really be fathomed by bound,
    1146     addCuts() simply treats all the cuts as loose as it does the bookkeeping.
    1147 
    1148     canFix true if extra information being passed
    1149   */
    1150   int addCuts(CbcNode * node, CoinWarmStartBasis *&lastws,bool canFix);
    1151 
    1152   /** Traverse the tree from node to root and prep the model
    1153 
    1154     addCuts1() begins the job of prepping the model to match the current
    1155     subproblem. The model is stripped of all cuts, and the search tree is
    1156     traversed from node to root to determine the changes required. Appropriate
    1157     bounds changes are installed, a list of cuts is collected but not
    1158     installed, and an appropriate basis (minus the cuts, but big enough to
    1159     accommodate them) is constructed.
    1160 
    1161     \todo addCuts1() is called in contexts where it's known in advance that
    1162           all that's desired is to determine a list of cuts and do the
    1163           bookkeeping (adjust the reference counts). The work of installing
    1164           bounds and building a basis goes to waste.
    1165   */
    1166   void addCuts1(CbcNode * node, CoinWarmStartBasis *&lastws);
    1167 
    1168   /// Return the list of cuts initially collected for this subproblem
    1169   inline CbcCountRowCut ** addedCuts() const
    1170   { return addedCuts_;};
    1171   /// Number of entries in the list returned by #addedCuts()
    1172   inline int currentNumberCuts() const
    1173   { return currentNumberCuts_;};
    1174   /// Global cuts
    1175   inline OsiCuts * globalCuts()
    1176   { return &globalCuts_;};
    1177   /// Copy and set a pointer to a row cut which will be added instead of normal branching.
    1178   void setNextRowCut(const OsiRowCut & cut);
    1179   /// Get a pointer to current node (be careful)
    1180   inline CbcNode * currentNode() const
    1181   { return currentNode_;};
    11821109  /** State of search
    11831110      0 - no solution
     
    14111338  /// Set pointers for speed
    14121339  void setPointers(const OsiSolverInterface * solver);
     1340  /** Perform reduced cost fixing
     1341
     1342    Fixes integer variables at their current value based on reduced cost
     1343    penalties.  Returns number fixed
     1344  */
     1345  int reducedCostFix() ;
     1346
     1347  /** Return an empty basis object of the specified size
     1348
     1349    A useful utility when constructing a basis for a subproblem from scratch.
     1350    The object returned will be of the requested capacity and appropriate for
     1351    the solver attached to the model.
     1352  */
     1353  CoinWarmStartBasis *getEmptyBasis(int ns = 0, int na = 0) const ;
     1354
     1355  /** Remove inactive cuts from the model
     1356
     1357    An OsiSolverInterface is expected to maintain a valid basis, but not a
     1358    valid solution, when loose cuts are deleted. Restoring a valid solution
     1359    requires calling the solver to reoptimise. If it's certain the solution
     1360    will not be required, set allowResolve to false to suppress
     1361    reoptimisation.
     1362    If saveCuts then slack cuts will be saved
     1363  */
     1364  void takeOffCuts(OsiCuts &cuts,
     1365                     bool allowResolve,OsiCuts * saveCuts) ;
     1366
     1367  /** Determine and install the active cuts that need to be added for
     1368    the current subproblem
     1369
     1370    The whole truth is a bit more complicated. The first action is a call to
     1371    addCuts1(). addCuts() then sorts through the list, installs the tight
     1372    cuts in the model, and does bookkeeping (adjusts reference counts).
     1373    The basis returned from addCuts1() is adjusted accordingly.
     1374   
     1375    If it turns out that the node should really be fathomed by bound,
     1376    addCuts() simply treats all the cuts as loose as it does the bookkeeping.
     1377
     1378    canFix true if extra information being passed
     1379  */
     1380  int addCuts(CbcNode * node, CoinWarmStartBasis *&lastws,bool canFix);
     1381
     1382  /** Traverse the tree from node to root and prep the model
     1383
     1384    addCuts1() begins the job of prepping the model to match the current
     1385    subproblem. The model is stripped of all cuts, and the search tree is
     1386    traversed from node to root to determine the changes required. Appropriate
     1387    bounds changes are installed, a list of cuts is collected but not
     1388    installed, and an appropriate basis (minus the cuts, but big enough to
     1389    accommodate them) is constructed.
     1390
     1391    \todo addCuts1() is called in contexts where it's known in advance that
     1392          all that's desired is to determine a list of cuts and do the
     1393          bookkeeping (adjust the reference counts). The work of installing
     1394          bounds and building a basis goes to waste.
     1395  */
     1396  void addCuts1(CbcNode * node, CoinWarmStartBasis *&lastws);
     1397
     1398  /// Get the hotstart solution
     1399  inline const double * hotstartSolution() const
     1400  { return hotstartSolution_;};
     1401  /// Get the hotstart priorities
     1402  inline const int * hotstartPriorities() const
     1403  { return hotstartPriorities_;};
     1404
     1405  /// Return the list of cuts initially collected for this subproblem
     1406  inline CbcCountRowCut ** addedCuts() const
     1407  { return addedCuts_;};
     1408  /// Number of entries in the list returned by #addedCuts()
     1409  inline int currentNumberCuts() const
     1410  { return currentNumberCuts_;};
     1411  /// Global cuts
     1412  inline OsiCuts * globalCuts()
     1413  { return &globalCuts_;};
     1414  /// Copy and set a pointer to a row cut which will be added instead of normal branching.
     1415  void setNextRowCut(const OsiRowCut & cut);
     1416  /// Get a pointer to current node (be careful)
     1417  inline CbcNode * currentNode() const
     1418  { return currentNode_;};
    14131419  //@}
    14141420
     
    15001506  */
    15011507  int stateOfSearch_;
    1502   /// Hotstart strategy 0 =off, 1=branch if incorrect,2=branch even if correct, ....
    1503   int hotstartStrategy_;
     1508  /// Hotstart solution
     1509  double * hotstartSolution_;
     1510  /// Hotstart priorities
     1511  int * hotstartPriorities_;
    15041512  /// Number of heuristic solutions
    15051513  int numberHeuristicSolutions_;
Note: See TracChangeset for help on using the changeset viewer.