Skip to content

Commit e4003b5

Browse files
committed
Created structs MipRaceIncumbent and MipRaceRecord
1 parent b3406f0 commit e4003b5

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

highs/lp_data/HStruct.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,23 @@ struct HotStart {
6161
std::vector<int8_t> nonbasicMove;
6262
};
6363

64+
struct MipRaceIncumbent {
65+
HighsInt start_write_incumbent = -1;
66+
HighsInt finish_write_incumbent = -1;
67+
double best_incumbent_objective = -kHighsInf;
68+
std::vector<double> best_incumbent_solution;
69+
void clear();
70+
void initialise(const HighsInt num_col);
71+
void write(const double objective, const std::vector<double>& solution);
72+
bool readOk(double& objective, std::vector<double>& solution) const;
73+
};
74+
75+
struct MipRaceRecord {
76+
std::vector<MipRaceIncumbent> record;
77+
void clear();
78+
void initialise(const HighsInt num_race_instance, const HighsInt num_col);
79+
};
80+
6481
struct HighsBasis {
6582
// Logical flags for a HiGHS basis:
6683
//

highs/mip/HighsMipSolverData.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2785,3 +2785,49 @@ void HighsMipSolverData::updatePrimalDualIntegral(const double from_lower_bound,
27852785
}
27862786

27872787
void HighsPrimaDualIntegral::initialise() { this->value = -kHighsInf; }
2788+
2789+
void MipRaceIncumbent::clear() {
2790+
this->start_write_incumbent = -1;
2791+
this->finish_write_incumbent = -1;
2792+
this->best_incumbent_objective = -kHighsInf;
2793+
this->best_incumbent_solution.clear();
2794+
}
2795+
2796+
void MipRaceIncumbent::initialise(const HighsInt num_col) {
2797+
this->clear();
2798+
this->best_incumbent_solution.resize(num_col);
2799+
}
2800+
2801+
void MipRaceIncumbent::write(const double objective,
2802+
const std::vector<double>& solution) {
2803+
assert(this->best_incumbent_solution.size() == solution.size());
2804+
this->start_write_incumbent++;
2805+
this->best_incumbent_objective = objective;
2806+
this->best_incumbent_solution = solution;
2807+
this->finish_write_incumbent++;
2808+
assert(this->start_write_incumbent == this->finish_write_incumbent);
2809+
}
2810+
2811+
bool MipRaceIncumbent::readOk(double& objective,
2812+
std::vector<double>& solution) const {
2813+
const HighsInt start_write_incumbent = this->start_write_incumbent;
2814+
assert(this->finish_write_incumbent <= start_write_incumbent);
2815+
// If a write call has not completed, return failure
2816+
if (this->finish_write_incumbent < start_write_incumbent) return false;
2817+
// finish_write_incumbent = start_write_incumbent so start reading
2818+
objective = this->best_incumbent_objective;
2819+
solution = this->best_incumbent_solution;
2820+
// Read is OK if no new write has started
2821+
return this->start_write_incumbent == start_write_incumbent;
2822+
}
2823+
2824+
void MipRaceRecord::clear() { this->record.clear(); }
2825+
2826+
void MipRaceRecord::initialise(const HighsInt num_race_instance,
2827+
const HighsInt num_col) {
2828+
this->clear();
2829+
MipRaceIncumbent mip_race_incumbent;
2830+
mip_race_incumbent.initialise(num_col);
2831+
for (HighsInt instance = 0; instance < num_race_instance; instance++)
2832+
this->record.push_back(mip_race_incumbent);
2833+
}

0 commit comments

Comments
 (0)