Changeset 56


Ignore:
Timestamp:
Feb 4, 2005 2:53:35 PM (17 years ago)
Author:
forrest
Message:

allow easier way of debugging row cuts

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/CbcModel.cpp

    r54 r56  
    423423  originalContinuousObjective_ = solver_->getObjValue();
    424424  bestPossibleObjective_=originalContinuousObjective_;
    425 
    426 # ifdef CBC_DEBUG
    427425/*
    428426  OsiRowCutDebugger knows an optimal answer for a subset of MIP problems.
     
    430428  see if it cuts off the optimal answer.
    431429*/
    432   solver_->activateRowCutDebugger(problemName.c_str()) ;
     430  // If debugger exists set specialOptions_ bit
     431  if (solver_->getRowCutDebuggerAlways())
     432    specialOptions_ |= 1;
     433
     434# ifdef CBC_DEBUG
     435  if ((specialOptions_&1)==0)
     436    solver_->activateRowCutDebugger(problemName.c_str()) ;
     437  if (solver_->getRowCutDebuggerAlways())
     438    specialOptions_ |= 1;
    433439# endif
    434440
     
    851857      { deleteNode = true ; }
    852858
    853 #     ifdef CBC_DEBUG
    854 /*
    855   This doesn't work as intended --- getRowCutDebugger will return null
    856   unless the current feasible solution region includes the optimal solution
    857   that RowCutDebugger knows. There's no way to tell inactive from off the
    858   optimal path.
    859 */
    860       const OsiRowCutDebugger *debugger = solver_->getRowCutDebugger() ;
    861       if (debugger)
    862       { if(debugger->onOptimalPath(*solver_))
    863           printf("On optimal path\n") ;
    864         else
    865           printf("Not on optimal path\n") ; }
    866 #     endif
     859      if ((specialOptions_&1)!=0) {
     860        /*
     861          This doesn't work as intended --- getRowCutDebugger will return null
     862          unless the current feasible solution region includes the optimal solution
     863          that RowCutDebugger knows. There's no way to tell inactive from off the
     864          optimal path.
     865        */
     866        const OsiRowCutDebugger *debugger = solver_->getRowCutDebugger() ;
     867        if (debugger)
     868          { if(debugger->onOptimalPath(*solver_))
     869            printf("On optimal path\n") ;
     870          else
     871            printf("Not on optimal path\n") ; }
     872      }
    867873/*
    868874  Reoptimize, possibly generating cuts and/or using heuristics to find
     
    12581264  currentNode_(NULL),
    12591265  integerVariable_(NULL),
    1260   strategy_(0),
     1266  specialOptions_(0),
    12611267  subTreeModel_(NULL),
    12621268  numberStoppedSubTrees_(0),
     
    13311337  nextRowCut_(NULL),
    13321338  currentNode_(NULL),
    1333   strategy_(0),
     1339  specialOptions_(0),
    13341340  subTreeModel_(NULL),
    13351341  numberStoppedSubTrees_(0),
     
    14861492  numberIterations_(rhs.numberIterations_),
    14871493  status_(rhs.status_),
    1488   strategy_(rhs.strategy_),
     1494  specialOptions_(rhs.specialOptions_),
    14891495  subTreeModel_(rhs.subTreeModel_),
    14901496  numberStoppedSubTrees_(rhs.numberStoppedSubTrees_),
     
    17011707    numberIterations_ = rhs.numberIterations_;
    17021708    status_ = rhs.status_;
    1703     strategy_ = rhs.strategy_;
     1709    specialOptions_ = rhs.specialOptions_;
    17041710    subTreeModel_ = rhs.subTreeModel_;
    17051711    numberStoppedSubTrees_ = rhs.numberStoppedSubTrees_;
     
    22792285  numberNewCuts = 0 ;
    22802286
    2281 # ifdef CBC_DEBUG
    2282 /*
    2283   See OsiRowCutDebugger for details. In a nutshell, make sure that current
    2284   variable values do not conflict with a known optimal solution. (Obviously
    2285   this can be fooled when there are multiple solutions.)
    2286 */
    22872287  bool onOptimalPath = false ;
    2288   const OsiRowCutDebugger *debugger = solver_->getRowCutDebugger() ;
    2289   if (debugger)
    2290     onOptimalPath = (debugger->onOptimalPath(*solver_)) ;
    2291 # endif
     2288  const OsiRowCutDebugger *debugger = NULL;
     2289  if ((specialOptions_&1)!=0) {
     2290    /*
     2291      See OsiRowCutDebugger for details. In a nutshell, make sure that current
     2292      variable values do not conflict with a known optimal solution. (Obviously
     2293      this can be fooled when there are multiple solutions.)
     2294    */
     2295    debugger = solver_->getRowCutDebugger() ;
     2296    if (debugger)
     2297      onOptimalPath = (debugger->onOptimalPath(*solver_)) ;
     2298  }
    22922299/*
    22932300  Resolve the problem. If we've lost feasibility, might as well bail out right
     
    23032310  else
    23042311  { printf("Infeasible %d rows\n",solver_->getNumRows()) ; }
     2312#endif
     2313  if ((specialOptions_&1)!=0) {
    23052314/*
    23062315  If the RowCutDebugger said we were compatible with the optimal solution,
     
    23082317  may have fathomed by bound, heading for a rediscovery of an optimal solution.
    23092318*/
    2310   if (onOptimalPath && !solver_->isDualObjectiveLimitReached()) {
    2311     if (!feasible) {
    2312       solver_->writeMps("infeas");
    2313       CoinWarmStartBasis *slack =
    2314         dynamic_cast<CoinWarmStartBasis *>(solver_->getEmptyWarmStart()) ;
    2315       solver_->setWarmStart(slack);
    2316       delete slack ;
    2317       solver_->setHintParam(OsiDoReducePrint,false,OsiHintDo,0) ;
    2318       solver_->initialSolve();
    2319     }
    2320     assert(feasible) ;
    2321   }
    2322 # endif
     2319    if (onOptimalPath && !solver_->isDualObjectiveLimitReached()) {
     2320      if (!feasible) {
     2321        solver_->writeMps("infeas");
     2322        CoinWarmStartBasis *slack =
     2323          dynamic_cast<CoinWarmStartBasis *>(solver_->getEmptyWarmStart()) ;
     2324        solver_->setWarmStart(slack);
     2325        delete slack ;
     2326        solver_->setHintParam(OsiDoReducePrint,false,OsiHintDo,0) ;
     2327        solver_->initialSolve();
     2328      }
     2329      assert(feasible) ;
     2330    }
     2331  }
    23232332
    23242333  if (!feasible) return (false) ;
     
    24852494          if (mustResolve) {
    24862495            feasible = resolve() ;
    2487 #         ifdef CBC_DEBUG
    2488             debugger = solver_->getRowCutDebugger() ;
    2489             if (debugger)
    2490               onOptimalPath = (debugger->onOptimalPath(*solver_)) ;
    2491             else
    2492               onOptimalPath=false;
    2493             if (onOptimalPath && !solver_->isDualObjectiveLimitReached())
    2494               assert(feasible) ;
    2495 #         endif
     2496            if ((specialOptions_&1)!=0) {
     2497              debugger = solver_->getRowCutDebugger() ;
     2498              if (debugger)
     2499                onOptimalPath = (debugger->onOptimalPath(*solver_)) ;
     2500              else
     2501                onOptimalPath=false;
     2502              if (onOptimalPath && !solver_->isDualObjectiveLimitReached())
     2503                assert(feasible) ;
     2504            }
    24962505            if (!feasible)
    24972506              break ;
     
    25152524      int numberColumnCutsAfter = theseCuts.sizeColCuts() ;
    25162525
    2517 #ifdef CBC_DEBUG
    2518       if (onOptimalPath) {
    2519         int k ;
    2520         for (k = numberRowCutsBefore;k<numberRowCutsAfter;k++) {
    2521           OsiRowCut thisCut = theseCuts.rowCut(k) ;
    2522           assert(!debugger->invalidCut(thisCut)) ;
    2523         }
     2526      if ((specialOptions_&1)!=0) {
     2527        if (onOptimalPath) {
     2528          int k ;
     2529          for (k = numberRowCutsBefore;k<numberRowCutsAfter;k++) {
     2530            OsiRowCut thisCut = theseCuts.rowCut(k) ;
     2531            if(debugger->invalidCut(thisCut)) {
     2532              solver_->writeMps("badCut");
     2533            }
     2534            assert(!debugger->invalidCut(thisCut)) ;
     2535          }
     2536        }
    25242537      }
    2525 #endif
    25262538
    25272539/*
     
    38753887          const OsiRowCut * thisCut = theseCuts.rowCutPtr(j);
    38763888          if (thisCut->globallyValid()) {
    3877 #         ifdef CBC_DEBUG
    3878             /* As these are global cuts -
    3879                a) Always get debugger object
    3880                b) Not fatal error to cutoff optimal (if we have just got optimal)
    3881             */
    3882             const OsiRowCutDebugger *debugger = solver_->getRowCutDebuggerAlways() ;
    3883             if (debugger) {
    3884               if(debugger->invalidCut(*thisCut))
    3885                 printf("ZZZZ Global cut - cuts off optimal solution!\n");
    3886             }
    3887 #         endif
     3889            if ((specialOptions_&1)!=0) {
     3890              /* As these are global cuts -
     3891                 a) Always get debugger object
     3892                 b) Not fatal error to cutoff optimal (if we have just got optimal)
     3893              */
     3894              const OsiRowCutDebugger *debugger = solver_->getRowCutDebuggerAlways() ;
     3895              if (debugger) {
     3896                if(debugger->invalidCut(*thisCut))
     3897                  printf("ZZZZ Global cut - cuts off optimal solution!\n");
     3898              }
     3899            }
    38883900            // add to global list
    38893901            globalCuts_.insert(*thisCut);
  • trunk/include/CbcModel.hpp

    r54 r56  
    12441244  /// Indices of integer variables
    12451245  int * integerVariable_;
    1246   /// 0 bit gomory, 1 probing, 2 knapsack, 3 oddhole
    1247   int strategy_;
     1246  /// 0 bit - check if cuts valid (if on list)
     1247  int specialOptions_;
    12481248  /// User node comparison function
    12491249  CbcCompareBase * nodeCompare_;
Note: See TracChangeset for help on using the changeset viewer.