Changeset 277


Ignore:
Timestamp:
Mar 16, 2006 2:18:04 PM (14 years ago)
Author:
lou
Message:

Revise cbc build process for better control of solvers included in build
(COIN_USE_XXX -> CBC_USE_XXX). Add CbcEventHandler? for independence from
clp.

Location:
trunk
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/CbcHeuristic.cpp

    r264 r277  
    99#include <cfloat>
    1010
    11 #ifdef COIN_USE_CLP
     11#ifdef CBC_USE_CLP
    1212#include "OsiClpSolverInterface.hpp"
    1313#endif
     
    5656                                  double cutoff, std::string name) const
    5757{
    58 #ifdef COIN_USE_CLP
     58#ifdef CBC_USE_CLP
    5959  OsiClpSolverInterface * osiclp = dynamic_cast< OsiClpSolverInterface*> (solver);
     60# ifndef CBC_ONLY_CLP
    6061  if (osiclp) {
     62# endif
    6163    // go faster stripes
    6264    if (osiclp->getNumRows()<300&&osiclp->getNumCols()<500) {
     
    6870    // Used to be automatically set
    6971    osiclp->setSpecialOptions(osiclp->specialOptions()|(128+64));
     72# ifndef CBC_ONLY_CLP
    7073  }
     74# endif
    7175#endif
    7276  // Reduce printout
  • trunk/CbcModel.cpp

    r273 r277  
    1313#include <cmath>
    1414#include <cfloat>
    15 #ifdef COIN_USE_CLP
     15
     16#ifdef CBC_USE_CLP
    1617// include Presolve from Clp
    1718#include "ClpPresolve.hpp"
    1819#include "OsiClpSolverInterface.hpp"
     20#endif
     21
     22#ifdef CBC_ONLY_CLP
    1923#include "ClpEventHandler.hpp"
     24#else
     25#include "CbcEventHandler.hpp"
    2026#endif
    2127
     
    420426    strategy_->setupPrinting(*this,handler_->logLevel());
    421427  }
     428/*
     429  Set up the event handler.
     430*/
    422431  eventHappened_=false;
    423 #ifdef COIN_USE_CLP
     432#ifdef CBC_ONLY_CLP
    424433  ClpEventHandler * eventHandler=NULL;
    425434  {
    426     OsiClpSolverInterface * clpSolver 
     435    OsiClpSolverInterface * clpSolver
    427436      = dynamic_cast<OsiClpSolverInterface *> (solver_);
    428     if (clpSolver) {
    429       ClpSimplex * clpSimplex = clpSolver->getModelPtr();
    430       eventHandler = clpSimplex->eventHandler();
    431     }
    432   }
     437    eventHandler = clpSolver->getModelPtr()->eventHandler() ;
     438  }
     439#else
     440  CbcEventHandler *eventHandler = new CbcEventHandler(this) ;
    433441#endif
    434442 
     
    608616*/
    609617  continuousSolver_ = solver_->clone() ;
    610 #ifdef COIN_USE_CLP
     618#ifdef CBC_USE_CLP
    611619  OsiClpSolverInterface * clpSolver
    612620    = dynamic_cast<OsiClpSolverInterface *> (solver_);
     621# ifndef CBC_ONLY_CLP
    613622  if (clpSolver) {
     623# endif
    614624    ClpSimplex * clpSimplex = clpSolver->getModelPtr();
    615625    // take off names
    616626    clpSimplex->dropNames();
    617   }
     627# ifndef CBC_ONLY_CLP
     628  }
     629# endif
    618630#endif
    619631
     
    970982        }
    971983      }
    972 #ifdef COIN_USE_CLP
    973984      if (eventHandler) {
     985# ifdef CBC_ONLY_CLP
    974986        if (!eventHandler->event(ClpEventHandler::solution)) {
    975987          eventHappened_=true; // exit
    976988        }
    977       }
    978 #endif
     989# else
     990        if (!eventHandler->event(CbcEventHandler::solution)) {
     991          eventHappened_=true; // exit
     992        }
     993# endif
     994      }
    979995      // Do from deepest
    980996      tree_->cleanTree(this, newCutoff,bestPossibleObjective_) ;
     
    10191035        << numberNodes_<< nNodes<< bestObjective_<< bestPossibleObjective_
    10201036        << CoinMessageEol ;
    1021 #ifdef COIN_USE_CLP
    1022       if (eventHandler) {
    1023         if (!eventHandler->event(ClpEventHandler::treeStatus)) {
    1024           eventHappened_=true; // exit
    1025         }
    1026       }
    1027 #endif
     1037# ifdef CBC_ONLY_CLP
     1038      if (!eventHandler->event(ClpEventHandler::treeStatus)) {
     1039        eventHappened_=true; // exit
     1040      }
     1041# else
     1042      if (!eventHandler->event(CbcEventHandler::treeStatus)) {
     1043        eventHappened_=true; // exit
     1044      }
     1045# endif
    10281046    }
    10291047    // If no solution but many nodes - signal change in strategy
     
    12061224                                               feasible ? solver_->getObjValue()
    12071225                                               : COIN_DBL_MAX);
    1208     }
     1226      }
    12091227/*
    12101228  Check for abort on limits: node count, solution count, time, integrality gap.
     
    12221240
    12231241  Finally, attach a partial nodeInfo object and store away any cuts that we
    1224   created back in solveWithCuts. addCuts() will also deal with the cut
    1225   reference counts.
     1242  created back in solveWithCuts. addCuts() will initialise the reference
     1243  counts for these new cuts.
    12261244
    12271245  TODO: (lh) I'm confused. We create a nodeInfo without checking whether we
     
    12681286                anyAction = newNode->chooseBranch(this,node,numberPassesLeft) ; // dynamic did nothing
    12691287            }
     1288/*
     1289  Yep, false positives for sure. And no easy way to distinguish honest
     1290  infeasibility from `found a solution and tightened objective target.'
     1291
    12701292            if (onOptimalPath)
    12711293              assert (anyAction!=-2); // can be useful but gives false positives on strong
     1294*/
    12721295            numberPassesLeft--;
    12731296            if (numberPassesLeft<=-1) {
     
    13231346        { anyAction = -2 ; }
    13241347        // May have slipped through i.e. anyAction == 0 and objective above cutoff
     1348        // I think this will screw up cut reference counts if executed.
     1349        // We executed addCuts just above. (lh)
    13251350        if ( anyAction >=0 ) {
    13261351          assert (newNode);
     
    13531378/*
    13541379  At this point, there are three possibilities:
    1355     * We have a live node (variable() >= 0) which will require further
    1356       branching to resolve. Before we push it onto the search tree, try for
    1357       a heuristic solution.
     1380    * newNode is live and will require further branching to resolve
     1381      (variable() >= 0). Increment the cut reference counts by
     1382      numberBranches() to allow for use by children of this node, and
     1383      decrement by 1 because we've executed one arm of the branch of our
     1384      parent (consuming one reference). Before we push newNode onto the
     1385      search tree, try for a heuristic solution.
    13581386    * We have a solution, in which case newNode is non-null but we have no
    13591387      branching variable. Decrement the cut counts and save the solution.
    13601388    * The node was found to be infeasible, in which case it's already been
    13611389      deleted, and newNode is null.
    1362 
    1363   TODO: (lh) Now I'm more confused. I thought that the call to addCuts() above
    1364         took care of incrementing the reference counts for cuts at newNode.
    1365         Clearly I need to look more carefully.
    1366 */
    1367 #ifdef COIN_USE_CLP
    1368         if (eventHandler) {
    1369           if (!eventHandler->event(ClpEventHandler::node)) {
    1370             eventHappened_=true; // exit
    1371           }
     1390*/
     1391# ifdef CBC_ONLY_CLP
     1392        if (!eventHandler->event(ClpEventHandler::node)) {
     1393          eventHappened_=true; // exit
    13721394        }
    1373 #endif
     1395# else
     1396        if (!eventHandler->event(CbcEventHandler::node)) {
     1397          eventHappened_=true; // exit
     1398        }
     1399# endif
    13741400        assert (!newNode || newNode->objectiveValue() <= getCutoff()) ;
    13751401        if (statistics_) {
     
    14661492  End of the non-abort actions. The next block of code is executed if we've
    14671493  aborted because we hit one of the limits. Clean up by deleting the live set
    1468   and break out of the node processing loop.
     1494  and break out of the node processing loop. Note that on an abort, node may
     1495  have been pushed back onto the tree for further processing, in which case
     1496  it'll be deleted in cleanTree. We need to check.
    14691497*/
    14701498      else
     
    19201948  heuristic_(NULL),
    19211949  lastHeuristic_(NULL),
     1950  eventHandler_(NULL),
    19221951  numberObjects_(0),
    19231952  object_(NULL),
     
    20412070  heuristic_(NULL),
    20422071  lastHeuristic_(NULL),
     2072  eventHandler_(NULL),
    20432073  numberObjects_(0),
    20442074  object_(NULL),
     
    23152345  }
    23162346  lastHeuristic_ = NULL;
     2347/*
     2348  When using CLP only, work with clp's event handler.
     2349*/
     2350# ifdef CBC_ONLY_CLP
     2351  eventHandler_ = NULL ;
     2352# else
     2353  if (rhs.eventHandler_)
     2354  { eventHandler_ = new CbcEventHandler(*rhs.eventHandler_) ; }
     2355  else
     2356  { eventHandler_ = NULL ; }
     2357# endif
    23172358  numberObjects_=rhs.numberObjects_;
    23182359  if (numberObjects_) {
     
    25952636    }
    25962637    lastHeuristic_ = NULL;
     2638/*
     2639  Event handler is clp's responsibility when it's the only solver.
     2640*/
     2641#   ifndef CBC_ONLY_CLP
     2642    if (eventHandler_)
     2643      delete eventHandler_ ;
     2644    if (rhs.eventHandler_)
     2645    { eventHandler_ = new CbcEventHandler(*rhs.eventHandler_) ; }
     2646    else
     2647    { eventHandler_ = NULL ; }
     2648#   endif
    25972649    for (i=0;i<numberObjects_;i++)
    25982650      delete object_[i];
     
    27102762  delete [] heuristic_;
    27112763  heuristic_=NULL;
     2764# ifndef CBC_ONLY_CLP
     2765  delete eventHandler_ ;
     2766  eventHandler_ = NULL ;
     2767# endif
    27122768  delete nodeCompare_;
    27132769  nodeCompare_=NULL;
     
    32633319
    32643320  int numberFixed = 0 ;
    3265 #ifdef COIN_USE_CLP
     3321
     3322/*
     3323  At issue here are the clp-specific asserts. The two code blocks do exactly
     3324  the same thing, except that the first code block knows it's using clp and
     3325  does not do runtime checks. Merging the two results in unreadable nested
     3326  ifdef's.
     3327*/
     3328#ifdef CBC_ONLY_CLP
    32663329  OsiClpSolverInterface * clpSolver
    32673330    = dynamic_cast<OsiClpSolverInterface *> (solver_);
    3268   ClpSimplex * clpSimplex=NULL;
    3269   if (clpSolver)
    3270     clpSimplex = clpSolver->getModelPtr();
    3271 #endif
     3331  ClpSimplex * clpSimplex = clpSolver->getModelPtr();
    32723332  for (int i = 0 ; i < numberIntegers_ ; i++)
    32733333  { int iColumn = integerVariable_[i] ;
     
    32763336    { if (solution[iColumn] < lower[iColumn]+integerTolerance && djValue > gap)
    32773337      { solver_->setColUpper(iColumn,lower[iColumn]) ;
    3278 #ifdef COIN_USE_CLP
     3338        assert (clpSimplex->getColumnStatus(iColumn)==ClpSimplex::atLowerBound);
     3339        numberFixed++ ; }
     3340      else
     3341      if (solution[iColumn] > upper[iColumn]-integerTolerance && -djValue > gap)
     3342      { solver_->setColLower(iColumn,upper[iColumn]) ;
     3343      if (clpSimplex)
     3344        assert (clpSimplex->getColumnStatus(iColumn)==ClpSimplex::atUpperBound);
     3345        numberFixed++ ; } } }
     3346#else                           // CBC_ONLY_CLP
     3347# ifdef CBC_USE_CLP
     3348  OsiClpSolverInterface * clpSolver
     3349    = dynamic_cast<OsiClpSolverInterface *> (solver_);
     3350  ClpSimplex * clpSimplex=NULL;
     3351  if (clpSolver)
     3352    clpSimplex = clpSolver->getModelPtr();
     3353# endif
     3354  for (int i = 0 ; i < numberIntegers_ ; i++)
     3355  { int iColumn = integerVariable_[i] ;
     3356    double djValue = direction*reducedCost[iColumn] ;
     3357    if (upper[iColumn]-lower[iColumn] > integerTolerance)
     3358    { if (solution[iColumn] < lower[iColumn]+integerTolerance && djValue > gap)
     3359      { solver_->setColUpper(iColumn,lower[iColumn]) ;
     3360#ifdef CBC_USE_CLP
    32793361      if (clpSimplex)
    32803362        assert (clpSimplex->getColumnStatus(iColumn)==ClpSimplex::atLowerBound);
     
    32843366      if (solution[iColumn] > upper[iColumn]-integerTolerance && -djValue > gap)
    32853367      { solver_->setColLower(iColumn,upper[iColumn]) ;
    3286 #ifdef COIN_USE_CLP
     3368#ifdef CBC_USE_CLP
    32873369      if (clpSimplex)
    32883370        assert (clpSimplex->getColumnStatus(iColumn)==ClpSimplex::atUpperBound);
    32893371#endif
    32903372        numberFixed++ ; } } }
     3373#endif                          // CBC_ONLY_CLP
    32913374 
    32923375  return numberFixed; }
     
    33593442/*
    33603443  Resolve the problem. If we've lost feasibility, might as well bail out right
    3361   after the debug stuff.
     3444  after the debug stuff. The resolve will also refresh cached copies of the
     3445  solver solution (cbcColLower_, ...)
    33623446*/
    33633447  double objectiveValue = solver_->getObjValue()*solver_->getObjSense();
     
    34233507  }
    34243508/*
    3425   Do reduced cost fixing, and then grab the primal solution and bounds vectors.
     3509  Do reduced cost fixing.
    34263510*/
    34273511  reducedCostFix() ;
    3428   const double *lower = solver_->getColLower() ;
    3429   const double *upper = solver_->getColUpper() ;
    3430   const double *solution = solver_->getColSolution() ;
    34313512/*
    34323513  Set up for at most numberTries rounds of cut generation. If numberTries is
     
    34783559    OsiCuts theseCuts ;
    34793560/*
     3561  Depending on actions in the loop (bound changes, addition of cuts,
     3562  reoptimisation) these pointers can change.
     3563*/
     3564    const double *lower = solver_->getColLower() ;
     3565    const double *upper = solver_->getColUpper() ;
     3566    const double *solution = solver_->getColSolution() ;
     3567/*
    34803568  Scan previously generated global column and row cuts to see if any are
    34813569  useful.
    3482   I can't see why this code
    3483   needs its own copy of the primal solution. Removed the dec'l.
    34843570*/
    34853571    int numberViolated=0;
     
    35223608  CglProbing indicates that it can fix a variable. Reoptimisation is required
    35233609  to take full advantage.
     3610
     3611  The need to resolve here should only happen after a heuristic solution.
     3612  However, when it's triggered, the solution may change, which implies a reload
     3613  of lower, upper, and solution. (Note default OSI implementation of
     3614  optimalBasisIsAvailable always returns false.)
    35243615*/
    35253616    // This should only happen after heuristic solution
     
    35283619      //printf("XXXXYY no opt basis\n");
    35293620      resolve(node ? node->nodeInfo() : NULL,3);
     3621/* dylp bug
     3622
     3623  Need to reload cached solution pointers after resolve. Solver not required
     3624  to use same vector for revised solution. cbcColLower_, etc., set by
     3625  CbcModel::setPointers() in CbcModel::resolve(). Any reason not to convert
     3626  this routine to use cbcColLower_, etc.?
     3627*/
     3628      lower = cbcColLower_ ;
     3629      upper = cbcColUpper_ ;
     3630      solution = cbcColSolution_ ;
    35303631    }
    35313632    if (nextRowCut_) {
     
    35353636        nextRowCut_->print();
    35363637      const OsiRowCut * cut=nextRowCut_;
    3537       const double * solution = solver_->getColSolution();
     3638      // const double * solution = solver_->getColSolution();
    35383639      double lb = cut->lb();
    35393640      double ub = cut->ub();
     
    35953696          if (mustResolve) {
    35963697            int returncode = resolve(node ? node->nodeInfo() : NULL,2);
     3698/* dylp bug
     3699
     3700  Need to reload cached solution pointers after resolve. Solver not required
     3701  to use same vector for revised solution.
     3702*/
     3703            lower = cbcColLower_ ;
     3704            upper = cbcColUpper_ ;
     3705            solution = cbcColSolution_ ;
    35973706            feasible = returnCode  != 0 ;
    35983707            if (returncode<0)
     
    36413750        }
    36423751      }
     3752      assert(lower == solver_->getColLower()) ;
     3753      assert(upper == solver_->getColUpper()) ;
     3754      assert(solution == solver_->getColSolution()) ;
    36433755
    36443756/*
     
    38273939      delete [] oldLower ;
    38283940      delete [] oldUpper ;
     3941      assert(lower == solver_->getColLower()) ;
     3942      assert(upper == solver_->getColUpper()) ;
     3943      assert(solution == solver_->getColSolution()) ;
    38293944#endif
    38303945    }
     
    38613976  the set of row cuts (cuts.insert()) supplied as a parameter. The new basis
    38623977  must be set with setWarmStart().
    3863 
    3864   TODO: It's not clear to me why we can't separate this into two sections.
    3865         The first would add the row cuts, and be executed only if row cuts
    3866         need to be installed. The second would call resolve() and would be
    3867         executed if either row or column cuts have been installed.
    38683978
    38693979  TODO: Seems to me the original code could allocate addCuts with size 0, if
     
    38944004        CoinWarmStartBasis * basis = dynamic_cast<CoinWarmStartBasis*>(solver_->getWarmStart()) ;
    38954005        assert(basis != NULL); // make sure not volume
    3896         //basis->resize(numberRowsAtStart+numberNewCuts_,numberColumns) ;
     4006/* dylp bug
     4007
     4008  Consistent size used by OsiDylp as sanity check. Implicit resize seen
     4009  as an error. Hence this call to resize is necessary.
     4010*/
     4011        basis->resize(numberRowsAtStart+numberNewCuts_,numberColumns) ;
    38974012        for (i = 0 ; i < numberToAdd ; i++)
    38984013        { basis->setArtifStatus(numberRowsNow+i,
     
    39744089  We've lost feasibility --- this node won't be referencing the cuts we've
    39754090  been collecting, so decrement the reference counts.
    3976 
    3977   TODO: Presumably this is in preparation for backtracking. Seems like it
    3978         should be the `else' off the previous `if'.
    39794091*/
    39804092    if (!feasible)
     
    41364248  TODO: All this should probably be hidden in a method of the CbcCutGenerator
    41374249  class.
     4250
     4251  TODO: Can the loop that scans over whichGenerator to accumulate per generator
     4252        counts be replaced by values in countRowCuts and countColumnCuts?
    41384253*/
    41394254#ifdef NODE_LOG
     
    43134428          }
    43144429        }
    4315 #ifdef COIN_USE_CLP
     4430#ifdef CBC_USE_CLP
    43164431        OsiClpSolverInterface * clpSolver
    43174432          = dynamic_cast<OsiClpSolverInterface *> (solver_);
    4318         if (clpSolver) {
     4433# ifndef CBC_ONLY_CLP
     4434        if (clpSolver) {
     4435# endif
    43194436          // Maybe solver might like to know only column bounds will change
    43204437          //int options = clpSolver->specialOptions();
    43214438          //clpSolver->setSpecialOptions(options|128);
    43224439          clpSolver->synchronizeModel();
    4323         }
     4440# ifndef CBC_ONLY_CLP
     4441        }
     4442# endif
    43244443#endif
    43254444      } else {
    4326 #ifdef COIN_USE_CLP
     4445#ifdef CBC_USE_CLP
    43274446        OsiClpSolverInterface * clpSolver
    43284447          = dynamic_cast<OsiClpSolverInterface *> (solver_);
    4329         if (clpSolver) {
     4448# ifndef CBC_ONLY_CLP
     4449        if (clpSolver) {
     4450# endif
    43304451        // make sure factorization can't carry over
    43314452          int options = clpSolver->specialOptions();
    43324453          clpSolver->setSpecialOptions(options&(~8));
    4333         }
     4454# ifndef CBC_ONLY_CLP
     4455        }
     4456# endif
    43344457#endif
    43354458      }
     
    64376560      assert(debugger->onOptimalPath(*cleanModel));
    64386561#endif
    6439 #ifdef COIN_USE_CLP
     6562#ifdef CBC_USE_CLP
    64406563    // do presolve - for now just clp but easy to get osi interface
    64416564    OsiClpSolverInterface * clpSolver
    64426565      = dynamic_cast<OsiClpSolverInterface *> (cleanModel);
     6566# ifndef CBC_ONLY_CLP
    64436567    if (clpSolver) {
     6568# endif
    64446569      ClpSimplex * clp = clpSolver->getModelPtr();
    64456570      clp->messageHandler()->setLogLevel(cleanModel->messageHandler()->logLevel());
     
    65566681        }
    65576682      }
    6558     }
     6683# ifndef CBC_ONLY_CLP
     6684    }
     6685# endif
    65596686#endif
    65606687    if (!feasible||!doIntegerPresolve) {
     
    72867413    dblParam_[CbcOptimizationDirection];
    72877414}
    7288 #ifdef COIN_USE_CLP
     7415
     7416/*
     7417  There is no overlap of events used in cbc and events used in clp. And code
     7418  must explicitly register an event. So there's no chance that using the clp
     7419  event handler can ever affect clp directly. That said, I've elected to
     7420  do the following: If cbc is built using only clp, the existing code remains
     7421  in place: cbc will use ClpEventHandler. If cbc is built for generic OSI
     7422  solvers, only CbcEventHandler is available, and it will be used by all
     7423  solvers, clp included. If, over time, it remains true that there's no good
     7424  reason to retain ClpEventHandler, removal amounts to deleting the event
     7425  handling code protected by CBC_ONLY_CLP.    -- lh, 060210 --
     7426*/
     7427
     7428#ifdef CBC_ONLY_CLP
     7429
     7430/* Clp-specific routines to set/get an event handler. */
     7431
    72897432// Pass in Event handler (cloned and deleted at end)
    72907433void
     
    72937436  OsiClpSolverInterface * clpSolver
    72947437    = dynamic_cast<OsiClpSolverInterface *> (solver_);
    7295   if (clpSolver) {
    7296     ClpSimplex * clpSimplex = clpSolver->getModelPtr();
    7297     clpSimplex->passInEventHandler(eventHandler);
    7298   }
     7438  ClpSimplex * clpSimplex = clpSolver->getModelPtr();
     7439  clpSimplex->passInEventHandler(eventHandler);
    72997440}
    73007441// Event handler
     
    73047445  OsiClpSolverInterface * clpSolver
    73057446    = dynamic_cast<OsiClpSolverInterface *> (solver_);
    7306   if (clpSolver) {
    7307     ClpSimplex * clpSimplex = clpSolver->getModelPtr();
    7308     return clpSimplex->eventHandler();
    7309   } else {
    7310     return NULL;
    7311   }
    7312 }
     7447  ClpSimplex * clpSimplex = clpSolver->getModelPtr();
     7448  return clpSimplex->eventHandler();
     7449}
     7450
     7451#else           // not CBC_ONLY_CLP
     7452
     7453/* Equivalent functionality for generic OSI solvers using CbcEventHandler. */
     7454
     7455/*
     7456  Delete any existing handler and create a clone of the one supplied.
     7457*/
     7458void CbcModel::passInEventHandler (const CbcEventHandler *eventHandler)
     7459{
     7460  delete eventHandler_;
     7461  eventHandler_ = eventHandler->clone();
     7462}
     7463
     7464/*
     7465  CbcEventHandler* CbcModel::eventHandler is inlined in CbcModel.hpp.
     7466*/
     7467
    73137468#endif
     7469
    73147470// Set log level
    73157471void
     
    73227478    if (value<oldLevel)
    73237479      solver_->messageHandler()->setLogLevel(value);
    7324 #ifdef COIN_USE_CLP
     7480#ifdef CBC_USE_CLP
    73257481    OsiClpSolverInterface * clpSolver
    73267482      = dynamic_cast<OsiClpSolverInterface *> (solver_);
     7483# ifndef CBC_ONLY_CLP
    73277484    if (clpSolver) {
     7485# endif
    73287486      ClpSimplex * clpSimplex = clpSolver->getModelPtr();
    7329       int oldLevel = clpSimplex->logLevel();
     7487      oldLevel = clpSimplex->logLevel();
    73307488      if (value<oldLevel)
    73317489        clpSimplex->setLogLevel(value);
    7332     }
    7333 #endif
     7490# ifndef CBC_ONLY_CLP
     7491    }
     7492# endif
     7493#else           // CBC_USE_CLP
     7494/*
     7495  For generic OSI solvers, try the DoReducePrint hint.
     7496*/
     7497    solver_->setHintParam(OsiDoReducePrint,true,OsiHintDo) ;
     7498#endif          // CBC_USE_CLP
    73347499  }
    73357500}
  • trunk/CbcNode.cpp

    r271 r277  
    3030#include "CbcFeasibilityBase.hpp"
    3131#include "CbcMessage.hpp"
     32#ifdef CBC_USE_CLP
    3233#include "OsiClpSolverInterface.hpp"
    3334#include "ClpSimplexOther.hpp"
     35#endif
    3436using namespace std;
    3537#include "CglCutGenerator.hpp"
     
    11721174      if (beforeSolution&&saveLimit<100)
    11731175        solver->setIntParam(OsiMaxNumIterationHotStart,100); // go to end
    1174      
     1176#     ifdef CBC_USE_CLP     
    11751177      /* If we are doing all strong branching in one go then we create new arrays
    11761178         to store information.  If clp NULL then doing old way.
     
    13301332        solver->markHotStart();
    13311333      }
     1334#     else      /* CBC_USE_CLP */
     1335
     1336      OsiSolverInterface *clp = NULL ;
     1337      double **outputSolution = NULL ;
     1338      int *outputStuff = NULL ;
     1339      double * newLower = NULL ;
     1340      double * newUpper = NULL ;
     1341
     1342      solver->markHotStart();
     1343
     1344#     endif     /* CBC_USE_CLP */
    13321345      /*
    13331346        Open a loop to do the strong branching LPs. For each candidate variable,
     
    17771790        delete [] objects;
    17781791      }
     1792#     ifdef CBC_USE_CLP
    17791793      if (osiclp&&!allNormal) {
    17801794        // back to normal
    17811795        osiclp->setHintParam(OsiDoInBranchAndCut,true,OsiHintDo,NULL) ;
    17821796      }
     1797#     endif
    17831798    }
    17841799    /*
     
    19391954  bool finished=false;
    19401955  int numberToFix=0;
     1956# ifdef CBC_USE_CLP
    19411957  OsiClpSolverInterface * osiclp = dynamic_cast< OsiClpSolverInterface*> (solver);
    19421958  int saveClpOptions=0;
     
    19461962    osiclp->setSpecialOptions(saveClpOptions|1024);
    19471963  }
     1964# else
     1965  OsiSolverInterface *osiclp = 0 ;
     1966# endif
    19481967  int saveSearchStrategy2 = model->searchStrategy();
    19491968  if (saveSearchStrategy2<999) {
     
    23292348        }
    23302349      }
     2350#     ifdef CBC_USE_CLP
    23312351      if (osiclp&&numberPenalties&&neededPenalties) {
    23322352        xPen += neededPenalties;
     
    23892409                   iObject,downCost[i],downPenalty,upCost[i],upPenalty);
    23902410        }
    2391       } else {
     2411      } else
     2412#     endif     /* CBC_USE_CLP */
     2413      {
    23922414        if (!skipAll) {
    23932415          // Mark hot start
     
    24032425          sort[iBestGot]=-1.0e120;
    24042426      }
    2405 #else
     2427#else           /* RANGING */
    24062428      if (!skipAll) {
    24072429        // Mark hot start
     
    24142436      if (iBestGot>=0)
    24152437        sort[iBestGot]=-COIN_DBL_MAX;
    2416 #endif
     2438#endif          /* RANGING */
    24172439      // Actions 0 - exit for repeat, 1 resolve and try old choice,2 exit for continue
    24182440#define ACTION 0
     
    31543176  delete [] upEstimate;
    31553177  delete [] downEstimate;
     3178# ifdef CBC_USE_CLP
    31563179  if (osiclp)
    31573180    osiclp->setSpecialOptions(saveClpOptions);
    3158  
     3181# endif
    31593182  // restore solution
    31603183  solver->setColSolution(saveSolution);
     
    32193242                          numberIntegerInfeasibilities,
    32203243                          numberObjectInfeasibilities);
    3221      
     3244# ifdef CBC_USE_CLP
    32223245  OsiClpSolverInterface * osiclp = dynamic_cast< OsiClpSolverInterface*> (solver);
    32233246  int saveClpOptions=0;
     
    32283251    osiclp->setSpecialOptions(saveClpOptions|1024);
    32293252  }
     3253# else
     3254  bool fastIterations = false ;
     3255# endif
    32303256  /*
    32313257    Scan for branching objects that indicate infeasibility. Choose candidates
     
    35293555  // restore solution
    35303556  solver->setColSolution(saveSolution);
     3557# ifdef CBC_USE_CLP
    35313558  if (osiclp)
    35323559    osiclp->setSpecialOptions(saveClpOptions);
     3560# endif
    35333561  model->reserveCurrentSolution(saveSolution);
    35343562  delete [] saveSolution;
  • trunk/CbcStrategy.cpp

    r271 r277  
    1010
    1111#include "OsiSolverInterface.hpp"
    12 #ifdef COIN_USE_CLP
     12#ifdef CBC_USE_CLP
    1313#include "OsiClpSolverInterface.hpp"
    1414#endif
     
    298298    OsiSolverInterface * solver = model.solver();
    299299    int logLevel = model.messageHandler()->logLevel();
    300 #ifdef COIN_USE_CLP
     300#ifdef CBC_USE_CLP
    301301    OsiClpSolverInterface * clpSolver = dynamic_cast< OsiClpSolverInterface*> (solver);
    302302    ClpSimplex * lpSolver=NULL;
     
    342342    } else {
    343343      // now tighten bounds
    344 #ifdef COIN_USE_CLP
     344#ifdef CBC_USE_CLP
    345345      if (clpSolver) {
    346346        // model has changed
  • trunk/Makefile

    r173 r277  
    33# - Makefile.Cbc
    44
     5# Define variables here to select the solvers that you want to incorporate into
     6# the cbc build. Be sure that the solvers are available and that the
     7# information in Makefile.location is correct for all selected solvers.
     8# Check Makefile.Cbc to specify the optimisation level of the build.
     9
     10# Compile-time configuration for Cbc. There are basically two options:
     11# (1)
     12# Build cbc to use only clp as the underlying lp solver. This is the most
     13# efficient configuration if you wish to take full advantage of capabilities
     14# supported by clp but not available through the standard OSI interface, and
     15# you have no interest in experimenting with other solvers.
     16# (2)
     17# Build cbc so that it can use some mix of one or more OSI solvers, not
     18# necessarily including clp. Use this option if you want to experiment with
     19# other solvers.
     20
     21# To specify a solver, add the name to the list here. Use the name given in
     22# Makefile.location, without the COIN_lib prefix, e.g., Clp, Cpx, Dylp, Glpk,
     23# etc. The default build uses Clp only. To use Clp and Dylp, you would say
     24# CBC_SOLVERS := Clp Dylp
     25
     26CBC_SOLVERS := Clp
     27
     28# Regardless of the number of solvers specified, it's a good idea to set the
     29# default solver. (All right, the real reason is it'll take too long to explain
     30# what happens if you don't. Check the code in CbcMain if you must know.)
     31# This must match one of the solver names given above, but all in lower case
     32# letters (don't ask).
     33
     34cbcDefaultSolver := clp
     35
    536###############################################################################
     37
     38# Bring on the boilerplate. Makefile.coin will bring in Makefile.<O/S> and
     39# Makefile.location.
    640
    741export CoinDir := $(shell cd ..; pwd)
    842export MakefileDir := $(CoinDir)/Makefiles
    943include ${MakefileDir}/Makefile.coin
    10 include ${MakefileDir}/Makefile.location
     44
     45# First check that all solvers specified by the user have been configured in
     46# Makefile.location.
     47
     48cbcMissingSolvers := $(filter-out \
     49        $(patsubst COIN_libOsi%,%,$(CoinLibsDefined)),$(CBC_SOLVERS))
     50
     51ifneq ($(cbcMissingSolvers),)
     52  $(foreach solver,$(cbcMissingSolvers), \
     53    $(warning $(solver) is not configured in Makefiles/Makefile.location.) \
     54    $(warning Probably the line 'CoinLibsDefined += COIN_lib$(solver)' is \
     55      commented out))
     56  $(error Please correct Makefile.location and try again.)
     57endif
     58
     59# Figure out the configuration based on the value of CBC_SOLVERS. We need to
     60# generate appropriate defines for the compilation command.
     61
     62CBC_DEFINES :=
     63
     64ifeq ($(CBC_SOLVERS),Clp)
     65  CBC_ONLY_CLP := 1
     66  CBC_DEFINES := CBC_ONLY_CLP CBC_USE_CLP
     67else
     68  CBC_ONLY_CLP := 0
     69  CBC_DEFINES := $(foreach solver,$(CBC_SOLVERS), \
     70      $(patsubst COIN_HAS_%,CBC_USE_%,\
     71        $(filter COIN_HAS_%,$($(solver)Define))))
     72endif
     73CBC_DEFINES += CBC_DEFAULT_SOLVER="\"$(cbcDefaultSolver)\""
     74export CBC_ONLY_CLP
     75export CBC_DEFINES
     76export CBC_SOLVERS
     77
     78$(warning CBC_DEFINES is $(CBC_DEFINES))
     79
     80$(warning Building cbc with solvers $(CBC_SOLVERS))
     81
     82# Pull together the full dependency list for cbc. You can't build cbc without
     83# the Coin, Osi, and Cgl libraries. Add Coin and Osi later, for technical
     84# reasons.
     85
     86libTgts := Cgl
     87
     88# This makefile fronts for two main programs down in the Test directory, cbc
     89# and solve. solve will always want OsiClp and Vol (note: not OsiVol). Add them
     90# here, if they're not already in CBC_SOLVERS, and add the list from
     91# CBC_SOLVERS.
     92
     93libTgts += $(filter-out $(CBC_SOLVERS),Vol)
     94libTgts += $(patsubst %,Osi%,$(CBC_SOLVERS))
     95libTgts += $(filter-out $(libTgts),OsiClp)
     96
     97# Relocate the OsiXXX targets to the Osi directory, then prepend Coin and Osi.
     98
     99libTgts := Coin Osi $(patsubst Osi%,Osi/Osi%,$(libTgts))
     100
     101$(warning Complete dependency list is $(libTgts))
    11102
    12103###############################################################################
     
    14105.DELETE_ON_ERROR:
    15106
    16 .PHONY: default install clean library unitTest solver solve libdepend libCbc doc
     107.PHONY: default install clean library unitTest cbc solver solve \
     108        libdepend libCbc doc
    17109
    18110default: install
     
    21113libCbc: library
    22114
     115ifneq ($(filter COIN_libOsiCbc,$(CoinLibsDefined)),)
     116        (cd $(CoinDir)/Osi/OsiCbc && $(MAKE) -f Makefile.lightweight install)
     117endif
     118
    23119install library: libdepend
    24120        ${MAKE} -f Makefile.Cbc $@
    25121
    26 # Uncomment below to build OsiDylp
     122# Build the dependencies. OsiCbc is its own strange animal, pick it off
     123# separately.
    27124
    28125libdepend:
    29         (cd $(CoinDir)/Coin && $(MAKE) install)
    30         (cd $(CoinDir)/Clp && $(MAKE) install)
    31 ifeq ($(VolDefine),COIN_HAS_VOL)
    32         (cd $(CoinDir)/Vol && $(MAKE) install)
    33 endif
    34 ifneq ($(filter COIN_libOsiClp,$(CoinLibsDefined)),)
    35         (cd $(CoinDir)/Osi/OsiClp && $(MAKE) install)
    36 endif
     126        $(foreach tgt,$(libTgts),(cd $(CoinDir)/$(tgt) && $(MAKE) install) ; )
    37127ifneq ($(filter COIN_libOsiCbc,$(CoinLibsDefined)),)
    38128        (cd $(CoinDir)/Osi/OsiCbc && $(MAKE) -f Makefile.lightweight install)
    39129endif
    40 #       (cd $(CoinDir)/Osi/OsiDylp && $(MAKE) install)
    41         (cd $(CoinDir)/Cgl && $(MAKE) install)
    42130
    43 unitTest:
     131unitTest cbc:
    44132        (cd Test && ${MAKE} unitTest)
    45133
     
    58146        @rm -rf Test/dep
    59147        @rm -f cbc
     148        @rm -f solve
    60149
    61150doc:
  • trunk/Makefile.Cbc

    r247 r277  
    55# highest level of optimization the compiler supports. If want something in
    66# between then specify the exact level you want, e.g., -O1 or -O2
    7 OptLevel := -O1
     7#OptLevel := -O1
    88OptLevel := -g
    99
     
    1717LIBSRC += CbcCountRowCut.cpp
    1818LIBSRC += CbcMessage.cpp
     19LIBSRC += CbcEventHandler.cpp
    1920LIBSRC += CbcHeuristic.cpp
    2021LIBSRC += CbcHeuristicLocal.cpp
     
    3233LIBSRC += CbcCompareActual.cpp
    3334LIBSRC += CbcCutGenerator.cpp
    34 LIBSRC += Cbc_C_Interface.cpp
     35
     36# Clp is deeply wired into the C interface. Just say Clp is required to use
     37# it.
     38
     39ifneq ($(filter CBC_USE_CLP, $(CBC_DEFINES)),)
     40  LIBSRC += Cbc_C_Interface.cpp
     41endif
    3542
    3643##############################################################################
    3744# You should not need to edit below this line.
    3845##############################################################################
    39 # The location of the customized Makefiles
     46# The location of the customized Makefiles. Unclear we need this again, but
     47# it can't hurt. As noted in Makefile, Makefile.coin will pull in
     48# Makefile.<O/S> and Makefile.location.
     49
    4050include ${MakefileDir}/Makefile.coin
    41 include ${MakefileDir}/Makefile.location
     51
     52CXXFLAGS += $(addprefix -D,$(CBC_DEFINES))
     53
     54# Defines to enable debugging code.
    4255
    4356ifeq ($(OptLevel),-g)
    4457#   CXXFLAGS += -DCBC_DEBUG
     58#   CXXFLAGS += -DCBC_DEBUG=2
     59#   CXXFLAGS += -DFULL_DEBUG
    4560#   CXXFLAGS += -DCHECK_NODE
    4661#   CXXFLAGS += -DCHECK_CUT_COUNTS
     
    4863#   CXXFLAGS += -lefence
    4964endif
    50 ifneq (,$(filter COIN_HAS_OSICLP, $(OsiClpDefine)))
    51 #  add in USE
    52 CXXFLAGS += $(addprefix -D,COIN_USE_CLP)
    53 endif
     65
     66# $(warning CXXFLAGS is $(CXXFLAGS))
    5467
    5568export ExtraIncDir  := ${CoinIncDir} ${zlibIncDir} ${bzlibIncDir}
  • trunk/Test/CbcMain.cpp

    r246 r277  
    4444#include  "CbcParam.hpp"
    4545
    46 #ifdef COIN_USE_CLP
     46#ifdef CBC_USE_CLP
    4747#include "OsiClpSolverInterface.hpp"
    4848#endif
    49 #ifdef COIN_USE_DYLP
     49#ifdef CBC_USE_DYLP
    5050#include "OsiDylpSolverInterface.hpp"
    5151#endif
    52 #ifdef COIN_USE_OSL
     52#ifdef CBC_USE_OSL
    5353#include "OsiOslSolverInterface.hpp"
    5454#endif
     
    560560}       /* end unnamed namespace */
    561561
     562int CbcOrClpRead_mode=1;
     563FILE * CbcOrClpReadCommand=stdin;
    562564
    563565int main (int argc, const char *argv[])
     
    584586    solverMap_t solvers ;
    585587
    586 #   ifdef COIN_USE_CLP
     588#   ifdef CBC_USE_CLP
    587589#     ifndef CBC_DEFAULT_SOLVER
    588590#       define CBC_DEFAULT_SOLVER "clp"
     
    592594      solvers["clp"] = 0 ;
    593595#   endif
    594 #   ifdef COIN_USE_DYLP
     596#   ifdef CBC_USE_DYLP
    595597#     ifndef CBC_DEFAULT_SOLVER
    596598#       define CBC_DEFAULT_SOLVER "dylp"
     
    600602      solvers["dylp"] = 0 ;
    601603#   endif
    602 #   ifdef COIN_USE_OSL
     604#   ifdef CBC_USE_OSL
    603605#     ifndef CBC_DEFAULT_SOLVER
    604606#       define CBC_DEFAULT_SOLVER "osl"
     
    10171019              if (!doScaling)
    10181020                solver->setHintParam(OsiDoScale,false,OsiHintTry);
    1019 #ifdef COIN_USE_CLP
     1021#ifdef CBC_USE_CLP
    10201022              OsiClpSolverInterface * si =
    10211023                dynamic_cast<OsiClpSolverInterface *>(solver) ;
     
    10851087                      model2->solver()->setHintParam(OsiDoDualInResolve,false,OsiHintTry);
    10861088                    }
    1087                     model2->branchAndBound();
     1089                    try
     1090                    { model2->branchAndBound(); }
     1091                    catch (CoinError err)
     1092                    { std::cerr << "Exception: "
     1093                                << err.className() << "::" << err.methodName()
     1094                                << std::endl ;
     1095                      std::cerr << err.message() << std::endl ;
     1096                      exit (1) ; }
    10881097                    // get back solution
    10891098                    model->originalModel(model2,false);
     
    11411150                else if (twomirAction==2)
    11421151                  model->addCutGenerator(&twomirGen,-99,"TwoMirCuts");
    1143                 model->branchAndBound() ; }
     1152                try
     1153                { model->branchAndBound(); }
     1154                catch (CoinError err)
     1155                { std::cerr << "Exception: "
     1156                            << err.className() << "::" << err.methodName()
     1157                            << std::endl ;
     1158                  std::cerr << err.message() << std::endl ;
     1159                  exit (1) ; }
     1160              }
    11441161              if (model->bestSolution())
    11451162              { std::cout << "Optimal solution "
     
    11551172              time1 = time2 ;
    11561173            } else {
    1157               // User is going to get what I think best
     1174/*
     1175  User is willing to accept cbc defaults. Do an initial solve.
     1176*/
    11581177              if (!doScaling)
    11591178                model->solver()->setHintParam(OsiDoScale,false,OsiHintTry);
    11601179              model->initialSolve();
    1161               // See if we want preprocessing
     1180/*
     1181  Integer preprocessing. For reasons that escape me just yet, the first thing
     1182  we'll do is clone the solver for the model.
     1183*/
    11621184              OsiSolverInterface * saveSolver=NULL;
    11631185              CglPreProcess process;
     
    12471269             
    12481270              model->solver()->setIntParam(OsiMaxNumIterationHotStart,100);
    1249 #ifdef COIN_USE_CLP
     1271#ifdef CBC_USE_CLP
    12501272              OsiClpSolverInterface * osiclp = dynamic_cast< OsiClpSolverInterface*> (model->solver());
    1251               // go faster stripes
    1252               if (osiclp->getNumRows()<300&&osiclp->getNumCols()<500) {
    1253                 osiclp->setupForRepeatedUse(2,0);
     1273# ifndef CBC_ONLY_CLP
     1274              if (osiclp) {
     1275# endif
     1276                // go faster stripes
     1277                if (osiclp->getNumRows()<300&&osiclp->getNumCols()<500) {
     1278                  osiclp->setupForRepeatedUse(2,0);
     1279                }
     1280# ifndef CBC_ONLY_CLP
    12541281              }
     1282# endif
    12551283#endif
    12561284              if (gapRatio < 1.0e100)
     
    12611289                          << ", so allowable gap set to "
    12621290                          << value2 << std::endl ; }
    1263               model->branchAndBound();
     1291              try
     1292              { model->branchAndBound(); }
     1293              catch (CoinError err)
     1294              { std::cerr << "Exception: "
     1295                          << err.className() << "::" << err.methodName()
     1296                          << std::endl ;
     1297                std::cerr << err.message() << std::endl ;
     1298                exit (1) ; }
    12641299              time2 = CoinCpuTime();
    12651300              totalTime += time2-time1;
     
    13961431                                                   "");
    13971432              assert(!status);
    1398               model->branchAndBound();
     1433              try
     1434              { model->branchAndBound(); }
     1435              catch (CoinError err)
     1436              { std::cerr << "Exception: "
     1437                          << err.className() << "::" << err.methodName()
     1438                          << std::endl ;
     1439                std::cerr << err.message() << std::endl ;
     1440                exit (1) ; }
    13991441              model->solver()->resolve();
    14001442              std::cout<<"Optimal solution "<<model->solver()->getObjValue()<<std::endl;
     
    14141456              model->setNodeComparison(compare);
    14151457              model->solver()->resolve();
    1416               model->branchAndBound();
     1458              try
     1459              { model->branchAndBound(); }
     1460              catch (CoinError err)
     1461              { std::cerr << "Exception: "
     1462                          << err.className() << "::" << err.methodName()
     1463                          << std::endl ;
     1464                std::cerr << err.message() << std::endl ;
     1465                exit (1) ; }
    14171466              model->solver()->resolve();
    14181467              std::cout<<"partial solution "<<model->solver()->getObjValue()<<std::endl;
  • trunk/Test/Makefile.test

    r246 r277  
    33# between then specify the exact level you want, e.g., -O1 or -O2
    44OptLevel := -g
     5LibType := SHARED
    56
    67##############################################################################
     
    910##############################################################################
    1011
    11 # The location of the customized Makefiles
    12 # also inherited from the parent Makefile
     12# Bring on the boilerplate, yet again.
    1313
     14MakefileDir := ../../Makefiles
    1415include ${MakefileDir}/Makefile.coin
    15 include ${MakefileDir}/Makefile.location
    1616
    1717# Include files, library directory and name, compile-time defines.
    1818
    19 # The pattern is (hopefully) obvious. Add or uncomment the appropriate lines
    20 # for your favourite solver. The appropriate lines of code must be installed in
    21 # the conditional compilation blocks in CbcMain.cpp in order for any of this to
    22 # work. One conditional compilation block is at the head of the file and
    23 # selects #include headers. The second is at the start of main() and creates a
    24 # vector of available solvers.
     19# Start out with empty vars. If for no other reason, we need this to establish
     20# these variables as simply expanded.
    2521
    26 IncDir := ${CbcIncDir} ${CglIncDir}
    27 IncDir += ${OsiClpIncDir} ${ClpIncDir}
    28 #IncDir += ${OsiDylpIncDir} ${DylpIncDir}
    29 IncDir += ${OsiOslIncDir} ${OslIncDir}
    30 IncDir += ${OsiIncDir} ${CoinIncDir}
    31 IncDir += ${bzlibIncDir} ${zlibIncDir} $(lapackIncDir)
    32 IncDir += ./include
     22IncDir :=
     23LibDir :=
     24LibName :=
     25Define := $(CBC_DEFINES)
    3326
    34 LibDir := ${CbcLibDir} ${CglLibDir}
    35 LibDir += ${OsiClpLibDir} ${ClpLibDir}
    36 #LibDir += ${OsiDylpLibDir} ${DylpLibDir}
    37 LibDir += ${OsiOslLibDir} ${OslLibDir}
    38 LibDir += ${OsiLibDir} ${CoinLibDir}
    39 LibDir += ${bzlibLibDir} ${zlibLibDir} $(lapackLibDir)
    40 LibDir += $(GlpkLibDir)
     27# Tell parameter handling to allow for CbcModel and OsiSolverInterface. You
     28# can't run the miplib test suite without OsiCbc.
    4129
    42 LibName := $(OsiCbcLibName) ${CbcLibName} ${CglLibName}
    43 LibName += ${OsiClpLibName} ${ClpLibName}
    44 ifeq ($(VolDefine),COIN_HAS_VOL)
    45 LibName += $(VolLibName)
    46 endif
    47 #LibName += ${OsiDylpLibName} ${DylpLibName}
    48 LibName += ${OsiOslLibName} ${OslLibName}
    49 LibName += ${OsiLibName} ${CoinLibName}
    50 LibName += ${bzlibLibName} ${zlibLibName} $(lapackLibName) $(readlineLibName)
    51 LibName += $(GlpkLibName)
     30CBC_SOLVERS += Cbc
    5231
    53 Define := ${CbcDefine} ${CglDefine}
    54 Define += ${OsiClpDefine} ${ClpDefine}
    55 #Define += ${OsiDylpDefine} ${DylpDefine}
    56 Define += ${OsiOslDefine} ${OslDefine}
    57 Define += ${OsiDefine} ${CoinDefine}
    58 Define += ${bzlibDefine} ${zlibDefine} $(lapackDefine)
     32$(warning CBC_SOLVERS is $(CBC_SOLVERS))
    5933
    60 # Unless overridden, cbc will select clp as the default solver.
    61 # CBC_DEFAULT_SOLVER is the hook to change the default when you're building the
    62 # code with multiple solvers. For example, to add dylp but leave clp as the
    63 # default, uncomment only the line to define COIN_USE_DYLP. To use both clp and
    64 # dylp, with dylp the default, also uncomment the line which defines
    65 # CBC_DEFAULT_SOLVER.  cbc chooses clp as the default because it's listed first
    66 # in the conditional compilation block at the head of CbcMain.cpp::main().  If
    67 # you build the code without clp, the first defined solver becomes the
    68 # default.
    69 
    70 #use clp
    71 ifneq (,$(filter COIN_HAS_OSICLP, $(Define)))
    72 #  add in USE
    73 CXXFLAGS += $(addprefix -D,COIN_USE_CLP)
     34ifneq ($(filter COIN_libOsiCbc,$(CoinLibsDefined)),)
     35  CXXFLAGS += -DCBC_USE_CBC
     36else
     37  $(warning OsiCbc not enabled in CoinLibsDefined. You will not be able to)
     38  $(warning run the `cbc -miplib' command. Edit Makefile.location if you)
     39  $(warning to enable OsiCbc.)
    7440endif
    7541
    76 #use dylp
    77 #CXXFLAGS += $(addprefix -D,COIN_USE_DYLP)
    78 #CXXFLAGS += $(addprefix -D,CBC_DEFAULT_SOLVER=\"dylp\")
    7942
    80 #use osl
    81 ifneq (,$(filter COIN_HAS_OSIOSL, $(CXXFLAGS)))
    82 CXXFLAGS += $(addprefix -D,COIN_USE_OSL)
    83 endif
    84 #CXXFLAGS += $(addprefix -D,CBC_DEFAULT_SOLVER=\"osl\")
     43# Add the required libraries: Coin, Osi, Cgl
    8544
    86 #tell parameter handling to allow for CbcModel and OsiSolverInterface
    87 ifneq ($(filter COIN_libOsiCbc,$(CoinLibsDefined)),)
    88 CXXFLAGS += -DCOIN_USE_CBC
    89 endif
     45IncDir += $(foreach lib,Coin Osi Cgl,$($(lib)IncDir))
     46LibDir += $(foreach lib,Coin Osi Cgl,$($(lib)LibDir))
     47LibName += $(foreach lib,Coin Osi Cgl,$($(lib)LibName))
     48Define += $(foreach lib,Coin Osi Cgl,$($(lib)Define))
     49
     50# Add the requested solver libraries: libXXX and libOsiXXX
     51
     52IncDir += $(foreach lib,$(CBC_SOLVERS),$($(lib)IncDir))
     53LibDir += $(foreach lib,$(CBC_SOLVERS),$($(lib)LibDir))
     54LibName += $(foreach lib,$(CBC_SOLVERS),$($(lib)LibName))
     55Define += $(foreach lib,$(CBC_SOLVERS),$($(lib)Define))
     56IncDir += $(foreach lib,$(CBC_SOLVERS),$(Osi$(lib)IncDir))
     57LibDir += $(foreach lib,$(CBC_SOLVERS),$(Osi$(lib)LibDir))
     58LibName += $(foreach lib,$(CBC_SOLVERS),$(Osi$(lib)LibName))
     59Define += $(foreach lib,$(CBC_SOLVERS),$(Osi$(lib)Define))
     60
     61# And a few other potentially useful libraries: z, bz, readline. Unfortunately
     62# the naming conventions are irregular.
     63
     64utilLibs := $(filter \
     65    $(patsubst COIN_%,%,$(CoinLibsDefined)),libz libbz readline)
     66utilLibs := $(patsubst lib%z,%zlib,$(utilLibs))
     67
     68IncDir += $(foreach lib,$(utilLibs),$($(lib)IncDir))
     69LibDir += $(foreach lib,$(utilLibs),$($(lib)LibDir))
     70LibName += $(foreach lib,$(utilLibs),$($(lib)LibName))
     71Define += $(foreach lib,$(utilLibs),$($(lib)Define))
     72
     73# Strip redundancy from IncDir, LibDir. Reordering should not be harmful for
     74# these, under normal circumstances.
     75
     76IncDir := ./include $(sort $(IncDir))
     77LibDir := $(sort $(LibDir))
     78
     79$(warning IncDir is $(IncDir))
     80$(warning LibDir is $(LibDir))
     81$(warning LibName is $(LibName))
     82$(warning Define is $(Define))
     83
    9084##############################################################################
    9185# You should not need to edit below this line.
  • trunk/Test/unitTest.cpp

    r107 r277  
    1414#include <cstdio>
    1515
    16 #ifdef COIN_USE_CBC
     16#include "CoinHelperFunctions.hpp"
     17
     18#ifdef CBC_USE_CBC
    1719#include "OsiCbcSolverInterface.hpp"
    18 #else
    19 //#define OsiCbcSolverInterface OsiClpSolverInterface
    20 #endif
    21 #ifdef COIN_USE_OSL
     20#endif
     21#ifdef CBC_USE_OSL
    2222#include "OsiOslSolverInterface.hpp"
    2323#endif
    24 #ifdef COIN_USE_SPX
     24#ifdef CBC_USE_SPX
    2525#include "OsiSpxSolverInterface.hpp"
    2626#endif
    27 #ifdef COIN_USE_DYLP
     27#ifdef CBC_USE_DYLP
    2828#include "OsiDylpSolverInterface.hpp"
    2929#endif
    30 #ifdef COIN_USE_GLPK
     30#ifdef CBC_USE_GLPK
    3131#include "OsiGlpkSolverInterface.hpp"
    3232#endif
    33 #ifdef COIN_USE_CLP
     33#ifdef CBC_USE_CLP
    3434#include "OsiClpSolverInterface.hpp"
    3535#endif
     
    4242void testingMessage( const char * const msg );
    4343
    44 #ifdef COIN_USE_CBC
     44#ifdef CBC_USE_CBC
    4545void CbcUnitTest (const std::vector<OsiCbcSolverInterface*> & vecEmptySiP,
    4646                  const std::string & mpsDir)
     
    9494    Load up the problem vector. Note that the row counts here include the
    9595    objective function.
    96    
     96 
     97    Set HOWMANY to 0 for no test, 1 for some, 2 for many, 3 for all.
    9798  */
    98   // 0 for no test, 1 for some, 2 for many, 3 for all
    9999#define HOWMANY 1
    100100#if HOWMANY
    101101#if HOWMANY>1
    102   PUSH_MPS("10teams",230,2025,924,917,7)
     102    PUSH_MPS("10teams",230,2025,924,917,7)
    103103#endif
    104104    PUSH_MPS("air03",124,10757,340160,338864.25,7)
     
    117117#endif
    118118    //    PUSH_MPS("dano3mip",3202,13873,728.1111,576.23162474,7)
    119     //PUSH_MPS("danoint",664,521,65.67,62.637280418,7)
     119    //    PUSH_MPS("danoint",664,521,65.67,62.637280418,7)
    120120    PUSH_MPS("dcmulti",290,548,188182,183975.5397,7)
    121121    PUSH_MPS("dsbmip",1182,1886,-305.19817501,-305.19817501,7)
     
    191191#endif
    192192    PUSH_MPS("vpm1",234,378,20,15.4167,7)
    193       PUSH_MPS("vpm2",234,378,13.75,9.8892645972,7)
     193    PUSH_MPS("vpm2",234,378,13.75,9.8892645972,7)
    194194#endif
    195195#undef PUSH_MPS
    196196   
    197     /*
    198       Create a vector of solver interfaces that we can use to run the test
    199       problems. The strategy is to create a fresh clone of the `empty' solvers
    200       from vecEmptySiP for each problem, then proceed in stages: read the MPS
    201       file, solve the problem, check the solution. If there are multiple
    202       solvers in vecSiP, the results of each solver are compared with its
    203       neighbors in the vector.
    204     */
    205     int numberSolvers=vecEmptySiP.size();
     197  /*
     198    Create a vector of solver interfaces that we can use to run the test
     199    problems. The strategy is to create a fresh clone of the `empty' solvers
     200    from vecEmptySiP for each problem, then proceed in stages: read the MPS
     201    file, solve the problem, check the solution. If there are multiple
     202    solvers in vecSiP, the results of each solver are compared with its
     203    neighbors in the vector.
     204  */
     205  int numberSolvers=vecEmptySiP.size();
    206206  std::vector<OsiSolverInterface*> vecSiP(numberSolvers) ;
    207207
    208208  // Create vector to store a name for each solver interface
    209   // and a count on the number of problems the solver intface solved.
     209  // and a count on the number of problems the solver interface solved.
    210210  std::vector<std::string> siName;
    211211  std::vector<int> numProbSolved;
     
    220220 
    221221  /*
    222     Open the main loop to step through the MPS problems.
     222    Open the main loops. Outer loop steps through MPS problems, inner loop
     223    steps through solvers.
    223224  */
    224225  for (m = 0 ; m < mpsName.size() ; m++)
    225     { std::cerr << "  processing mps file: " << mpsName[m]
    226                 << " (" << m+1 << " out of " << mpsName.size() << ")" << std::endl ;
     226  { std::cerr << "  processing mps file: " << mpsName[m]
     227              << " (" << m+1 << " out of " << mpsName.size() << ")"
     228              << std::endl ;
     229    for (i = vecSiP.size()-1 ; i >= 0 ; --i) {
     230      vecSiP[i] = vecEmptySiP[i]->clone() ;
    227231    /*
    228       Stage 1: Read the MPS file into each solver interface.
    229 
    230       Fill vecSiP with fresh clones of the solvers and read in the MPS file. As
    231       a basic check, make sure the size of the constraint matrix is correct.
     232      Stage 1: Read the MPS file into the solver interface.
     233
     234      As a basic check, make sure the size of the constraint matrix is correct.
    232235    */
    233     for (i = vecSiP.size()-1 ; i >= 0 ; --i)
    234       { vecSiP[i] = vecEmptySiP[i]->clone() ;
    235236     
    236237      std::string fn = mpsDir+mpsName[m] ;
     
    244245      assert(nc == nCols[m]) ;
    245246    /*
    246       Stage 2: Call each solver to solve the problem.
    247      
    248       We call each solver, then check the return code and objective.
    249      
     247      Stage 2: Call the solver to get a solution for the LP relaxation.
    250248    */
    251 
    252249      double startTime = CoinCpuTime();
    253250      OsiCbcSolverInterface * integerSolver =
    254251        dynamic_cast<OsiCbcSolverInterface *>(vecSiP[i]) ;
    255       assert (integerSolver);
     252      assert(integerSolver);
     253      integerSolver->initialSolve();
     254    /*
     255      Stage 3: Call the solver to perform branch and cut.
     256     
     257      We call each solver, then check the return code and objective.
     258      Limits are 50000 nodes and one hour of time.
     259    */
     260
    256261      integerSolver->setMaximumNodes(50000);
     262      integerSolver->setMaximumSeconds(60*60);
     263      integerSolver->getModelPtr()->messageHandler()->setLogLevel(1) ;
    257264      integerSolver->branchAndBound();
    258265     
     
    353360  else
    354361    miplibDir = dirsep == '/' ? "./Samples/miplib3/" : ".\\Samples\\miplib3\\";
    355 #ifdef COIN_USE_CBC
     362#ifdef CBC_USE_CBC
    356363
    357364  {
     
    359366    std::vector<OsiCbcSolverInterface*> vecSi;
    360367    CbcStrategyDefault strategy(false);
    361 #   if COIN_USE_OSL
     368#   if CBC_USE_OSL
    362369    OsiSolverInterface * oslSi = new OsiOslSolverInterface;
    363370    vecSi.push_back(new OsiCbcSolverInterface(oslSi,&strategy));
    364371#endif
    365 #   if COIN_USE_SPX
     372#   if CBC_USE_SPX
    366373    OsiSolverInterface * spxSi = new OsiSpxSolverInterface;
    367374    vecSi.push_back(new OsiCbcSolverInterface(spxSi,&strategy));
    368375#endif
    369 #   if COIN_USE_CLP
    370     OsiSolverInterface * clpSi = new OsiClpSolverInterface;
     376#   if CBC_USE_CLP
     377    OsiSolverInterface *clpSi = new OsiClpSolverInterface ;
     378    /* Quiet, already! */
     379    clpSi->setHintParam(OsiDoReducePrint,true,OsiHintDo) ;
    371380    vecSi.push_back(new OsiCbcSolverInterface(clpSi,&strategy));
    372381#endif
    373 #   if COIN_USE_DYLP
     382#   if CBC_USE_DYLP
    374383    OsiSolverInterface * dylpSi = new OsiDylpSolverInterface;
    375384    vecSi.push_back(new OsiCbcSolverInterface(dylpSi,&strategy));
    376385#endif
    377 #   if COIN_USE_GLPK
     386#   if CBC_USE_GLPK
    378387    OsiSolverInterface * glpkSi = new OsiGlpkSolverInterface;
    379388    vecSi.push_back(new OsiCbcSolverInterface(glpkSi,&strategy));
     
    396405void testingMessage( const char * const msg )
    397406{
    398   std::cerr <<msg;
    399   //cout <<endl <<"*****************************************"
    400   //     <<endl <<msg <<endl;
     407  std::cerr << msg << std::endl ;
     408  // std::cout << msg << std::endl ;
    401409}
    402410
  • trunk/include/CbcModel.hpp

    r271 r277  
    1212#include "CbcCompareBase.hpp"
    1313#include "CbcMessage.hpp"
    14 #ifdef COIN_USE_CLP
    15 #include "ClpEventHandler.hpp"
    16 #endif
    1714
    1815//class OsiSolverInterface;
     
    2926class CbcFeasibilityBase;
    3027class CbcStatistics;
     28#ifdef CBC_ONLY_CLP
     29class ClpEventHandler ;
     30#else
     31class CbcEventHandler ;
     32#endif
    3133
    3234//#############################################################################
     
    12131215  inline int priority(int sequence) const
    12141216  { return object_[sequence]->priority();};
     1217
     1218
     1219#ifdef CBC_ONLY_CLP
     1220   /// Pass in Event handler (cloned and deleted at end)
     1221   void passInEventHandler(const ClpEventHandler * eventHandler);
     1222   /// Event handler
     1223  ClpEventHandler * eventHandler() const;
     1224#else
     1225  /*! \brief Set an event handler
     1226 
     1227    A clone of the handler passed as a parameter is stored in CbcModel.
     1228  */
     1229  void passInEventHandler(const CbcEventHandler *eventHandler) ;
     1230
     1231  /*! \brief Retrieve a pointer to the event handler */
     1232  CbcEventHandler* CbcModel::eventHandler() const
     1233  { return (eventHandler_) ; } ;
     1234#endif
     1235
    12151236  //@}
    12161237   
     
    12631284  inline int logLevel() const
    12641285  { return handler_->logLevel();};
    1265 #ifdef COIN_USE_CLP
    1266    /// Pass in Event handler (cloned and deleted at end)
    1267    void passInEventHandler(const ClpEventHandler * eventHandler);
    1268    /// Event handler
    1269   ClpEventHandler * eventHandler() const;
    1270 #endif
    12711286  //@}
    12721287  //---------------------------------------------------------------------------
     
    17181733  /// Pointer to heuristic solver which found last solution (or NULL)
    17191734  CbcHeuristic * lastHeuristic_;
     1735  /*! Pointer to the event handler */
     1736# ifdef CBC_ONLY_CLP
     1737  ClpEventHandler *eventHandler_ ;
     1738# else
     1739  CbcEventHandler *eventHandler_ ;
     1740# endif
    17201741
    17211742  /// Total number of objects
Note: See TracChangeset for help on using the changeset viewer.