Ignore:
Timestamp:
Aug 21, 2009 12:19:13 PM (10 years ago)
Author:
forrest
Message:

fixes

File:
1 edited

Legend:

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

    r1211 r1212  
    577577#endif
    578578    } else if (largestObj<smallestObj*5.0&&!parentModel_&&
    579                numberIntegerObj*1.2<numberColumns) {
     579               !numberContinuousObj&&
     580               numberIntegerObj*2<numberColumns) {
    580581      // up priorities on costed
    581582      int iPriority=-1;
     
    14671468    feasible=false; // pretend infeasible
    14681469  }
     1470  numberSavedSolutions_=0;
    14691471  int saveNumberStrong = numberStrong_;
    14701472  int saveNumberBeforeTrust = numberBeforeTrust_;
     
    16601662  if(solverCharacteristics_->reducedCostsAccurate())
    16611663    analyzeObjective() ;
     1664  {
     1665    // may be able to change cutoff now
     1666    double cutoff = getCutoff();
     1667    double increment = getDblParam(CbcModel::CbcCutoffIncrement) ;
     1668    if (cutoff > bestObjective_-increment) {
     1669      cutoff = bestObjective_-increment ;
     1670      setCutoff(cutoff) ;
     1671    }
     1672  }
    16621673#ifdef COIN_HAS_CLP
    16631674  // Possible save of pivot method
     
    19781989      OsiClpSolverInterface * clpSolver
    19791990        = dynamic_cast<OsiClpSolverInterface *> (copy1);
    1980       if (clpSolver) {
     1991      if (false&&clpSolver) {
    19811992        numberRows = clpSolver->getNumRows();
    19821993        char * rotate = new char[numberRows];
    19831994        int n = clpSolver->getModelPtr()->findNetwork(rotate,1.0);
     1995        delete [] rotate;
    19841996#ifdef CLP_INVESTIGATE
    19851997        printf("INTA network %d rows out of %d\n",n,numberRows);
     
    22432255    }
    22442256    cpxSolver.branchAndBound();
    2245     static double totalTime=0.0;
    22462257    double timeTaken = CoinCpuTime()-time1;
    2247     totalTime += timeTaken;
    2248     sprintf(printBuffer,"Cplex took %g seconds - total %g",
    2249             timeTaken,totalTime);
     2258    sprintf(printBuffer,"Cplex took %g seconds",
     2259            timeTaken);
    22502260    messageHandler()->message(CBC_GENERAL,messages())
    22512261      << printBuffer << CoinMessageEol ;
     
    22662276  }
    22672277#endif
     2278  if(fastNodeDepth_==1000&&/*!parentModel_*/(specialOptions_&2048)==0) {
     2279    fastNodeDepth_=-1;
     2280    CbcObject * obj =
     2281      new CbcFollowOn(this);
     2282    obj->setPriority(1);
     2283    addObjects(1,&obj);
     2284  }
    22682285  int saveNumberSolves=numberSolves_;
    22692286  int saveNumberIterations=numberIterations_;
     
    27972814  */
    27982815  numberLongStrong_=0;
    2799   double totalTime = 0.0;
    28002816  CbcNode * createdNode=NULL;
    28012817#ifdef CBC_THREAD
     
    29342950      }
    29352951      //abort();
     2952    }
     2953  }
     2954  {
     2955    // may be able to change cutoff now
     2956    double cutoff = getCutoff();
     2957    double increment = getDblParam(CbcModel::CbcCutoffIncrement) ;
     2958    if (cutoff > bestObjective_-increment) {
     2959      cutoff = bestObjective_-increment ;
     2960      setCutoff(cutoff) ;
    29362961    }
    29372962  }
     
    32553280  Check for abort on limits: node count, solution count, time, integrality gap.
    32563281*/
    3257     totalTime = getCurrentSeconds() ;
    3258     double maxSeconds = getMaximumSeconds();
    3259     if (parentModel_)
    3260       maxSeconds=CoinMin(maxSeconds,parentModel_->getMaximumSeconds());
    32613282    if (!(numberNodes_ < intParam_[CbcMaxNumNode] &&
    32623283          numberSolutions_ < intParam_[CbcMaxNumSol] &&
    3263           totalTime < maxSeconds &&
     3284          !maximumSecondsReached() &&
    32643285          !stoppedOnGap_&&!eventHappened_&&(maximumNumberIterations_<0||
    32653286                                            numberIterations_<maximumNumberIterations_))) {
     
    34163437      if (parallelMode()>0)
    34173438        unlockThread();
     3439#ifdef CLP_INVESTIGATE
     3440      if (getCutoff()<1.0e20) {
     3441        if (fabs(getCutoff()-(bestObjective_-getCutoffIncrement()))>1.0e-6&&
     3442            !parentModel_)
     3443          printf("model cutoff in status %g, best %g, increment %g\n",
     3444                 getCutoff(),bestObjective_,getCutoffIncrement());
     3445        assert (getCutoff()<bestObjective_-getCutoffIncrement()+1.0e-6);
     3446      }
     3447#endif
    34183448      if (!intParam_[CbcPrinting]) {
    34193449        messageHandler()->message(CBC_STATUS,messages())
     
    37933823  it'll be deleted in cleanTree. We need to check.
    37943824*/
    3795     double maxSeconds = getMaximumSeconds();
    3796     if (parentModel_)
    3797       maxSeconds=CoinMin(maxSeconds,parentModel_->getMaximumSeconds());
    37983825    if (!(numberNodes_ < intParam_[CbcMaxNumNode] &&
    37993826          numberSolutions_ < intParam_[CbcMaxNumSol] &&
    3800           totalTime < maxSeconds &&
     3827          !maximumSecondsReached() &&
    38013828          !stoppedOnGap_&&!eventHappened_&&(maximumNumberIterations_<0||
    38023829                                            numberIterations_<maximumNumberIterations_))) {
     
    38203847            status_ = 1 ; }
    38213848          else
    3822         if (totalTime >= dblParam_[CbcMaximumSeconds])
     3849            if (maximumSecondsReached())
    38233850          { handler_->message(CBC_MAXTIME,messages_) << CoinMessageEol ;
    38243851          secondaryStatus_ = 4;
     
    42894316  sumChangeObjective2_(0.0),
    42904317  bestSolution_(NULL),
     4318  savedSolutions_(NULL),
    42914319  currentSolution_(NULL),
    42924320  testSolution_(NULL),
    42934321  minimumDrop_(1.0e-4),
    42944322  numberSolutions_(0),
     4323  numberSavedSolutions_(0),
     4324  maximumSavedSolutions_(0),
    42954325  stateOfSearch_(0),
    42964326  whenCuts_(-1),
     
    44564486  minimumDrop_(1.0e-4),
    44574487  numberSolutions_(0),
     4488  numberSavedSolutions_(0),
     4489  maximumSavedSolutions_(0),
    44584490  stateOfSearch_(0),
    44594491  whenCuts_(-1),
     
    45764608  strongInfo_[6]=0;
    45774609  solverCharacteristics_ = NULL;
    4578 
    45794610  nodeCompare_=new CbcCompareDefault();;
    45804611  problemFeasibility_=new CbcFeasibilityBase();
     
    46034634  // Initialize solution and integer variable vectors
    46044635  bestSolution_ = NULL; // to say no solution found
     4636  savedSolutions_ = NULL;
    46054637  numberIntegers_=0;
    46064638  int numberColumns = solver_->getNumCols();
     
    47244756  minimumDrop_(rhs.minimumDrop_),
    47254757  numberSolutions_(rhs.numberSolutions_),
     4758  numberSavedSolutions_(rhs.numberSavedSolutions_),
     4759  maximumSavedSolutions_(rhs.maximumSavedSolutions_),
    47264760  stateOfSearch_(rhs.stateOfSearch_),
    47274761  whenCuts_(rhs.whenCuts_),
     
    49304964  }
    49314965  int numberColumns = solver_->getNumCols();
     4966  if (maximumSavedSolutions_&&rhs.savedSolutions_) {
     4967    savedSolutions_ = new double * [maximumSavedSolutions_];
     4968    for (int i=0;i<maximumSavedSolutions_;i++)
     4969      savedSolutions_[i]=CoinCopyOfArray(rhs.savedSolutions_[i],numberColumns+2);
     4970  } else {
     4971    savedSolutions_=NULL;
     4972  }
    49324973  // Space for current solution
    49334974  currentSolution_ = new double[numberColumns];
     
    50285069      bestSolution_=NULL;
    50295070    }
     5071    for (int i=0;i<maximumSavedSolutions_;i++)
     5072      delete [] savedSolutions_[i];
     5073    delete [] savedSolutions_;
     5074    savedSolutions_=NULL;
    50305075    int numberColumns = rhs.getNumCols();
    50315076    if (numberColumns) {
     
    50405085      usedInSolution_=NULL;
    50415086    }
     5087    if (maximumSavedSolutions_) {
     5088      savedSolutions_ = new double * [maximumSavedSolutions_];
     5089      for (int i=0;i<maximumSavedSolutions_;i++)
     5090        savedSolutions_[i]=CoinCopyOfArray(rhs.savedSolutions_[i],numberColumns+2);
     5091    } else {
     5092      savedSolutions_=NULL;
     5093    }
    50425094    testSolution_=currentSolution_;
    50435095    minimumDrop_ = rhs.minimumDrop_;
    50445096    numberSolutions_=rhs.numberSolutions_;
     5097    numberSavedSolutions_=rhs.numberSavedSolutions_;
     5098    maximumSavedSolutions_=rhs.maximumSavedSolutions_;
    50455099    stateOfSearch_= rhs.stateOfSearch_;
    50465100    whenCuts_ = rhs.whenCuts_;
     
    53645418  delete continuousSolver_;
    53655419  continuousSolver_=NULL;
     5420  numberSavedSolutions_=0;
    53665421  delete [] bestSolution_;
    53675422  bestSolution_=NULL;
     5423  if (savedSolutions_) {
     5424    for (int i=0;i<maximumSavedSolutions_;i++)
     5425      delete [] savedSolutions_[i];
     5426    delete [] savedSolutions_;
     5427    savedSolutions_=NULL;
     5428  }
    53685429  delete [] currentSolution_;
    53695430  currentSolution_=NULL;
     
    54745535  resolveAfterTakeOffCuts_ = rhs.resolveAfterTakeOffCuts_;
    54755536  maximumNumberIterations_ = rhs.maximumNumberIterations_;
     5537  numberSavedSolutions_=rhs.numberSavedSolutions_;
     5538  maximumSavedSolutions_=rhs.maximumSavedSolutions_;
     5539  if (maximumSavedSolutions_) {
     5540    int n=solver_->getNumCols();
     5541    savedSolutions_ = new double * [maximumSavedSolutions_];
     5542    for (int i=0;i<maximumSavedSolutions_;i++)
     5543      savedSolutions_[i]=CoinCopyOfArray(rhs.savedSolutions_[i],n+2);
     5544  }
    54765545  continuousPriority_ = rhs.continuousPriority_;
    54775546  numberThreads_ = rhs.numberThreads_;
     
    65696638  sumChangeObjective1_ += solver_->getObjValue()*solver_->getObjSense()
    65706639    - objectiveValue ;
    6571   if ( getCurrentSeconds() > dblParam_[CbcMaximumSeconds] )
     6640  if ( maximumSecondsReached() )
    65726641    numberTries=0; // exit
    65736642  //if ((numberNodes_%100)==0)
     
    75907659      feasible = ( resolve(node ? node->nodeInfo() : NULL,2) != 0) ;
    75917660      //solver_->setHintParam(OsiDoDualInResolve,true,OsiHintTry);
    7592       if ( getCurrentSeconds() > dblParam_[CbcMaximumSeconds] )
     7661      if ( maximumSecondsReached() ) {
    75937662        numberTries=0; // exit
     7663        break;
     7664      }
    75947665#     ifdef CBC_DEBUG
    75957666      printf("Obj value after cuts %g %d rows\n",solver_->getObjValue(),
     
    78147885    reducedCostFix() ;
    78157886  // If at root node do heuristics
    7816   if (!numberNodes_) {
     7887  if (!numberNodes_&&!maximumSecondsReached()) {
    78177888    // First see if any cuts are slack
    78187889    int numberRows = solver_->getNumRows();
     
    81558226              }
    81568227            }
    8157           } else if (thisCuts+generator_[i]->numberColumnCuts()<smallProblem) {
     8228          } else if ((thisCuts+generator_[i]->numberColumnCuts()<smallProblem)
     8229                     &&!generator_[i] ->whetherToUse()) {
    81588230            if (howOften!=1&&!probingWasOnBut) {
    81598231              if (generator_[i]->whatDepth()<0||howOften!=-1) {
     
    82118283      if (stored&&!generator_[i]->numberCutsInTotal())
    82128284        continue;
     8285      double average=0.0;
     8286      int n=generator_[i]->numberCutsInTotal();
     8287      if (n) {
     8288        average = generator_[i]->numberElementsInTotal();
     8289        average /= n;
     8290      }
    82138291      if (handler_->logLevel()>1||!numberNodes_) {
    82148292        handler_->message(CBC_GENERATOR,messages_)
     
    82168294          <<generator_[i]->cutGeneratorName()
    82178295          //<<generator_[i]->numberCutsInTotal()<<count[i]
    8218           << generator_[i]->numberCutsInTotal()
     8296          << n
     8297          << average
    82198298          <<generator_[i]->numberColumnCuts()
    82208299          <<generator_[i]->numberCutsActive()
     
    1049810577      */
    1049910578      specialOptions_ |= 256; // mark as full cut scan should be done
    10500       bestObjective_ = objectiveValue;
    10501       int numberColumns = solver_->getNumCols();
    10502       if (!bestSolution_)
    10503         bestSolution_ = new double[numberColumns];
    10504       CoinCopyN(solution,numberColumns,bestSolution_);
     10579      saveBestSolution(solution,objectiveValue);
     10580      //bestObjective_ = objectiveValue;
     10581      //int numberColumns = solver_->getNumCols();
     10582      //if (!bestSolution_)
     10583      //bestSolution_ = new double[numberColumns];
     10584      //CoinCopyN(solution,numberColumns,bestSolution_);
    1050510585     
    1050610586      cutoff = bestObjective_-dblParam_[CbcCutoffIncrement];
     
    1067810758        NB - Not all of this if from solve with cuts
    1067910759      */
    10680       bestObjective_ = objectiveValue;
    10681       int numberColumns = solver_->getNumCols();
    10682       if (!bestSolution_)
    10683         bestSolution_ = new double[numberColumns];
    10684       CoinCopyN(candidate,numberColumns,bestSolution_);
     10760      saveBestSolution(solution,objectiveValue);
     10761      //bestObjective_ = objectiveValue;
     10762      //int numberColumns = solver_->getNumCols();
     10763      //if (!bestSolution_)
     10764      //bestSolution_ = new double[numberColumns];
     10765      //CoinCopyN(candidate,numberColumns,bestSolution_);
    1068510766
    1068610767      // don't update if from solveWithCuts
     
    1208112162      messageHandler()->message(CBC_GENERAL,messages())
    1208212163        << printBuffer << CoinMessageEol ;
    12083       // may be able to change cutoff now
    12084       double cutoff = getCutoff();
    12085       double increment = getDblParam(CbcModel::CbcCutoffIncrement) ;
    12086       if (cutoff > objectiveValue-increment) {
    12087         cutoff = objectiveValue-increment ;
    12088         setCutoff(cutoff) ;
    12089       }
    12090     }
    12091   }
     12164    }
     12165  }
     12166  if (bestSolution_)
     12167    saveExtraSolution(bestSolution_,bestObjective_);
    1209212168  bestObjective_ = objectiveValue;
     12169  // may be able to change cutoff now
     12170  double cutoff = getCutoff();
     12171  double increment = getDblParam(CbcModel::CbcCutoffIncrement) ;
     12172  if (cutoff > objectiveValue-increment) {
     12173    cutoff = objectiveValue-increment ;
     12174    setCutoff(cutoff) ;
     12175  }
    1209312176  int n = CoinMax(numberColumns,solver_->getNumCols());
    1209412177  delete [] bestSolution_;
     
    1222212305          if (!heuristic_[i]->shouldHeurRun(whereFrom))
    1222312306            continue;
     12307          if (maximumSecondsReached())
     12308            break;
    1222412309          // see if heuristic will do anything
    1222512310          double saveValue = heuristicValue ;
     
    1274912834            delete [] up;
    1275012835            delete [] numberDown;
     12836            delete [] priority;
    1275112837            delete [] numberUp;
    1275212838            delete [] numberDownInfeasible;
     
    1275612842            solver_->getHintParam(OsiDoReducePrint,takeHint,strength);
    1275712843            ClpSimplex * simplex = clpSolver->getModelPtr();
     12844            //printf("mod cutoff %g solver %g offset %g\n",
     12845            //   getCutoff(),simplex->dualObjectiveLimit(),simplex->objectiveOffset());
    1275812846            int saveLevel = simplex->logLevel();
    1275912847            if (strength!=OsiHintIgnore&&takeHint&&saveLevel==1)
     
    1282612914              double largest=-1.0;
    1282712915              for (int i=0;i<numberIntegers_;i++) {
    12828 #ifndef NDEBUG
    1282912916                CbcSimpleIntegerDynamicPseudoCost * obj =
    1283012917                  dynamic_cast <CbcSimpleIntegerDynamicPseudoCost *>(object_[i]) ;
    12831                 assert (obj&&obj->columnNumber()==integerVariable_[i]);
    12832 #else
    12833                 CbcSimpleIntegerDynamicPseudoCost * obj =
    12834                   static_cast <CbcSimpleIntegerDynamicPseudoCost *>(object_[i]) ;
    12835 #endif
     12918                if (!obj)
     12919                  continue;
     12920                assert (obj->columnNumber()==integerVariable_[i]);
    1283612921                if (info->numberUp_[i]>0) {
    1283712922                  if (info->downPseudo_[i]>largest)
     
    1446114546  }
    1446214547}
     14548// Number of saved solutions (including best)
     14549int
     14550CbcModel::numberSavedSolutions() const
     14551{
     14552  if (!bestSolution_)
     14553    return 0;
     14554  else
     14555    return numberSavedSolutions_+1;
     14556}
     14557// Set maximum number of extra saved solutions
     14558void
     14559CbcModel::setMaximumSavedSolutions(int value)
     14560{
     14561  if (value<maximumSavedSolutions_) {
     14562    for (int i=value;i<maximumSavedSolutions_;i++)
     14563      delete [] savedSolutions_[i];
     14564    maximumSavedSolutions_=value;
     14565    numberSavedSolutions_ = CoinMin(numberSavedSolutions_,
     14566                                    maximumSavedSolutions_);
     14567    if (!maximumSavedSolutions_)
     14568      delete [] savedSolutions_;
     14569  } else if (value>maximumSavedSolutions_) {
     14570    double ** temp = new double * [value];
     14571    int i;
     14572    for ( i=0;i<maximumSavedSolutions_;i++)
     14573      temp[i]=savedSolutions_[i];
     14574    for ( ;i<value;i++)
     14575      temp[i]=NULL;
     14576    delete [] savedSolutions_;
     14577    maximumSavedSolutions_=value;
     14578    savedSolutions_ = temp;
     14579  }
     14580}
     14581// Return a saved solution objective (0==best) - COIN_DBL_MAX if off end
     14582double
     14583CbcModel::savedSolutionObjective(int which) const
     14584{
     14585  if (which==0) {
     14586    return bestObjective_;
     14587  } else if (which<=numberSavedSolutions_) {
     14588    double * sol = savedSolutions_[which-1];
     14589    assert (static_cast<int>(sol[0])==solver_->getNumCols());
     14590    return sol[1];
     14591  } else {
     14592    return COIN_DBL_MAX;
     14593  }
     14594}
     14595// Return a saved solution (0==best) - NULL if off end
     14596const double *
     14597CbcModel::savedSolution(int which) const
     14598{
     14599  if (which==0) {
     14600    return bestSolution_;
     14601  } else if (which<=numberSavedSolutions_) {
     14602    double * sol = savedSolutions_[which-1];
     14603    assert (static_cast<int>(sol[0])==solver_->getNumCols());
     14604    return sol+2;
     14605  } else {
     14606    return NULL;
     14607  }
     14608}
     14609// Save a solution
     14610void
     14611CbcModel::saveExtraSolution(const double * solution, double objectiveValue)
     14612{
     14613  double * save=NULL;
     14614  if (maximumSavedSolutions_) {
     14615    if (!savedSolutions_) {
     14616      savedSolutions_ = new double * [maximumSavedSolutions_];
     14617      for (int i=0;i<maximumSavedSolutions_;i++)
     14618        savedSolutions_[i]=NULL;
     14619    }
     14620    int n=solver_->getNumCols();
     14621    int k;
     14622    for (k=numberSavedSolutions_-1;k>=0;k--) {
     14623      double * sol = savedSolutions_[k];
     14624      assert (static_cast<int>(sol[0])==n);
     14625      if (objectiveValue>sol[1])
     14626        break;
     14627    }
     14628    k++; // where to put
     14629    if (k<maximumSavedSolutions_) {
     14630      if (numberSavedSolutions_==maximumSavedSolutions_) {
     14631        save = savedSolutions_[numberSavedSolutions_-1];
     14632      } else {
     14633        save = new double [n+2];
     14634        numberSavedSolutions_++;
     14635      }
     14636      // move up
     14637      for (int j=maximumSavedSolutions_-1;j>k;j--)
     14638        savedSolutions_[j]=savedSolutions_[j-1];
     14639      savedSolutions_[k]=save;
     14640      save[0]=n;
     14641      save[1]=objectiveValue;
     14642      memcpy(save+2,solution,n*sizeof(double));
     14643    }
     14644  }
     14645}
     14646// Save a solution to best and move current to saved
     14647void
     14648CbcModel::saveBestSolution(const double * solution, double objectiveValue)
     14649{
     14650  int n=solver_->getNumCols();
     14651  if (bestSolution_)
     14652    saveExtraSolution(bestSolution_,bestObjective_);
     14653  else
     14654    bestSolution_ = new double [n];
     14655  bestObjective_=objectiveValue;
     14656  memcpy(bestSolution_,solution,n*sizeof(double));
     14657}
     14658// Delete best and saved solutions
     14659void
     14660CbcModel::deleteSolutions()
     14661{
     14662  delete [] bestSolution_;
     14663  bestSolution_=NULL;
     14664  for (int i=0;i<maximumSavedSolutions_;i++) {
     14665    delete [] savedSolutions_[i];
     14666    savedSolutions_[i]=NULL;
     14667  }
     14668}
    1446314669// Below this is deprecated or at least fairly deprecated
    1446414670/*
     
    1492515131    solver_->setInteger(index);
    1492615132}
     15133// Return true if maximum time reached
     15134bool
     15135CbcModel::maximumSecondsReached() const
     15136{
     15137  double totalTime = getCurrentSeconds() ;
     15138  double maxSeconds = getMaximumSeconds();
     15139  if (totalTime>=maxSeconds)
     15140    return true;
     15141  if (!parentModel_) {
     15142    return false;
     15143  } else {
     15144    totalTime += parentModel_->getCurrentSeconds();
     15145    maxSeconds=parentModel_->getMaximumSeconds();
     15146    return (totalTime>=maxSeconds);
     15147  }
     15148}
    1492715149// Check original model before it gets messed up
    1492815150void
Note: See TracChangeset for help on using the changeset viewer.