diff --git a/ortools/sat/BUILD.bazel b/ortools/sat/BUILD.bazel index d835841691..aa2c3197ff 100644 --- a/ortools/sat/BUILD.bazel +++ b/ortools/sat/BUILD.bazel @@ -3901,7 +3901,6 @@ cc_library( ":util", "//ortools/util:logging", "//ortools/util:sorted_interval_list", - "//ortools/util:time_limit", "@abseil-cpp//absl/log:check", ], ) diff --git a/ortools/sat/csharp/sat.i b/ortools/sat/csharp/sat.i index 4f436237f3..cfe50f0f8b 100644 --- a/ortools/sat/csharp/sat.i +++ b/ortools/sat/csharp/sat.i @@ -93,6 +93,7 @@ JAGGED_MATRIX_AS_CSHARP_ARRAY(int64_t, int64_t, long, Int64VectorVector); // Wrap the SolveWrapper class. %unignore operations_research::sat::SolveWrapper; +%unignore operations_research::sat::SolveWrapper::SolveWrapper; %unignore operations_research::sat::SolveWrapper::AddBestBoundCallbackFromClass; %unignore operations_research::sat::SolveWrapper::AddLogCallbackFromClass; %unignore operations_research::sat::SolveWrapper::AddSolutionCallback; diff --git a/ortools/sat/java/sat.i b/ortools/sat/java/sat.i index e318961736..af1b325e2b 100644 --- a/ortools/sat/java/sat.i +++ b/ortools/sat/java/sat.i @@ -169,6 +169,7 @@ PROTO2_RETURN(operations_research::sat::CpSolverResponse, // Wrap the SolveWrapper class. %unignore operations_research::sat::SolveWrapper; +%unignore operations_research::sat::SolveWrapper::SolveWrapper; %rename (addBestBoundCallback) operations_research::sat::SolveWrapper::AddBestBoundCallback; %rename (addLogCallback) operations_research::sat::SolveWrapper::AddLogCallback; %rename (addSolutionCallback) operations_research::sat::SolveWrapper::AddSolutionCallback; diff --git a/ortools/sat/swig_helper.cc b/ortools/sat/swig_helper.cc index 609d362d93..b235b1d050 100644 --- a/ortools/sat/swig_helper.cc +++ b/ortools/sat/swig_helper.cc @@ -26,6 +26,7 @@ #include "ortools/sat/cp_model_utils.h" #include "ortools/sat/model.h" #include "ortools/sat/sat_parameters.pb.h" +#include "ortools/sat/util.h" #include "ortools/util/logging.h" #include "ortools/util/sorted_interval_list.h" @@ -102,6 +103,10 @@ void SolutionCallback::SetWrapperClass(SolveWrapper* wrapper) const { bool SolutionCallback::HasResponse() const { return has_response_; } +SolveWrapper::SolveWrapper() { + shared_time_limit_ = model_.GetOrCreate(); +} + void SolveWrapper::SetParameters( const operations_research::sat::SatParameters& parameters) { model_.Add(NewSatParameters(parameters)); @@ -154,9 +159,7 @@ operations_research::sat::CpSolverResponse SolveWrapper::Solve( return operations_research::sat::SolveCpModel(model_proto, &model_); } -void SolveWrapper::StopSearch() { - ::operations_research::sat::StopSearch(&model_); -} +void SolveWrapper::StopSearch() { shared_time_limit_->Stop(); } std::string CpSatHelper::ModelStats( const operations_research::sat::CpModelProto& model_proto) { diff --git a/ortools/sat/swig_helper.h b/ortools/sat/swig_helper.h index d7ed361325..8c5890eccd 100644 --- a/ortools/sat/swig_helper.h +++ b/ortools/sat/swig_helper.h @@ -21,6 +21,7 @@ #include "ortools/sat/cp_model.pb.h" #include "ortools/sat/model.h" #include "ortools/sat/sat_parameters.pb.h" +#include "ortools/sat/util.h" #include "ortools/util/sorted_interval_list.h" namespace operations_research { @@ -95,6 +96,7 @@ class BestBoundCallback { // This class is not meant to be reused after one solve. class SolveWrapper { public: + SolveWrapper(); // The arguments of the functions defined below must follow these rules // to be wrapped by swig correctly: // 1) Their types must include the full operations_research::sat:: @@ -124,6 +126,7 @@ class SolveWrapper { private: Model model_; + ModelSharedTimeLimit* shared_time_limit_; }; // Static methods are stored in a module which name can vary.