Changeset 72


Ignore:
Timestamp:
Mar 3, 2005 4:30:44 PM (17 years ago)
Author:
forrest
Message:

debug for lotsize and when_ for heuristic

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/CbcBranchLotsize.cpp

    r2 r72  
    1515#include "CoinSort.hpp"
    1616#include "CoinError.hpp"
    17 
    18 
     17/*
     18  CBC_PRINT 1 just does sanity checks - no printing
     19            2
     20*/
     21//#define CBC_PRINT 1
     22// First/last variable to print info on
     23#if CBC_PRINT
     24// preset does all - change to x,x to just do x
     25static int firstPrint=0;
     26static int lastPrint=1000000;
     27static CbcModel * saveModel=NULL;
     28#endif
     29// Just for debug (CBC_PRINT defined in CbcBranchLotsize.cpp)
     30void
     31CbcLotsize::printLotsize(double value,bool condition,int type) const
     32{
     33#if CBC_PRINT
     34  if (columnNumber_>=firstPrint&&columnNumber_<=lastPrint) {
     35    int printIt = CBC_PRINT-1;
     36    // Get details
     37    OsiSolverInterface * solver = saveModel->solver();
     38    double currentLower = solver->getColLower()[columnNumber_];
     39    double currentUpper = solver->getColUpper()[columnNumber_];
     40    int i;
     41    // See if in a valid range (with two tolerances)
     42    bool inRange=false;
     43    bool inRange2=false;
     44    double integerTolerance =
     45      model_->getDblParam(CbcModel::CbcIntegerTolerance);
     46    // increase if type 2
     47    if (type==2) {
     48      integerTolerance *= 100.0;
     49      type=0;
     50      printIt=2; // always print
     51    }
     52    // bounds should match some bound
     53    int rangeL=-1;
     54    int rangeU=-1;
     55    if (rangeType_==1) {
     56      for (i=0;i<numberRanges_;i++) {
     57        if (fabs(currentLower-bound_[i])<1.0e-12)
     58          rangeL=i;
     59        if (fabs(currentUpper-bound_[i])<1.0e-12)
     60          rangeU=i;
     61        if (fabs(value-bound_[i])<integerTolerance)
     62          inRange=true;
     63        if (fabs(value-bound_[i])<1.0e8)
     64          inRange2=true;
     65      }
     66    } else {
     67      for (i=0;i<numberRanges_;i++) {
     68        if (fabs(currentLower-bound_[2*i])<1.0e-12)
     69          rangeL=i;
     70        if (fabs(currentUpper-bound_[2*i+1])<1.0e-12)
     71          rangeU=i;
     72        if (value>bound_[2*i]-integerTolerance&&
     73            value<bound_[2*i+1]+integerTolerance)
     74          inRange=true;
     75        if (value>bound_[2*i]-integerTolerance&&
     76            value<bound_[2*i+1]+integerTolerance)
     77          inRange=true;
     78      }
     79    }
     80    assert (rangeL>=0&&rangeU>=0);
     81    bool abortIt=false;
     82    switch (type) {
     83      // returning from findRange (fall through to just check)
     84    case 0:
     85      if (printIt) {
     86        printf("findRange returns %s for column %d and value %g",
     87               condition ? "true" : "false",columnNumber_,value);
     88        if (printIt>1)
     89          printf(" LP bounds %g, %g",currentLower,currentUpper);
     90        printf("\n");
     91      }
     92      // Should match
     93    case 1:
     94      if (inRange!=condition) {
     95        printIt=2;
     96        abortIt=true;
     97      }
     98      break;
     99      //
     100    case 2:
     101      break;
     102      //
     103    case 3:
     104      break;
     105      //
     106    case 4:
     107      break;
     108    }
     109  }
     110#endif
     111}
    19112/** Default Constructor
    20113
     
    40133  : CbcObject(model)
    41134{
     135#if CBC_PRINT
     136  if (!saveModel)
     137    saveModel=model;
     138#endif
    42139  assert (numberPoints>0);
    43140  columnNumber_ = iColumn ;
     
    178275      iHi=range_-1;
    179276    } else if (value<bound_[range_]+integerTolerance) {
     277#if CBC_PRINT
     278      printLotsize(value,true,0);
     279#endif
    180280      return true;
    181281    } else if (value<bound_[range_+1]-integerTolerance) {
     282#ifdef CBC_PRINT
     283      printLotsize(value,false,0);
     284#endif
    182285      return false;
    183286    } else {
     
    223326        range_++;
    224327    }
     328#ifdef CBC_PRINT
     329    printLotsize(value,(infeasibility<integerTolerance),0);
     330#endif
    225331    return (infeasibility<integerTolerance);
    226332  } else {
     
    230336      iHi=range_-1;
    231337    } else if (value<bound_[2*range_+1]+integerTolerance) {
     338#ifdef CBC_PRINT
     339      printLotsize(value,true,0);
     340#endif
    232341      return true;
    233342    } else if (value<bound_[2*range_+2]-integerTolerance) {
     343#ifdef CBC_PRINT
     344      printLotsize(value,false,0);
     345#endif
    234346      return false;
    235347    } else {
     
    275387      infeasibility = bound_[2*range_+2]-value;
    276388    }
     389#ifdef CBC_PRINT
     390    printLotsize(value,(infeasibility<integerTolerance),0);
     391#endif
    277392    return (infeasibility<integerTolerance);
    278393  }
     
    346461  else
    347462    infeasibility /= largestGap_;
     463#ifdef CBC_PRINT
     464    printLotsize(value,infeasibility,1);
     465#endif
    348466  return infeasibility;
    349467}
     
    381499  double integerTolerance =
    382500    model_->getDblParam(CbcModel::CbcIntegerTolerance);
     501#ifdef CBC_PRINT
     502  // print details
     503  printLotsize(value,true,2);
     504#endif
    383505  // Scaling may have moved it a bit
    384506  assert (fabs(value-nearest)<=100.0*integerTolerance);
  • trunk/CbcHeuristic.cpp

    r64 r72  
    107107                         double * betterSolution)
    108108{
     109
     110  // See if to do
     111  if (!when()||(when()==1&&model_->phase()!=1))
     112    return 0; // switched off
    109113
    110114  OsiSolverInterface * solver = model_->solver();
     
    407411  matrix_ = *model_->solver()->getMatrixByCol();
    408412  matrixByRow_ = *model_->solver()->getMatrixByRow();
     413  // make sure model okay for heuristic
     414  validate();
     415}
     416// Validate model i.e. sets when_ to 0 if necessary (may be NULL)
     417void
     418CbcRounding::validate()
     419{
    409420}
    410421
  • trunk/include/CbcBranchLotsize.hpp

    r2 r72  
    109109  { return bound_;};
    110110
     111private:
     112  /// Just for debug (CBC_PRINT defined in CbcBranchLotsize.cpp)
     113  void printLotsize(double value,bool condition,int type) const;
    111114
    112115private:
  • trunk/include/CbcHeuristic.hpp

    r6 r72  
    5454                       OsiCuts & cs) {return 0;};
    5555
     56  /// Validate model i.e. sets when_ to 0 if necessary (may be NULL)
     57  virtual void validate() {};
     58
    5659  /// Sets "when" flag - 0 off, 1 at root, 2 other than root, 3 always
    5760  inline void setWhen(int value)
     
    108111  virtual int solution(double & objectiveValue,
    109112                       double * newSolution);
     113  /// Validate model i.e. sets when_ to 0 if necessary (may be NULL)
     114  virtual void validate();
    110115
    111116
Note: See TracChangeset for help on using the changeset viewer.