Skip to content

Commit

Permalink
Corrected updatePrimaDualIntegral to updatePrimalDualIntegral; formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
jajhall committed Nov 6, 2024
1 parent ed08ba1 commit 38b7dcf
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 54 deletions.
3 changes: 1 addition & 2 deletions src/lp_data/Highs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4543,8 +4543,7 @@ void Highs::reportSolvedLpQpStats() {
std::fabs(info_.objective_function_value - dual_objective_value) /
std::max(1.0, std::fabs(info_.objective_function_value));
highsLogUser(log_options, HighsLogType::kInfo,
"Relative P-D gap : %17.10e\n",
relative_primal_dual_gap);
"Relative P-D gap : %17.10e\n", relative_primal_dual_gap);
}
double run_time = timer_.readRunHighsClock();
highsLogUser(log_options, HighsLogType::kInfo,
Expand Down
24 changes: 12 additions & 12 deletions src/mip/HighsMipSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ void HighsMipSolver::run() {

bool bound_change = mipdata_->lower_bound != prev_lower_bound;
if (!submip && bound_change)
mipdata_->updatePrimaDualIntegral(prev_lower_bound, mipdata_->lower_bound,
mipdata_->upper_bound,
mipdata_->upper_bound);
mipdata_->updatePrimalDualIntegral(prev_lower_bound, mipdata_->lower_bound,
mipdata_->upper_bound,
mipdata_->upper_bound);

mipdata_->printDisplayLine();
search.installNode(mipdata_->nodequeue.popBestBoundNode());
Expand Down Expand Up @@ -352,7 +352,7 @@ void HighsMipSolver::run() {

bool bound_change = mipdata_->lower_bound != prev_lower_bound;
if (!submip && bound_change)
mipdata_->updatePrimaDualIntegral(
mipdata_->updatePrimalDualIntegral(
prev_lower_bound, mipdata_->lower_bound, mipdata_->upper_bound,
mipdata_->upper_bound);
mipdata_->printDisplayLine();
Expand Down Expand Up @@ -383,7 +383,7 @@ void HighsMipSolver::run() {

bool bound_change = mipdata_->lower_bound != prev_lower_bound;
if (!submip && bound_change)
mipdata_->updatePrimaDualIntegral(
mipdata_->updatePrimalDualIntegral(
prev_lower_bound, mipdata_->lower_bound, mipdata_->upper_bound,
mipdata_->upper_bound);
mipdata_->printDisplayLine();
Expand All @@ -396,9 +396,9 @@ void HighsMipSolver::run() {
mipdata_->nodequeue.getBestLowerBound());
bool bound_change = mipdata_->lower_bound != prev_lower_bound;
if (!submip && bound_change)
mipdata_->updatePrimaDualIntegral(prev_lower_bound, mipdata_->lower_bound,
mipdata_->upper_bound,
mipdata_->upper_bound);
mipdata_->updatePrimalDualIntegral(
prev_lower_bound, mipdata_->lower_bound, mipdata_->upper_bound,
mipdata_->upper_bound);
mipdata_->printDisplayLine();
if (mipdata_->nodequeue.empty()) break;

Expand Down Expand Up @@ -566,7 +566,7 @@ void HighsMipSolver::run() {

bool bound_change = mipdata_->lower_bound != prev_lower_bound;
if (!submip && bound_change)
mipdata_->updatePrimaDualIntegral(
mipdata_->updatePrimalDualIntegral(
prev_lower_bound, mipdata_->lower_bound, mipdata_->upper_bound,
mipdata_->upper_bound);
break;
Expand All @@ -584,7 +584,7 @@ void HighsMipSolver::run() {

bool bound_change = mipdata_->lower_bound != prev_lower_bound;
if (!submip && bound_change)
mipdata_->updatePrimaDualIntegral(
mipdata_->updatePrimalDualIntegral(
prev_lower_bound, mipdata_->lower_bound, mipdata_->upper_bound,
mipdata_->upper_bound);
mipdata_->printDisplayLine();
Expand Down Expand Up @@ -623,7 +623,7 @@ void HighsMipSolver::run() {

bool bound_change = mipdata_->lower_bound != prev_lower_bound;
if (!submip && bound_change)
mipdata_->updatePrimaDualIntegral(
mipdata_->updatePrimalDualIntegral(
prev_lower_bound, mipdata_->lower_bound, mipdata_->upper_bound,
mipdata_->upper_bound);
break;
Expand Down Expand Up @@ -664,7 +664,7 @@ void HighsMipSolver::cleanupSolve() {

// Need to complete the calculation of P-D integral, checking for NO
// gap change
mipdata_->updatePrimaDualIntegral(
mipdata_->updatePrimalDualIntegral(
mipdata_->lower_bound, mipdata_->lower_bound, mipdata_->upper_bound,
mipdata_->upper_bound, false);
analysis_.mipTimerStart(kMipClockPostsolve);
Expand Down
65 changes: 32 additions & 33 deletions src/mip/HighsMipSolverData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,8 @@ void HighsMipSolverData::runSetup() {

bool bound_change = upper_bound != prev_upper_bound;
if (!mipsolver.submip && bound_change)
updatePrimaDualIntegral(lower_bound, lower_bound, prev_upper_bound,
upper_bound);
updatePrimalDualIntegral(lower_bound, lower_bound, prev_upper_bound,
upper_bound);

double new_upper_limit = computeNewUpperLimit(solobj, 0.0, 0.0);
saveReportMipSolution(new_upper_limit);
Expand Down Expand Up @@ -672,8 +672,8 @@ void HighsMipSolverData::runSetup() {

bool bound_change = lower_bound != prev_lower_bound;
if (!mipsolver.submip && bound_change)
updatePrimaDualIntegral(prev_lower_bound, lower_bound, upper_bound,
upper_bound);
updatePrimalDualIntegral(prev_lower_bound, lower_bound, upper_bound,
upper_bound);

pruned_treeweight = 1.0;
return;
Expand Down Expand Up @@ -725,8 +725,8 @@ void HighsMipSolverData::runSetup() {

bool bound_change = lower_bound != prev_lower_bound;
if (!mipsolver.submip && bound_change)
updatePrimaDualIntegral(prev_lower_bound, lower_bound,
upper_bound, upper_bound);
updatePrimalDualIntegral(prev_lower_bound, lower_bound,
upper_bound, upper_bound);

pruned_treeweight = 1.0;
return;
Expand Down Expand Up @@ -1180,20 +1180,20 @@ void HighsMipSolverData::performRestart() {
// lower_bound still relates to the original model, and the offset
// is never applied, since MIP solving is complete, and
// lower_bound is set to upper_bound, so apply the offset now, so
// that housekeeping in updatePrimaDualIntegral is correct
// that housekeeping in updatePrimalDualIntegral is correct
double prev_lower_bound = lower_bound - mipsolver.model_->offset_;

lower_bound = upper_bound;

// There must be a gap change, since it's now zero, so always call
// updatePrimaDualIntegral (unless solving a sub-MIP)
// updatePrimalDualIntegral (unless solving a sub-MIP)
//
// Surely there must be a lower bound change
bool bound_change = lower_bound != prev_lower_bound;
assert(bound_change);
if (!mipsolver.submip && bound_change)
updatePrimaDualIntegral(prev_lower_bound, lower_bound, upper_bound,
upper_bound);
updatePrimalDualIntegral(prev_lower_bound, lower_bound, upper_bound,
upper_bound);
if (mipsolver.solution_objective_ != kHighsInf &&
mipsolver.modelstatus_ == HighsModelStatus::kInfeasible)
mipsolver.modelstatus_ = HighsModelStatus::kOptimal;
Expand Down Expand Up @@ -1277,8 +1277,8 @@ bool HighsMipSolverData::addIncumbent(const std::vector<double>& sol,

bool bound_change = upper_bound != prev_upper_bound;
if (!mipsolver.submip && bound_change)
updatePrimaDualIntegral(lower_bound, lower_bound, prev_upper_bound,
upper_bound);
updatePrimalDualIntegral(lower_bound, lower_bound, prev_upper_bound,
upper_bound);

incumbent = sol;
double new_upper_limit = computeNewUpperLimit(solobj, 0.0, 0.0);
Expand Down Expand Up @@ -1468,8 +1468,7 @@ void HighsMipSolverData::printDisplayLine(const int solution_source) {

double lb;
double ub;
const double gap =
1e2 * gapFromBounds(lower_bound, upper_bound, lb, ub);
const double gap = 1e2 * gapFromBounds(lower_bound, upper_bound, lb, ub);
if (mipsolver.options_mip_->objective_bound < ub)
ub = mipsolver.options_mip_->objective_bound;

Expand Down Expand Up @@ -1579,8 +1578,8 @@ HighsLpRelaxation::Status HighsMipSolverData::evaluateRootLp() {

bool bound_change = lower_bound != prev_lower_bound;
if (!mipsolver.submip && bound_change)
updatePrimaDualIntegral(prev_lower_bound, lower_bound, upper_bound,
upper_bound);
updatePrimalDualIntegral(prev_lower_bound, lower_bound, upper_bound,
upper_bound);
pruned_treeweight = 1.0;
num_nodes += 1;
num_leaves += 1;
Expand Down Expand Up @@ -1629,8 +1628,8 @@ HighsLpRelaxation::Status HighsMipSolverData::evaluateRootLp() {

bool bound_change = lower_bound != prev_lower_bound;
if (!mipsolver.submip && bound_change)
updatePrimaDualIntegral(prev_lower_bound, lower_bound, upper_bound,
upper_bound);
updatePrimalDualIntegral(prev_lower_bound, lower_bound, upper_bound,
upper_bound);
pruned_treeweight = 1.0;
num_nodes += 1;
num_leaves += 1;
Expand All @@ -1646,8 +1645,8 @@ HighsLpRelaxation::Status HighsMipSolverData::evaluateRootLp() {

bool bound_change = lower_bound != prev_lower_bound;
if (!mipsolver.submip && bound_change)
updatePrimaDualIntegral(prev_lower_bound, lower_bound, upper_bound,
upper_bound);
updatePrimalDualIntegral(prev_lower_bound, lower_bound, upper_bound,
upper_bound);
pruned_treeweight = 1.0;
num_nodes += 1;
num_leaves += 1;
Expand All @@ -1661,8 +1660,8 @@ HighsLpRelaxation::Status HighsMipSolverData::evaluateRootLp() {

bool bound_change = lower_bound != prev_lower_bound;
if (!mipsolver.submip && bound_change)
updatePrimaDualIntegral(prev_lower_bound, lower_bound, upper_bound,
upper_bound);
updatePrimalDualIntegral(prev_lower_bound, lower_bound, upper_bound,
upper_bound);

if (lpWasSolved) {
redcostfixing.addRootRedcost(mipsolver,
Expand Down Expand Up @@ -1721,8 +1720,8 @@ void HighsMipSolverData::evaluateRootNode() {

bool bound_change = lower_bound != prev_lower_bound;
if (!mipsolver.submip && bound_change)
updatePrimaDualIntegral(prev_lower_bound, lower_bound, upper_bound,
upper_bound);
updatePrimalDualIntegral(prev_lower_bound, lower_bound, upper_bound,
upper_bound);

printDisplayLine();

Expand Down Expand Up @@ -2375,16 +2374,16 @@ double possInfRelDiff(const double v0, const double v1, const double den) {
return rel_diff;
}

void HighsMipSolverData::updatePrimaDualIntegral(const double from_lower_bound,
const double to_lower_bound,
const double from_upper_bound,
const double to_upper_bound,
const bool check_bound_change,
const bool check_prev_data) {
// Parameters to updatePrimaDualIntegral are lower and upper bounds
void HighsMipSolverData::updatePrimalDualIntegral(const double from_lower_bound,
const double to_lower_bound,
const double from_upper_bound,
const double to_upper_bound,
const bool check_bound_change,
const bool check_prev_data) {
// Parameters to updatePrimalDualIntegral are lower and upper bounds
// before/after a change
//
// updatePrimaDualIntegral should only be called when there is a
// updatePrimalDualIntegral should only be called when there is a
// change in one of the bounds, except when the final update is
// made, in which case the bounds must NOT have changed. By default,
// a check for some bound change is made, unless check_bound_change
Expand Down Expand Up @@ -2446,7 +2445,7 @@ void HighsMipSolverData::updatePrimaDualIntegral(const double from_lower_bound,
}
}
if (pdi.value > -kHighsInf) {
// updatePrimaDualIntegral has been called previously, so can
// updatePrimalDualIntegral has been called previously, so can
// usually test housekeeping, even if gap is still inf
//
// The one case where the checking can't be done comes after restart, where
Expand Down
12 changes: 6 additions & 6 deletions src/mip/HighsMipSolverData.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,12 @@ struct HighsMipSolverData {
void finishSymmetryDetection(const highs::parallel::TaskGroup& taskGroup,
std::unique_ptr<SymmetryDetectionData>& symData);

void updatePrimaDualIntegral(const double from_lower_bound,
const double to_lower_bound,
const double from_upper_bound,
const double to_upper_bound,
const bool check_bound_change = true,
const bool check_prev_data = true);
void updatePrimalDualIntegral(const double from_lower_bound,
const double to_lower_bound,
const double from_upper_bound,
const double to_upper_bound,
const bool check_bound_change = true,
const bool check_prev_data = true);
double gapFromBounds(const double use_lower_bound,
const double use_upper_bound, double& lb, double& ub);

Expand Down
2 changes: 1 addition & 1 deletion src/mip/HighsPrimalHeuristics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ void HighsPrimalHeuristics::rootReducedCost() {
const bool bound_change =
mipsolver.mipdata_->lower_bound != prev_lower_bound;
if (!mipsolver.submip && bound_change)
mipsolver.mipdata_->updatePrimaDualIntegral(
mipsolver.mipdata_->updatePrimalDualIntegral(
prev_lower_bound, mipsolver.mipdata_->lower_bound,
mipsolver.mipdata_->upper_bound, mipsolver.mipdata_->upper_bound);
localdom.backtrack();
Expand Down

0 comments on commit 38b7dcf

Please sign in to comment.