Skip to content

Commit 72ce723

Browse files
committed
Added getBasisInverseCol and getBasisInverseRow plus sparse variants to highspy
1 parent bafb26d commit 72ce723

File tree

1 file changed

+66
-8
lines changed

1 file changed

+66
-8
lines changed

src/highs_bindings.cpp

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ std::tuple<HighsStatus, HighsRanging> highs_getRanging(Highs* h) {
187187
return std::make_tuple(status, ranging);
188188
}
189189

190-
std::tuple<HighsStatus, dense_array_t<HighsInt>> highs_getBasicVariables(Highs* h) {
190+
std::tuple<HighsStatus, dense_array_t<HighsInt>>
191+
highs_getBasicVariables(Highs* h) {
191192
HighsInt num_row = h->getNumRow();
192193

193194
HighsStatus status = HighsStatus::kOk;
@@ -197,7 +198,62 @@ std::tuple<HighsStatus, dense_array_t<HighsInt>> highs_getBasicVariables(Highs*
197198
return std::make_tuple(status, py::cast(basic_variables));
198199
}
199200

200-
std::tuple<HighsStatus, dense_array_t<double>> highs_getBasisSolve(Highs* h, dense_array_t<double> rhs) {
201+
std::tuple<HighsStatus, dense_array_t<double>>
202+
highs_getBasisInverseRow(Highs* h, HighsInt row) {
203+
HighsInt num_row = h->getNumRow();
204+
205+
HighsStatus status = HighsStatus::kOk;
206+
std::vector<double> solution_vector(num_row);
207+
double* solution_vector_ptr = static_cast<double*>(solution_vector.data());
208+
209+
if (num_row > 0) status = h->getBasisInverseRow(row, solution_vector_ptr);
210+
return std::make_tuple(status, py::cast(solution_vector));
211+
}
212+
213+
std::tuple<HighsStatus, dense_array_t<double>, HighsInt, dense_array_t<HighsInt>>
214+
highs_getBasisInverseRowSparse(Highs* h, HighsInt row) {
215+
HighsInt num_row = h->getNumRow();
216+
217+
HighsStatus status = HighsStatus::kOk;
218+
HighsInt solution_num_nz = 0;
219+
std::vector<double> solution_vector(num_row);
220+
std::vector<HighsInt> solution_index(num_row);
221+
double* solution_vector_ptr = static_cast<double*>(solution_vector.data());
222+
HighsInt* solution_index_ptr = static_cast<HighsInt*>(solution_index.data());
223+
224+
if (num_row > 0) status = h->getBasisInverseRow(row, solution_vector_ptr, &solution_num_nz, solution_index_ptr);
225+
return std::make_tuple(status, py::cast(solution_vector), solution_num_nz, py::cast(solution_index));
226+
}
227+
228+
std::tuple<HighsStatus, dense_array_t<double>>
229+
highs_getBasisInverseCol(Highs* h, HighsInt col) {
230+
HighsInt num_row = h->getNumRow();
231+
232+
HighsStatus status = HighsStatus::kOk;
233+
std::vector<double> solution_vector(num_row);
234+
double* solution_vector_ptr = static_cast<double*>(solution_vector.data());
235+
236+
if (num_row > 0) status = h->getBasisInverseCol(col, solution_vector_ptr);
237+
return std::make_tuple(status, py::cast(solution_vector));
238+
}
239+
240+
std::tuple<HighsStatus, dense_array_t<double>, HighsInt, dense_array_t<HighsInt>>
241+
highs_getBasisInverseColSparse(Highs* h, HighsInt col) {
242+
HighsInt num_row = h->getNumRow();
243+
244+
HighsStatus status = HighsStatus::kOk;
245+
HighsInt solution_num_nz = 0;
246+
std::vector<double> solution_vector(num_row);
247+
std::vector<HighsInt> solution_index(num_row);
248+
double* solution_vector_ptr = static_cast<double*>(solution_vector.data());
249+
HighsInt* solution_index_ptr = static_cast<HighsInt*>(solution_index.data());
250+
251+
if (num_row > 0) status = h->getBasisInverseCol(col, solution_vector_ptr, &solution_num_nz, solution_index_ptr);
252+
return std::make_tuple(status, py::cast(solution_vector), solution_num_nz, py::cast(solution_index));
253+
}
254+
255+
std::tuple<HighsStatus, dense_array_t<double>>
256+
highs_getBasisSolve(Highs* h, dense_array_t<double> rhs) {
201257
HighsInt num_row = h->getNumRow();
202258

203259
py::buffer_info rhs_info = rhs.request();
@@ -211,7 +267,8 @@ std::tuple<HighsStatus, dense_array_t<double>> highs_getBasisSolve(Highs* h, den
211267
return std::make_tuple(status, py::cast(solution_vector));
212268
}
213269

214-
std::tuple<HighsStatus, dense_array_t<double>, HighsInt, dense_array_t<HighsInt>> highs_getBasisSolveSparse(Highs* h, dense_array_t<double> rhs) {
270+
std::tuple<HighsStatus, dense_array_t<double>, HighsInt, dense_array_t<HighsInt>>
271+
highs_getBasisSolveSparse(Highs* h, dense_array_t<double> rhs) {
215272
HighsInt num_row = h->getNumRow();
216273

217274
py::buffer_info rhs_info = rhs.request();
@@ -242,7 +299,8 @@ std::tuple<HighsStatus, dense_array_t<double>> highs_getBasisTransposeSolve(High
242299
return std::make_tuple(status, py::cast(solution_vector));
243300
}
244301

245-
std::tuple<HighsStatus, dense_array_t<double>, HighsInt, dense_array_t<HighsInt>> highs_getBasisTransposeSolveSparse(Highs* h, dense_array_t<double> rhs) {
302+
std::tuple<HighsStatus, dense_array_t<double>, HighsInt, dense_array_t<HighsInt>>
303+
highs_getBasisTransposeSolveSparse(Highs* h, dense_array_t<double> rhs) {
246304
HighsInt num_row = h->getNumRow();
247305

248306
py::buffer_info rhs_info = rhs.request();
@@ -1110,10 +1168,10 @@ PYBIND11_MODULE(_core, m, py::mod_gil_not_used()) {
11101168
.def("getObjectiveValue", &Highs::getObjectiveValue)
11111169
.def("getDualObjectiveValue", &Highs::getDualObjectiveValue)
11121170
.def("getBasicVariables", &highs_getBasicVariables)
1113-
// .def("getBasisInverseRow", &highs_getBasisInverseRow)
1114-
// .def("getBasisInverseRowSparse", &highs_getBasisInverseRowSparse)
1115-
// .def("getBasisInverseCol", &highs_getBasisInverseCol)
1116-
// .def("getBasisInverseColSparse", &highs_getBasisInverseColSparse)
1171+
.def("getBasisInverseRow", &highs_getBasisInverseRow)
1172+
.def("getBasisInverseRowSparse", &highs_getBasisInverseRowSparse)
1173+
.def("getBasisInverseCol", &highs_getBasisInverseCol)
1174+
.def("getBasisInverseColSparse", &highs_getBasisInverseColSparse)
11171175
.def("getBasisSolve", &highs_getBasisSolve)
11181176
.def("getBasisSolveSparse", &highs_getBasisSolveSparse)
11191177
.def("getBasisTransposeSolve", &highs_getBasisTransposeSolve)

0 commit comments

Comments
 (0)