Changeset 1230


Ignore:
Timestamp:
Sep 14, 2009 6:10:02 AM (10 years ago)
Author:
forrest
Message:

fixes to get all solutions

Location:
trunk/Cbc/src
Files:
7 edited

Legend:

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

    r1224 r1230  
    6969    switches_(1)
    7070{
    71   if (howOften<-2000) {
     71  if (howOften<-1900) {
    7272    setGlobalCuts(true);
    7373    howOften+=2000;
    74   } else if (howOften<-1000) {
     74  } else if (howOften<-900) {
    7575    setGlobalCutsAtRoot(true);
    7676    howOften+=1000;
     
    244244    if (globalCuts())
    245245      info.options |=16;
     246    if (fullScan<0)
     247      info.options |= 128;
    246248    incrementNumberTimesEntered();
    247249    CglProbing* generator =
  • trunk/Cbc/src/CbcCutGenerator.hpp

    r1221 r1230  
    5656    \p cs.
    5757
    58     If \p fullScan is >0, the generator is obliged to call the CGL
     58    If \p fullScan is !=0, the generator is obliged to call the CGL
    5959    \c generateCuts routine.  Otherwise, it is free to make a local decision.
     60    Negative fullScan says things like at integer solution
    6061    The current implementation uses \c whenCutGenerator_ to decide.
    6162
  • trunk/Cbc/src/CbcEventHandler.hpp

    r1221 r1230  
    9191    /*! A heuristic solution has been found. */
    9292    heuristicSolution,
    93     /*! A solution will be found unless user takes action. */
    94     beforeSolution,
     93    /*! A solution will be found unless user takes action (first check). */
     94    beforeSolution1,
     95    /*! A solution will be found unless user takes action (thorough check). */
     96    beforeSolution2,
    9597    /*! End of search. */
    9698    endSearch
     
    113115    /*! RestartRoot --- undo root node and start branch-and-cut afresh. */
    114116    restartRoot,
     117    /*! Add special cuts. */
     118    addCuts,
    115119    /*! Pretend solution never happened. */
    116120    killSolution
  • trunk/Cbc/src/CbcHeuristicDivePseudoCost.cpp

    r1224 r1230  
    164164        dynamic_cast <CbcSimpleIntegerDynamicPseudoCost *>(objects[i]) ;
    165165      if (obj1) {
    166         int iColumn = obj1->columnNumber();
     166        //int iColumn = obj1->columnNumber();
    167167        double downPseudoCost = obj1->downDynamicPseudoCost();
    168168        double downShadow = obj1->downShadowPrice();
  • trunk/Cbc/src/CbcModel.cpp

    r1224 r1230  
    33753375          eventHappened_=true; // exit
    33763376        }
     3377        newCutoff = getCutoff();
    33773378      }
    33783379      if (parallelMode()>0)
     
    68516852    if (currentPassNumber_ == 1 && howOftenGlobalScan_ > 0 &&
    68526853        (numberNodes_%howOftenGlobalScan_) == 0&&
    6853         doCutsNow(1)) {
     6854        (doCutsNow(1)||true)) {
    68546855      int numberCuts = globalCuts_.sizeColCuts() ;
    68556856      int i;
     
    1042410425      solver_->setHintParam(OsiDoDualInInitial,true,OsiHintTry);
    1042510426      solver_->initialSolve();
     10427#if 0
     10428      if (solver_->isProvenOptimal()) {
     10429        solver_->writeMps("feasible");
     10430        printf("XXXXXXXXXXXX - saving feasible\n");
     10431      }
     10432#endif
    1042610433      if (!solver_->isProvenOptimal())
    1042710434        {
     
    1092710934      cutoff = objectiveValue; // relax
    1092810935    CbcEventHandler::CbcAction action =
    10929       dealWithEventHandler(CbcEventHandler::beforeSolution,
     10936      dealWithEventHandler(CbcEventHandler::beforeSolution2,
    1093010937                           objectiveValue,solution);
    1093110938    if (action==CbcEventHandler::killSolution) {
     
    1117211179CbcModel::dealWithEventHandler(CbcEventHandler::CbcEvent event,
    1117311180                                                   double objValue,
    11174                                                    double * solution)
     11181                                                   const double * solution)
    1117511182{
    1117611183  CbcEventHandler *eventHandler = getEventHandler() ;
     
    1117811185    // Temporarily put in best
    1117911186    double saveObj = bestObjective_;
    11180     double * saveSol = bestSolution_;
     11187    int numberColumns = solver_->getNumCols();
     11188    double * saveSol = CoinCopyOfArray(bestSolution_,numberColumns);
     11189    if (!saveSol)
     11190      bestSolution_ = new double [numberColumns];
    1118111191    bestObjective_ = objValue;
    11182     bestSolution_ = solution;
     11192    memcpy(bestSolution_,solution,numberColumns*sizeof(double));
    1118311193    CbcEventHandler::CbcAction action =
    1118411194      eventHandler->event(event);
    1118511195    bestObjective_ = saveObj;
    11186     bestSolution_ = saveSol;
     11196    if (saveSol) {
     11197      memcpy(bestSolution_,saveSol,numberColumns*sizeof(double));
     11198      delete [] saveSol;
     11199    } else {
     11200      delete [] bestSolution_;
     11201      bestSolution_ = NULL;
     11202    }
    1118711203    return action;
    1118811204  } else {
     
    1379813814    if (newNode)
    1379913815      if (newNode&&newNode->active()) {
    13800         if (newNode->branchingObject() == NULL&&solverCharacteristics_->solverType()==4) {
    13801           // need to check if any cuts would do anything
    13802           OsiCuts theseCuts;
    13803           // reset probing info
    13804           //if (probingInfo_)
    13805           //probingInfo_->initializeFixing(solver_);
    13806           for (int i = 0;i<numberCutGenerators_;i++) {
    13807             bool generate = generator_[i]->normal();
    13808             // skip if not optimal and should be (maybe a cut generator has fixed variables)
    13809             if (generator_[i]->needsOptimalBasis()&&!solver_->basisIsAvailable())
    13810               generate=false;
    13811             if (!generator_[i]->mustCallAgain())
    13812               generate=false; // only special cuts
    13813             if (generate) {
    13814               generator_[i]->generateCuts(theseCuts,1,solver_,NULL) ;
    13815               int numberRowCutsAfter = theseCuts.sizeRowCuts() ;
    13816               if (numberRowCutsAfter) {
    13817                 // need dummy branch
    13818                 newNode->setBranchingObject(new CbcDummyBranchingObject(this));
    13819                 newNode->nodeInfo()->initializeInfo(1);
    13820                 break;
     13816        if (newNode->branchingObject() == NULL) {
     13817          const double * solution = solver_->getColSolution();
     13818          CbcEventHandler::CbcAction action =
     13819            dealWithEventHandler(CbcEventHandler::beforeSolution1,
     13820                                 getSolverObjValue(),solution);
     13821          if (action==CbcEventHandler::addCuts||
     13822              solverCharacteristics_->solverType()==4) {
     13823            // need to check if any cuts would do anything
     13824            OsiCuts theseCuts;
     13825            // reset probing info
     13826            //if (probingInfo_)
     13827            //probingInfo_->initializeFixing(solver_);
     13828            for (int i = 0;i<numberCutGenerators_;i++) {
     13829              bool generate = generator_[i]->normal();
     13830              // skip if not optimal and should be (maybe a cut generator has fixed variables)
     13831              if (generator_[i]->needsOptimalBasis()&&!solver_->basisIsAvailable())
     13832                generate=false;
     13833              if (!generator_[i]->mustCallAgain())
     13834                generate=false; // only special cuts
     13835              if (generate) {
     13836                generator_[i]->generateCuts(theseCuts,-1,solver_,NULL) ;
     13837                int numberRowCutsAfter = theseCuts.sizeRowCuts() ;
     13838                if (numberRowCutsAfter)
     13839                  break;
    1382113840              }
     13841            }
     13842            int numberRowCutsAfter = theseCuts.sizeRowCuts() ;
     13843            if (numberRowCutsAfter||
     13844                action==CbcEventHandler::addCuts) {
     13845              // need dummy branch
     13846              newNode->setBranchingObject(new CbcDummyBranchingObject(this));
     13847              newNode->nodeInfo()->initializeInfo(1);
    1382213848            }
    1382313849          }
     
    1393413960            setBestSolution(CBC_SOLUTION,objectiveValue,
    1393513961                            solver_->getColSolution()) ;
    13936             foundSolution=1;
     13962            // Check if was found
     13963            if (bestObjective_<getCutoff())
     13964              foundSolution=1;
    1393713965          }
    1393813966          //assert(nodeInfo->numberPointingToThis() <= 2) ;
  • trunk/Cbc/src/CbcModel.hpp

    r1224 r1230  
    10681068  CbcEventHandler::CbcAction dealWithEventHandler(CbcEventHandler::CbcEvent event,
    10691069                                                   double objValue,
    1070                                                    double * solution);
     1070                                                   const double * solution);
    10711071
    10721072  /** Call this to really test if a valid solution can be feasible
     
    11461146  inline void setObjValue(double value)
    11471147  { bestObjective_=value * solver_->getObjSense() ;}
     1148  /// Get solver objective function value (as minimization)
     1149  inline double getSolverObjValue() const
     1150  { return solver_->getObjValue() * solver_->getObjSense() ;}
    11481151 
    11491152  /** The best solution to the integer programming problem.
  • trunk/Cbc/src/CbcSolver.cpp

    r1224 r1230  
    29042904  const double * columnUpper = solver->getColUpper() ;
    29052905  const double * solution = solver->getColSolution();
    2906   //int numberColumns = solver->getNumCols() ;
    29072906  //int numberRows = solver->getNumRows();
    29082907  //double direction = solver->getObjSense();
     
    29282927  OsiObject ** objects = babModel->objects();
    29292928  int numberObjects = babModel->numberObjects();
     2929  int numberColumns = solver->getNumCols() ;
    29302930  for (int iObj = 0;iObj<numberObjects;iObj++) {
    29312931    CbcSOS * objSOS =
     
    29612961      for (int i=0;i<n;i++) {
    29622962        iColumn = which[i];
    2963         int convex2=-1;
    2964         for (j=columnStart[iColumn];j<columnStart[iColumn]+columnLength[iColumn];j++) {
    2965           int iRow = row[j];
    2966           if (iRow==convex) {
    2967             double value = element[j];
    2968             if (value==1.0) {
    2969               convex2=iRow;
     2963        // Column may have been added
     2964        if (iColumn<numberColumns) {
     2965          int convex2=-1;
     2966          for (j=columnStart[iColumn];j<columnStart[iColumn]+columnLength[iColumn];j++) {
     2967            int iRow = row[j];
     2968            if (iRow==convex) {
     2969              double value = element[j];
     2970              if (value==1.0) {
     2971                convex2=iRow;
     2972              }
    29702973            }
    29712974          }
     2975          if (convex2<0&&convex>=0) {
     2976            printf("odd convexity row\n");
     2977            convex=-2;
     2978          }
     2979#if COIN_DEVELOP>2
     2980          printf("col %d has weight %g and value %g, bounds %g %g\n",
     2981                 iColumn,weight[i],solution[iColumn],columnLower[iColumn],
     2982                 columnUpper[iColumn]);
     2983#endif
    29722984        }
    2973         if (convex2<0&&convex>=0) {
    2974           printf("odd convexity row\n");
    2975           convex=-2;
    2976         }
    2977 #if COIN_DEVELOP>2
    2978         printf("col %d has weight %g and value %g, bounds %g %g\n",
    2979                iColumn,weight[i],solution[iColumn],columnLower[iColumn],
    2980                columnUpper[iColumn]);
    2981 #endif
    29822985      }
    29832986    }
     
    86348637                  originalSolver->setBasis(*basis);
    86358638                  delete basis;
     8639                  originalSolver->setDblParam(OsiDualObjectiveLimit,COIN_DBL_MAX);
    86368640                  originalSolver->resolve();
    86378641                  if (!originalSolver->isProvenOptimal()) {
     
    86418645                    delete basis;
    86428646                    originalSolver->initialSolve();
     8647#ifdef CLP_INVESTIGATE
     8648                    if (!originalSolver->isProvenOptimal()) {
     8649                      if (saveSolver) {
     8650                        printf("saveSolver and originalSolver matrices saved\n");
     8651                        saveSolver->writeMps("infA");
     8652                      } else {
     8653                        printf("originalSolver matrix saved\n");
     8654                        originalSolver->writeMps("infB");
     8655                      }
     8656                    }
     8657#endif             
    86438658                  }
    86448659                  assert (originalSolver->isProvenOptimal());
Note: See TracChangeset for help on using the changeset viewer.