Ignore:
Timestamp:
Feb 13, 2008 3:52:57 PM (11 years ago)
Author:
forrest
Message:

add diving heuristics

File:
1 edited

Legend:

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

    r868 r871  
    2626  :CbcHeuristic(model)
    2727{
     28  downLocks_ =NULL;
     29  upLocks_ = NULL;
    2830  // Get a copy of original matrix
    2931  assert(model.solver());
    30   matrix_ = *model.solver()->getMatrixByCol();
    31   validate();
     32  // model may have empty matrix - wait until setModel
     33  const CoinPackedMatrix * matrix = model.solver()->getMatrixByCol();
     34  if (matrix) {
     35    matrix_ = *matrix;
     36  }
    3237  percentageToFix_ = 0.2;
    3338  maxIterations_ = 100;
     
    5863  CbcHeuristic::generateCpp(fp,"heuristicDiveCoefficient");
    5964  if (percentageToFix_!=other.percentageToFix_)
    60     fprintf(fp,"3  heuristicDiveCoefficient.setPercentageToFix(%d);\n",percentageToFix_);
     65    fprintf(fp,"3  heuristicDiveCoefficient.setPercentageToFix(%.2f);\n",percentageToFix_);
    6166  else
    62     fprintf(fp,"4  heuristicDiveCoefficient.setPercentageToFix(%d);\n",percentageToFix_);
     67    fprintf(fp,"4  heuristicDiveCoefficient.setPercentageToFix(%.2f);\n",percentageToFix_);
    6368  if (maxIterations_!=other.maxIterations_)
    6469    fprintf(fp,"3  heuristicDiveCoefficient.setMaxIterations(%d);\n",maxIterations_);
     
    6671    fprintf(fp,"4  heuristicDiveCoefficient.setMaxIterations(%d);\n",maxIterations_);
    6772  if (maxTime_!=other.maxTime_)
    68     fprintf(fp,"3  heuristicDiveCoefficient.setMaxTime(%d);\n",maxTime_);
     73    fprintf(fp,"3  heuristicDiveCoefficient.setMaxTime(%.2f);\n",maxTime_);
    6974  else
    70     fprintf(fp,"4  heuristicDiveCoefficient.setMaxTime(%d);\n",maxTime_);
     75    fprintf(fp,"4  heuristicDiveCoefficient.setMaxTime(%.2f);\n",maxTime_);
    7176  fprintf(fp,"3  cbcModel->addHeuristic(&heuristicDiveCoefficient);\n");
    7277}
     
    8287{
    8388  int numberIntegers = model_->numberIntegers();
    84   downLocks_ = CoinCopyOfArray(rhs.downLocks_,numberIntegers);
    85   upLocks_ = CoinCopyOfArray(rhs.upLocks_,numberIntegers);
     89  if (rhs.downLocks_) {
     90    int numberIntegers = model_->numberIntegers();
     91    downLocks_ = CoinCopyOfArray(rhs.downLocks_,numberIntegers);
     92    upLocks_ = CoinCopyOfArray(rhs.upLocks_,numberIntegers);
     93  } else {
     94    downLocks_ = NULL;
     95    upLocks_ = NULL;
     96  }
    8697}
    8798
     
    98109    delete [] downLocks_;
    99110    delete [] upLocks_;
    100     int numberIntegers = model_->numberIntegers();
    101     downLocks_ = CoinCopyOfArray(rhs.downLocks_,numberIntegers);
    102     upLocks_ = CoinCopyOfArray(rhs.upLocks_,numberIntegers);
     111    if (rhs.downLocks_) {
     112      int numberIntegers = model_->numberIntegers();
     113      downLocks_ = CoinCopyOfArray(rhs.downLocks_,numberIntegers);
     114      upLocks_ = CoinCopyOfArray(rhs.upLocks_,numberIntegers);
     115    } else {
     116      downLocks_ = NULL;
     117      upLocks_ = NULL;
     118    }
    103119  }
    104120  return *this;
     
    112128  // Get a copy of original matrix
    113129  assert(model_->solver());
    114   matrix_ = *model_->solver()->getMatrixByCol();
    115   validate();
     130  // model may have empty matrix - wait until setModel
     131  const CoinPackedMatrix * matrix = model_->solver()->getMatrixByCol();
     132  if (matrix) {
     133    matrix_ = *matrix;
     134    validate();
     135  }
    116136}
    117137
     
    165185  bool * fixedAtLowerBound = new bool [numberIntegers];
    166186
    167   const int maxNumberAtBoundToFix = floor(percentageToFix_ * numberIntegers);
     187  const int maxNumberAtBoundToFix = (int) floor(percentageToFix_ * numberIntegers);
    168188
    169189  // count how many fractional variables
     
    418438  // Get a copy of original matrix (and by row for rounding);
    419439  assert(model_->solver());
    420   matrix_ = *model_->solver()->getMatrixByCol();
    421   //  matrixByRow_ = *model_->solver()->getMatrixByRow();
    422   // make sure model okay for heuristic
    423   validate();
     440  const CoinPackedMatrix * matrix = model_->solver()->getMatrixByCol();
     441  if (matrix) {
     442    matrix_ = *matrix;
     443    // make sure model okay for heuristic
     444    validate();
     445  }
    424446}
    425447
     
    436458  int numberIntegers = model_->numberIntegers();
    437459  const int * integerVariable = model_->integerVariable();
     460  delete [] downLocks_;
     461  delete [] upLocks_;
    438462  downLocks_ = new unsigned short [numberIntegers];
    439463  upLocks_ = new unsigned short [numberIntegers];
Note: See TracChangeset for help on using the changeset viewer.