Skip to content

Commit

Permalink
writePrimalSolution: flush file after each call (ERGO-Code#1880)
Browse files Browse the repository at this point in the history
  • Loading branch information
few committed Aug 17, 2024
1 parent 53273e7 commit 129c6a2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/highs_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1195,12 +1195,11 @@ PYBIND11_MODULE(_core, m) {
.def_property(
"mip_solution",
[](const HighsCallbackDataOut& self) -> py::array {
// XXX: This is clearly wrong, most likely we need to have the
// length as an input data parameter
return py::array(3, self.mip_solution);
return py::array(self.mip_solution_size, self.mip_solution);
},
[](HighsCallbackDataOut& self, py::array_t<double> new_mip_solution) {
self.mip_solution = new_mip_solution.mutable_data();
self.mip_solution_size = new_mip_solution.shape(0);
});
py::class_<HighsCallbackDataIn>(callbacks, "HighsCallbackDataIn")
.def(py::init<>())
Expand Down
1 change: 1 addition & 0 deletions src/lp_data/HighsCallbackStruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ typedef struct {
double mip_dual_bound;
double mip_gap;
double* mip_solution;
HighsInt mip_solution_size;
HighsInt cutpool_num_col;
HighsInt cutpool_num_cut;
HighsInt cutpool_num_nz;
Expand Down
1 change: 1 addition & 0 deletions src/lp_data/HighsModelUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ void writePrimalSolution(FILE* file, const HighsLogOptions& log_options,
ss << "\n";
highsFprintfString(file, log_options, ss.str());
}
fflush(file);
}

void writeModelSolution(FILE* file, const HighsLogOptions& log_options,
Expand Down
3 changes: 3 additions & 0 deletions src/mip/HighsMipSolverData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ void HighsMipSolverData::runSetup() {
assert(!mipsolver.submip);
mipsolver.callback_->clearHighsCallbackDataOut();
mipsolver.callback_->data_out.mip_solution = mipsolver.solution_.data();
mipsolver.callback_->data_out.mip_solution_size = mipsolver.solution_.size();
const bool interrupt = interruptFromCallbackWithData(
kCallbackMipSolution, mipsolver.solution_objective_,
"Feasible solution");
Expand Down Expand Up @@ -832,6 +833,7 @@ double HighsMipSolverData::transformNewIntegerFeasibleSolution(
mipsolver.callback_->active[kCallbackMipSolution]) {
mipsolver.callback_->clearHighsCallbackDataOut();
mipsolver.callback_->data_out.mip_solution = solution.col_value.data();
mipsolver.callback_->data_out.mip_solution_size = solution.col_value.size();
const bool interrupt = interruptFromCallbackWithData(
kCallbackMipSolution, mipsolver_objective_value, "Feasible solution");
assert(!interrupt);
Expand Down Expand Up @@ -1928,6 +1930,7 @@ void HighsMipSolverData::saveReportMipSolution(const double new_upper_limit) {
if (mipsolver.callback_->active[kCallbackMipImprovingSolution]) {
mipsolver.callback_->clearHighsCallbackDataOut();
mipsolver.callback_->data_out.mip_solution = mipsolver.solution_.data();
mipsolver.callback_->data_out.mip_solution_size = mipsolver.solution_.size();
const bool interrupt = interruptFromCallbackWithData(
kCallbackMipImprovingSolution, mipsolver.solution_objective_,
"Improving solution");
Expand Down

0 comments on commit 129c6a2

Please sign in to comment.