Changeset 871 for trunk/Cbc/src/CbcHeuristicDiveFractional.cpp
 Timestamp:
 Feb 13, 2008 3:52:57 PM (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/Cbc/src/CbcHeuristicDiveFractional.cpp
r868 r871 26 26 :CbcHeuristic(model) 27 27 { 28 downLocks_ =NULL; 29 upLocks_ = NULL; 28 30 // Get a copy of original matrix 29 31 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 } 32 37 percentageToFix_ = 0.2; 33 38 maxIterations_ = 100; … … 58 63 CbcHeuristic::generateCpp(fp,"heuristicDiveFractional"); 59 64 if (percentageToFix_!=other.percentageToFix_) 60 fprintf(fp,"3 heuristicDiveFractional.setPercentageToFix(% d);\n",percentageToFix_);65 fprintf(fp,"3 heuristicDiveFractional.setPercentageToFix(%.f);\n",percentageToFix_); 61 66 else 62 fprintf(fp,"4 heuristicDiveFractional.setPercentageToFix(% d);\n",percentageToFix_);67 fprintf(fp,"4 heuristicDiveFractional.setPercentageToFix(%.f);\n",percentageToFix_); 63 68 if (maxIterations_!=other.maxIterations_) 64 69 fprintf(fp,"3 heuristicDiveFractional.setMaxIterations(%d);\n",maxIterations_); … … 66 71 fprintf(fp,"4 heuristicDiveFractional.setMaxIterations(%d);\n",maxIterations_); 67 72 if (maxTime_!=other.maxTime_) 68 fprintf(fp,"3 heuristicDiveFractional.setMaxTime(% d);\n",maxTime_);73 fprintf(fp,"3 heuristicDiveFractional.setMaxTime(%.2f);\n",maxTime_); 69 74 else 70 fprintf(fp,"4 heuristicDiveFractional.setMaxTime(% d);\n",maxTime_);75 fprintf(fp,"4 heuristicDiveFractional.setMaxTime(%.2f);\n",maxTime_); 71 76 fprintf(fp,"3 cbcModel>addHeuristic(&heuristicDiveFractional);\n"); 72 77 } … … 82 87 { 83 88 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 } 86 97 } 87 98 … … 98 109 delete [] downLocks_; 99 110 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 } 103 119 } 104 120 return *this; … … 112 128 // Get a copy of original matrix 113 129 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 } 116 136 } 117 137 … … 165 185 bool * fixedAtLowerBound = new bool [numberIntegers]; 166 186 167 const int maxNumberAtBoundToFix = floor(percentageToFix_ * numberIntegers);187 const int maxNumberAtBoundToFix = (int) floor(percentageToFix_ * numberIntegers); 168 188 169 189 // count how many fractional variables … … 404 424 // Get a copy of original matrix (and by row for rounding); 405 425 assert(model_>solver()); 406 matrix_ = *model_>solver()>getMatrixByCol(); 407 // matrixByRow_ = *model_>solver()>getMatrixByRow(); 408 // make sure model okay for heuristic 409 validate(); 426 const CoinPackedMatrix * matrix = model_>solver()>getMatrixByCol(); 427 if (matrix) { 428 matrix_ = *matrix; 429 // make sure model okay for heuristic 430 validate(); 431 } 410 432 } 411 433 … … 422 444 int numberIntegers = model_>numberIntegers(); 423 445 const int * integerVariable = model_>integerVariable(); 446 delete [] downLocks_; 447 delete [] upLocks_; 424 448 downLocks_ = new unsigned short [numberIntegers]; 425 449 upLocks_ = new unsigned short [numberIntegers];
Note: See TracChangeset
for help on using the changeset viewer.