setSolution() from Highs accepts solution hint

This commit is contained in:
Pavlo Muts
2025-07-22 10:29:52 +02:00
parent 95e8a33097
commit 0ab3f0fabd
2 changed files with 18 additions and 2 deletions

View File

@@ -925,6 +925,22 @@ absl::StatusOr<SolveResultProto> HighsSolver::Solve(
return absl::OkStatus();
};
if (model_parameters.solution_hints_size() > 0) {
// Take the first solution hint and set the solution.
const SolutionHintProto& hint = model_parameters.solution_hints(0);
const int num_vars = highs_->getModel().lp_.num_col_;
// Highs accepts only full solutions, on partial solutions it will
// return an error.
if (hint.variable_values().ids_size() == num_vars) {
HighsSolution sol = HighsSolution();
sol.col_value.resize(num_vars);
for (const auto [id, val] : MakeView(hint.variable_values())) {
sol.col_value[variable_data_.at(id).index] = val;
}
RETURN_IF_ERROR(ToStatus(highs_->setSolution(sol)));
}
}
RETURN_IF_ERROR(ListInvertedBounds().ToStatus());
// TODO(b/271595607): delete this code once we upgrade HiGHS, if HiGHS does
// return a proper infeasibility status for models with empty integer bounds.

View File

@@ -164,8 +164,8 @@ INSTANTIATE_TEST_SUITE_P(HighsLpModelSolveParametersTest,
/*supports_duals=*/true,
/*supports_primal_only_warm_starts=*/false)));
// MIP hint appears to be supported by Highs::setSolution, this is not yet
// implemented.
// Highs::setSolution is implemented, but it only accepts complete solutions.
// The test below generates partial solutuions, so we skip it.
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(MipSolutionHintTest);
// HiGHS does not support branching priority.