Skip to content

Commit

Permalink
Added ../src/mip/HighsMipAnalysis.cpp ../src/mip/HighsMipAnalysis.h .…
Browse files Browse the repository at this point in the history
…./src/mip/MipTimer.h !
  • Loading branch information
jajhall committed Sep 25, 2024
1 parent f321644 commit 81f442a
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/mip/HighsMipAnalysis.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* This file is part of the HiGHS linear optimization suite */
/* */
/* Written and engineered 2008-2024 by Julian Hall, Ivet Galabova, */
/* Leona Gottwald and Michael Feldmeier */
/* */
/* Available as open-source under the MIT License */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**@file simplex/HighsMipAnalysis.cpp
* @brief
*/
#include "mip/HighsMipAnalysis.h"

#include <cmath>

#include "mip/MipTimer.h"

void HighsMipAnalysis::setup(const HighsLp& lp, const HighsOptions& options) {
setupMipTime(options);
}

void HighsMipAnalysis::setupMipTime(const HighsOptions& options) {
analyse_mip_time = true; // ToDo: Make this conditional
// kHighsAnalysisLevelSolverTime & options.highs_analysis_level;
if (analyse_mip_time) {
HighsTimerClock clock;
clock.timer_pointer_ = timer_;
MipTimer mip_timer;
mip_timer.initialiseMipClocks(clock);
mip_clocks = clock;
}
}

void HighsMipAnalysis::mipTimerStart(const HighsInt mip_clock
// , const HighsInt thread_id
) {
if (!analyse_mip_time) return;
// assert(analyse_mip_time);
mip_clocks.timer_pointer_->start(mip_clocks.clock_[mip_clock]);
}

void HighsMipAnalysis::mipTimerStop(const HighsInt mip_clock
// , const HighsInt thread_id
) {
if (!analyse_mip_time) return;
// assert(analyse_mip_time);
mip_clocks.timer_pointer_->stop(mip_clocks.clock_[mip_clock]);
}

void HighsMipAnalysis::reportMipTimer() {
if (!analyse_mip_time) return;
// assert(analyse_mip_time);
MipTimer mip_timer;
mip_timer.reportMipCoreClock(mip_clocks);
}
42 changes: 42 additions & 0 deletions src/mip/HighsMipAnalysis.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* This file is part of the HiGHS linear optimization suite */
/* */
/* Written and engineered 2008-2024 by Julian Hall, Ivet Galabova, */
/* Leona Gottwald and Michael Feldmeier */
/* */
/* Available as open-source under the MIT License */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**@file mip/HighsMipAnalysis.h
* @brief Analyse MIP iterations, both for run-time control and data
* gathering
*/
#ifndef MIP_HIGHSMIPANALYSIS_H_
#define MIP_HIGHSMIPANALYSIS_H_

#include "lp_data/HighsAnalysis.h"
#include "lp_data/HighsLp.h"
#include "util/HighsTimer.h"

class HighsMipAnalysis {
public:
HighsMipAnalysis() : timer_(nullptr), analyse_mip_time(false) {}

HighsTimer* timer_;
void setup(const HighsLp& lp, const HighsOptions& options);

void setupMipTime(const HighsOptions& options);
void mipTimerStart(const HighsInt mip_clock
// , const HighsInt thread_id = 0
);
void mipTimerStop(const HighsInt mip_clock
// , const HighsInt thread_id = 0
);
void reportMipTimer();

HighsTimerClock mip_clocks;
bool analyse_mip_time;
};

#endif /* MIP_HIGHSMIPANALYSIS_H_ */
67 changes: 67 additions & 0 deletions src/mip/MipTimer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* This file is part of the HiGHS linear optimization suite */
/* */
/* Written and engineered 2008-2024 by Julian Hall, Ivet Galabova, */
/* Leona Gottwald and Michael Feldmeier */
/* */
/* Available as open-source under the MIT License */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**@file mip/MipTimer.h
* @brief Indices of mip iClocks
*/
#ifndef MIP_MIPTIMER_H_
#define MIP_MIPTIMER_H_

// Clocks for profiling the MIP dual mip solver
enum iClockMip {
kMipClockTotal = 0,
kMipClockPresolve,
kMipClockSolve,
kMipClockPostsolve,
kNumMipClock //!< Number of MIP clocks
};

class MipTimer {
public:
void initialiseMipClocks(HighsTimerClock& mip_timer_clock) {
HighsTimer* timer_pointer = mip_timer_clock.timer_pointer_;
std::vector<HighsInt>& clock = mip_timer_clock.clock_;
clock.resize(kNumMipClock);
clock[kMipClockTotal] = timer_pointer->total_clock;
clock[kMipClockPresolve] = timer_pointer->presolve_clock;
clock[kMipClockSolve] = timer_pointer->solve_clock;
clock[kMipClockPostsolve] = timer_pointer->postsolve_clock;
// clock[kMipClockTotal] = timer_pointer->clock_def("MIP total");
}

bool reportMipClockList(const char* grepStamp,
const std::vector<HighsInt> mip_clock_list,
const HighsTimerClock& mip_timer_clock,
const double tolerance_percent_report_ = -1) {
HighsTimer* timer_pointer = mip_timer_clock.timer_pointer_;
const std::vector<HighsInt>& clock = mip_timer_clock.clock_;
HighsInt mip_clock_list_size = mip_clock_list.size();
std::vector<HighsInt> clockList;
clockList.resize(mip_clock_list_size);
for (HighsInt en = 0; en < mip_clock_list_size; en++) {
clockList[en] = clock[mip_clock_list[en]];
}
const double ideal_sum_time =
timer_pointer->clock_time[clock[kMipClockTotal]];
const double tolerance_percent_report =
tolerance_percent_report_ >= 0 ? tolerance_percent_report_ : 1e-8;
return timer_pointer->reportOnTolerance(
grepStamp, clockList, ideal_sum_time, tolerance_percent_report);
};

void reportMipCoreClock(const HighsTimerClock& mip_timer_clock) {
// const std::vector<HighsInt>& clock = mip_timer_clock.clock_;
const std::vector<HighsInt> mip_clock_list{
kMipClockPresolve, kMipClockSolve, kMipClockPostsolve};
reportMipClockList("MipCore", mip_clock_list, mip_timer_clock);
};
};

#endif /* MIP_MIPTIMER_H_ */

0 comments on commit 81f442a

Please sign in to comment.