From 38b7dcf847405cf79987e1efd18545336e649c3c Mon Sep 17 00:00:00 2001 From: JAJHall Date: Wed, 6 Nov 2024 12:28:35 +0000 Subject: [PATCH] Corrected updatePrimaDualIntegral to updatePrimalDualIntegral; formatted --- src/lp_data/Highs.cpp | 3 +- src/mip/HighsMipSolver.cpp | 24 ++++++------ src/mip/HighsMipSolverData.cpp | 65 +++++++++++++++---------------- src/mip/HighsMipSolverData.h | 12 +++--- src/mip/HighsPrimalHeuristics.cpp | 2 +- 5 files changed, 52 insertions(+), 54 deletions(-) diff --git a/src/lp_data/Highs.cpp b/src/lp_data/Highs.cpp index 958ee22eca..823bff0047 100644 --- a/src/lp_data/Highs.cpp +++ b/src/lp_data/Highs.cpp @@ -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, diff --git a/src/mip/HighsMipSolver.cpp b/src/mip/HighsMipSolver.cpp index 48627099b4..25680c407f 100644 --- a/src/mip/HighsMipSolver.cpp +++ b/src/mip/HighsMipSolver.cpp @@ -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()); @@ -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(); @@ -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(); @@ -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; @@ -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; @@ -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(); @@ -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; @@ -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); diff --git a/src/mip/HighsMipSolverData.cpp b/src/mip/HighsMipSolverData.cpp index a0b1b05250..e6057a6b32 100644 --- a/src/mip/HighsMipSolverData.cpp +++ b/src/mip/HighsMipSolverData.cpp @@ -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); @@ -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; @@ -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; @@ -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; @@ -1277,8 +1277,8 @@ bool HighsMipSolverData::addIncumbent(const std::vector& 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); @@ -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; @@ -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; @@ -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; @@ -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; @@ -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, @@ -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(); @@ -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 @@ -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 diff --git a/src/mip/HighsMipSolverData.h b/src/mip/HighsMipSolverData.h index 6d16540426..82b141bbea 100644 --- a/src/mip/HighsMipSolverData.h +++ b/src/mip/HighsMipSolverData.h @@ -226,12 +226,12 @@ struct HighsMipSolverData { void finishSymmetryDetection(const highs::parallel::TaskGroup& taskGroup, std::unique_ptr& 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); diff --git a/src/mip/HighsPrimalHeuristics.cpp b/src/mip/HighsPrimalHeuristics.cpp index f9c17ae7d8..5908f4373c 100644 --- a/src/mip/HighsPrimalHeuristics.cpp +++ b/src/mip/HighsPrimalHeuristics.cpp @@ -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();