Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
quantresearch1 committed Dec 6, 2024
1 parent 4a7f24a commit c3c2d3a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 19 deletions.
8 changes: 6 additions & 2 deletions src/Highs.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,13 @@ class Highs {
const HighsModel& getModel() const { return model_; }

/**
* @brief Return a const reference to the internal HighsSolution instance
* @brief Get the status of both primal and dual solutions
* @return A pair containing the primal solution status (first) and dual
* solution status (second)
*/
const HighsSolution& getSolution() const { return solution_; }
std::pair<SolutionStatus, SolutionStatus> getSolutionStatus() const {
return ekk_instance_.getSolutionStatus();
}

/**
* @brief Zero all clocks in the internal HighsTimer instance
Expand Down
28 changes: 17 additions & 11 deletions src/highs_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,8 @@ highs_getColsEntries(Highs* h, HighsInt num_set_entries,
py::cast(value));
}

std::tuple<HighsStatus, HighsVarType>
highs_getColIntegrality(Highs* h, HighsInt col) {
std::tuple<HighsStatus, HighsVarType> highs_getColIntegrality(Highs* h,
HighsInt col) {
HighsInt col_ = static_cast<HighsInt>(col);
HighsVarType integrality;
HighsStatus status = h->getColIntegrality(col_, integrality);
Expand Down Expand Up @@ -621,19 +621,23 @@ std::tuple<HighsStatus, int> highs_getRowByName(Highs* h,
}

// Wrap the setCallback function to appropriately handle user data.
// pybind11 automatically ensures GIL is re-acquired when the callback is called.
// pybind11 automatically ensures GIL is re-acquired when the callback is
// called.
HighsStatus highs_setCallback(
Highs* h,
std::function<void(int, const std::string&, const HighsCallbackDataOut*, HighsCallbackDataIn*, py::handle)> fn,
std::function<void(int, const std::string&, const HighsCallbackDataOut*,
HighsCallbackDataIn*, py::handle)>
fn,
py::handle data) {
if (static_cast<bool>(fn) == false)
return h->setCallback((HighsCallbackFunctionType) nullptr, nullptr);
else
return h->setCallback(
[fn](int callbackType, const std::string& msg,
const HighsCallbackDataOut* dataOut,
HighsCallbackDataIn* dataIn, void* d) {
return fn(callbackType, msg, dataOut, dataIn, py::handle(reinterpret_cast<PyObject*>(d)));
const HighsCallbackDataOut* dataOut, HighsCallbackDataIn* dataIn,
void* d) {
return fn(callbackType, msg, dataOut, dataIn,
py::handle(reinterpret_cast<PyObject*>(d)));
},
data.ptr());
}
Expand Down Expand Up @@ -749,7 +753,8 @@ PYBIND11_MODULE(_core, m) {
.value("kHighsDebugLevelNone", HighsDebugLevel::kHighsDebugLevelNone)
.value("kHighsDebugLevelCheap", HighsDebugLevel::kHighsDebugLevelCheap)
.value("kHighsDebugLevelCostly", HighsDebugLevel::kHighsDebugLevelCostly)
.value("kHighsDebugLevelExpensive", HighsDebugLevel::kHighsDebugLevelExpensive)
.value("kHighsDebugLevelExpensive",
HighsDebugLevel::kHighsDebugLevelExpensive)
.value("kHighsDebugLevelMin", HighsDebugLevel::kHighsDebugLevelMin)
.value("kHighsDebugLevelMax", HighsDebugLevel::kHighsDebugLevelMax)
.export_values();
Expand Down Expand Up @@ -833,8 +838,7 @@ PYBIND11_MODULE(_core, m) {
&HighsInfo::max_complementarity_violation)
.def_readwrite("sum_complementarity_violations",
&HighsInfo::sum_complementarity_violations)
.def_readwrite("primal_dual_integral",
&HighsInfo::primal_dual_integral);
.def_readwrite("primal_dual_integral", &HighsInfo::primal_dual_integral);
py::class_<HighsOptions>(m, "HighsOptions")
.def(py::init<>())
.def_readwrite("presolve", &HighsOptions::presolve)
Expand Down Expand Up @@ -982,7 +986,8 @@ PYBIND11_MODULE(_core, m) {
py::arg("local_upper_penalty") = py::none(),
py::arg("local_rhs_penalty") = py::none())
.def("getIis", &Highs::getIis)
.def("presolve", &Highs::presolve, py::call_guard<py::gil_scoped_release>())
.def("presolve", &Highs::presolve,
py::call_guard<py::gil_scoped_release>())
.def("writeSolution", &highs_writeSolution)
.def("readSolution", &Highs::readSolution)
.def("setOptionValue",
Expand Down Expand Up @@ -1027,6 +1032,7 @@ PYBIND11_MODULE(_core, m) {
// &highs_getModelStatus not needed once getModelStatus(const bool
// scaled_model) disappears from, Highs.h
.def("getModelStatus", &highs_getModelStatus) //&Highs::getModelStatus)
.def("getSolutionStatus", &Highs::getSolutionStatus)
.def("getModelPresolveStatus", &Highs::getModelPresolveStatus)
.def("getRanging", &highs_getRanging)
.def("getObjectiveValue", &Highs::getObjectiveValue)
Expand Down
8 changes: 6 additions & 2 deletions src/simplex/HEkk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ void HEkk::clearEkkData() {
this->solve_bailout_ = false;
this->called_return_from_solve_ = false;
this->exit_algorithm_ = SimplexAlgorithm::kNone;
this->return_primal_solution_status_ = 0;
this->return_dual_solution_status_ = 0;
this->return_primal_solution_status_ = SolutionStatus::kSolutionStatusNone;
this->return_dual_solution_status_ = SolutionStatus::kSolutionStatusNone;

this->proof_index_.clear();
this->proof_value_.clear();
Expand Down Expand Up @@ -1413,6 +1413,10 @@ HighsSolution HEkk::getSolution() {
return solution;
}

std::pair<SolutionStatus, SolutionStatus> HEkk::getSolutionStatus() const {
return {return_primal_solution_status_, return_dual_solution_status_};
}

HighsBasis HEkk::getHighsBasis(HighsLp& use_lp) const {
HighsInt num_col = use_lp.num_col_;
HighsInt num_row = use_lp.num_row_;
Expand Down
9 changes: 5 additions & 4 deletions src/simplex/HEkk.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class HEkk {
solve_bailout_(false),
called_return_from_solve_(false),
exit_algorithm_(SimplexAlgorithm::kNone),
return_primal_solution_status_(0),
return_dual_solution_status_(0),
return_primal_solution_status_(SolutionStatus::kSolutionStatusNone),
return_dual_solution_status_(SolutionStatus::kSolutionStatusNone),
original_num_col_(0),
original_num_row_(0),
original_num_nz_(0),
Expand Down Expand Up @@ -131,6 +131,7 @@ class HEkk {
HVector& residual, double& residual_norm);

HighsSolution getSolution();
std::pair<SolutionStatus, SolutionStatus> getSolutionStatus() const;
HighsBasis getHighsBasis(HighsLp& use_lp) const;

const SimplexBasis& getSimplexBasis() { return basis_; }
Expand Down Expand Up @@ -206,8 +207,8 @@ class HEkk {
bool solve_bailout_;
bool called_return_from_solve_;
SimplexAlgorithm exit_algorithm_;
HighsInt return_primal_solution_status_;
HighsInt return_dual_solution_status_;
SolutionStatus return_primal_solution_status_;
SolutionStatus return_dual_solution_status_;

// Data to be retained after proving primal infeasibility
vector<HighsInt> proof_index_;
Expand Down

0 comments on commit c3c2d3a

Please sign in to comment.