Skip to content

Commit

Permalink
deal with some tolerance issues in CbcDive
Browse files Browse the repository at this point in the history
  • Loading branch information
jjhforrest committed Jul 22, 2024
1 parent 72fa111 commit 1322a91
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/CbcHeuristicDive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,15 @@ int CbcHeuristicDive::solution(double &solutionValue, int &numberNodes,
back[iColumn] = i;
double value = newSolution[iColumn];
// clean
if (value<lower[iColumn]) {
value = lower[iColumn];
newSolution[iColumn] = value;
solver->setColUpper(iColumn,value);
} else if (value>upper[iColumn]) {
value = upper[iColumn];
newSolution[iColumn] = value;
solver->setColLower(iColumn,value);
}
value = CoinMin(value, upperBefore[iColumn]);
value = CoinMax(value, lowerBefore[iColumn]);
newSolution[iColumn] = value;
Expand Down Expand Up @@ -434,6 +443,9 @@ int CbcHeuristicDive::solution(double &solutionValue, int &numberNodes,
if (!isHeuristicInteger(solver, iColumn))
continue;
double value = newSolution[iColumn];
// deal with tolerance problems
if (value<lower[iColumn] || value>upper[iColumn])
continue;
if (fabs(floor(value + 0.5) - value) > integerTolerance) {
assert(downLocks_[i] == 0 || upLocks_[i] == 0);
double obj = objective[iColumn];
Expand All @@ -459,6 +471,16 @@ int CbcHeuristicDive::solution(double &solutionValue, int &numberNodes,
if (!isHeuristicInteger(solver, iColumn))
continue;
double value = newSolution[iColumn];
// clean
if (value<lower[iColumn]) {
value = lower[iColumn];
newSolution[iColumn] = value;
solver->setColUpper(iColumn,value);
} else if (value>upper[iColumn]) {
value = upper[iColumn];
newSolution[iColumn] = value;
solver->setColLower(iColumn,value);
}
if (fabs(floor(value + 0.5) - value) > integerTolerance) {
assert(downLocks_[i] == 0 || upLocks_[i] == 0);
if (downLocks_[i] == 0 && upLocks_[i] == 0) {
Expand Down
5 changes: 5 additions & 0 deletions src/CbcHeuristicDiveCoefficient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ bool CbcHeuristicDiveCoefficient::selectVariableToBranch(OsiSolverInterface *sol
int numberIntegers = model_->numberIntegers();
const int *integerVariable = model_->integerVariable();
double integerTolerance = model_->getDblParam(CbcModel::CbcIntegerTolerance);
const double * lower = solver->getColLower();
const double * upper = solver->getColUpper();

bestColumn = -1;
bestRound = -1; // -1 rounds down, +1 rounds up
Expand All @@ -84,6 +86,9 @@ bool CbcHeuristicDiveCoefficient::selectVariableToBranch(OsiSolverInterface *sol
if (!isHeuristicInteger(solver, iColumn))
continue;
double value = newSolution[iColumn];
// deal with tolerance problems
if (value<lower[iColumn] || value>upper[iColumn])
continue;
double fraction = value - floor(value);
int round = 0;
if (fabs(floor(value + 0.5) - value) > integerTolerance) {
Expand Down

0 comments on commit 1322a91

Please sign in to comment.