Changeset 285


Ignore:
Timestamp:
Mar 27, 2006 6:24:15 PM (14 years ago)
Author:
lou
Message:

Remove CBC_ONLY_CLP build option, use of ClpEventHandler?.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CbcModel.cpp

    r282 r285  
    2020#endif
    2121
    22 #ifdef CBC_ONLY_CLP
    23 #include "ClpEventHandler.hpp"
    24 #else
    2522#include "CbcEventHandler.hpp"
    26 #endif
    2723
    2824#include "OsiSolverInterface.hpp"
     
    426422    strategy_->setupPrinting(*this,handler_->logLevel());
    427423  }
    428 /*
    429   Set up the event handler.
    430 */
    431424  eventHappened_=false;
    432 #ifdef CBC_ONLY_CLP
    433   ClpEventHandler * eventHandler=NULL;
    434   {
    435     OsiClpSolverInterface * clpSolver
    436       = dynamic_cast<OsiClpSolverInterface *> (solver_);
    437     eventHandler = clpSolver->getModelPtr()->eventHandler() ;
    438   }
    439 #else
    440   CbcEventHandler *eventHandler = new CbcEventHandler(this) ;
    441 #endif
     425  CbcEventHandler *eventHandler = getEventHandler() ;
    442426 
    443427  if (!nodeCompare_)
     
    619603  OsiClpSolverInterface * clpSolver
    620604    = dynamic_cast<OsiClpSolverInterface *> (solver_);
    621 # ifndef CBC_ONLY_CLP
    622605  if (clpSolver) {
    623 # endif
    624606    ClpSimplex * clpSimplex = clpSolver->getModelPtr();
    625607    // take off names
    626608    clpSimplex->dropNames();
    627 # ifndef CBC_ONLY_CLP
    628   }
    629 # endif
     609  }
    630610#endif
    631611
     
    983963      }
    984964      if (eventHandler) {
    985 # ifdef CBC_ONLY_CLP
    986         if (!eventHandler->event(ClpEventHandler::solution)) {
    987           eventHappened_=true; // exit
    988         }
    989 # else
    990965        if (!eventHandler->event(CbcEventHandler::solution)) {
    991966          eventHappened_=true; // exit
    992967        }
    993 # endif
    994968      }
    995969      // Do from deepest
     
    10361010        <<getCurrentSeconds()
    10371011        << CoinMessageEol ;
    1038 # ifdef CBC_ONLY_CLP
    1039       if (!eventHandler->event(ClpEventHandler::treeStatus)) {
    1040         eventHappened_=true; // exit
    1041       }
    1042 # else
    10431012      if (!eventHandler->event(CbcEventHandler::treeStatus)) {
    10441013        eventHappened_=true; // exit
    10451014      }
    1046 # endif
    10471015    }
    10481016    // If no solution but many nodes - signal change in strategy
     
    13931361      deleted, and newNode is null.
    13941362*/
    1395 # ifdef CBC_ONLY_CLP
    1396         if (!eventHandler->event(ClpEventHandler::node)) {
    1397           eventHappened_=true; // exit
    1398         }
    1399 # else
    14001363        if (!eventHandler->event(CbcEventHandler::node)) {
    14011364          eventHappened_=true; // exit
    14021365        }
    1403 # endif
    14041366        assert (!newNode || newNode->objectiveValue() <= getCutoff()) ;
    14051367        if (statistics_) {
     
    19521914  heuristic_(NULL),
    19531915  lastHeuristic_(NULL),
    1954   eventHandler_(NULL),
     1916  eventHandler_(0),
    19551917  numberObjects_(0),
    19561918  object_(NULL),
     
    20171979  handler_->setLogLevel(2);
    20181980  messages_ = CbcMessage();
     1981  eventHandler_ = new CbcEventHandler() ;
    20191982}
    20201983
     
    20742037  heuristic_(NULL),
    20752038  lastHeuristic_(NULL),
    2076   eventHandler_(NULL),
     2039  eventHandler_(0),
    20772040  numberObjects_(0),
    20782041  object_(NULL),
     
    21322095  handler_->setLogLevel(2);
    21332096  messages_ = CbcMessage();
     2097  eventHandler_ = new CbcEventHandler() ;
    21342098  solver_ = rhs.clone();
    21352099  referenceSolver_ = solver_->clone();
     
    23492313  }
    23502314  lastHeuristic_ = NULL;
    2351 /*
    2352   When using CLP only, work with clp's event handler.
    2353 */
    2354 # ifdef CBC_ONLY_CLP
    2355   eventHandler_ = NULL ;
    2356 # else
    23572315  if (rhs.eventHandler_)
    23582316  { eventHandler_ = new CbcEventHandler(*rhs.eventHandler_) ; }
    23592317  else
    23602318  { eventHandler_ = NULL ; }
    2361 # endif
    23622319  numberObjects_=rhs.numberObjects_;
    23632320  if (numberObjects_) {
     
    26402597    }
    26412598    lastHeuristic_ = NULL;
    2642 /*
    2643   Event handler is clp's responsibility when it's the only solver.
    2644 */
    2645 #   ifndef CBC_ONLY_CLP
    26462599    if (eventHandler_)
    26472600      delete eventHandler_ ;
     
    26502603    else
    26512604    { eventHandler_ = NULL ; }
    2652 #   endif
    26532605    for (i=0;i<numberObjects_;i++)
    26542606      delete object_[i];
     
    27462698  if (ourSolver_) delete solver_;
    27472699  gutsOfDestructor();
     2700  delete eventHandler_ ;
     2701  eventHandler_ = NULL ;
    27482702}
    27492703// Clears out as much as possible (except solver)
     
    27662720  delete [] heuristic_;
    27672721  heuristic_=NULL;
    2768 # ifndef CBC_ONLY_CLP
    2769   delete eventHandler_ ;
    2770   eventHandler_ = NULL ;
    2771 # endif
    27722722  delete nodeCompare_;
    27732723  nodeCompare_=NULL;
     
    33243274  int numberFixed = 0 ;
    33253275
    3326 /*
    3327   At issue here are the clp-specific asserts. The two code blocks do exactly
    3328   the same thing, except that the first code block knows it's using clp and
    3329   does not do runtime checks. Merging the two results in unreadable nested
    3330   ifdef's.
    3331 */
    3332 #ifdef CBC_ONLY_CLP
    3333   OsiClpSolverInterface * clpSolver
    3334     = dynamic_cast<OsiClpSolverInterface *> (solver_);
    3335   ClpSimplex * clpSimplex = clpSolver->getModelPtr();
    3336   for (int i = 0 ; i < numberIntegers_ ; i++)
    3337   { int iColumn = integerVariable_[i] ;
    3338     double djValue = direction*reducedCost[iColumn] ;
    3339     if (upper[iColumn]-lower[iColumn] > integerTolerance)
    3340     { if (solution[iColumn] < lower[iColumn]+integerTolerance && djValue > gap)
    3341       { solver_->setColUpper(iColumn,lower[iColumn]) ;
    3342         assert (clpSimplex->getColumnStatus(iColumn)==ClpSimplex::atLowerBound);
    3343         numberFixed++ ; }
    3344       else
    3345       if (solution[iColumn] > upper[iColumn]-integerTolerance && -djValue > gap)
    3346       { solver_->setColLower(iColumn,upper[iColumn]) ;
    3347       if (clpSimplex)
    3348         assert (clpSimplex->getColumnStatus(iColumn)==ClpSimplex::atUpperBound);
    3349         numberFixed++ ; } } }
    3350 #else                           // CBC_ONLY_CLP
    33513276# ifdef CBC_USE_CLP
    33523277  OsiClpSolverInterface * clpSolver
     
    33753300#endif
    33763301        numberFixed++ ; } } }
    3377 #endif                          // CBC_ONLY_CLP
    33783302 
    33793303  return numberFixed; }
     
    44374361        OsiClpSolverInterface * clpSolver
    44384362          = dynamic_cast<OsiClpSolverInterface *> (solver_);
    4439 # ifndef CBC_ONLY_CLP
    44404363        if (clpSolver) {
    4441 # endif
    44424364          // Maybe solver might like to know only column bounds will change
    44434365          //int options = clpSolver->specialOptions();
    44444366          //clpSolver->setSpecialOptions(options|128);
    44454367          clpSolver->synchronizeModel();
    4446 # ifndef CBC_ONLY_CLP
    44474368        }
    4448 # endif
    44494369#endif
    44504370      } else {
     
    44524372        OsiClpSolverInterface * clpSolver
    44534373          = dynamic_cast<OsiClpSolverInterface *> (solver_);
    4454 # ifndef CBC_ONLY_CLP
    44554374        if (clpSolver) {
    4456 # endif
    44574375        // make sure factorization can't carry over
    44584376          int options = clpSolver->specialOptions();
    44594377          clpSolver->setSpecialOptions(options&(~8));
    4460 # ifndef CBC_ONLY_CLP
    44614378        }
    4462 # endif
    44634379#endif
    44644380      }
     
    65706486    OsiClpSolverInterface * clpSolver
    65716487      = dynamic_cast<OsiClpSolverInterface *> (cleanModel);
    6572 # ifndef CBC_ONLY_CLP
    65736488    if (clpSolver) {
    6574 # endif
    65756489      ClpSimplex * clp = clpSolver->getModelPtr();
    65766490      clp->messageHandler()->setLogLevel(cleanModel->messageHandler()->logLevel());
     
    66876601        }
    66886602      }
    6689 # ifndef CBC_ONLY_CLP
    6690     }
    6691 # endif
     6603    }
    66926604#endif
    66936605    if (!feasible||!doIntegerPresolve) {
     
    74217333
    74227334/*
    7423   There is no overlap of events used in cbc and events used in clp. And code
    7424   must explicitly register an event. So there's no chance that using the clp
    7425   event handler can ever affect clp directly. That said, I've elected to
    7426   do the following: If cbc is built using only clp, the existing code remains
    7427   in place: cbc will use ClpEventHandler. If cbc is built for generic OSI
    7428   solvers, only CbcEventHandler is available, and it will be used by all
    7429   solvers, clp included. If, over time, it remains true that there's no good
    7430   reason to retain ClpEventHandler, removal amounts to deleting the event
    7431   handling code protected by CBC_ONLY_CLP.    -- lh, 060210 --
    7432 */
    7433 
    7434 #ifdef CBC_ONLY_CLP
    7435 
    7436 /* Clp-specific routines to set/get an event handler. */
    7437 
    7438 // Pass in Event handler (cloned and deleted at end)
    7439 void
    7440 CbcModel::passInEventHandler(const ClpEventHandler * eventHandler)
    7441 {
    7442   OsiClpSolverInterface * clpSolver
    7443     = dynamic_cast<OsiClpSolverInterface *> (solver_);
    7444   ClpSimplex * clpSimplex = clpSolver->getModelPtr();
    7445   clpSimplex->passInEventHandler(eventHandler);
    7446 }
    7447 // Event handler
    7448 ClpEventHandler *
    7449 CbcModel::eventHandler() const
    7450 {
    7451   OsiClpSolverInterface * clpSolver
    7452     = dynamic_cast<OsiClpSolverInterface *> (solver_);
    7453   ClpSimplex * clpSimplex = clpSolver->getModelPtr();
    7454   return clpSimplex->eventHandler();
    7455 }
    7456 
    7457 #else           // not CBC_ONLY_CLP
    7458 
    7459 /* Equivalent functionality for generic OSI solvers using CbcEventHandler. */
    7460 
    7461 /*
    74627335  Delete any existing handler and create a clone of the one supplied.
    74637336*/
     
    74657338{
    74667339  delete eventHandler_;
    7467   eventHandler_ = eventHandler->clone();
     7340  eventHandler = NULL ;
     7341  if (eventHandler)
     7342    eventHandler_ = eventHandler->clone();
    74687343}
    74697344
     
    74727347*/
    74737348
    7474 #endif
    74757349
    74767350// Set log level
     
    74877361    OsiClpSolverInterface * clpSolver
    74887362      = dynamic_cast<OsiClpSolverInterface *> (solver_);
    7489 # ifndef CBC_ONLY_CLP
    74907363    if (clpSolver) {
    7491 # endif
    74927364      ClpSimplex * clpSimplex = clpSolver->getModelPtr();
    74937365      oldLevel = clpSimplex->logLevel();
    74947366      if (value<oldLevel)
    74957367        clpSimplex->setLogLevel(value);
    7496 # ifndef CBC_ONLY_CLP
    7497     }
    7498 # endif
     7368    }
    74997369#else           // CBC_USE_CLP
    75007370/*
    7501   For generic OSI solvers, try the DoReducePrint hint.
    7502 */
    7503     solver_->setHintParam(OsiDoReducePrint,true,OsiHintDo) ;
     7371  For generic OSI solvers, if the new log level is 0, try the
     7372  DoReducePrint hint for emphasis.
     7373*/
     7374    if (value == 0) {
     7375      solver_->setHintParam(OsiDoReducePrint,true,OsiHintDo) ;
     7376    }
    75047377#endif          // CBC_USE_CLP
    75057378  }
Note: See TracChangeset for help on using the changeset viewer.