Skip to content

Commit

Permalink
Merge pull request #1740 from ERGO-Code/fix-1733
Browse files Browse the repository at this point in the history
Added setBasis to highspy, both for logical basis and specific basis
  • Loading branch information
jajhall committed May 7, 2024
2 parents d146930 + 6bdca6c commit d43682a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
24 changes: 23 additions & 1 deletion examples/call_highs_from_python.py
Expand Up @@ -197,6 +197,28 @@
run_time = h.getRunTime()
print("Total HiGHS run time is ", run_time)

# Get an optimal basis

# Clear so that incumbent model is empty
h.clear()
print("25fv47 as HighsModel")

h.readModel("check/instances/25fv47.mps")

h.run()
simplex_iteration_count = h.getInfo().simplex_iteration_count
print("From initial basis, simplex iteration count =", simplex_iteration_count)
basis = h.getBasis()
h.clearSolver()

h.setBasis(basis)
h.run()
simplex_iteration_count = h.getInfo().simplex_iteration_count
print("From optimal basis, simplex iteration count =", simplex_iteration_count)
status = h.setBasis()
h.run()
simplex_iteration_count = h.getInfo().simplex_iteration_count
print("From logical basis, simplex iteration count =", simplex_iteration_count)


# Define a callback
Expand Down Expand Up @@ -316,4 +338,4 @@ def user_interrupt_callback(
print("...")
for icol in range(num_var-2, num_var):
print(icol, solution.col_value[icol],
h.basisStatusToString(basis.col_status[icol]))
h.basisStatusToString(basis.col_status[icol]))
10 changes: 10 additions & 0 deletions src/highs_bindings.cpp
Expand Up @@ -285,6 +285,14 @@ HighsStatus highs_deleteRows(Highs* h, HighsInt num_set_entries, std::vector<Hig
return h->deleteRows(num_set_entries, indices.data());
}

HighsStatus highs_setBasis(Highs* h, HighsBasis& basis) {
return h->setBasis(basis);
}

HighsStatus highs_setLogicalBasis(Highs* h) {
return h->setBasis();
}

std::tuple<HighsStatus, py::object> highs_getOptionValue(
Highs* h, const std::string& option) {
HighsOptionType option_type;
Expand Down Expand Up @@ -927,6 +935,8 @@ PYBIND11_MODULE(_core, m) {
.def("deleteVars", &highs_deleteCols) // alias
.def("deleteRows", &highs_deleteRows)
.def("setSolution", &Highs::setSolution)
.def("setBasis", &highs_setBasis)
.def("setBasis", &highs_setLogicalBasis)
.def("modelStatusToString", &Highs::modelStatusToString)
.def("solutionStatusToString", &Highs::solutionStatusToString)
.def("basisStatusToString", &Highs::basisStatusToString)
Expand Down

0 comments on commit d43682a

Please sign in to comment.