Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added setBasis to highspy, both for logical basis and specific basis #1740

Merged
merged 2 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion examples/call_highs_from_python.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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