Skip to content

Commit 36645a4

Browse files
committed
Fixed issues with unit tests
1 parent f389330 commit 36645a4

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

check/TestCallbacks.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,6 @@ HighsCallbackFunctionType userkMipUserSetPartialSolution =
253253
// get every other index
254254
std::vector<HighsInt> index;
255255
std::vector<double> value;
256-
index.reserve(callback_data.optimal_solution.size() / 2);
257-
value.reserve(callback_data.optimal_solution.size() / 2);
258256

259257
for (HighsInt i = 0; i < callback_data.optimal_solution.size(); i++) {
260258
if (i % 2 == 0) {

check/TestIpx.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ TEST_CASE("test-ipx", "[highs_ipx]") {
5454

5555
highs::parallel::initialize_scheduler();
5656

57+
// set empty callback to avoid issues
58+
HighsCallback callback(nullptr);
59+
lps.SetCallback(&callback);
60+
5761
Int status = lps.Solve();
5862
bool is_solved = status == IPX_STATUS_solved;
5963
REQUIRE(is_solved);

src/lp_data/HighsCallback.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ void HighsCallback::clearHighsCallbackOutput() {
3939
}
4040

4141
void HighsCallback::clearHighsCallbackInput() {
42-
this->data_in.user_interrupt = false;
42+
size_t num_col = highs != nullptr ? highs->getNumCol() : 0;
4343

4444
// make sure buffer size is correct and reset the contents if previously used
4545
if (this->data_in.user_has_solution ||
46-
highs->getNumCol() != this->data_in.user_solution.size()) {
47-
this->data_in.user_solution.assign(highs->getNumCol(), kHighsUndefined);
46+
num_col != this->data_in.user_solution.size()) {
47+
this->data_in.user_solution.assign(num_col, kHighsUndefined);
4848
}
4949

50+
this->data_in.user_interrupt = false;
5051
this->data_in.user_has_solution = false;
5152
}
5253

@@ -261,17 +262,24 @@ HighsStatus HighsCallbackInput::repairSolution() {
261262
}
262263

263264
// set callback to stop at first feasible solution
265+
bool user_interrupt = false;
266+
264267
HighsCallbackFunctionType mip_callback =
265-
[](int callback_type, const std::string& message,
266-
const HighsCallbackOutput* data_out, HighsCallbackInput* data_in,
267-
void* user_callback_data) {
268+
[&](int callback_type, const std::string& message,
269+
const HighsCallbackOutput* data_out, HighsCallbackInput* data_in,
270+
void* user_callback_data) {
268271
if (callback_type == kCallbackMipSolution) {
269-
data_in->user_interrupt = true;
272+
user_interrupt = true;
273+
} else {
274+
data_in->user_interrupt = user_interrupt;
270275
}
271276
};
272277

273278
clone.setCallback(mip_callback);
274279
clone.startCallback(kCallbackMipSolution);
280+
clone.startCallback(kCallbackMipInterrupt);
281+
clone.startCallback(kCallbackSimplexInterrupt);
282+
clone.startCallback(kCallbackIpmInterrupt);
275283
clone.run();
276284

277285
auto status = clone.getModelStatus();

0 commit comments

Comments
 (0)