Skip to content

Commit

Permalink
trying to init mipworker deque
Browse files Browse the repository at this point in the history
  • Loading branch information
galabovaa committed Feb 20, 2025
1 parent bc04e0c commit 3caa540
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 98 deletions.
28 changes: 22 additions & 6 deletions src/mip/HighsMipSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ void HighsMipSolver::run() {
mipdata_ = decltype(mipdata_)(new HighsMipSolverData(*this));
analysis_.mipTimerStart(kMipClockPresolve);
analysis_.mipTimerStart(kMipClockInit);

mipdata_->init();

analysis_.mipTimerStop(kMipClockInit);
analysis_.mipTimerStart(kMipClockRunPresolve);
mipdata_->runPresolve(options_mip_->presolve_reduction_limit);
Expand Down Expand Up @@ -158,11 +160,24 @@ void HighsMipSolver::run() {
highsLogUser(options_mip_->log_options, HighsLogType::kInfo,
"MIP-Timing: %11.2g - starting setup\n", timer_.read());
analysis_.mipTimerStart(kMipClockRunSetup);

mipdata_->runSetup();

analysis_.mipTimerStop(kMipClockRunSetup);
if (analysis_.analyse_mip_time && !submip)
highsLogUser(options_mip_->log_options, HighsLogType::kInfo,
"MIP-Timing: %11.2g - completed setup\n", timer_.read());

// Initialize master worker.
HighsMipWorker master_worker(*this, mipdata_->lp);

// mipdata_->lps.push_back(mipdata_->lp);
// mipdata_->workers.push_back(HighsMipWorker(*this, mipdata_->lps.back()));

// mipdata_->workers.emplace(mipdata_->workers.end(), HighsMipWorker(*this, mipdata_->lps.back()));

// HighsMipWorker& master_worker = mipdata_->workers.at(0);

restart:
if (modelstatus_ == HighsModelStatus::kNotset) {
// Check limits have not been reached before evaluating root node
Expand All @@ -186,7 +201,9 @@ void HighsMipSolver::run() {
"MIP-Timing: %11.2g - starting evaluate root node\n",
timer_.read());
analysis_.mipTimerStart(kMipClockEvaluateRootNode);
mipdata_->evaluateRootNode();

mipdata_->evaluateRootNode(master_worker);

analysis_.mipTimerStop(kMipClockEvaluateRootNode);
// Sometimes the analytic centre calculation is not completed when
// evaluateRootNode returns, so stop its clock if it's running
Expand Down Expand Up @@ -224,12 +241,11 @@ void HighsMipSolver::run() {
// HighsMipWorker master_worker(*this, mipdata_->lp);
// HighsSearch& search = *master_worker.search_ptr_.get();


HighsMipWorker master_worker(*this, mipdata_->lp);
HighsSearch search{master_worker, mipdata_->pseudocost};

mipdata_->debugSolution.registerDomain(search.getLocalDomain());
HighsSeparation sepa(*this);
// HighsSeparation sepa(*this);
HighsSeparation sepa(master_worker);

search.setLpRelaxation(&mipdata_->lp);

Expand Down Expand Up @@ -324,12 +340,12 @@ void HighsMipSolver::run() {

if (mipdata_->incumbent.empty()) {
analysis_.mipTimerStart(kMipClockRens);
mipdata_->heuristics.RENS(
mipdata_->heuristics.RENS(master_worker,
mipdata_->lp.getLpSolver().getSolution().col_value);
analysis_.mipTimerStop(kMipClockRens);
} else {
analysis_.mipTimerStart(kMipClockRins);
mipdata_->heuristics.RINS(
mipdata_->heuristics.RINS(master_worker,
mipdata_->lp.getLpSolver().getSolution().col_value);
analysis_.mipTimerStop(kMipClockRins);
}
Expand Down
81 changes: 78 additions & 3 deletions src/mip/HighsMipSolverData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,78 @@
#include "presolve/HPresolve.h"
#include "util/HighsIntegers.h"

HighsMipSolverData::HighsMipSolverData(HighsMipSolver& mipsolver)
: mipsolver(mipsolver),
cutpool(mipsolver.numCol(), mipsolver.options_mip_->mip_pool_age_limit,
mipsolver.options_mip_->mip_pool_soft_limit),
conflictPool(5 * mipsolver.options_mip_->mip_pool_age_limit,
mipsolver.options_mip_->mip_pool_soft_limit),
domain(mipsolver),
lps(1, HighsLpRelaxation(mipsolver)),
lp(lps.at(0)),
// workers({HighsMipWorker(mipsolver, lp)}),
pseudocost(),
cliquetable(mipsolver.numCol()),
implications(mipsolver),
heuristics_ptr(new HighsPrimalHeuristics(mipsolver)),
heuristics(*heuristics_ptr.get()),
// heuristics(mipsolver),
objectiveFunction(mipsolver),
presolve_status(HighsPresolveStatus::kNotSet),
cliquesExtracted(false),
rowMatrixSet(false),
analyticCenterComputed(false),
analyticCenterStatus(HighsModelStatus::kNotset),
detectSymmetries(false),
numRestarts(0),
numRestartsRoot(0),
numCliqueEntriesAfterPresolve(0),
numCliqueEntriesAfterFirstPresolve(0),
feastol(0.0),
epsilon(0.0),
heuristic_effort(0.0),
dispfreq(0),
firstlpsolobj(-kHighsInf),
rootlpsolobj(-kHighsInf),
numintegercols(0),
maxTreeSizeLog2(0),
pruned_treeweight(0),
avgrootlpiters(0.0),
disptime(0.0),
last_disptime(0.0),
firstrootlpiters(0),
num_nodes(0),
num_leaves(0),
num_leaves_before_run(0),
num_nodes_before_run(0),
total_repair_lp(0),
total_repair_lp_feasible(0),
total_repair_lp_iterations(0),
total_lp_iterations(0),
heuristic_lp_iterations(0),
sepa_lp_iterations(0),
sb_lp_iterations(0),
total_lp_iterations_before_run(0),
heuristic_lp_iterations_before_run(0),
sepa_lp_iterations_before_run(0),
sb_lp_iterations_before_run(0),
num_disp_lines(0),
numImprovingSols(0),
lower_bound(-kHighsInf),
upper_bound(kHighsInf),
upper_limit(kHighsInf),
optimality_limit(kHighsInf),
debugSolution(mipsolver) {
domain.addCutpool(cutpool);
domain.addConflictPool(conflictPool);

// workers.emplace(workers.end(), HighsMipWorker(mipsolver, lps.back()));

// ig:here
// workers.emplace_back(std::move(HighsMipWorker(mipsolver, lp)));

}

std::string HighsMipSolverData::solutionSourceToString(
const int solution_source, const bool code) {
if (solution_source == kSolutionSourceNone) {
Expand Down Expand Up @@ -1852,7 +1924,7 @@ HighsLpRelaxation::Status HighsMipSolverData::evaluateRootLp() {
} while (true);
}

void HighsMipSolverData::evaluateRootNode() {
void HighsMipSolverData::evaluateRootNode(HighsMipWorker& worker) {
const bool compute_analytic_centre = true;
if (!compute_analytic_centre) printf("NOT COMPUTING ANALYTIC CENTRE!\n");
HighsInt maxSepaRounds = mipsolver.submip ? 5 : kHighsIInf;
Expand Down Expand Up @@ -2014,7 +2086,10 @@ void HighsMipSolverData::evaluateRootNode() {
HighsInt stall = 0;
double smoothprogress = 0.0;
HighsInt nseparounds = 0;
HighsSeparation sepa(mipsolver);

// HighsSeparation sepa(mipsolver);
HighsSeparation sepa(worker);

sepa.setLpRelaxation(&lp);

while (lp.scaledOptimal(status) && !lp.getFractionalIntegers().empty() &&
Expand Down Expand Up @@ -2210,7 +2285,7 @@ void HighsMipSolverData::evaluateRootNode() {
if (upper_limit != kHighsInf && !moreHeuristicsAllowed()) break;

if (checkLimits()) return;
heuristics.RENS(rootlpsol);
heuristics.RENS(worker, rootlpsol);
heuristics.flushStatistics();

if (checkLimits()) return;
Expand Down
74 changes: 10 additions & 64 deletions src/mip/HighsMipSolverData.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,19 @@ struct HighsMipSolverData {
HighsCutPool cutpool;
HighsConflictPool conflictPool;
HighsDomain domain;
HighsLpRelaxation lp;

std::deque<HighsLpRelaxation> lps;
std::deque<HighsMipWorker> workers;
// std::deque<HighsPrimalHeuristics> heuristics_deque;

HighsLpRelaxation& lp;

std::unique_ptr<HighsPrimalHeuristics> heuristics_ptr;
HighsPrimalHeuristics heuristics;

HighsPseudocost pseudocost;
HighsCliqueTable cliquetable;
HighsImplications implications;
HighsPrimalHeuristics heuristics;
HighsRedcostFixing redcostfixing;
HighsObjectiveFunction objectiveFunction;
presolve::HighsPostsolveStack postSolveStack;
Expand Down Expand Up @@ -158,67 +162,7 @@ struct HighsMipSolverData {

HighsDebugSol debugSolution;

HighsMipSolverData(HighsMipSolver& mipsolver)
: mipsolver(mipsolver),
cutpool(mipsolver.numCol(), mipsolver.options_mip_->mip_pool_age_limit,
mipsolver.options_mip_->mip_pool_soft_limit),
conflictPool(5 * mipsolver.options_mip_->mip_pool_age_limit,
mipsolver.options_mip_->mip_pool_soft_limit),
domain(mipsolver),
lp(mipsolver),
pseudocost(),
cliquetable(mipsolver.numCol()),
implications(mipsolver),
heuristics(mipsolver),
objectiveFunction(mipsolver),
presolve_status(HighsPresolveStatus::kNotSet),
cliquesExtracted(false),
rowMatrixSet(false),
analyticCenterComputed(false),
analyticCenterStatus(HighsModelStatus::kNotset),
detectSymmetries(false),
numRestarts(0),
numRestartsRoot(0),
numCliqueEntriesAfterPresolve(0),
numCliqueEntriesAfterFirstPresolve(0),
feastol(0.0),
epsilon(0.0),
heuristic_effort(0.0),
dispfreq(0),
firstlpsolobj(-kHighsInf),
rootlpsolobj(-kHighsInf),
numintegercols(0),
maxTreeSizeLog2(0),
pruned_treeweight(0),
avgrootlpiters(0.0),
disptime(0.0),
last_disptime(0.0),
firstrootlpiters(0),
num_nodes(0),
num_leaves(0),
num_leaves_before_run(0),
num_nodes_before_run(0),
total_repair_lp(0),
total_repair_lp_feasible(0),
total_repair_lp_iterations(0),
total_lp_iterations(0),
heuristic_lp_iterations(0),
sepa_lp_iterations(0),
sb_lp_iterations(0),
total_lp_iterations_before_run(0),
heuristic_lp_iterations_before_run(0),
sepa_lp_iterations_before_run(0),
sb_lp_iterations_before_run(0),
num_disp_lines(0),
numImprovingSols(0),
lower_bound(-kHighsInf),
upper_bound(kHighsInf),
upper_limit(kHighsInf),
optimality_limit(kHighsInf),
debugSolution(mipsolver) {
domain.addCutpool(cutpool);
domain.addConflictPool(conflictPool);
}
HighsMipSolverData(HighsMipSolver& mipsolver);

bool solutionRowFeasible(const std::vector<double>& solution) const;
HighsModelStatus trivialHeuristics();
Expand Down Expand Up @@ -270,7 +214,9 @@ struct HighsMipSolverData {
bool rootSeparationRound(HighsSeparation& sepa, HighsInt& ncuts,
HighsLpRelaxation::Status& status);
HighsLpRelaxation::Status evaluateRootLp();
void evaluateRootNode();

void evaluateRootNode(HighsMipWorker& worker);

bool addIncumbent(const std::vector<double>& sol, double solobj,
const int solution_source,
const bool print_display_line = true);
Expand Down
9 changes: 5 additions & 4 deletions src/mip/HighsMipWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ HighsMipWorker::HighsMipWorker(const HighsMipSolver& mipsolver__,
mipsolver__.options_mip_->mip_pool_soft_limit),
conflictpool_(5 * mipsolver__.options_mip_->mip_pool_age_limit,
mipsolver__.options_mip_->mip_pool_soft_limit),
cliquetable_(mipsolver__.numCol()),
// cliquetable_(mipsolver__.numCol()),
pseudocost_(mipsolver__),
pscostinit_(pseudocost_, 1),
clqtableinit_(mipsolver_.numCol()),
// clqtableinit_(mipsolver_.numCol()),
implicinit_(mipsolver_),
pscostinit(pscostinit_),
implicinit(implicinit_),
clqtableinit(clqtableinit_) {
implicinit(implicinit_)
// clqtableinit(clqtableinit_)
{

search_ptr_ =
std::unique_ptr<HighsSearch>(new HighsSearch(*this, pseudocost_));
Expand Down
8 changes: 4 additions & 4 deletions src/mip/HighsMipWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef HIGHS_MIP_WORKER_H_
#define HIGHS_MIP_WORKER_H_

#include "mip/HighsCliqueTable.h"
// #include "mip/HighsCliqueTable.h"
#include "mip/HighsConflictPool.h"
#include "mip/HighsCutPool.h"

Expand All @@ -32,7 +32,7 @@ class HighsMipWorker {
const HighsMipSolver& mipsolver_;
const HighsMipSolverData& mipdata_;

HighsCliqueTable cliquetable_;
// HighsCliqueTable cliquetable_;

HighsPseudocost pseudocost_;

Expand All @@ -50,13 +50,13 @@ class HighsMipWorker {

// members for worker threads.
HighsPseudocostInitialization pscostinit_;
HighsCliqueTable clqtableinit_;
// HighsCliqueTable clqtableinit_;
HighsImplications implicinit_;

// References to members, initialized to local objects for worker threads,
// modify to mip solver for main worker.
HighsPseudocostInitialization& pscostinit;
HighsCliqueTable& clqtableinit;
// HighsCliqueTable& clqtableinit;
HighsImplications& implicinit;

// Solution information.
Expand Down
17 changes: 10 additions & 7 deletions src/mip/HighsPrimalHeuristics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,11 @@ bool HighsPrimalHeuristics::solveSubMip(
submipsolver.implicinit = &mipsolver.mipdata_->implications;
// Solve the sub-MIP
submipsolver.run();
mipsolver.max_submip_level =
std::max(submipsolver.max_submip_level + 1, mipsolver.max_submip_level);

// ig:here
// mipsolver.max_submip_level =
// std::max(submipsolver.max_submip_level + 1, mipsolver.max_submip_level);

if (submipsolver.mipdata_) {
double numUnfixed = mipsolver.mipdata_->integral_cols.size() +
mipsolver.mipdata_->continuous_cols.size();
Expand Down Expand Up @@ -215,7 +218,7 @@ class HeuristicNeighbourhood {
HighsInt numTotal;

public:
HeuristicNeighbourhood(HighsMipSolver& mipsolver, HighsDomain& localdom)
HeuristicNeighbourhood(const HighsMipSolver& mipsolver, HighsDomain& localdom)
: localdom(localdom),
numFixed(0),
startCheckedChanges(localdom.getDomainChangeStack().size()),
Expand Down Expand Up @@ -314,12 +317,12 @@ void HighsPrimalHeuristics::rootReducedCost() {
mipsolver.analysis_.mipTimerStop(kMipClockSolveSubMipRootReducedCost);
}

void HighsPrimalHeuristics::RENS(const std::vector<double>& tmp) {
void HighsPrimalHeuristics::RENS(HighsMipWorker& worker, const std::vector<double>& tmp) {
HighsPseudocost pscost(mipsolver.mipdata_->pseudocost);

// HighsSearch heur(mipsolver, pscost);

HighsMipWorker worker{mipsolver, mipsolver.mipdata_->lp};
// HighsMipWorker worker{mipsolver, mipsolver.mipdata_->lp};
HighsSearch heur(worker, pscost);

HighsDomain& localdom = heur.getLocalDomain();
Expand Down Expand Up @@ -567,7 +570,7 @@ void HighsPrimalHeuristics::RENS(const std::vector<double>& tmp) {
lp_iterations += heur.getLocalLpIterations();
}

void HighsPrimalHeuristics::RINS(const std::vector<double>& relaxationsol) {
void HighsPrimalHeuristics::RINS(HighsMipWorker& worker, const std::vector<double>& relaxationsol) {
if (int(relaxationsol.size()) != mipsolver.numCol()) return;

intcols.erase(std::remove_if(intcols.begin(), intcols.end(),
Expand All @@ -580,7 +583,7 @@ void HighsPrimalHeuristics::RINS(const std::vector<double>& relaxationsol) {

// HighsSearch heur(mipsolver, pscost);

HighsMipWorker worker{mipsolver, mipsolver.mipdata_->lp};
// HighsMipWorker worker{mipsolver, mipsolver.mipdata_->lp};
HighsSearch heur(worker, pscost);

HighsDomain& localdom = heur.getLocalDomain();
Expand Down
Loading

0 comments on commit 3caa540

Please sign in to comment.