diff --git a/ortools/port/proto_utils.h b/ortools/port/proto_utils.h index aacc755f4c..3809974d27 100644 --- a/ortools/port/proto_utils.h +++ b/ortools/port/proto_utils.h @@ -16,16 +16,17 @@ #include -#if !defined(__PORTABLE_PLATFORM__) -#include "ortools/util/parse_proto.h" -#endif // !defined(__PORTABLE_PLATFORM__) - +#include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" #include "google/protobuf/message.h" #include "google/protobuf/message_lite.h" #include "google/protobuf/text_format.h" +#if !defined(__PORTABLE_PLATFORM__) +#include "ortools/util/parse_proto.h" +#endif // !defined(__PORTABLE_PLATFORM__) + namespace operations_research { template @@ -33,7 +34,10 @@ std::string ProtobufDebugString(const P& message) { #if defined(__PORTABLE_PLATFORM__) return std::string(message.GetTypeName()); #else // defined(__PORTABLE_PLATFORM__) - return message.DebugString(); + std::string output; + google::protobuf::TextFormat::PrintToString(message, &output); + absl::StripTrailingAsciiWhitespace(&output); + return output; #endif // !defined(__PORTABLE_PLATFORM__) } @@ -42,7 +46,12 @@ std::string ProtobufShortDebugString(const P& message) { #if defined(__PORTABLE_PLATFORM__) return std::string(message.GetTypeName()); #else // defined(__PORTABLE_PLATFORM__) - return message.ShortDebugString(); + std::string output; + google::protobuf::TextFormat::Printer printer; + printer.SetSingleLineMode(true); + printer.PrintToString(message, &output); + absl::StripTrailingAsciiWhitespace(&output); + return output; #endif // !defined(__PORTABLE_PLATFORM__) } diff --git a/ortools/sat/c_api/BUILD.bazel b/ortools/sat/c_api/BUILD.bazel index 665af9ae01..2f41d3b1ab 100644 --- a/ortools/sat/c_api/BUILD.bazel +++ b/ortools/sat/c_api/BUILD.bazel @@ -25,7 +25,6 @@ cc_library( "//ortools/sat:cp_model_solver", "//ortools/sat:model", "//ortools/sat:sat_parameters_cc_proto", - "//ortools/util:time_limit", "@abseil-cpp//absl/log:check", ], ) diff --git a/ortools/sat/c_api/cp_solver_c.cc b/ortools/sat/c_api/cp_solver_c.cc index ab3ca3029a..c66b944f59 100644 --- a/ortools/sat/c_api/cp_solver_c.cc +++ b/ortools/sat/c_api/cp_solver_c.cc @@ -48,7 +48,7 @@ void* SolveCpNewEnv() { return new Model(); } void SolveCpDestroyEnv(void* const cenv) { delete static_cast(cenv); } -void SolveCpStopSolve(void* cenv) { StopSearch(static_cast(cenv)); } +void SolveCpStopSearch(void* cenv) { StopSearch(static_cast(cenv)); } void SolveCpInterruptible(void* const cenv, const void* creq, int creq_len, const void* cparams, int cparams_len, void** cres, diff --git a/ortools/sat/c_api/cp_solver_c.h b/ortools/sat/c_api/cp_solver_c.h index b005c19b51..708ad88086 100644 --- a/ortools/sat/c_api/cp_solver_c.h +++ b/ortools/sat/c_api/cp_solver_c.h @@ -27,7 +27,7 @@ void SolveCpModelWithParameters(const void* creq, int creq_len, void* SolveCpNewEnv(); void SolveCpDestroyEnv(void* cenv); -void SolveCpStopSolve(void* cenv); +void SolveCpStopSearch(void* cenv); // Allows for interruptible solves. Solves can be interrupted by calling // `SolveCpStopSolve` with the `cenv` argument. void SolveCpInterruptible(void* cenv, const void* creq, int creq_len, diff --git a/ortools/sat/go/cpmodel/cp_solver.go b/ortools/sat/go/cpmodel/cp_solver.go index 9110642229..c37fa9702f 100644 --- a/ortools/sat/go/cpmodel/cp_solver.go +++ b/ortools/sat/go/cpmodel/cp_solver.go @@ -72,7 +72,7 @@ func SolveCpModelWithParameters(input *cmpb.CpModelProto, params *sppb.SatParame // SolveCpModelInterruptibleWithParameters solves a CP Model with the given input proto // and parameters and returns a CPSolverResponse. The solve can be interrupted by calling -// the `stopSolve`. +// the `stopSearch`. func SolveCpModelInterruptibleWithParameters(input *cmpb.CpModelProto, params *sppb.SatParameters, interrupt <-chan struct{}) (*cmpb.CpSolverResponse, error) { // Create the environment for interrupting solves. env := newEnvWrapper() @@ -100,7 +100,7 @@ func SolveCpModelInterruptibleWithParameters(input *cmpb.CpModelProto, params *s go func() { select { case <-interrupt: - env.stopSolve() + env.stopSearch() case <-solveDone: } }() @@ -111,7 +111,7 @@ func SolveCpModelInterruptibleWithParameters(input *cmpb.CpModelProto, params *s // so). select { case <-interrupt: - env.stopSolve() + env.stopSearch() default: } @@ -141,7 +141,7 @@ type envWrapper struct { // The returned object must be destroyed with delete() for the C++ object not to // leak. // -// This object is thread-safe: delete() and stopSolve() can be called +// This object is thread-safe: delete() and stopSearch() can be called // concurrently. func newEnvWrapper() *envWrapper { return &envWrapper{ @@ -149,14 +149,14 @@ func newEnvWrapper() *envWrapper { } } -// stopSolve triggers the C++ SolveCpStopSolve method with the environment. +// stopSearch triggers the C++ SolveCpStopSearch method with the environment. // // If the environment has been deleted this has no effect. -func (intr *envWrapper) stopSolve() { +func (intr *envWrapper) stopSearch() { intr.mutex.Lock() defer intr.mutex.Unlock() if uintptr(intr.ptr) != 0 { - C.SolveCpStopSolve(intr.ptr) + C.SolveCpStopSearch(intr.ptr) } }