From 25fad30e11a204040db751a5c571edc68483f823 Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Mon, 25 Mar 2024 18:20:43 +0100 Subject: [PATCH] math_opt update --- ortools/math_opt/core/BUILD.bazel | 18 +-- ortools/math_opt/core/c_api/solver.cc | 4 +- ortools/math_opt/core/python/BUILD.bazel | 2 +- ortools/math_opt/core/python/solver.cc | 2 +- ortools/math_opt/core/solve_interrupter.cc | 104 ------------ ortools/math_opt/core/solve_interrupter.h | 151 ------------------ ortools/math_opt/core/solver.h | 2 +- ortools/math_opt/core/solver_interface.h | 2 +- ortools/math_opt/cpp/BUILD.bazel | 4 +- .../compute_infeasible_subsystem_arguments.h | 2 +- ortools/math_opt/cpp/solve_arguments.h | 2 +- ortools/math_opt/solvers/BUILD.bazel | 14 +- ortools/math_opt/solvers/cp_sat_solver.cc | 2 +- ortools/math_opt/solvers/cp_sat_solver.h | 2 +- ortools/math_opt/solvers/glop_solver.cc | 2 +- ortools/math_opt/solvers/glop_solver.h | 2 +- ortools/math_opt/solvers/glpk_solver.cc | 2 +- ortools/math_opt/solvers/glpk_solver.h | 2 +- ortools/math_opt/solvers/gscip_solver.cc | 2 +- ortools/math_opt/solvers/gscip_solver.h | 2 +- ortools/math_opt/solvers/gurobi_callback.cc | 2 +- ortools/math_opt/solvers/gurobi_callback.h | 2 +- ortools/math_opt/solvers/gurobi_solver.cc | 2 +- ortools/math_opt/solvers/gurobi_solver.h | 2 +- ortools/math_opt/solvers/pdlp_solver.cc | 2 +- ortools/math_opt/solvers/pdlp_solver.h | 2 +- 26 files changed, 33 insertions(+), 302 deletions(-) delete mode 100644 ortools/math_opt/core/solve_interrupter.cc delete mode 100644 ortools/math_opt/core/solve_interrupter.h diff --git a/ortools/math_opt/core/BUILD.bazel b/ortools/math_opt/core/BUILD.bazel index abb5f3a67c..aa95a0c9e7 100644 --- a/ortools/math_opt/core/BUILD.bazel +++ b/ortools/math_opt/core/BUILD.bazel @@ -80,7 +80,6 @@ cc_library( hdrs = ["solver_interface.h"], deps = [ ":non_streamable_solver_init_arguments", - ":solve_interrupter", "//ortools/base:map_util", "//ortools/base:status_macros", "//ortools/math_opt:callback_cc_proto", @@ -91,6 +90,7 @@ cc_library( "//ortools/math_opt:parameters_cc_proto", "//ortools/math_opt:result_cc_proto", "//ortools/port:proto_utils", + "//ortools/util:solve_interrupter", "@com_google_absl//absl/base:core_headers", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/log:check", @@ -109,7 +109,6 @@ cc_library( ":math_opt_proto_utils", ":model_summary", ":non_streamable_solver_init_arguments", - ":solve_interrupter", ":solver_debug", ":solver_interface", "//ortools/base:status_macros", @@ -127,6 +126,7 @@ cc_library( "//ortools/math_opt/validators:result_validator", "//ortools/math_opt/validators:solve_parameters_validator", "//ortools/port:proto_utils", + "//ortools/util:solve_interrupter", "@com_google_absl//absl/log:check", "@com_google_absl//absl/memory", "@com_google_absl//absl/status", @@ -135,20 +135,6 @@ cc_library( ], ) -cc_library( - name = "solve_interrupter", - srcs = ["solve_interrupter.cc"], - hdrs = ["solve_interrupter.h"], - deps = [ - "//ortools/base:intops", - "//ortools/base:linked_hash_map", - "//ortools/base:logging", - "@com_google_absl//absl/base:core_headers", - "@com_google_absl//absl/strings", - "@com_google_absl//absl/synchronization", - ], -) - cc_library( name = "non_streamable_solver_init_arguments", srcs = ["non_streamable_solver_init_arguments.cc"], diff --git a/ortools/math_opt/core/c_api/solver.cc b/ortools/math_opt/core/c_api/solver.cc index f6c5468ed4..e59b63d533 100644 --- a/ortools/math_opt/core/c_api/solver.cc +++ b/ortools/math_opt/core/c_api/solver.cc @@ -26,14 +26,14 @@ #include "absl/status/statusor.h" #include "ortools/base/status_builder.h" #include "ortools/base/status_macros.h" -#include "ortools/math_opt/core/solve_interrupter.h" #include "ortools/math_opt/core/solver.h" #include "ortools/math_opt/model.pb.h" #include "ortools/math_opt/parameters.pb.h" #include "ortools/math_opt/result.pb.h" +#include "ortools/util/solve_interrupter.h" struct MathOptInterrupter { - operations_research::math_opt::SolveInterrupter cpp_interrupter; + operations_research::SolveInterrupter cpp_interrupter; }; namespace operations_research::math_opt { diff --git a/ortools/math_opt/core/python/BUILD.bazel b/ortools/math_opt/core/python/BUILD.bazel index 63cc2da306..0c08f02fad 100644 --- a/ortools/math_opt/core/python/BUILD.bazel +++ b/ortools/math_opt/core/python/BUILD.bazel @@ -47,9 +47,9 @@ pybind_extension( "//ortools/math_opt:model_update_cc_proto", "//ortools/math_opt:parameters_cc_proto", "//ortools/math_opt:result_cc_proto", - "//ortools/math_opt/core:solve_interrupter", "//ortools/math_opt/core:solver", "//ortools/math_opt/core:solver_debug", + "//ortools/util:solve_interrupter", "@com_google_absl//absl/memory", "@com_google_absl//absl/status:statusor", "@pybind11_abseil//pybind11_abseil:import_status_module", diff --git a/ortools/math_opt/core/python/solver.cc b/ortools/math_opt/core/python/solver.cc index 0e5c87b8e2..8e083bee82 100644 --- a/ortools/math_opt/core/python/solver.cc +++ b/ortools/math_opt/core/python/solver.cc @@ -27,7 +27,6 @@ #include "absl/status/statusor.h" #include "ortools/base/status_macros.h" #include "ortools/math_opt/callback.pb.h" -#include "ortools/math_opt/core/solve_interrupter.h" #include "ortools/math_opt/core/solver_debug.h" #include "ortools/math_opt/infeasible_subsystem.pb.h" #include "ortools/math_opt/model.pb.h" @@ -35,6 +34,7 @@ #include "ortools/math_opt/model_update.pb.h" #include "ortools/math_opt/parameters.pb.h" #include "ortools/math_opt/result.pb.h" +#include "ortools/util/solve_interrupter.h" #include "pybind11/attr.h" #include "pybind11/cast.h" #include "pybind11/gil.h" diff --git a/ortools/math_opt/core/solve_interrupter.cc b/ortools/math_opt/core/solve_interrupter.cc deleted file mode 100644 index 5a4c7b68bb..0000000000 --- a/ortools/math_opt/core/solve_interrupter.cc +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2010-2024 Google LLC -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "ortools/math_opt/core/solve_interrupter.h" - -#include -#include -#include -#include -#include - -#include "absl/synchronization/mutex.h" -#include "ortools/base/linked_hash_map.h" -#include "ortools/base/logging.h" -#include "ortools/base/strong_int.h" - -namespace operations_research { -namespace math_opt { - -void SolveInterrupter::Interrupt() { - const absl::MutexLock lock(&mutex_); - - // Here we don't use compare_exchange_strong since we need to hold the lock - // before changing the value of interrupted_ anyway. So there is no need to - // use this complex function. - if (interrupted_.load()) { - // We must not call the callbacks more than once. - return; - } - - // We need to change this value while holding the lock since in - // AddInterruptionCallback() we must know if we need to call the new callback - // of if this function has called it. - interrupted_ = true; - - // We are holding the lock while calling callbacks. This make it impossible to - // call Interrupt(), AddInterruptionCallback(), or - // RemoveInterruptionCallback() from a callback but it ensures that external - // code that can modify callbacks_ will wait the end of Interrupt. - for (const auto& [callback_id, callback] : callbacks_) { - callback(); - } -} - -SolveInterrupter::CallbackId SolveInterrupter::AddInterruptionCallback( - Callback callback) { - const absl::MutexLock lock(&mutex_); - - // We must make this call while holding the lock since we want to be sure that - // the calls to the callbacks_ won't occur before we registered the new - // one. If we were not holding the lock, this could return false and before we - // could add the new callback to callbacks_, the Interrupt() function may - // still have called them. - // - // We make the call before putting the callback in the map to since we need to - // move it in place. - if (interrupted_.load()) { - callback(); - } - - const CallbackId id = next_callback_id_; - ++next_callback_id_; - CHECK(callbacks_.try_emplace(id, std::move(callback)).second); - return id; -} - -void SolveInterrupter::RemoveInterruptionCallback(CallbackId id) { - const absl::MutexLock lock(&mutex_); - CHECK_EQ(callbacks_.erase(id), 1) << "unregistered callback id: " << id; -} - -ScopedSolveInterrupterCallback::ScopedSolveInterrupterCallback( - SolveInterrupter* const interrupter, SolveInterrupter::Callback callback) - : interrupter_(interrupter), - callback_id_( - interrupter != nullptr - ? std::make_optional( - interrupter->AddInterruptionCallback(std::move(callback))) - : std::nullopt) {} - -ScopedSolveInterrupterCallback::~ScopedSolveInterrupterCallback() { - RemoveCallbackIfNecessary(); -} - -void ScopedSolveInterrupterCallback::RemoveCallbackIfNecessary() { - if (callback_id_) { - CHECK_NE(interrupter_, nullptr); - interrupter_->RemoveInterruptionCallback(*callback_id_); - callback_id_.reset(); - } -} - -} // namespace math_opt -} // namespace operations_research diff --git a/ortools/math_opt/core/solve_interrupter.h b/ortools/math_opt/core/solve_interrupter.h deleted file mode 100644 index 335f6f1552..0000000000 --- a/ortools/math_opt/core/solve_interrupter.h +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright 2010-2024 Google LLC -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef OR_TOOLS_MATH_OPT_CORE_SOLVE_INTERRUPTER_H_ -#define OR_TOOLS_MATH_OPT_CORE_SOLVE_INTERRUPTER_H_ - -#include -#include -#include -#include -#include - -#include "absl/base/thread_annotations.h" -#include "absl/strings/string_view.h" -#include "absl/synchronization/mutex.h" -#include "ortools/base/linked_hash_map.h" -#include "ortools/base/strong_int.h" - -namespace operations_research { -namespace math_opt { - -// Interrupter used by solvers to know if/when they should interrupt the solve. -// -// Once triggered with Interrupt(), an interrupter can't be reset. It can be -// triggered from any thread. -// -// Thread-safety: APIs on this class are safe to call concurrently from multiple -// threads. -class SolveInterrupter { - public: - // Id used to identify a callback. - DEFINE_STRONG_INT_TYPE(CallbackId, int64_t); - - using Callback = std::function; - - SolveInterrupter() = default; - - SolveInterrupter(const SolveInterrupter&) = delete; - SolveInterrupter& operator=(const SolveInterrupter&) = delete; - - // Interrupts the solve as soon as possible. - // - // Once requested the interruption can't be reset. The user should use a new - // SolveInterrupter for later solves. - // - // It is safe to call this function multiple times. Only the first call will - // have visible effects; other calls will be ignored. - void Interrupt(); - - // Returns true if the solve interruption has been requested. - // - // This API is fast; it costs the read of an atomic. - inline bool IsInterrupted() const { return interrupted_.load(); } - - // Registers a callback to be called when the interruption is requested. - // - // The callback is immediately called if the interrupter has already been - // triggered or if it is triggered during the registration. This is typically - // useful for a solver implementation so that it does not have to test - // IsInterrupted() to do the same thing it does in the callback. Simply - // registering the callback is enough. - // - // The callback function can't make calls to AddInterruptionCallback(), - // RemoveInterruptionCallback() and Interrupt(). This would result is a - // deadlock. Calling IsInterrupted() is fine though. - CallbackId AddInterruptionCallback(Callback callback); - - // Unregisters a callback previously registered. It fails (with a CHECK) if - // the callback was already unregistered or unkonwn. After this calls returns, - // the caller can assume the callback won't be called. - // - // This function can't be called from a callback since this would result in a - // deadlock. - void RemoveInterruptionCallback(CallbackId id); - - private: - // This atomic must never be reset to false! - // - // The mutex_ should be held when setting it to true. - std::atomic interrupted_ = false; - - absl::Mutex mutex_; - - // The id to use for the next registered callback. - CallbackId next_callback_id_ ABSL_GUARDED_BY(mutex_) = {}; - - // The list of callbacks. We use a linked_hash_map to make sure the order of - // calls to callback when the interrupter is triggered is stable. - gtl::linked_hash_map callbacks_ ABSL_GUARDED_BY(mutex_); -}; - -// Class implementing RAII for interruption callbacks. -// -// Usage: -// -// SolveInterrupter* const interrupter = ...; -// { -// const ScopedSolveInterrupterCallback scoped_intr_cb(interrupter, [](){ -// // Do something when/if interrupter is not nullptr and is triggered. -// } -// ... -// } -// // At this point, the callback will have been removed. -// -// The function RemoveCallbackIfNecessary() can be used to remove the callback -// before the destruction of this object. -class ScopedSolveInterrupterCallback { - public: - // Adds a callback to the interrupter if it is not nullptr. Does nothing when - // interrupter is nullptr. - ScopedSolveInterrupterCallback(SolveInterrupter* interrupter, - SolveInterrupter::Callback callback); - - ScopedSolveInterrupterCallback(const ScopedSolveInterrupterCallback&) = - delete; - ScopedSolveInterrupterCallback& operator=( - const ScopedSolveInterrupterCallback&) = delete; - - // Removes the callback if necessary. - ~ScopedSolveInterrupterCallback(); - - // Removes the callback from the interrupter. If it has already been removed - // by a previous call or if a null interrupter was passed to the constructor, - // this function has no effect. - void RemoveCallbackIfNecessary(); - - // Returns the optional interrupter. - SolveInterrupter* interrupter() const { return interrupter_; } - - private: - // Optional interrupter. - SolveInterrupter* const interrupter_; - - // Unset after the callback has been reset. - std::optional callback_id_; -}; - -} // namespace math_opt -} // namespace operations_research - -#endif // OR_TOOLS_MATH_OPT_CORE_SOLVE_INTERRUPTER_H_ diff --git a/ortools/math_opt/core/solver.h b/ortools/math_opt/core/solver.h index 145f06b3f2..d598f2c0d5 100644 --- a/ortools/math_opt/core/solver.h +++ b/ortools/math_opt/core/solver.h @@ -22,7 +22,6 @@ #include "ortools/math_opt/callback.pb.h" #include "ortools/math_opt/core/concurrent_calls_guard.h" #include "ortools/math_opt/core/model_summary.h" -#include "ortools/math_opt/core/solve_interrupter.h" #include "ortools/math_opt/core/solver_interface.h" #include "ortools/math_opt/infeasible_subsystem.pb.h" #include "ortools/math_opt/model.pb.h" @@ -30,6 +29,7 @@ #include "ortools/math_opt/model_update.pb.h" #include "ortools/math_opt/parameters.pb.h" #include "ortools/math_opt/result.pb.h" +#include "ortools/util/solve_interrupter.h" namespace operations_research { namespace math_opt { diff --git a/ortools/math_opt/core/solver_interface.h b/ortools/math_opt/core/solver_interface.h index 0ea41e448e..88f542c221 100644 --- a/ortools/math_opt/core/solver_interface.h +++ b/ortools/math_opt/core/solver_interface.h @@ -26,13 +26,13 @@ #include "absl/synchronization/mutex.h" #include "ortools/math_opt/callback.pb.h" #include "ortools/math_opt/core/non_streamable_solver_init_arguments.h" -#include "ortools/math_opt/core/solve_interrupter.h" #include "ortools/math_opt/infeasible_subsystem.pb.h" #include "ortools/math_opt/model.pb.h" #include "ortools/math_opt/model_parameters.pb.h" #include "ortools/math_opt/model_update.pb.h" #include "ortools/math_opt/parameters.pb.h" #include "ortools/math_opt/result.pb.h" +#include "ortools/util/solve_interrupter.h" namespace operations_research { namespace math_opt { diff --git a/ortools/math_opt/cpp/BUILD.bazel b/ortools/math_opt/cpp/BUILD.bazel index 5399a3df62..6945d63592 100644 --- a/ortools/math_opt/cpp/BUILD.bazel +++ b/ortools/math_opt/cpp/BUILD.bazel @@ -334,8 +334,8 @@ cc_library( ":model_solve_parameters", ":parameters", "//ortools/base:status_macros", - "//ortools/math_opt/core:solve_interrupter", "//ortools/math_opt/storage:model_storage", + "//ortools/util:solve_interrupter", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/status", ], @@ -505,7 +505,7 @@ cc_library( deps = [ ":message_callback", ":parameters", - "//ortools/math_opt/core:solve_interrupter", + "//ortools/util:solve_interrupter", ], ) diff --git a/ortools/math_opt/cpp/compute_infeasible_subsystem_arguments.h b/ortools/math_opt/cpp/compute_infeasible_subsystem_arguments.h index ef03f196ac..3eb6b645da 100644 --- a/ortools/math_opt/cpp/compute_infeasible_subsystem_arguments.h +++ b/ortools/math_opt/cpp/compute_infeasible_subsystem_arguments.h @@ -14,9 +14,9 @@ #ifndef OR_TOOLS_MATH_OPT_CPP_COMPUTE_INFEASIBLE_SUBSYSTEM_ARGUMENTS_H_ #define OR_TOOLS_MATH_OPT_CPP_COMPUTE_INFEASIBLE_SUBSYSTEM_ARGUMENTS_H_ -#include "ortools/math_opt/core/solve_interrupter.h" // IWYU pragma: export #include "ortools/math_opt/cpp/message_callback.h" // IWYU pragma: export #include "ortools/math_opt/cpp/parameters.h" // IWYU pragma: export +#include "ortools/util/solve_interrupter.h" // IWYU pragma: export namespace operations_research::math_opt { diff --git a/ortools/math_opt/cpp/solve_arguments.h b/ortools/math_opt/cpp/solve_arguments.h index ae5dd81916..746b01f5df 100644 --- a/ortools/math_opt/cpp/solve_arguments.h +++ b/ortools/math_opt/cpp/solve_arguments.h @@ -18,12 +18,12 @@ #define OR_TOOLS_MATH_OPT_CPP_SOLVE_ARGUMENTS_H_ #include "absl/status/status.h" -#include "ortools/math_opt/core/solve_interrupter.h" // IWYU pragma: export #include "ortools/math_opt/cpp/callback.h" // IWYU pragma: export #include "ortools/math_opt/cpp/message_callback.h" // IWYU pragma: export #include "ortools/math_opt/cpp/model_solve_parameters.h" // IWYU pragma: export #include "ortools/math_opt/cpp/parameters.h" // IWYU pragma: export #include "ortools/math_opt/storage/model_storage.h" +#include "ortools/util/solve_interrupter.h" // IWYU pragma: export namespace operations_research::math_opt { diff --git a/ortools/math_opt/solvers/BUILD.bazel b/ortools/math_opt/solvers/BUILD.bazel index d0905e24fe..cb9bfc3029 100644 --- a/ortools/math_opt/solvers/BUILD.bazel +++ b/ortools/math_opt/solvers/BUILD.bazel @@ -44,13 +44,13 @@ cc_library( "//ortools/math_opt/core:invalid_indicators", "//ortools/math_opt/core:inverted_bounds", "//ortools/math_opt/core:math_opt_proto_utils", - "//ortools/math_opt/core:solve_interrupter", "//ortools/math_opt/core:solver_interface", "//ortools/math_opt/core:sparse_submatrix", "//ortools/math_opt/core:sparse_vector_view", "//ortools/math_opt/solvers/gscip:gscip_solver_constraint_handler", "//ortools/math_opt/validators:callback_validator", "//ortools/port:proto_utils", + "//ortools/util:solve_interrupter", "@com_google_absl//absl/cleanup", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/container:flat_hash_set", @@ -117,10 +117,10 @@ cc_library( "//ortools/math_opt:solution_cc_proto", "//ortools/math_opt:sparse_containers_cc_proto", "//ortools/math_opt/core:math_opt_proto_utils", - "//ortools/math_opt/core:solve_interrupter", "//ortools/math_opt/core:solver_interface", "//ortools/math_opt/core:sparse_vector_view", "//ortools/math_opt/solvers/gurobi:g_gurobi", + "//ortools/util:solve_interrupter", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/status", "@com_google_absl//absl/status:statusor", @@ -164,13 +164,13 @@ cc_library( "//ortools/math_opt/core:inverted_bounds", "//ortools/math_opt/core:math_opt_proto_utils", "//ortools/math_opt/core:non_streamable_solver_init_arguments", - "//ortools/math_opt/core:solve_interrupter", "//ortools/math_opt/core:solver_interface", "//ortools/math_opt/core:sorted", "//ortools/math_opt/core:sparse_vector_view", "//ortools/math_opt/solvers/gurobi:g_gurobi", "//ortools/math_opt/validators:callback_validator", "//ortools/port:proto_utils", + "//ortools/util:solve_interrupter", "//ortools/util:testing_utils", "@com_google_absl//absl/algorithm:container", "@com_google_absl//absl/container:flat_hash_map", @@ -217,12 +217,12 @@ cc_library( "//ortools/math_opt:sparse_containers_cc_proto", "//ortools/math_opt/core:inverted_bounds", "//ortools/math_opt/core:math_opt_proto_utils", - "//ortools/math_opt/core:solve_interrupter", "//ortools/math_opt/core:solver_interface", "//ortools/math_opt/core:sparse_vector_view", "//ortools/math_opt/validators:callback_validator", "//ortools/port:proto_utils", "//ortools/util:logging", + "//ortools/util:solve_interrupter", "//ortools/util:strong_integers", "//ortools/util:time_limit", "@com_google_absl//absl/cleanup", @@ -263,13 +263,13 @@ cc_library( "//ortools/math_opt:sparse_containers_cc_proto", "//ortools/math_opt/core:inverted_bounds", "//ortools/math_opt/core:math_opt_proto_utils", - "//ortools/math_opt/core:solve_interrupter", "//ortools/math_opt/core:solver_interface", "//ortools/math_opt/core:sparse_vector_view", "//ortools/math_opt/io:proto_converter", "//ortools/math_opt/validators:callback_validator", "//ortools/port:proto_utils", "//ortools/sat:sat_parameters_cc_proto", + "//ortools/util:solve_interrupter", "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/log", "@com_google_absl//absl/log:check", @@ -406,7 +406,6 @@ cc_library( "//ortools/math_opt:sparse_containers_cc_proto", "//ortools/math_opt/core:inverted_bounds", "//ortools/math_opt/core:math_opt_proto_utils", - "//ortools/math_opt/core:solve_interrupter", "//ortools/math_opt/core:solver_interface", "//ortools/math_opt/validators:callback_validator", "//ortools/pdlp:iteration_stats", @@ -415,6 +414,7 @@ cc_library( "//ortools/pdlp:solve_log_cc_proto", "//ortools/pdlp:solvers_cc_proto", "//ortools/port:proto_utils", + "//ortools/util:solve_interrupter", "@com_google_absl//absl/log", "@com_google_absl//absl/memory", "@com_google_absl//absl/status", @@ -484,7 +484,6 @@ cc_library( "//ortools/math_opt/core:empty_bounds", "//ortools/math_opt/core:inverted_bounds", "//ortools/math_opt/core:math_opt_proto_utils", - "//ortools/math_opt/core:solve_interrupter", "//ortools/math_opt/core:solver_interface", "//ortools/math_opt/core:sparse_submatrix", "//ortools/math_opt/core:sparse_vector_view", @@ -493,6 +492,7 @@ cc_library( "//ortools/math_opt/solvers/glpk:rays", "//ortools/math_opt/validators:callback_validator", "//ortools/port:proto_utils", + "//ortools/util:solve_interrupter", "@com_google_absl//absl/cleanup", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/log", diff --git a/ortools/math_opt/solvers/cp_sat_solver.cc b/ortools/math_opt/solvers/cp_sat_solver.cc index 9b40de8192..26cf41421c 100644 --- a/ortools/math_opt/solvers/cp_sat_solver.cc +++ b/ortools/math_opt/solvers/cp_sat_solver.cc @@ -44,7 +44,6 @@ #include "ortools/math_opt/callback.pb.h" #include "ortools/math_opt/core/inverted_bounds.h" #include "ortools/math_opt/core/math_opt_proto_utils.h" -#include "ortools/math_opt/core/solve_interrupter.h" #include "ortools/math_opt/core/solver_interface.h" #include "ortools/math_opt/core/sparse_vector_view.h" #include "ortools/math_opt/infeasible_subsystem.pb.h" @@ -59,6 +58,7 @@ #include "ortools/math_opt/validators/callback_validator.h" #include "ortools/port/proto_utils.h" #include "ortools/sat/sat_parameters.pb.h" +#include "ortools/util/solve_interrupter.h" namespace operations_research { namespace math_opt { diff --git a/ortools/math_opt/solvers/cp_sat_solver.h b/ortools/math_opt/solvers/cp_sat_solver.h index 6839ba9516..f5622c3180 100644 --- a/ortools/math_opt/solvers/cp_sat_solver.h +++ b/ortools/math_opt/solvers/cp_sat_solver.h @@ -23,7 +23,6 @@ #include "ortools/linear_solver/linear_solver.pb.h" #include "ortools/math_opt/callback.pb.h" #include "ortools/math_opt/core/inverted_bounds.h" -#include "ortools/math_opt/core/solve_interrupter.h" #include "ortools/math_opt/core/solver_interface.h" #include "ortools/math_opt/infeasible_subsystem.pb.h" #include "ortools/math_opt/model.pb.h" @@ -32,6 +31,7 @@ #include "ortools/math_opt/parameters.pb.h" #include "ortools/math_opt/result.pb.h" #include "ortools/math_opt/sparse_containers.pb.h" +#include "ortools/util/solve_interrupter.h" namespace operations_research { namespace math_opt { diff --git a/ortools/math_opt/solvers/glop_solver.cc b/ortools/math_opt/solvers/glop_solver.cc index cc33d174f5..addfdab6ad 100644 --- a/ortools/math_opt/solvers/glop_solver.cc +++ b/ortools/math_opt/solvers/glop_solver.cc @@ -47,7 +47,6 @@ #include "ortools/math_opt/callback.pb.h" #include "ortools/math_opt/core/inverted_bounds.h" #include "ortools/math_opt/core/math_opt_proto_utils.h" -#include "ortools/math_opt/core/solve_interrupter.h" #include "ortools/math_opt/core/solver_interface.h" #include "ortools/math_opt/core/sparse_vector_view.h" #include "ortools/math_opt/infeasible_subsystem.pb.h" @@ -61,6 +60,7 @@ #include "ortools/math_opt/validators/callback_validator.h" #include "ortools/port/proto_utils.h" #include "ortools/util/logging.h" +#include "ortools/util/solve_interrupter.h" #include "ortools/util/strong_integers.h" #include "ortools/util/time_limit.h" diff --git a/ortools/math_opt/solvers/glop_solver.h b/ortools/math_opt/solvers/glop_solver.h index d4b382a5f5..634ee13e5d 100644 --- a/ortools/math_opt/solvers/glop_solver.h +++ b/ortools/math_opt/solvers/glop_solver.h @@ -29,7 +29,6 @@ #include "ortools/lp_data/lp_types.h" #include "ortools/math_opt/callback.pb.h" #include "ortools/math_opt/core/inverted_bounds.h" -#include "ortools/math_opt/core/solve_interrupter.h" #include "ortools/math_opt/core/solver_interface.h" #include "ortools/math_opt/infeasible_subsystem.pb.h" #include "ortools/math_opt/model.pb.h" @@ -39,6 +38,7 @@ #include "ortools/math_opt/result.pb.h" #include "ortools/math_opt/solution.pb.h" #include "ortools/math_opt/sparse_containers.pb.h" +#include "ortools/util/solve_interrupter.h" namespace operations_research { namespace math_opt { diff --git a/ortools/math_opt/solvers/glpk_solver.cc b/ortools/math_opt/solvers/glpk_solver.cc index de652eb2ec..819fecfb74 100644 --- a/ortools/math_opt/solvers/glpk_solver.cc +++ b/ortools/math_opt/solvers/glpk_solver.cc @@ -48,7 +48,6 @@ #include "ortools/math_opt/core/empty_bounds.h" #include "ortools/math_opt/core/inverted_bounds.h" #include "ortools/math_opt/core/math_opt_proto_utils.h" -#include "ortools/math_opt/core/solve_interrupter.h" #include "ortools/math_opt/core/solver_interface.h" #include "ortools/math_opt/core/sparse_submatrix.h" #include "ortools/math_opt/core/sparse_vector_view.h" @@ -67,6 +66,7 @@ #include "ortools/math_opt/sparse_containers.pb.h" #include "ortools/math_opt/validators/callback_validator.h" #include "ortools/port/proto_utils.h" +#include "ortools/util/solve_interrupter.h" namespace operations_research { namespace math_opt { diff --git a/ortools/math_opt/solvers/glpk_solver.h b/ortools/math_opt/solvers/glpk_solver.h index afd4ddbcf8..19c0cb18d4 100644 --- a/ortools/math_opt/solvers/glpk_solver.h +++ b/ortools/math_opt/solvers/glpk_solver.h @@ -25,7 +25,6 @@ #include "absl/status/statusor.h" #include "ortools/base/logging.h" #include "ortools/math_opt/callback.pb.h" -#include "ortools/math_opt/core/solve_interrupter.h" #include "ortools/math_opt/core/solver_interface.h" #include "ortools/math_opt/infeasible_subsystem.pb.h" #include "ortools/math_opt/model.pb.h" @@ -35,6 +34,7 @@ #include "ortools/math_opt/result.pb.h" #include "ortools/math_opt/solution.pb.h" #include "ortools/math_opt/sparse_containers.pb.h" +#include "ortools/util/solve_interrupter.h" extern "C" { #include diff --git a/ortools/math_opt/solvers/gscip_solver.cc b/ortools/math_opt/solvers/gscip_solver.cc index fdf7432664..cb22fb0b72 100644 --- a/ortools/math_opt/solvers/gscip_solver.cc +++ b/ortools/math_opt/solvers/gscip_solver.cc @@ -51,7 +51,6 @@ #include "ortools/math_opt/core/invalid_indicators.h" #include "ortools/math_opt/core/inverted_bounds.h" #include "ortools/math_opt/core/math_opt_proto_utils.h" -#include "ortools/math_opt/core/solve_interrupter.h" #include "ortools/math_opt/core/solver_interface.h" #include "ortools/math_opt/core/sparse_submatrix.h" #include "ortools/math_opt/core/sparse_vector_view.h" @@ -67,6 +66,7 @@ #include "ortools/math_opt/sparse_containers.pb.h" #include "ortools/math_opt/validators/callback_validator.h" #include "ortools/port/proto_utils.h" +#include "ortools/util/solve_interrupter.h" #include "scip/type_cons.h" #include "scip/type_var.h" diff --git a/ortools/math_opt/solvers/gscip_solver.h b/ortools/math_opt/solvers/gscip_solver.h index cefd68e001..2e94c213ec 100644 --- a/ortools/math_opt/solvers/gscip_solver.h +++ b/ortools/math_opt/solvers/gscip_solver.h @@ -32,7 +32,6 @@ #include "ortools/math_opt/callback.pb.h" #include "ortools/math_opt/core/invalid_indicators.h" #include "ortools/math_opt/core/inverted_bounds.h" -#include "ortools/math_opt/core/solve_interrupter.h" #include "ortools/math_opt/core/solver_interface.h" #include "ortools/math_opt/infeasible_subsystem.pb.h" #include "ortools/math_opt/model.pb.h" @@ -42,6 +41,7 @@ #include "ortools/math_opt/result.pb.h" #include "ortools/math_opt/solvers/gscip/gscip_solver_constraint_handler.h" #include "ortools/math_opt/sparse_containers.pb.h" +#include "ortools/util/solve_interrupter.h" #include "scip/type_cons.h" #include "scip/type_var.h" diff --git a/ortools/math_opt/solvers/gurobi_callback.cc b/ortools/math_opt/solvers/gurobi_callback.cc index 1e20e78be1..8249b1d3ca 100644 --- a/ortools/math_opt/solvers/gurobi_callback.cc +++ b/ortools/math_opt/solvers/gurobi_callback.cc @@ -35,12 +35,12 @@ #include "ortools/gurobi/environment.h" #include "ortools/math_opt/callback.pb.h" #include "ortools/math_opt/core/math_opt_proto_utils.h" -#include "ortools/math_opt/core/solve_interrupter.h" #include "ortools/math_opt/core/solver_interface.h" #include "ortools/math_opt/core/sparse_vector_view.h" #include "ortools/math_opt/solution.pb.h" #include "ortools/math_opt/solvers/message_callback_data.h" #include "ortools/math_opt/sparse_containers.pb.h" +#include "ortools/util/solve_interrupter.h" namespace operations_research { namespace math_opt { diff --git a/ortools/math_opt/solvers/gurobi_callback.h b/ortools/math_opt/solvers/gurobi_callback.h index e0b2bc352b..81513acefb 100644 --- a/ortools/math_opt/solvers/gurobi_callback.h +++ b/ortools/math_opt/solvers/gurobi_callback.h @@ -23,11 +23,11 @@ #include "ortools/base/linked_hash_map.h" #include "ortools/gurobi/environment.h" #include "ortools/math_opt/callback.pb.h" -#include "ortools/math_opt/core/solve_interrupter.h" #include "ortools/math_opt/core/solver_interface.h" #include "ortools/math_opt/solvers/gurobi/g_gurobi.h" #include "ortools/math_opt/solvers/message_callback_data.h" #include "ortools/math_opt/sparse_containers.pb.h" +#include "ortools/util/solve_interrupter.h" namespace operations_research { namespace math_opt { diff --git a/ortools/math_opt/solvers/gurobi_solver.cc b/ortools/math_opt/solvers/gurobi_solver.cc index e80f9be7a4..c58d7f7c00 100644 --- a/ortools/math_opt/solvers/gurobi_solver.cc +++ b/ortools/math_opt/solvers/gurobi_solver.cc @@ -51,7 +51,6 @@ #include "ortools/math_opt/core/inverted_bounds.h" #include "ortools/math_opt/core/math_opt_proto_utils.h" #include "ortools/math_opt/core/non_streamable_solver_init_arguments.h" -#include "ortools/math_opt/core/solve_interrupter.h" #include "ortools/math_opt/core/solver_interface.h" #include "ortools/math_opt/core/sorted.h" #include "ortools/math_opt/core/sparse_vector_view.h" @@ -69,6 +68,7 @@ #include "ortools/math_opt/sparse_containers.pb.h" #include "ortools/math_opt/validators/callback_validator.h" #include "ortools/port/proto_utils.h" +#include "ortools/util/solve_interrupter.h" #include "ortools/util/testing_utils.h" namespace operations_research { diff --git a/ortools/math_opt/solvers/gurobi_solver.h b/ortools/math_opt/solvers/gurobi_solver.h index ab03067beb..cb95e2cee9 100644 --- a/ortools/math_opt/solvers/gurobi_solver.h +++ b/ortools/math_opt/solvers/gurobi_solver.h @@ -32,7 +32,6 @@ #include "ortools/math_opt/callback.pb.h" #include "ortools/math_opt/core/invalid_indicators.h" #include "ortools/math_opt/core/inverted_bounds.h" -#include "ortools/math_opt/core/solve_interrupter.h" #include "ortools/math_opt/core/solver_interface.h" #include "ortools/math_opt/infeasible_subsystem.pb.h" #include "ortools/math_opt/model.pb.h" @@ -45,6 +44,7 @@ #include "ortools/math_opt/solvers/gurobi_callback.h" #include "ortools/math_opt/solvers/message_callback_data.h" #include "ortools/math_opt/sparse_containers.pb.h" +#include "ortools/util/solve_interrupter.h" namespace operations_research { namespace math_opt { diff --git a/ortools/math_opt/solvers/pdlp_solver.cc b/ortools/math_opt/solvers/pdlp_solver.cc index 41c798ddb3..194d975d31 100644 --- a/ortools/math_opt/solvers/pdlp_solver.cc +++ b/ortools/math_opt/solvers/pdlp_solver.cc @@ -38,7 +38,6 @@ #include "ortools/math_opt/callback.pb.h" #include "ortools/math_opt/core/inverted_bounds.h" #include "ortools/math_opt/core/math_opt_proto_utils.h" -#include "ortools/math_opt/core/solve_interrupter.h" #include "ortools/math_opt/core/solver_interface.h" #include "ortools/math_opt/infeasible_subsystem.pb.h" #include "ortools/math_opt/model.pb.h" @@ -56,6 +55,7 @@ #include "ortools/pdlp/solve_log.pb.h" #include "ortools/pdlp/solvers.pb.h" #include "ortools/port/proto_utils.h" +#include "ortools/util/solve_interrupter.h" namespace operations_research { namespace math_opt { diff --git a/ortools/math_opt/solvers/pdlp_solver.h b/ortools/math_opt/solvers/pdlp_solver.h index af2064d9a2..86c1e1ce15 100644 --- a/ortools/math_opt/solvers/pdlp_solver.h +++ b/ortools/math_opt/solvers/pdlp_solver.h @@ -18,7 +18,6 @@ #include "absl/status/statusor.h" #include "ortools/math_opt/callback.pb.h" -#include "ortools/math_opt/core/solve_interrupter.h" #include "ortools/math_opt/core/solver_interface.h" #include "ortools/math_opt/infeasible_subsystem.pb.h" #include "ortools/math_opt/model.pb.h" @@ -29,6 +28,7 @@ #include "ortools/math_opt/solvers/pdlp_bridge.h" #include "ortools/pdlp/primal_dual_hybrid_gradient.h" #include "ortools/pdlp/solvers.pb.h" +#include "ortools/util/solve_interrupter.h" namespace operations_research { namespace math_opt {