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/CbcHeuristicDiveVectorLength.cpp

    r868 r871  
    2828  // Get a copy of original matrix
    2929  assert(model.solver());
    30   matrix_ = *model.solver()->getMatrixByCol();
    31   validate();
     30  downLocks_ =NULL;
     31  upLocks_ = NULL;
     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,"heuristicDiveVectorLength");
    5964  if (percentageToFix_!=other.percentageToFix_)
    60     fprintf(fp,"3  heuristicDiveVectorLength.setPercentageToFix(%d);\n",percentageToFix_);
     65    fprintf(fp,"3  heuristicDiveVectorLength.setPercentageToFix(%.2f);\n",percentageToFix_);
    6166  else
    62     fprintf(fp,"4  heuristicDiveVectorLength.setPercentageToFix(%d);\n",percentageToFix_);
     67    fprintf(fp,"4  heuristicDiveVectorLength.setPercentageToFix(%.2f);\n",percentageToFix_);
    6368  if (maxIterations_!=other.maxIterations_)
    6469    fprintf(fp,"3  heuristicDiveVectorLength.setMaxIterations(%d);\n",maxIterations_);
     
    6671    fprintf(fp,"4  heuristicDiveVectorLength.setMaxIterations(%d);\n",maxIterations_);
    6772  if (maxTime_!=other.maxTime_)
    68     fprintf(fp,"3  heuristicDiveVectorLength.setMaxTime(%d);\n",maxTime_);
     73    fprintf(fp,"3  heuristicDiveVectorLength.setMaxTime(%.2f);\n",maxTime_);
    6974  else
    70     fprintf(fp,"4  heuristicDiveVectorLength.setMaxTime(%d);\n",maxTime_);
     75    fprintf(fp,"4  heuristicDiveVectorLength.setMaxTime(%.2f);\n",maxTime_);
    7176  fprintf(fp,"3  cbcModel->addHeuristic(&heuristicDiveVectorLength);\n");
    7277}
     
    8186  maxTime_(rhs.maxTime_)
    8287{
    83   int numberIntegers = model_->numberIntegers();
    84   downLocks_ = CoinCopyOfArray(rhs.downLocks_,numberIntegers);
    85   upLocks_ = CoinCopyOfArray(rhs.upLocks_,numberIntegers);
     88  if (rhs.downLocks_) {
     89    int numberIntegers = model_->numberIntegers();
     90    downLocks_ = CoinCopyOfArray(rhs.downLocks_,numberIntegers);
     91    upLocks_ = CoinCopyOfArray(rhs.upLocks_,numberIntegers);
     92  } else {
     93    downLocks_ = NULL;
     94    upLocks_ = NULL;
     95  }
    8696}
    8797
     
    99109    delete [] upLocks_;
    100110    int numberIntegers = model_->numberIntegers();
    101     downLocks_ = CoinCopyOfArray(rhs.downLocks_,numberIntegers);
    102     upLocks_ = CoinCopyOfArray(rhs.upLocks_,numberIntegers);
     111    if (rhs.downLocks_) {
     112      downLocks_ = CoinCopyOfArray(rhs.downLocks_,numberIntegers);
     113      upLocks_ = CoinCopyOfArray(rhs.upLocks_,numberIntegers);
     114    } else {
     115      downLocks_ = NULL;
     116      upLocks_ = NULL;
     117    }
    103118  }
    104119  return *this;
     
    112127  // Get a copy of original matrix
    113128  assert(model_->solver());
    114   matrix_ = *model_->solver()->getMatrixByCol();
    115   validate();
     129  // model may have empty matrix - wait until setModel
     130  const CoinPackedMatrix * matrix = model_->solver()->getMatrixByCol();
     131  if (matrix) {
     132    matrix_ = *matrix;
     133    validate();
     134  }
    116135}
    117136
     
    165184  bool * fixedAtLowerBound = new bool [numberIntegers];
    166185
    167   const int maxNumberAtBoundToFix = floor(percentageToFix_ * numberIntegers);
     186  const int maxNumberAtBoundToFix = (int) floor(percentageToFix_ * numberIntegers);
    168187
    169188  // count how many fractional variables
     
    411430  // Get a copy of original matrix (and by row for rounding);
    412431  assert(model_->solver());
    413   matrix_ = *model_->solver()->getMatrixByCol();
    414   //  matrixByRow_ = *model_->solver()->getMatrixByRow();
    415   // make sure model okay for heuristic
    416   validate();
     432  const CoinPackedMatrix * matrix = model_->solver()->getMatrixByCol();
     433  if (matrix) {
     434    matrix_ = *matrix;
     435    // make sure model okay for heuristic
     436    validate();
     437  }
    417438}
    418439
     
    429450  int numberIntegers = model_->numberIntegers();
    430451  const int * integerVariable = model_->integerVariable();
     452  delete [] downLocks_;
     453  delete [] upLocks_;
    431454  downLocks_ = new unsigned short [numberIntegers];
    432455  upLocks_ = new unsigned short [numberIntegers];
Note: See TracChangeset for help on using the changeset viewer.