Skip to content

Commit

Permalink
Added highs_setSolution and highs_setSparseSolution to highs_bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
jajhall committed Jul 14, 2024
1 parent 7fd28a1 commit 39569be
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/highs_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,24 @@ HighsStatus highs_deleteRows(Highs* h, HighsInt num_set_entries, std::vector<Hig
return h->deleteRows(num_set_entries, indices.data());
}


HighsStatus highs_setSolution(Highs* h, HighsSolution& solution) {
return h->setSolution(solution);
}

HighsStatus highs_setSparseSolution(Highs* h, HighsInt num_entries,
py::array_t<HighsInt> index,
py::array_t<double> value) {
py::buffer_info index_info = index.request();
py::buffer_info value_info = value.request();

HighsInt* index_ptr = reinterpret_cast<HighsInt*>(index_info.ptr);
double* value_ptr = static_cast<double*>(value_info.ptr);

return h->setSolution(num_entries, index_ptr, value_ptr);
}


HighsStatus highs_setBasis(Highs* h, HighsBasis& basis) {
return h->setBasis(basis);
}
Expand Down Expand Up @@ -935,7 +953,8 @@ PYBIND11_MODULE(_core, m) {
.def("deleteCols", &highs_deleteCols)
.def("deleteVars", &highs_deleteCols) // alias
.def("deleteRows", &highs_deleteRows)
.def("setSolution", &Highs::setSolution)
.def("setSolution", &highs_setSolution)
.def("setSolution", &highs_setSparseSolution)
.def("setBasis", &highs_setBasis)
.def("setBasis", &highs_setLogicalBasis)
.def("modelStatusToString", &Highs::modelStatusToString)
Expand Down
1 change: 1 addition & 0 deletions src/lp_data/HStruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct HighsSolution {
std::vector<double> col_dual;
std::vector<double> row_value;
std::vector<double> row_dual;
bool hasUndefined();
void invalidate();
void clear();
};
Expand Down
1 change: 1 addition & 0 deletions src/lp_data/Highs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3413,6 +3413,7 @@ HighsStatus Highs::completeSolutionFromDiscreteAssignment() {
break;
}
}
assert(solution_.hasUndefined() == contains_undefined_values);
if (!contains_undefined_values) {
bool valid, integral, feasible;
// Determine whether this solution is integer feasible
Expand Down
6 changes: 6 additions & 0 deletions src/lp_data/HighsSolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,12 @@ bool isBasisRightSize(const HighsLp& lp, const HighsBasis& basis) {
basis.row_status.size() == static_cast<size_t>(lp.num_row_);
}

bool HighsSolution::hasUndefined() {
for (HighsInt iCol = 0; iCol < HighsInt(this->col_value.size()); iCol++)
if (this->col_value[iCol] == kHighsUndefined) return true;
return false;
}

void HighsSolution::invalidate() {
this->value_valid = false;
this->dual_valid = false;
Expand Down

0 comments on commit 39569be

Please sign in to comment.