From 281a9f8e142134a08083abd3fb32200be60fdf60 Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Fri, 7 Feb 2025 17:08:01 +0100 Subject: [PATCH] export from google3 --- ortools/algorithms/set_cover.proto | 2 + ortools/algorithms/set_cover_invariant.h | 1 - ortools/algorithms/set_cover_model.cc | 4 +- ortools/algorithms/set_cover_model.h | 1 - ortools/algorithms/set_cover_solve.cc | 5 +- ortools/base/macros.h | 2 +- ortools/flatzinc/checker.cc | 2 +- ortools/graph/shortest_paths.h | 68 +++---------------- ortools/init/BUILD.bazel | 2 +- ortools/init/init.cc | 33 +++++---- ortools/java/com/google/ortools/Loader.java | 4 +- ortools/linear_solver/model_exporter.cc | 22 +++--- ortools/pdlp/primal_dual_hybrid_gradient.cc | 2 +- ortools/sat/BUILD.bazel | 4 ++ ortools/sat/CMakeLists.txt | 2 +- ortools/sat/all_different_test.cc | 6 +- ortools/sat/c_api/BUILD.bazel | 31 +++++++++ .../sat/{go/cpmodel => c_api}/cp_solver_c.cc | 2 +- .../sat/{go/cpmodel => c_api}/cp_solver_c.h | 6 +- ortools/sat/cp_model_expand.cc | 4 +- ortools/sat/go/cpmodel/BUILD.bazel | 17 +---- ortools/sat/go/cpmodel/cp_solver.go | 2 +- tools/docker/python/build-manylinux.sh | 6 +- 23 files changed, 102 insertions(+), 126 deletions(-) create mode 100644 ortools/sat/c_api/BUILD.bazel rename ortools/sat/{go/cpmodel => c_api}/cp_solver_c.cc (98%) rename ortools/sat/{go/cpmodel => c_api}/cp_solver_c.h (91%) diff --git a/ortools/algorithms/set_cover.proto b/ortools/algorithms/set_cover.proto index fbd56089ad..ac181a1f5d 100644 --- a/ortools/algorithms/set_cover.proto +++ b/ortools/algorithms/set_cover.proto @@ -20,6 +20,8 @@ import "ortools/util/int128.proto"; option java_package = "com.google.ortools.algorithms"; option java_multiple_files = true; +// TODO(user): use uint64 instead of int32 for indices, as the solver +// supports it. message SetCoverProto { message Subset { // The cost for using the given subset. diff --git a/ortools/algorithms/set_cover_invariant.h b/ortools/algorithms/set_cover_invariant.h index be60c58050..532b6d834c 100644 --- a/ortools/algorithms/set_cover_invariant.h +++ b/ortools/algorithms/set_cover_invariant.h @@ -63,7 +63,6 @@ class SetCoverDecision { // are covered 1 time or less (not overcovered) in the current solution; // is_redundant_, whether a subset can be removed from the solution. // is_redundant_[subset] == (num_non_overcovered_elements_[subet] == 0). - class SetCoverInvariant { public: // The consistency level of the invariant. diff --git a/ortools/algorithms/set_cover_model.cc b/ortools/algorithms/set_cover_model.cc index 425f65dbfa..ff7a8e3f73 100644 --- a/ortools/algorithms/set_cover_model.cc +++ b/ortools/algorithms/set_cover_model.cc @@ -340,12 +340,14 @@ void SetCoverModel::CreateSparseRowView() { for (const SubsetIndex subset : SubsetRange()) { // Sort the columns. It's not super-critical to improve performance here // as this needs to be done only once. - // std::sort(columns_[subset].begin(), columns_[subset].end()); BaseInt* data = reinterpret_cast(columns_[subset].data()); RadixSort(absl::MakeSpan(data, columns_[subset].size())); + ElementIndex preceding_element(-1); for (const ElementIndex element : columns_[subset]) { + DCHECK_GT(element, preceding_element); // Fail if there is a repetition. ++row_sizes[element]; + preceding_element = element; } } for (const ElementIndex element : ElementRange()) { diff --git a/ortools/algorithms/set_cover_model.h b/ortools/algorithms/set_cover_model.h index eda634f114..2e4d1c76e2 100644 --- a/ortools/algorithms/set_cover_model.h +++ b/ortools/algorithms/set_cover_model.h @@ -296,7 +296,6 @@ class SetCoverModel { bool elements_in_subsets_are_sorted_; // Costs for each subset. - SubsetCostVector subset_costs_; // Vector of columns. Each column corresponds to a subset and contains the diff --git a/ortools/algorithms/set_cover_solve.cc b/ortools/algorithms/set_cover_solve.cc index 2720c8dcc1..ab1cda7b7b 100644 --- a/ortools/algorithms/set_cover_solve.cc +++ b/ortools/algorithms/set_cover_solve.cc @@ -18,6 +18,7 @@ #include "absl/log/check.h" #include "absl/strings/match.h" #include "absl/strings/str_join.h" +#include "absl/strings/string_view.h" #include "absl/time/time.h" #include "ortools/algorithms/set_cover_heuristics.h" #include "ortools/algorithms/set_cover_invariant.h" @@ -160,7 +161,7 @@ SetCoverModel ReadModel(const std::string& input_file, } } -SubsetBoolVector ReadSolution(const std::string& input_file, +SubsetBoolVector ReadSolution(absl::string_view input_file, FileFormat input_format) { switch (input_format) { case FileFormat::TXT: @@ -198,7 +199,7 @@ void WriteModel(const SetCoverModel& model, const std::string& output_file, } void WriteSolution(const SetCoverModel& model, const SubsetBoolVector& solution, - const std::string& output_file, FileFormat output_format) { + absl::string_view output_file, FileFormat output_format) { switch (output_format) { case FileFormat::TXT: WriteSetCoverSolutionText(model, solution, output_file); diff --git a/ortools/base/macros.h b/ortools/base/macros.h index 85dc470feb..0a67d92e6d 100644 --- a/ortools/base/macros.h +++ b/ortools/base/macros.h @@ -16,7 +16,7 @@ #include // for size_t. -#include "ortools/base/base_export.h" // for OR_DLL +#include "ortools/base/base_export.h" // for OR_DLL #define COMPILE_ASSERT(x, msg) diff --git a/ortools/flatzinc/checker.cc b/ortools/flatzinc/checker.cc index dcf82e94af..e606e2800c 100644 --- a/ortools/flatzinc/checker.cc +++ b/ortools/flatzinc/checker.cc @@ -1072,7 +1072,7 @@ bool CheckSetNotIn(const Constraint& ct, bool CheckSetInReif(const Constraint& ct, const std::function& evaluator) { const int64_t value = Eval(ct.arguments[0], evaluator); - const bool status = Eval(ct.arguments[2], evaluator) != 0; + const int64_t status = Eval(ct.arguments[2], evaluator); return status == ct.arguments[1].Contains(value); } diff --git a/ortools/graph/shortest_paths.h b/ortools/graph/shortest_paths.h index 6fcdcbb095..c117e99d16 100644 --- a/ortools/graph/shortest_paths.h +++ b/ortools/graph/shortest_paths.h @@ -116,10 +116,6 @@ class GenericPathContainer { using NodeIndex = typename GraphType::NodeIndex; using Impl = internal::PathContainerImpl; - // TODO(b/385094969): Remove this when all clients are migrated, and use - // factory functions instead. - GenericPathContainer(); - // This type is neither copyable nor movable. GenericPathContainer(const GenericPathContainer&) = delete; GenericPathContainer& operator=(const GenericPathContainer&) = delete; @@ -153,9 +149,6 @@ class GenericPathContainer { // Builds a path container which only stores distances between path nodes. static GenericPathContainer BuildPathDistanceContainer(); - ABSL_DEPRECATED("Use factory function BuildPathDistanceContainer instead.") - static void BuildPathDistanceContainer(GenericPathContainer* path_container); - // Builds a path container which stores explicit paths and distances between // path nodes in a memory-compact representation. // In this case `GetPenultimateNodeInPath()` is `O(log(path_tree_size))`, @@ -168,11 +161,6 @@ class GenericPathContainer { // `O(log(path_tree_size) * path_size)`. static GenericPathContainer BuildInMemoryCompactPathContainer(); - ABSL_DEPRECATED( - "Use factory function BuildInMemoryCompactPathContainer instead.") - static void BuildInMemoryCompactPathContainer( - GenericPathContainer* path_container); - // TODO(user): Add save-to-disk container. // TODO(user): Add `BuildInMemoryFastPathContainer()`, which does // `GetPenultimateNodeInPath()` in `O(1)`. @@ -230,12 +218,12 @@ void ComputeOneToAllShortestPaths( // Computes shortest paths from the node `source` to nodes in `destinations`. // TODO(b/385094969): Remove second template parameter when all clients are // migrated. -template +template void ComputeOneToManyShortestPaths( const GraphType& graph, const std::vector& arc_lengths, typename GraphType::NodeIndex source, const std::vector& destinations, - GenericPathContainer* const path_container) { + GenericPathContainer* const path_container) { std::vector sources(1, source); ComputeManyToManyShortestPathsWithMultipleThreads( graph, arc_lengths, sources, destinations, 1, path_container); @@ -282,13 +270,10 @@ void ComputeManyToAllShortestPathsWithMultipleThreads( } // Computes shortest paths between all nodes of the graph. -// TODO(b/385094969): Remove second template parameter when all clients are -// migrated. -template +template void ComputeAllToAllShortestPathsWithMultipleThreads( const GraphType& graph, const std::vector& arc_lengths, - int num_threads, - GenericPathContainer* const path_container) { + int num_threads, GenericPathContainer* const path_container) { std::vector all_nodes; GetGraphNodesFromGraph(graph, &all_nodes); ComputeManyToManyShortestPathsWithMultipleThreads( @@ -635,15 +620,13 @@ bool InsertOrUpdateEntry( // using a binary heap-based Dijkstra algorithm. // TODO(user): Investigate alternate implementation which wouldn't use // AdjustablePriorityQueue. -// TODO(b/385094969): Remove second template parameter when all clients are -// migrated. -template +template void ComputeOneToManyOnGraph( const GraphType* const graph, const std::vector* const arc_lengths, typename GraphType::NodeIndex source, const std::vector* const destinations, - typename GenericPathContainer::Impl* const paths) { + typename GenericPathContainer::Impl* const paths) { using NodeIndex = typename GraphType::NodeIndex; using ArcIndex = typename GraphType::ArcIndex; using NodeEntryT = NodeEntry; @@ -715,9 +698,6 @@ void ComputeOneToManyOnGraph( } // namespace internal -template -GenericPathContainer::GenericPathContainer() = default; - template GenericPathContainer::~GenericPathContainer() = default; @@ -744,22 +724,6 @@ void GenericPathContainer::GetPath( container_->GetPath(from, to, path); } -template -void GenericPathContainer::BuildPathDistanceContainer( - GenericPathContainer* const path_container) { - CHECK(path_container != nullptr); - path_container->container_ = std::make_unique< - internal::DistanceContainer>(); -} - -template -void GenericPathContainer::BuildInMemoryCompactPathContainer( - GenericPathContainer* const path_container) { - CHECK(path_container != nullptr); - path_container->container_ = std::make_unique< - internal::InMemoryCompactPathContainer>(); -} - template GenericPathContainer GenericPathContainer::BuildPathDistanceContainer() { @@ -776,22 +740,12 @@ GenericPathContainer::BuildInMemoryCompactPathContainer() { NodeIndex, GraphType::kNilNode>>()); } -// TODO(b/385094969): Remove second template parameter when all clients are -// migrated. -template +template void ComputeManyToManyShortestPathsWithMultipleThreads( const GraphType& graph, const std::vector& arc_lengths, const std::vector& sources, const std::vector& destinations, - int num_threads, - GenericPathContainer* const paths) { - static_assert(std::is_same_v, - "use an explicit `GenericPathContainer` instead of using " - "`PathContainer`"); - static_assert(GraphType::kNilNode == PathContainerGraphType::kNilNode, - "use an explicit `GenericPathContainer` instead of using " - "`PathContainer`"); + int num_threads, GenericPathContainer* const paths) { if (graph.num_nodes() > 0) { CHECK_EQ(graph.num_arcs(), arc_lengths.size()) << "Number of arcs in graph must match arc length vector size"; @@ -812,10 +766,8 @@ void ComputeManyToManyShortestPathsWithMultipleThreads( pool->StartWorkers(); for (int i = 0; i < unique_sources.size(); ++i) { pool->Schedule(absl::bind_front( - &internal::ComputeOneToManyOnGraph, - &graph, &arc_lengths, unique_sources[i], &unique_destinations, - container)); + &internal::ComputeOneToManyOnGraph, &graph, &arc_lengths, + unique_sources[i], &unique_destinations, container)); } } container->Finalize(); diff --git a/ortools/init/BUILD.bazel b/ortools/init/BUILD.bazel index 95b55c918c..47a185fa3d 100644 --- a/ortools/init/BUILD.bazel +++ b/ortools/init/BUILD.bazel @@ -15,8 +15,8 @@ package(default_visibility = ["//visibility:public"]) cc_library( name = "init", - hdrs = ["init.h"], srcs = ["init.cc"], + hdrs = ["init.h"], deps = [ "//ortools/base", "//ortools/gurobi:environment", diff --git a/ortools/init/init.cc b/ortools/init/init.cc index c02a33f709..e80ce87a4f 100644 --- a/ortools/init/init.cc +++ b/ortools/init/init.cc @@ -22,25 +22,24 @@ #include "ortools/sat/cp_model_solver_helpers.h" namespace operations_research { - void CppBridge::InitLogging(const std::string& usage) { - absl::SetProgramUsageMessage(usage); - absl::InitializeLog(); - } +void CppBridge::InitLogging(const std::string& usage) { + absl::SetProgramUsageMessage(usage); + absl::InitializeLog(); +} - void CppBridge::SetFlags(const CppFlags& flags) { - absl::SetFlag(&FLAGS_stderrthreshold, flags.stderrthreshold); - absl::EnableLogPrefix(flags.log_prefix); - if (!flags.cp_model_dump_prefix.empty()) { - absl::SetFlag(&FLAGS_cp_model_dump_prefix, flags.cp_model_dump_prefix); - } - absl::SetFlag(&FLAGS_cp_model_dump_models, flags.cp_model_dump_models); - absl::SetFlag(&FLAGS_cp_model_dump_submodels, - flags.cp_model_dump_submodels); - absl::SetFlag(&FLAGS_cp_model_dump_response, flags.cp_model_dump_response); +void CppBridge::SetFlags(const CppFlags& flags) { + absl::SetFlag(&FLAGS_stderrthreshold, flags.stderrthreshold); + absl::EnableLogPrefix(flags.log_prefix); + if (!flags.cp_model_dump_prefix.empty()) { + absl::SetFlag(&FLAGS_cp_model_dump_prefix, flags.cp_model_dump_prefix); } + absl::SetFlag(&FLAGS_cp_model_dump_models, flags.cp_model_dump_models); + absl::SetFlag(&FLAGS_cp_model_dump_submodels, flags.cp_model_dump_submodels); + absl::SetFlag(&FLAGS_cp_model_dump_response, flags.cp_model_dump_response); +} - bool CppBridge::LoadGurobiSharedLibrary(const std::string& full_library_path) { - return LoadGurobiDynamicLibrary({full_library_path}).ok(); - } +bool CppBridge::LoadGurobiSharedLibrary(const std::string& full_library_path) { + return LoadGurobiDynamicLibrary({full_library_path}).ok(); +} } // namespace operations_research diff --git a/ortools/java/com/google/ortools/Loader.java b/ortools/java/com/google/ortools/Loader.java index 8fa3bf913f..68c7606e4f 100644 --- a/ortools/java/com/google/ortools/Loader.java +++ b/ortools/java/com/google/ortools/Loader.java @@ -142,8 +142,8 @@ public static synchronized void loadNativeLibraries() { URI resourceURI = getNativeResourceURI(); Path tempPath = unpackNativeResources(resourceURI); // libraries order does matter ! - List dlls = Arrays.asList( - "zlib1", "abseil_dll", "re2", "utf8_validity", "libprotobuf", "highs", "ortools", "jniortools"); + List dlls = Arrays.asList("zlib1", "abseil_dll", "re2", "utf8_validity", + "libprotobuf", "highs", "ortools", "jniortools"); for (String dll : dlls) { try { // System.out.println("System.load(" + dll + ")"); diff --git a/ortools/linear_solver/model_exporter.cc b/ortools/linear_solver/model_exporter.cc index cd4ecd5983..23fd23ff5b 100644 --- a/ortools/linear_solver/model_exporter.cc +++ b/ortools/linear_solver/model_exporter.cc @@ -140,7 +140,7 @@ class MPModelProtoExporter { // into two constraints, one for the left hand side (_lhs) and one for right // hand side (_rhs). bool AppendConstraint(const MPConstraintProto& ct_proto, - const std::string& name, LineBreaker& line_breaker, + absl::string_view name, LineBreaker& line_breaker, std::vector& show_variable, std::string* output); // Clears "output" and writes a term to it, in "LP" format. Returns false on @@ -159,8 +159,8 @@ class MPModelProtoExporter { // Same as AppendMpsLineHeader. Appends an extra new-line at the end the // string pointed to by output. - void AppendMpsLineHeaderWithNewLine(const std::string& id, - const std::string& name, + void AppendMpsLineHeaderWithNewLine(absl::string_view id, + absl::string_view name, std::string* output) const; // Appends an MPS term in various contexts. The term consists of a head name, @@ -186,7 +186,7 @@ class MPModelProtoExporter { // Appends a line describing the bound of a variablenew-line if two columns // are already present on the MPS line. // Used by and in complement to AppendMpsTermWithContext. - void AppendMpsBound(const std::string& bound_type, const std::string& name, + void AppendMpsBound(absl::string_view bound_type, absl::string_view name, double value, std::string* output) const; const MPModelProto& proto_; @@ -392,7 +392,7 @@ std::string DoubleToString(double d) { return absl::StrCat((d)); } } // namespace bool MPModelProtoExporter::AppendConstraint(const MPConstraintProto& ct_proto, - const std::string& name, + absl::string_view name, LineBreaker& line_breaker, std::vector& show_variable, std::string* output) { @@ -414,7 +414,7 @@ bool MPModelProtoExporter::AppendConstraint(const MPConstraintProto& ct_proto, absl::StrAppend(output, " ", name, ": ", line_breaker.GetOutput()); } else { if (ub != +kInfinity) { - std::string rhs_name = name; + std::string rhs_name(name); if (lb != -kInfinity) { absl::StrAppend(&rhs_name, "_rhs"); } @@ -427,7 +427,7 @@ bool MPModelProtoExporter::AppendConstraint(const MPConstraintProto& ct_proto, absl::StrAppend(output, relation); } if (lb != -kInfinity) { - std::string lhs_name = name; + std::string lhs_name(name); if (ub != +kInfinity) { absl::StrAppend(&lhs_name, "_lhs"); } @@ -462,7 +462,7 @@ bool IsBoolean(const MPVariableProto& var) { floor(var.upper_bound()) == 1.0; } -void UpdateMaxSize(const std::string& new_string, int* size) { +void UpdateMaxSize(absl::string_view new_string, int* size) { const int new_size = new_string.size(); if (new_size > *size) *size = new_size; } @@ -687,7 +687,7 @@ void MPModelProtoExporter::AppendMpsLineHeader(absl::string_view id, } void MPModelProtoExporter::AppendMpsLineHeaderWithNewLine( - const std::string& id, const std::string& name, std::string* output) const { + absl::string_view id, absl::string_view name, std::string* output) const { AppendMpsLineHeader(id, name, output); absl::StripTrailingAsciiWhitespace(output); absl::StrAppend(output, "\n"); @@ -704,8 +704,8 @@ void MPModelProtoExporter::AppendMpsTermWithContext(absl::string_view head_name, AppendNewLineIfTwoColumns(output); } -void MPModelProtoExporter::AppendMpsBound(const std::string& bound_type, - const std::string& name, double value, +void MPModelProtoExporter::AppendMpsBound(absl::string_view bound_type, + absl::string_view name, double value, std::string* output) const { AppendMpsLineHeader(bound_type, "BOUND", output); AppendMpsPair(name, value, output); diff --git a/ortools/pdlp/primal_dual_hybrid_gradient.cc b/ortools/pdlp/primal_dual_hybrid_gradient.cc index ef0c9a18e5..a027b46936 100644 --- a/ortools/pdlp/primal_dual_hybrid_gradient.cc +++ b/ortools/pdlp/primal_dual_hybrid_gradient.cc @@ -1262,7 +1262,7 @@ std::optional PreprocessSolver::ApplyPresolveIfEnabled( // set it for completeness. presolved_qp->objective_scaling_factor = glop_lp.objective_scaling_factor(); sharded_qp_ = ShardedQuadraticProgram(std::move(*presolved_qp), num_threads_, - num_shards_); + num_shards_, params.scheduler_type()); // A status of `INIT` means the preprocessor created a (usually) smaller // problem that needs solving. Other statuses mean the preprocessor solved // the problem completely. diff --git a/ortools/sat/BUILD.bazel b/ortools/sat/BUILD.bazel index a61e041b5e..fa6efa3591 100644 --- a/ortools/sat/BUILD.bazel +++ b/ortools/sat/BUILD.bazel @@ -2054,6 +2054,7 @@ cc_test( "//ortools/base", "//ortools/base:gmock_main", "//ortools/util:sorted_interval_list", + "@com_google_absl//absl/types:span", ], ) @@ -2656,9 +2657,11 @@ cc_library( ":model", ":precedences", ":sat_base", + ":util", "//ortools/base", "//ortools/base:mathutil", "//ortools/base:strong_vector", + "//ortools/graph", "//ortools/graph:max_flow", "//ortools/util:strong_integers", "@com_google_absl//absl/algorithm:container", @@ -2982,6 +2985,7 @@ cc_test( "//ortools/base", "//ortools/base:gmock_main", "//ortools/base:mathutil", + "//ortools/base:stl_util", "//ortools/util:random_engine", "//ortools/util:sorted_interval_list", "@com_google_absl//absl/container:btree", diff --git a/ortools/sat/CMakeLists.txt b/ortools/sat/CMakeLists.txt index a27ad417ce..e49cc257ce 100644 --- a/ortools/sat/CMakeLists.txt +++ b/ortools/sat/CMakeLists.txt @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -file(GLOB _SRCS "*.h" "*.cc" "python/linear_expr.*") +file(GLOB _SRCS "*.h" "*.cc" "python/linear_expr.*" "c_api/*.h" "c_api/*.cc") list(FILTER _SRCS EXCLUDE REGEX ".*/.*_test.cc") list(FILTER _SRCS EXCLUDE REGEX ".*/.*_fuzz.cc") list(REMOVE_ITEM _SRCS diff --git a/ortools/sat/all_different_test.cc b/ortools/sat/all_different_test.cc index 4ea2114a2f..a69afc5eb7 100644 --- a/ortools/sat/all_different_test.cc +++ b/ortools/sat/all_different_test.cc @@ -20,6 +20,7 @@ #include #include +#include "absl/types/span.h" #include "gtest/gtest.h" #include "ortools/base/logging.h" #include "ortools/sat/integer.h" @@ -36,8 +37,9 @@ namespace { class AllDifferentTest : public ::testing::TestWithParam { public: std::function AllDifferent( - const std::vector& vars) { - return [=](Model* model) { + absl::Span vars) { + return [=, vars = std::vector(vars.begin(), vars.end())]( + Model* model) { if (GetParam() == "binary") { model->Add(AllDifferentBinary(vars)); } else if (GetParam() == "ac") { diff --git a/ortools/sat/c_api/BUILD.bazel b/ortools/sat/c_api/BUILD.bazel new file mode 100644 index 0000000000..ce0b294d2f --- /dev/null +++ b/ortools/sat/c_api/BUILD.bazel @@ -0,0 +1,31 @@ +# Copyright 2010-2025 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. + +load("@rules_cc//cc:defs.bzl", "cc_library") + +package(default_visibility = ["//visibility:public"]) + +cc_library( + name = "cp_solver_c", + srcs = ["cp_solver_c.cc"], + hdrs = ["cp_solver_c.h"], + deps = [ + "//ortools/base:memutil", + "//ortools/sat:cp_model_cc_proto", + "//ortools/sat:cp_model_solver", + "//ortools/sat:model", + "//ortools/sat:sat_parameters_cc_proto", + "//ortools/util:time_limit", + "@com_google_absl//absl/log:check", + ], +) diff --git a/ortools/sat/go/cpmodel/cp_solver_c.cc b/ortools/sat/c_api/cp_solver_c.cc similarity index 98% rename from ortools/sat/go/cpmodel/cp_solver_c.cc rename to ortools/sat/c_api/cp_solver_c.cc index 4ae14780a1..17333d1b88 100644 --- a/ortools/sat/go/cpmodel/cp_solver_c.cc +++ b/ortools/sat/c_api/cp_solver_c.cc @@ -11,7 +11,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "ortools/sat/go/cpmodel/cp_solver_c.h" +#include "ortools/sat/c_api/cp_solver_c.h" #include #include diff --git a/ortools/sat/go/cpmodel/cp_solver_c.h b/ortools/sat/c_api/cp_solver_c.h similarity index 91% rename from ortools/sat/go/cpmodel/cp_solver_c.h rename to ortools/sat/c_api/cp_solver_c.h index f9a00520cc..643cbe8753 100644 --- a/ortools/sat/go/cpmodel/cp_solver_c.h +++ b/ortools/sat/c_api/cp_solver_c.h @@ -11,8 +11,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef OR_TOOLS_SAT_GO_CP_SOLVER_C_H_ -#define OR_TOOLS_SAT_GO_CP_SOLVER_C_H_ +#ifndef OR_TOOLS_SAT_C_API_CP_SOLVER_C_H_ +#define OR_TOOLS_SAT_C_API_CP_SOLVER_C_H_ #include #include @@ -38,4 +38,4 @@ void SolveCpInterruptible(void* limit_reached, const void* creq, int creq_len, } // extern "C" #endif -#endif // OR_TOOLS_SAT_GO_CP_SOLVER_C_H_ +#endif // OR_TOOLS_SAT_C_API_CP_SOLVER_C_H_ diff --git a/ortools/sat/cp_model_expand.cc b/ortools/sat/cp_model_expand.cc index df68ef5ecb..9ab3045ec1 100644 --- a/ortools/sat/cp_model_expand.cc +++ b/ortools/sat/cp_model_expand.cc @@ -869,8 +869,8 @@ void ExpandElement(ConstraintProto* ct, PresolveContext* context) { // Adds clauses so that literals[i] true <=> encoding[values[i]] true. // This also implicitly use the fact that exactly one alternative is true. -void LinkLiteralsAndValues(const std::vector& literals, - const std::vector& values, +void LinkLiteralsAndValues(absl::Span literals, + absl::Span values, const absl::flat_hash_map& encoding, PresolveContext* context) { CHECK_EQ(literals.size(), values.size()); diff --git a/ortools/sat/go/cpmodel/BUILD.bazel b/ortools/sat/go/cpmodel/BUILD.bazel index 69f5a79f32..3b12cff8df 100644 --- a/ortools/sat/go/cpmodel/BUILD.bazel +++ b/ortools/sat/go/cpmodel/BUILD.bazel @@ -20,7 +20,7 @@ go_library( "cp_solver.go", "domain.go", ], - cdeps = [":cp_solver_c"], + cdeps = ["//ortools/sat/c_api:cp_solver_c"], cgo = True, importpath = "github.com/google/or-tools/ortools/sat/go/cpmodel", visibility = ["//visibility:public"], @@ -49,18 +49,3 @@ go_test( "@org_golang_google_protobuf//testing/protocmp", ], ) - -cc_library( - name = "cp_solver_c", - srcs = ["cp_solver_c.cc"], - hdrs = ["cp_solver_c.h"], - deps = [ - "//ortools/base:memutil", - "//ortools/sat:cp_model_cc_proto", - "//ortools/sat:cp_model_solver", - "//ortools/sat:model", - "//ortools/sat:sat_parameters_cc_proto", - "//ortools/util:time_limit", - "@com_google_absl//absl/log:check", - ], -) diff --git a/ortools/sat/go/cpmodel/cp_solver.go b/ortools/sat/go/cpmodel/cp_solver.go index 967827e4c5..2f9b887667 100644 --- a/ortools/sat/go/cpmodel/cp_solver.go +++ b/ortools/sat/go/cpmodel/cp_solver.go @@ -27,7 +27,7 @@ import ( /* #include // for free #include -#include "ortools/sat/go/cpmodel/cp_solver_c.h" +#include "ortools/sat/c_api/cp_solver_c.h" */ import "C" diff --git a/tools/docker/python/build-manylinux.sh b/tools/docker/python/build-manylinux.sh index 1b8cbf6654..c3b86c770a 100755 --- a/tools/docker/python/build-manylinux.sh +++ b/tools/docker/python/build-manylinux.sh @@ -196,9 +196,9 @@ function test_wheel() { "ortools/linear_solver/samples/simple_lp_program.py" "ortools/linear_solver/samples/simple_mip_program.py" "ortools/sat/samples/simple_sat_program.py" - "ortools/constraint_solver/samples/tsp.py" - "ortools/constraint_solver/samples/vrp.py" - "ortools/constraint_solver/samples/cvrptw_break.py" + "ortools/routing/samples/tsp.py" + "ortools/routing/samples/vrp.py" + "ortools/routing/samples/cvrptw_break.py" ) # Run all the specified test scripts using the current environment.