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/CbcHeuristicDiveGuided.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,"heuristicDiveGuided");
    5964  if (percentageToFix_!=other.percentageToFix_)
    60     fprintf(fp,"3  heuristicDiveGuided.setPercentageToFix(%d);\n",percentageToFix_);
     65    fprintf(fp,"3  heuristicDiveGuided.setPercentageToFix(%.2f);\n",percentageToFix_);
    6166  else
    62     fprintf(fp,"4  heuristicDiveGuided.setPercentageToFix(%d);\n",percentageToFix_);
     67    fprintf(fp,"4  heuristicDiveGuided.setPercentageToFix(%.2f);\n",percentageToFix_);
    6368  if (maxIterations_!=other.maxIterations_)
    6469    fprintf(fp,"3  heuristicDiveGuided.setMaxIterations(%d);\n",maxIterations_);
     
    6671    fprintf(fp,"4  heuristicDiveGuided.setMaxIterations(%d);\n",maxIterations_);
    6772  if (maxTime_!=other.maxTime_)
    68     fprintf(fp,"3  heuristicDiveGuided.setMaxTime(%d);\n",maxTime_);
     73    fprintf(fp,"3  heuristicDiveGuided.setMaxTime(%.2f);\n",maxTime_);
    6974  else
    70     fprintf(fp,"4  heuristicDiveGuided.setMaxTime(%d);\n",maxTime_);
     75    fprintf(fp,"4  heuristicDiveGuided.setMaxTime(%.2f);\n",maxTime_);
    7176  fprintf(fp,"3  cbcModel->addHeuristic(&heuristicDiveGuided);\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
     
    169189  bool * fixedAtLowerBound = new bool [numberIntegers];
    170190
    171   const int maxNumberAtBoundToFix = floor(percentageToFix_ * numberIntegers);
     191  const int maxNumberAtBoundToFix = (int) floor(percentageToFix_ * numberIntegers);
    172192
    173193  // count how many fractional variables
     
    408428  // Get a copy of original matrix (and by row for rounding);
    409429  assert(model_->solver());
    410   matrix_ = *model_->solver()->getMatrixByCol();
    411   //  matrixByRow_ = *model_->solver()->getMatrixByRow();
    412   // make sure model okay for heuristic
    413   validate();
     430  const CoinPackedMatrix * matrix = model_->solver()->getMatrixByCol();
     431  if (matrix) {
     432    matrix_ = *matrix;
     433    // make sure model okay for heuristic
     434    validate();
     435  }
    414436}
    415437
     
    426448  int numberIntegers = model_->numberIntegers();
    427449  const int * integerVariable = model_->integerVariable();
     450  delete [] downLocks_;
     451  delete [] upLocks_;
    428452  downLocks_ = new unsigned short [numberIntegers];
    429453  upLocks_ = new unsigned short [numberIntegers];
Note: See TracChangeset for help on using the changeset viewer.