diff --git a/src/highs_bindings.cpp b/src/highs_bindings.cpp index 4883bd6c25..e7f9e49cac 100644 --- a/src/highs_bindings.cpp +++ b/src/highs_bindings.cpp @@ -285,6 +285,24 @@ HighsStatus highs_deleteRows(Highs* h, HighsInt num_set_entries, std::vectordeleteRows(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 index, + py::array_t value) { + py::buffer_info index_info = index.request(); + py::buffer_info value_info = value.request(); + + HighsInt* index_ptr = reinterpret_cast(index_info.ptr); + double* value_ptr = static_cast(value_info.ptr); + + return h->setSolution(num_entries, index_ptr, value_ptr); +} + + HighsStatus highs_setBasis(Highs* h, HighsBasis& basis) { return h->setBasis(basis); } @@ -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) diff --git a/src/lp_data/HStruct.h b/src/lp_data/HStruct.h index 863020bfde..e54657d406 100644 --- a/src/lp_data/HStruct.h +++ b/src/lp_data/HStruct.h @@ -33,6 +33,7 @@ struct HighsSolution { std::vector col_dual; std::vector row_value; std::vector row_dual; + bool hasUndefined(); void invalidate(); void clear(); }; diff --git a/src/lp_data/Highs.cpp b/src/lp_data/Highs.cpp index bf3c72b384..fee0502b58 100644 --- a/src/lp_data/Highs.cpp +++ b/src/lp_data/Highs.cpp @@ -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 diff --git a/src/lp_data/HighsSolution.cpp b/src/lp_data/HighsSolution.cpp index 4ad8617ddd..77d3daa8ce 100644 --- a/src/lp_data/HighsSolution.cpp +++ b/src/lp_data/HighsSolution.cpp @@ -1438,6 +1438,12 @@ bool isBasisRightSize(const HighsLp& lp, const HighsBasis& basis) { basis.row_status.size() == static_cast(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;