Add nullability to SolveInterrupter in linear solver (#4958)

This commit is contained in:
Guillaume Chatelet
2025-12-18 16:53:26 +01:00
committed by Corentin Le Molgat
parent a05ea60fd5
commit 5a867fd457
6 changed files with 14 additions and 7 deletions

View File

@@ -598,5 +598,6 @@ cc_library(
":linear_solver_cc_proto",
"//ortools/util:lazy_mutable_copy",
"//ortools/util:solve_interrupter",
"@abseil-cpp//absl/base:nullability",
],
)

View File

@@ -516,7 +516,6 @@ absl::string_view ToString(
}
LOG(FATAL) << "Unrecognized solver type: "
<< static_cast<int>(optimization_problem_type);
return "";
}
bool AbslParseFlag(const absl::string_view text,

View File

@@ -17,6 +17,7 @@
#include <string>
#include <utility>
#include "absl/base/nullability.h"
#include "ortools/linear_solver/linear_solver.h"
#include "ortools/linear_solver/linear_solver.pb.h"
#include "ortools/util/lazy_mutable_copy.h"
@@ -26,8 +27,9 @@ namespace operations_research {
// TODO(b/311704821): this function should not delegate to MPSolver, also true
// for the functions below.
MPSolutionResponse SolveMPModel(LazyMutableCopy<MPModelRequest> request,
const SolveInterrupter* interrupter) {
MPSolutionResponse SolveMPModel(
LazyMutableCopy<MPModelRequest> request,
const SolveInterrupter* absl_nullable interrupter) {
MPSolutionResponse response;
if (interrupter != nullptr) {
std::atomic<bool> atomic_bool = false;

View File

@@ -20,6 +20,7 @@
#include <string>
#include "absl/base/nullability.h"
#include "ortools/linear_solver/linear_solver.pb.h"
#include "ortools/util/lazy_mutable_copy.h"
#include "ortools/util/solve_interrupter.h"
@@ -41,8 +42,9 @@ namespace operations_research {
* Passing a non-null pointer with any other solver type immediately returns an
* MPSOLVER_INCOMPATIBLE_OPTIONS error.
*/
MPSolutionResponse SolveMPModel(LazyMutableCopy<MPModelRequest> request,
const SolveInterrupter* interrupter = nullptr);
MPSolutionResponse SolveMPModel(
LazyMutableCopy<MPModelRequest> request,
const SolveInterrupter* absl_nullable interrupter = nullptr);
bool SolverTypeSupportsInterruption(MPModelRequest::SolverType solver);

View File

@@ -15,11 +15,13 @@
#include <optional>
#include "absl/base/nullability.h"
#include "ortools/util/python/py_solve_interrupter.h"
namespace operations_research {
std::optional<bool> IsInterrupted(const PySolveInterrupter* interrupter) {
std::optional<bool> IsInterrupted(
const PySolveInterrupter* absl_nullable interrupter) {
if (interrupter == nullptr) {
return std::nullopt;
}

View File

@@ -31,7 +31,8 @@ namespace operations_research {
//
// The Clif/pybind11 wrapper will return a `bool | None` value, with None for
// nullopt.
std::optional<bool> IsInterrupted(const PySolveInterrupter* interrupter);
std::optional<bool> IsInterrupted(
const PySolveInterrupter* absl_nullable interrupter);
// Class that keeps a reference on a std::shared_ptr<PySolveInterrupter> to
// test that the C++ object survive the cleanup of the Python reference.