Skip to content

Commit cf8dc44

Browse files
committed
re-enable test and fix cut aging
1 parent f97964c commit cf8dc44

File tree

2 files changed

+46
-46
lines changed

2 files changed

+46
-46
lines changed

check/TestCallbacks.cpp

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -429,46 +429,46 @@ TEST_CASE("highs-callback-mip-cut-pool", "[highs_callback]") {
429429
highs.resetGlobalScheduler(true);
430430
}
431431

432-
// TEST_CASE("highs-callback-mip-user-solution", "[highs_callback]") {
433-
// // const std::vector<std::string> model = {"rgn", "flugpl", "gt2", "egout",
434-
// // "bell5", "lseu", "sp150x300d"};//, "p0548", "dcmulti"}; const
435-
// // std::vector<HighsInt> require_origin = {0, 1, 2, 3, 4, 5, 6};
436-
// const std::vector<std::string> model = {"p0548", "flugpl", "gt2", "egout",
437-
// "sp150x300d"};
438-
// const std::vector<HighsInt> require_origin = {0, 1, 2, 3, 4}; //, 4, 5, 6};
439-
// assert(model.size() == require_origin.size());
440-
// Highs highs;
441-
// highs.setOptionValue("output_flag", dev_run);
442-
// highs.setOptionValue("mip_rel_gap", 0);
443-
// HighsInt from_model = 0;
444-
// HighsInt to_model = HighsInt(model.size());
445-
// for (HighsInt iModel = from_model; iModel < to_model; iModel++) {
446-
// const std::string filename =
447-
// std::string(HIGHS_DIR) + "/check/instances/" + model[iModel] + ".mps";
448-
// highs.readModel(filename);
449-
// highs.run();
450-
// std::vector<double> optimal_solution = highs.getSolution().col_value;
451-
// double objective_function_value0 = highs.getInfo().objective_function_value;
452-
// highs.clearSolver();
453-
454-
// UserMipSolution user_callback_data;
455-
// user_callback_data.optimal_objective_value = objective_function_value0;
456-
// user_callback_data.optimal_solution = optimal_solution.data();
457-
// user_callback_data.require_user_solution_callback_origin =
458-
// require_origin[iModel];
459-
// void* p_user_callback_data = (void*)(&user_callback_data);
460-
461-
// // highs.setOptionValue("presolve", kHighsOffString);
462-
// highs.setCallback(userkMipUserSolution, p_user_callback_data);
463-
// highs.startCallback(kCallbackMipUserSolution);
464-
// highs.run();
465-
// highs.stopCallback(kCallbackMipUserSolution);
466-
// double objective_function_value1 = highs.getInfo().objective_function_value;
467-
// double objective_diff =
468-
// std::fabs(objective_function_value1 - objective_function_value0) /
469-
// std::max(1.0, std::fabs(objective_function_value0));
470-
// REQUIRE(objective_diff < 1e-12);
471-
// }
472-
473-
// highs.resetGlobalScheduler(true);
474-
// }
432+
TEST_CASE("highs-callback-mip-user-solution", "[highs_callback]") {
433+
// const std::vector<std::string> model = {"rgn", "flugpl", "gt2", "egout",
434+
// "bell5", "lseu", "sp150x300d"};//, "p0548", "dcmulti"}; const
435+
// std::vector<HighsInt> require_origin = {0, 1, 2, 3, 4, 5, 6};
436+
const std::vector<std::string> model = {"p0548", "flugpl", "gt2", "egout",
437+
"sp150x300d"};
438+
const std::vector<HighsInt> require_origin = {0, 1, 2, 3, 4}; //, 4, 5, 6};
439+
assert(model.size() == require_origin.size());
440+
Highs highs;
441+
highs.setOptionValue("output_flag", dev_run);
442+
highs.setOptionValue("mip_rel_gap", 0);
443+
HighsInt from_model = 0;
444+
HighsInt to_model = HighsInt(model.size());
445+
for (HighsInt iModel = from_model; iModel < to_model; iModel++) {
446+
const std::string filename =
447+
std::string(HIGHS_DIR) + "/check/instances/" + model[iModel] + ".mps";
448+
highs.readModel(filename);
449+
highs.run();
450+
std::vector<double> optimal_solution = highs.getSolution().col_value;
451+
double objective_function_value0 = highs.getInfo().objective_function_value;
452+
highs.clearSolver();
453+
454+
UserMipSolution user_callback_data;
455+
user_callback_data.optimal_objective_value = objective_function_value0;
456+
user_callback_data.optimal_solution = optimal_solution.data();
457+
user_callback_data.require_user_solution_callback_origin =
458+
require_origin[iModel];
459+
void* p_user_callback_data = (void*)(&user_callback_data);
460+
461+
// highs.setOptionValue("presolve", kHighsOffString);
462+
highs.setCallback(userkMipUserSolution, p_user_callback_data);
463+
highs.startCallback(kCallbackMipUserSolution);
464+
highs.run();
465+
highs.stopCallback(kCallbackMipUserSolution);
466+
double objective_function_value1 = highs.getInfo().objective_function_value;
467+
double objective_diff =
468+
std::fabs(objective_function_value1 - objective_function_value0) /
469+
std::max(1.0, std::fabs(objective_function_value0));
470+
REQUIRE(objective_diff < 1e-12);
471+
}
472+
473+
highs.resetGlobalScheduler(true);
474+
}

highs/mip/HighsCutPool.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ double HighsCutPool::getParallelism(HighsInt row1, HighsInt row2,
148148
}
149149

150150
void HighsCutPool::lpCutRemoved(HighsInt cut, bool thread_safe) {
151-
numLps_[cut].fetch_add(-1, std::memory_order_relaxed);
152-
if (thread_safe) return;
151+
const HighsInt n = numLps_[cut].fetch_add(-1, std::memory_order_relaxed);
152+
if (thread_safe || n > 1) return;
153153
if (matrix_.columnsLinked(cut)) {
154154
propRows.erase(std::make_pair(ages_[cut], cut));
155155
propRows.emplace(1, cut);
@@ -287,7 +287,7 @@ void HighsCutPool::separate(const std::vector<double>& sol, HighsDomain& domain,
287287

288288
matrix_.removeRow(i);
289289
ages_[i] = -1;
290-
rhs_[i] = 0;
290+
rhs_[i] = kHighsInf;
291291
usedInRound_[i] = false;
292292
hasSynced_[i] = false;
293293
auto range = hashToCutMap.equal_range(h);

0 commit comments

Comments
 (0)