Skip to content

Commit

Permalink
Formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
jajhall committed Jan 24, 2025
1 parent e552c59 commit e3f0922
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 86 deletions.
84 changes: 49 additions & 35 deletions src/mip/HighsMipSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ HighsMipSolver::HighsMipSolver(HighsCallback& callback,
HighsMipSolver::~HighsMipSolver() = default;

void HighsMipSolver::run() {
const bool debug_logging = false;//true;
const bool debug_logging = false; // true;
modelstatus_ = HighsModelStatus::kNotset;

if (submip) {
Expand Down Expand Up @@ -234,9 +234,11 @@ void HighsMipSolver::run() {
int64_t num_nodes = mipdata_->nodequeue.numNodes();
if (num_nodes > 1) {
// Should be exactly one node on the queue?
if (debug_logging) printf(
"HighsMipSolver::run() popping node from nodequeue with %d > 1 nodes\n",
HighsInt(num_nodes));
if (debug_logging)
printf(
"HighsMipSolver::run() popping node from nodequeue with %d > 1 "
"nodes\n",
HighsInt(num_nodes));
assert(num_nodes == 1);
}

Expand Down Expand Up @@ -275,22 +277,23 @@ void HighsMipSolver::run() {
auto limitReached = [&]() -> bool {
bool limit_reached = false;
for (HighsInt iSearch = 0; iSearch < use_mip_concurrency; iSearch++) {
HighsSearch& search = iSearch == 0 ? master_search : worker_search;
limit_reached = limit_reached || search.limit_reached_;
HighsSearch& search = iSearch == 0 ? master_search : worker_search;
limit_reached = limit_reached || search.limit_reached_;
}
return limit_reached;
};

// Lambda checking whether lopp pass is to be skipped
auto performedDive = [&](const HighsSearch& search, const HighsInt iSearch) -> bool {
auto performedDive = [&](const HighsSearch& search,
const HighsInt iSearch) -> bool {
if (iSearch == 0) {
assert(search.performed_dive_);
assert(search.performed_dive_);
} else {
assert(!search.performed_dive_);
assert(!search.performed_dive_);
}
return search.performed_dive_;
};

// Perform concurrent dives
for (HighsInt iSearch = 0; iSearch < use_mip_concurrency; iSearch++) {
HighsSearch& search = iSearch == 0 ? master_search : worker_search;
Expand All @@ -310,7 +313,6 @@ void HighsMipSolver::run() {
analysis_.mipTimerStop(kMipClockOpenNodesToQueue);

search.flushStatistics();

}

for (HighsInt iSearch = 0; iSearch < use_mip_concurrency; iSearch++) {
Expand All @@ -329,7 +331,8 @@ void HighsMipSolver::run() {
prev_lower_bound, mipdata_->lower_bound, mipdata_->upper_bound,
mipdata_->upper_bound);
mipdata_->printDisplayLine();
if (debug_logging) printf("HighsMipSolver::run() break on limit_reached - 0\n");
if (debug_logging)
printf("HighsMipSolver::run() break on limit_reached - 0\n");
break;
}

Expand Down Expand Up @@ -361,7 +364,10 @@ void HighsMipSolver::run() {
prev_lower_bound, mipdata_->lower_bound, mipdata_->upper_bound,
mipdata_->upper_bound);
mipdata_->printDisplayLine();
if (debug_logging) printf("HighsMipSolver::run() break on mipdata_->domain.infeasible() - 0\n");
if (debug_logging)
printf(
"HighsMipSolver::run() break on mipdata_->domain.infeasible() - "
"0\n");
break;
}

Expand All @@ -376,8 +382,10 @@ void HighsMipSolver::run() {
mipdata_->upper_bound);
mipdata_->printDisplayLine();
if (mipdata_->nodequeue.empty()) {
if (debug_logging) printf("HighsMipSolver::run() break on mipdata_->nodequeue.empty()\n");
break;
if (debug_logging)
printf(
"HighsMipSolver::run() break on mipdata_->nodequeue.empty()\n");
break;
}

// if global propagation found bound changes, we update the local domain
Expand Down Expand Up @@ -479,7 +487,6 @@ void HighsMipSolver::run() {
// remove the iteration limit when installing a new node
// mipdata_->lp.setIterationLimit();


/*
} // HighsInt iSearch = 0...use_mip_concurrency
Expand All @@ -493,10 +500,6 @@ void HighsMipSolver::run() {
-analysis_.mipTimerRead(kMipClockNodeSearch);
analysis_.mipTimerStart(kMipClockNodeSearch);





while (!mipdata_->nodequeue.empty()) {
assert(!search.hasNode());

Expand All @@ -522,7 +525,10 @@ void HighsMipSolver::run() {
numStallNodes >= options_mip_->mip_max_stall_nodes) {
limit_reached = true;
modelstatus_ = HighsModelStatus::kSolutionLimit;
if (debug_logging) printf("HighsMipSolver::run() break on HighsModelStatus::kSolutionLimit\n");
if (debug_logging)
printf(
"HighsMipSolver::run() break on "
"HighsModelStatus::kSolutionLimit\n");
break;
}
} else
Expand Down Expand Up @@ -563,13 +569,17 @@ void HighsMipSolver::run() {
mipdata_->updatePrimalDualIntegral(
prev_lower_bound, mipdata_->lower_bound,
mipdata_->upper_bound, mipdata_->upper_bound);
if (debug_logging) printf("HighsMipSolver::run() break on mipdata_->domain.infeasible() - 1\n");
if (debug_logging)
printf(
"HighsMipSolver::run() break on "
"mipdata_->domain.infeasible() - 1\n");
break;
}

if (mipdata_->checkLimits()) {
limit_reached = true;
if (debug_logging) printf("HighsMipSolver::run() break on limit_reached - 1\n");
if (debug_logging)
printf("HighsMipSolver::run() break on limit_reached - 1\n");
break;
}

Expand Down Expand Up @@ -622,7 +632,10 @@ void HighsMipSolver::run() {
mipdata_->updatePrimalDualIntegral(
prev_lower_bound, mipdata_->lower_bound, mipdata_->upper_bound,
mipdata_->upper_bound);
if (debug_logging) printf("HighsMipSolver::run() break on mipdata_->domain.infeasible() - 2\n");
if (debug_logging)
printf(
"HighsMipSolver::run() break on mipdata_->domain.infeasible() "
"- 2\n");
break;
}

Expand All @@ -640,28 +653,29 @@ void HighsMipSolver::run() {
mipdata_->lp.setStoredBasis(basis);
}

if (debug_logging) printf("HighsMipSolver::run() break on completed node search\n");
if (debug_logging)
printf("HighsMipSolver::run() break on completed node search\n");
break;
} // while(!mipdata_->nodequeue.empty())
analysis_.mipTimerStop(kMipClockNodeSearch);
if (analysis_.analyse_mip_time) {
this_node_search_time += analysis_.mipTimerRead(kMipClockNodeSearch);
analysis_.node_search_time.push_back(this_node_search_time);
this_node_search_time += analysis_.mipTimerRead(kMipClockNodeSearch);
analysis_.node_search_time.push_back(this_node_search_time);
}
} // HighsInt iSearch = 0...use_mip_concurrency

} // HighsInt iSearch = 0...use_mip_concurrency

/*
for (HighsInt iSearch = 0; iSearch < use_mip_concurrency; iSearch++) {
HighsSearch& search = iSearch == 0 ? master_search : worker_search;
if (!performedDive(search, iSearch)) continue;
*/
limit_reached = limitReached();
if (limit_reached) {
if (debug_logging) printf("HighsMipSolver::run() break on limit_reached - 2\n");
break;
}
// } // HighsInt iSearch = 0...use_mip_concurrency
limit_reached = limitReached();
if (limit_reached) {
if (debug_logging)
printf("HighsMipSolver::run() break on limit_reached - 2\n");
break;
}
// } // HighsInt iSearch = 0...use_mip_concurrency
} // while(search.hasNode())
analysis_.mipTimerStop(kMipClockSearch);

Expand Down
102 changes: 51 additions & 51 deletions src/mip/HighsSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1965,9 +1965,10 @@ void HighsSearch::dive() {
// average nodes

HighsInt iterlimit = 10 * std::max(mipsolver.mipdata_->lp.getAvgSolveIters(),
mipsolver.mipdata_->avgrootlpiters);
iterlimit = std::max({HighsInt{10000}, iterlimit,
HighsInt((3 * mipsolver.mipdata_->firstrootlpiters) / 2)});
mipsolver.mipdata_->avgrootlpiters);
iterlimit =
std::max({HighsInt{10000}, iterlimit,
HighsInt((3 * mipsolver.mipdata_->firstrootlpiters) / 2)});

mipsolver.mipdata_->lp.setIterationLimit(iterlimit);

Expand All @@ -1979,94 +1980,93 @@ void HighsSearch::dive() {
// Possibly apply primal heuristics
if (considerHeuristics && mipsolver.mipdata_->moreHeuristicsAllowed()) {
analysis_.mipTimerStart(kMipClockEvaluateNode);
const HighsSearch::NodeResult evaluate_node_result =
this->evaluateNode();
const HighsSearch::NodeResult evaluate_node_result = this->evaluateNode();
analysis_.mipTimerStop(kMipClockEvaluateNode);

if (evaluate_node_result == HighsSearch::NodeResult::kSubOptimal) {
printf(
"HighsMipSolver::run() evaluate_node_result == "
"HighsSearch::NodeResult::kSubOptimal\n");
assert(345 == 678);
break;
printf(
"HighsMipSolver::run() evaluate_node_result == "
"HighsSearch::NodeResult::kSubOptimal\n");
assert(345 == 678);
break;
}

if (this->currentNodePruned()) {
++mipsolver.mipdata_->num_leaves;
this->flushStatistics();
++mipsolver.mipdata_->num_leaves;
this->flushStatistics();
} else {
analysis_.mipTimerStart(kMipClockPrimalHeuristics);
if (mipsolver.mipdata_->incumbent.empty()) {
analysis_.mipTimerStart(kMipClockRandomizedRounding0);
mipsolver.mipdata_->heuristics.randomizedRounding(
mipsolver.mipdata_->lp.getLpSolver().getSolution().col_value);
analysis_.mipTimerStop(kMipClockRandomizedRounding0);
}
if (mipsolver.mipdata_->incumbent.empty()) {
analysis_.mipTimerStart(kMipClockRens);
mipsolver.mipdata_->heuristics.RENS(
mipsolver.mipdata_->lp.getLpSolver().getSolution().col_value);
analysis_.mipTimerStop(kMipClockRens);
} else {
analysis_.mipTimerStart(kMipClockRins);
mipsolver.mipdata_->heuristics.RINS(
mipsolver.mipdata_->lp.getLpSolver().getSolution().col_value);
analysis_.mipTimerStop(kMipClockRins);
}
mipsolver.mipdata_->heuristics.flushStatistics();
analysis_.mipTimerStop(kMipClockPrimalHeuristics);
analysis_.mipTimerStart(kMipClockPrimalHeuristics);
if (mipsolver.mipdata_->incumbent.empty()) {
analysis_.mipTimerStart(kMipClockRandomizedRounding0);
mipsolver.mipdata_->heuristics.randomizedRounding(
mipsolver.mipdata_->lp.getLpSolver().getSolution().col_value);
analysis_.mipTimerStop(kMipClockRandomizedRounding0);
}

if (mipsolver.mipdata_->incumbent.empty()) {
analysis_.mipTimerStart(kMipClockRens);
mipsolver.mipdata_->heuristics.RENS(
mipsolver.mipdata_->lp.getLpSolver().getSolution().col_value);
analysis_.mipTimerStop(kMipClockRens);
} else {
analysis_.mipTimerStart(kMipClockRins);
mipsolver.mipdata_->heuristics.RINS(
mipsolver.mipdata_->lp.getLpSolver().getSolution().col_value);
analysis_.mipTimerStop(kMipClockRins);
}

mipsolver.mipdata_->heuristics.flushStatistics();
analysis_.mipTimerStop(kMipClockPrimalHeuristics);
}
}

considerHeuristics = false;

if (mipsolver.mipdata_->domain.infeasible()) break;

if (!this->currentNodePruned()) {
double this_dive_time = -analysis_.mipTimerRead(kMipClockTheDive);
analysis_.mipTimerStart(kMipClockTheDive);
const HighsSearch::NodeResult search_dive_result = this->theDive();
analysis_.mipTimerStop(kMipClockTheDive);
if (analysis_.analyse_mip_time) {
this_dive_time += analysis_.mipTimerRead(kMipClockTheDive);
analysis_.dive_time.push_back(this_dive_time);
this_dive_time += analysis_.mipTimerRead(kMipClockTheDive);
analysis_.dive_time.push_back(this_dive_time);
}
if (search_dive_result == HighsSearch::NodeResult::kSubOptimal) break;

++mipsolver.mipdata_->num_leaves;

this->flushStatistics();
}

if (mipsolver.mipdata_->checkLimits()) {
limit_reached_ = true;
break;
}

HighsInt numPlungeNodes = mipsolver.mipdata_->num_nodes - plungestart;
if (numPlungeNodes >= 100) break;

analysis_.mipTimerStart(kMipClockBacktrackPlunge);
const bool backtrack_plunge =
this->backtrackPlunge(mipsolver.mipdata_->nodequeue);
this->backtrackPlunge(mipsolver.mipdata_->nodequeue);
analysis_.mipTimerStop(kMipClockBacktrackPlunge);
if (!backtrack_plunge) break;

assert(this->hasNode());

if (mipsolver.mipdata_->conflictPool.getNumConflicts() >
options_mip_->mip_pool_soft_limit) {
options_mip_->mip_pool_soft_limit) {
analysis_.mipTimerStart(kMipClockPerformAging2);
mipsolver.mipdata_->conflictPool.performAging();
analysis_.mipTimerStop(kMipClockPerformAging2);
}

this->flushStatistics();
mipsolver.mipdata_->printDisplayLine();
// printf("continue plunging due to good estimate\n");
}
}
analysis_.mipTimerStop(kMipClockDive);
}

Expand Down

0 comments on commit e3f0922

Please sign in to comment.