diff --git a/WORKSPACE b/WORKSPACE index 2c43128082f..8981e067433 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,48 +1,52 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository") + #Import the gflags files. git_repository( - name = "com_github_gflags_gflags", + name = "com_github_gflags_gflags", + commit = "f8a0efe03aa69b3336d8e228b37d4ccb17324b88", remote = "https://github.com/gflags/gflags.git", - tag = "v2.2.2", ) #Import the glog files. new_git_repository( - name = "com_github_glog_glog", + name = "com_github_glog_glog", build_file = "//bazel:glog.BUILD", remote = "https://github.com/google/glog.git", tag = "v0.3.5", ) -# proto_library rules implicitly depend on @com_google_protobuf//:protoc, -# which is the proto-compiler. -# This statement defines the @com_google_protobuf repo. http_archive( name = "com_google_protobuf", - urls = ["https://github.com/google/protobuf/archive/b4b0e304be5a68de3d0ee1af9b286f958750f5e4.zip"], - strip_prefix = "protobuf-b4b0e304be5a68de3d0ee1af9b286f958750f5e4", - sha256 = "ff771a662fb6bd4d3cc209bcccedef3e93980a49f71df1e987f6afa3bcdcba3a", + sha256 = "9510dd2afc29e7245e9e884336f848c8a6600a14ae726adb6befdb4f786f0be2", + strip_prefix = "protobuf-3.6.1.3", + urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.6.1.3.zip"], ) -# cc_proto_library rules implicitly depend on -# @com_google_protobuf_cc//:cc_toolchain, which is the C++ proto runtime -# (base classes and common utilities). http_archive( name = "com_google_protobuf_cc", - urls = ["https://github.com/google/protobuf/archive/b4b0e304be5a68de3d0ee1af9b286f958750f5e4.zip"], - strip_prefix = "protobuf-b4b0e304be5a68de3d0ee1af9b286f958750f5e4", - sha256 = "ff771a662fb6bd4d3cc209bcccedef3e93980a49f71df1e987f6afa3bcdcba3a", + sha256 = "9510dd2afc29e7245e9e884336f848c8a6600a14ae726adb6befdb4f786f0be2", + strip_prefix = "protobuf-3.6.1.3", + urls = ["https://github.com/protocolbuffers/protobuf/archive/v3.6.1.3.zip"], ) -new_http_archive( +http_archive( name = "gtest", - url = "https://github.com/google/googletest/archive/release-1.8.0.zip", build_file = "//bazel:gtest.BUILD", strip_prefix = "googletest-release-1.8.0/googletest", + url = "https://github.com/google/googletest/archive/release-1.8.0.zip", +) + +http_archive( + name = "com_google_absl", + sha256 = "fe4d9e424dc25ee57695509cf6c5a7dd582a7ac1ca1efb92713fb439b3e8b1c6", + urls = ["https://github.com/abseil/abseil-cpp/archive/20181200.zip"], + strip_prefix = "abseil-cpp-20181200", ) -new_http_archive( +http_archive( name = "glpk", - url = "http://ftp.gnu.org/gnu/glpk/glpk-4.52.tar.gz", - sha256 = "9a5dab356268b4f177c33e00ddf8164496dc2434e83bd1114147024df983a3bb", build_file = "//bazel:glpk.BUILD", + sha256 = "9a5dab356268b4f177c33e00ddf8164496dc2434e83bd1114147024df983a3bb", + url = "http://ftp.gnu.org/gnu/glpk/glpk-4.52.tar.gz", ) diff --git a/ortools/algorithms/BUILD b/ortools/algorithms/BUILD index 9a47212ca2b..c03c8eccc2f 100644 --- a/ortools/algorithms/BUILD +++ b/ortools/algorithms/BUILD @@ -7,6 +7,7 @@ cc_library( deps = [ "//ortools/base", "//ortools/base:hash", + "@com_google_absl//absl/container:flat_hash_map", ], ) @@ -20,7 +21,7 @@ cc_test( "//ortools/base", "//ortools/base:map_util", "//ortools/base:random", - "//ortools/base:strings", + "@com_google_absl//absl/strings", "@gtest//:main", ], ) @@ -59,6 +60,20 @@ cc_library( ], ) +cc_library( + name = "knapsack_solver_for_cuts", + srcs = ["knapsack_solver_for_cuts.cc"], + hdrs = ["knapsack_solver_for_cuts.h"], + visibility = ["//visibility:public"], + deps = [ + "//ortools/base", + "//ortools/base:int_type", + "//ortools/base:int_type_indexed_vector", + "//ortools/base:ptr_util", + "//ortools/util:time_limit", + ], +) + cc_library( name = "dense_doubly_linked_list", hdrs = ["dense_doubly_linked_list.h"], @@ -74,7 +89,8 @@ cc_library( deps = [ "//ortools/base", "//ortools/base:murmur", - "//ortools/base:strings", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", ], ) @@ -84,7 +100,7 @@ cc_library( hdrs = ["sparse_permutation.h"], deps = [ "//ortools/base", - "//ortools/base:strings", + "@com_google_absl//absl/strings", ], ) @@ -95,7 +111,7 @@ cc_library( deps = [ ":sparse_permutation", "//ortools/base", - "//ortools/base:strings", + "@com_google_absl//absl/strings", ], ) @@ -109,11 +125,12 @@ cc_library( ":dynamic_permutation", ":sparse_permutation", "//ortools/base", + "//ortools/base:canonical_errors", "//ortools/base:status", - "//ortools/base:strings", + "@com_google_absl//absl/strings", "//ortools/graph", + "//ortools/graph:iterators", "//ortools/graph:util", - "//ortools/util:iterators", "//ortools/util:stats", "//ortools/util:time_limit", ], diff --git a/ortools/algorithms/hungarian_test.cc b/ortools/algorithms/hungarian_test.cc index 4758b8b86ad..840f8adee91 100644 --- a/ortools/algorithms/hungarian_test.cc +++ b/ortools/algorithms/hungarian_test.cc @@ -2,7 +2,7 @@ #include "ortools/algorithms/hungarian.h" -#include +#include "absl/container/flat_hash_map.h" #include "gtest/gtest.h" #include "ortools/base/integral_types.h" #include "ortools/base/macros.h" @@ -15,19 +15,19 @@ namespace operations_research { // result as well as whether the result is the expected one. void GenericCheck(const int expected_assignment_size, - const std::unordered_map& direct_assignment, - const std::unordered_map& reverse_assignment, + const absl::flat_hash_map& direct_assignment, + const absl::flat_hash_map& reverse_assignment, const int expected_agents[], const int expected_tasks[]) { EXPECT_EQ(expected_assignment_size, direct_assignment.size()); EXPECT_EQ(expected_assignment_size, reverse_assignment.size()); for (int i = 0; i < expected_assignment_size; ++i) { - EXPECT_EQ(FindOrDie(direct_assignment, expected_agents[i]), + EXPECT_EQ(gtl::FindOrDie(direct_assignment, expected_agents[i]), expected_tasks[i]); - EXPECT_EQ(FindOrDie(reverse_assignment, expected_tasks[i]), + EXPECT_EQ(gtl::FindOrDie(reverse_assignment, expected_tasks[i]), expected_agents[i]); } for (const auto& direct_iter : direct_assignment) { - EXPECT_EQ(FindOrDie(reverse_assignment, direct_iter.second), + EXPECT_EQ(gtl::FindOrDie(reverse_assignment, direct_iter.second), direct_iter.first) << direct_iter.first << " -> " << direct_iter.second; } @@ -36,8 +36,8 @@ void GenericCheck(const int expected_assignment_size, void TestMinimization(const std::vector >& cost, const int expected_assignment_size, const int expected_agents[], const int expected_tasks[]) { - std::unordered_map direct_assignment; - std::unordered_map reverse_assignment; + absl::flat_hash_map direct_assignment; + absl::flat_hash_map reverse_assignment; MinimizeLinearAssignment(cost, &direct_assignment, &reverse_assignment); SCOPED_TRACE("Minimization"); GenericCheck(expected_assignment_size, direct_assignment, reverse_assignment, @@ -47,8 +47,8 @@ void TestMinimization(const std::vector >& cost, void TestMaximization(const std::vector >& cost, const int expected_assignment_size, const int expected_agents[], const int expected_tasks[]) { - std::unordered_map direct_assignment; - std::unordered_map reverse_assignment; + absl::flat_hash_map direct_assignment; + absl::flat_hash_map reverse_assignment; MaximizeLinearAssignment(cost, &direct_assignment, &reverse_assignment); SCOPED_TRACE("Maximization"); GenericCheck(expected_assignment_size, direct_assignment, reverse_assignment, diff --git a/ortools/base/BUILD b/ortools/base/BUILD index f1adb5d97fb..e08dfe241f8 100644 --- a/ortools/base/BUILD +++ b/ortools/base/BUILD @@ -8,7 +8,6 @@ cc_library( "integral_types.h", "logging.h", "macros.h", - "port.h", ], deps = [ "@com_github_gflags_gflags//:gflags", @@ -26,7 +25,6 @@ cc_library( ], ) - cc_library( name = "status", hdrs = [ @@ -58,6 +56,13 @@ cc_library( ], ) +cc_library( + name = "ptr_util", + hdrs = [ + "ptr_util.h", + ], +) + cc_library( name = "sysinfo", srcs = [ @@ -68,7 +73,7 @@ cc_library( ], deps = [ ":base", - ":strings", + "@com_google_absl//absl/strings:strings", ], ) @@ -83,11 +88,22 @@ cc_library( deps = [ ":base", ":status", - ":strings", + "@com_google_absl//absl/strings", "@com_google_protobuf_cc//:protobuf", ], ) +cc_library( + name = "filelineiter", + hdrs = ["filelineiter.h"], + deps = [ + ":base", + ":file", + ":status", + "@com_google_absl//absl/strings:strings", + ], +) + cc_library( name = "recordio", srcs = [ @@ -101,25 +117,20 @@ cc_library( ":base", ":file", ":status", - ":strings", + "@com_google_absl//absl/strings:strings", "@com_google_protobuf_cc//:protobuf", ], ) cc_library( - name = "filelinereader", - srcs = [ - "filelinereader.cc", - ], + name = "protoutil", hdrs = [ - "filelinereader.h", + "protoutil.h", ], deps = [ - ":base", - ":callback", - ":file", ":status", - ":strings", + ":statusor", + ":timer", "@com_google_protobuf_cc//:protobuf", ], ) @@ -132,7 +143,7 @@ cc_library( ], deps = [ ":base", - ":strings", + "@com_google_absl//absl/strings:strings", "@com_google_protobuf_cc//:protobuf", ], ) @@ -176,7 +187,7 @@ cc_library( deps = [ ":base", ":hash", - ":strings", + "@com_google_absl//absl/strings:strings", ], ) @@ -210,6 +221,13 @@ cc_library( ], ) +cc_library( + name = "canonical_errors", + hdrs = [ + "canonical_errors.h", + ], +) + cc_library( name = "stl_util", hdrs = [ @@ -240,28 +258,17 @@ cc_library( ], ) -cc_library( - name = "strongly_connected_components", - hdrs = [ - "strongly_connected_components.h", - ], - deps = [ - ":base", - ], -) - cc_library( name = "timer", srcs = [ - "time_support.cc", "timer.cc", ], hdrs = [ - "time_support.h", "timer.h", ], deps = [ ":base", + "@com_google_absl//absl/time", ], ) @@ -304,19 +311,6 @@ cc_library( ], ) -cc_library( - name = "mutex", - srcs = [ - "mutex.cc", - ], - hdrs = [ - "mutex.h", - ], - deps = [ - ":base", - ], -) - cc_library( name = "threadpool", srcs = [ @@ -327,27 +321,6 @@ cc_library( ], deps = [ ":base", - ":mutex", - ], -) - -cc_library( - name = "inlined_vector", - hdrs = [ - "inlined_vector.h", - ], - deps = [ - ":base", - ], -) - -cc_library( - name = "span", - hdrs = [ - "span.h", - ], - deps = [ - ":base", - ":inlined_vector", + "@com_google_absl//absl/synchronization", ], ) diff --git a/ortools/bop/BUILD b/ortools/bop/BUILD index c1a86311fc9..bb37c8e72c5 100644 --- a/ortools/bop/BUILD +++ b/ortools/bop/BUILD @@ -31,15 +31,16 @@ cc_library( "//ortools/base", "//ortools/base:int_type", "//ortools/base:int_type_indexed_vector", - # "//ortools/glop:lp_solver", - "//ortools/glop", + "@com_google_absl//absl/synchronization", + "//ortools/glop:lp_solver", +# "//ortools/glop", "//ortools/lp_data:base", "//ortools/sat:boolean_problem", "//ortools/sat:boolean_problem_cc_proto", "//ortools/sat:clause", "//ortools/sat:sat_base", "//ortools/sat:sat_solver", - # "//ortools/thread", + "//ortools/base:threadpool", "//ortools/util:stats", "//ortools/util:time_limit", ], @@ -88,8 +89,8 @@ cc_library( "//ortools/base:int_type_indexed_vector", "//ortools/base:random", "//ortools/base:stl_util", - # "//ortools/glop:lp_solver", - "//ortools/glop", + "//ortools/glop:lp_solver", + #"//ortools/glop", "//ortools/lp_data:lp_print_utils", "//ortools/sat:boolean_problem", "//ortools/sat:boolean_problem_cc_proto", @@ -120,8 +121,8 @@ cc_library( "//ortools/base:int_type_indexed_vector", "//ortools/base:random", "//ortools/base:stl_util", - # "//ortools/glop:lp_solver", - "//ortools/glop", + "//ortools/glop:lp_solver", + #"//ortools/glop", "//ortools/lp_data:lp_print_utils", "//ortools/sat:boolean_problem", "//ortools/sat:boolean_problem_cc_proto", @@ -197,8 +198,8 @@ cc_library( "//ortools/base:int_type_indexed_vector", "//ortools/base:statusor", "//ortools/base:stl_util", - # "//ortools/glop:lp_solver", - "//ortools/glop", + "//ortools/glop:lp_solver", + #"//ortools/glop", "//ortools/sat:boolean_problem", "//ortools/sat:boolean_problem_cc_proto", "//ortools/sat:sat_solver", @@ -228,14 +229,14 @@ cc_library( "//ortools/base:int_type_indexed_vector", "//ortools/base:random", "//ortools/base:stl_util", - # "//ortools/glop:lp_solver", - "//ortools/glop", + "//ortools/glop:lp_solver", + #"//ortools/glop", "//ortools/lp_data:lp_print_utils", "//ortools/sat:boolean_problem", "//ortools/sat:boolean_problem_cc_proto", "//ortools/sat:lp_utils", "//ortools/sat:sat_solver", - # "//ortools/thread", + "//ortools/base:threadpool", "//ortools/util:bitset", "//ortools/util:stats", "//ortools/util:time_limit", @@ -262,7 +263,7 @@ cc_library( "//ortools/base:int_type_indexed_vector", "//ortools/base:random", "//ortools/base:stl_util", - "//ortools/glop", + "//ortools/glop:lp_solver", "//ortools/lp_data", "//ortools/lp_data:lp_decomposer", "//ortools/lp_data:lp_utils", diff --git a/ortools/constraint_solver/BUILD b/ortools/constraint_solver/BUILD index b63ec963038..f90b8bf6709 100644 --- a/ortools/constraint_solver/BUILD +++ b/ortools/constraint_solver/BUILD @@ -1,4 +1,8 @@ -package(default_visibility = ["//visibility:public"]) +# Home of constraint solver constraint_solver + +package( + default_visibility = ["//visibility:public"], +) proto_library( name = "assignment_proto", @@ -11,34 +15,28 @@ cc_proto_library( ) proto_library( - name = "demon_profiler_proto", - srcs = ["demon_profiler.proto"], + name = "search_limit_proto", + srcs = ["search_limit.proto"], ) cc_proto_library( - name = "demon_profiler_cc_proto", - deps = [":demon_profiler_proto"], -) - -proto_library( - name = "model_proto", - srcs = ["model.proto"], + name = "search_limit_cc_proto", deps = [":search_limit_proto"], ) -cc_proto_library( - name = "model_cc_proto", - deps = [":model_proto"], +java_proto_library( + name = "search_limit_java_proto", + deps = [":search_limit_proto"], ) proto_library( - name = "search_limit_proto", - srcs = ["search_limit.proto"], + name = "demon_profiler_proto", + srcs = ["demon_profiler.proto"], ) cc_proto_library( - name = "search_limit_cc_proto", - deps = [":search_limit_proto"], + name = "demon_profiler_cc_proto", + deps = [":demon_profiler_proto"], ) proto_library( @@ -51,14 +49,39 @@ cc_proto_library( deps = ["solver_parameters_proto"], ) +java_proto_library( + name = "solver_parameters_java_proto", + deps = [":solver_parameters_proto"], +) + +#py_proto_library( +# name = "assignment_py_pb2", +# deps = [":assignment_proto"], +#) + +#py_proto_library( +# name = "search_limit_py_pb2", +# deps = [":search_limit_proto"], +#) + +#py_proto_library( +# name = "demon_profiler_py_pb2", +# deps = [":demon_profiler_proto"], +#) + +#py_proto_library( +# name = "solver_parameters_py_pb2", +# deps = [":solver_parameters_proto"], +#) + +# ----- Constraint Programming core engine ----- + +# This is the main library. cc_library( name = "cp", srcs = [ - "ac4_mdd_reset_table.cc", - "ac4r_table.cc", "alldiff_cst.cc", "assignment.cc", - "collect_variables.cc", "constraint_solver.cc", "constraints.cc", "count_cst.cc", @@ -70,17 +93,13 @@ cc_library( "expr_array.cc", "expr_cst.cc", "expressions.cc", - "gcc.cc", "graph_constraints.cc", "interval.cc", - "io.cc", "local_search.cc", "model_cache.cc", - "nogoods.cc", "pack.cc", "range_cst.cc", "resource.cc", - "sat_constraint.cc", "sched_constraints.cc", "sched_expr.cc", "sched_search.cc", @@ -88,46 +107,43 @@ cc_library( "table.cc", "timetabling.cc", "trace.cc", - "tree_monitor.cc", "utilities.cc", "visitor.cc", ], hdrs = [ "constraint_solver.h", "constraint_solveri.h", - "sat_constraint.h", ], - copts = [ - "-Wno-sign-compare", - "-Wno-deprecated", - ], - linkopts = ["-lz"], + visibility = ["//visibility:public"], deps = [ ":assignment_cc_proto", ":demon_profiler_cc_proto", - ":model_cc_proto", ":search_limit_cc_proto", ":solver_parameters_cc_proto", "//ortools/base", - "//ortools/base:callback", "//ortools/base:file", - "//ortools/base:hash", + "//ortools/base:recordio", + "//ortools/base:sysinfo", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/memory", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", + "@com_google_absl//absl/time", +# "//third_party/zlib:zlibonly", + "//ortools/base:bitmap", "//ortools/base:int_type", "//ortools/base:int_type_indexed_vector", "//ortools/base:map_util", - "//ortools/base:mathutil", - "//ortools/base:random", - "//ortools/base:recordio", - "//ortools/base:small_map", - "//ortools/base:status", "//ortools/base:stl_util", - "//ortools/base:strings", - # "//ortools/base:strings:human_readable", +# "//util/gzip:gzipstring", + "//ortools/base:hash", +# "//util/hash:jenkins", +# "//util/math:fastmath", + "//ortools/base:mathutil", "//ortools/graph:hamiltonian_path", - "//ortools/sat:sat_solver", "//ortools/util:bitset", "//ortools/util:cached_log", - "//ortools/util:iterators", "//ortools/util:monoid_operation_tree", "//ortools/util:piecewise_linear_function", "//ortools/util:range_minimum_query", @@ -136,30 +152,31 @@ cc_library( "//ortools/util:string_array", "//ortools/util:tuple_set", "//ortools/util:vector_map", - "//ortools/util:xml_helper", - "//ortools/base:bitmap", - # "//ortools/util/regexp/re2", - # "//ortools/util/textprogressbar", - # "//ortools/util/time:clock", - # "//ortools/util/time:datetime", + "//ortools/base:random", +# "//util/regexp/re2", + "//ortools/base:status", +# "//util/textprogressbar", + "//ortools/base:timer", +# "//util/zippy", ], ) -# Routing - -cc_proto_library( - name = "routing_enums_cc_proto", - deps = ["routing_enums_proto"], -) +# ----- Routing and ArcRouting ----- proto_library( name = "routing_enums_proto", srcs = ["routing_enums.proto"], + visibility = ["//visibility:public"], ) cc_proto_library( - name = "routing_parameters_cc_proto", - deps = ["routing_parameters_proto"], + name = "routing_enums_cc_proto", + deps = [":routing_enums_proto"], +) + +java_proto_library( + name = "routing_enums_java_proto", + deps = [":routing_enums_proto"], ) proto_library( @@ -168,6 +185,43 @@ proto_library( deps = [ ":routing_enums_proto", ":solver_parameters_proto", + "@com_google_protobuf_cc//:duration_proto", + "//ortools/util:optional_boolean_proto", + ], +) + +cc_proto_library( + name = "routing_parameters_cc_proto", + deps = [":routing_parameters_proto"], +) + +java_proto_library( + name = "routing_parameters_java_proto", + deps = [":routing_parameters_proto"], +) + +#py_proto_library( +# name = "routing_parameters_py_pb2", +# deps = [":routing_parameters_proto"], +#) + +cc_library( + name = "routing_parameters", + srcs = ["routing_parameters.cc"], + hdrs = ["routing_parameters.h"], + visibility = ["//visibility:public"], + deps = [ + ":cp", + ":routing_enums_cc_proto", + ":routing_parameters_cc_proto", + ":solver_parameters_cc_proto", + "//ortools/base", + "@com_google_protobuf_cc//:protobuf", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/time", + "//ortools/util:optional_boolean_cc_proto", + "//ortools/base:statusor", + "//ortools/base:protoutil", ], ) @@ -177,25 +231,25 @@ cc_library( "routing_flags.cc", ], hdrs = ["routing_flags.h"], - copts = [ - "-Wno-sign-compare", - "-Wno-deprecated", - ], + visibility = ["//visibility:public"], deps = [ ":cp", + ":routing_enums_cc_proto", + ":routing_parameters", ":routing_parameters_cc_proto", "//ortools/base", + "@com_google_protobuf_cc//:protobuf", + "@com_google_absl//absl/time", "//ortools/base:map_util", + "//ortools/util:optional_boolean_cc_proto", + "//ortools/base:protoutil", ], ) cc_library( name = "routing_types", hdrs = ["routing_types.h"], - copts = [ - "-Wno-sign-compare", - "-Wno-deprecated", - ], + visibility = ["//visibility:public"], deps = [ "//ortools/base", "//ortools/base:int_type", @@ -206,50 +260,79 @@ cc_library( name = "routing_neighborhoods", srcs = ["routing_neighborhoods.cc"], hdrs = ["routing_neighborhoods.h"], - copts = [ - "-Wno-sign-compare", - "-Wno-deprecated", - ], deps = [ ":cp", ":routing_types", ], ) +cc_library( + name = "routing_index_manager", + srcs = ["routing_index_manager.cc"], + hdrs = ["routing_index_manager.h"], + visibility = ["//visibility:public"], + deps = [ + ":routing_types", + "//ortools/base", + "@com_google_absl//absl/container:flat_hash_set", + "//ortools/base:int_type_indexed_vector", + "//ortools/base:map_util", + ], +) + cc_library( name = "routing", srcs = [ "routing.cc", + "routing_flow.cc", + "routing_lp_scheduling.cc", "routing_search.cc", ], - hdrs = ["routing.h"], - copts = [ - "-Wno-sign-compare", - "-Wno-deprecated", + hdrs = [ + "routing.h", + "routing_lp_scheduling.h", ], + visibility = ["//visibility:public"], deps = [ - ":model_cc_proto", + ":cp", + ":routing_enums_cc_proto", + ":routing_index_manager", ":routing_neighborhoods", + ":routing_parameters", ":routing_parameters_cc_proto", ":routing_types", "//ortools/base", - "//ortools/base:adjustable_priority_queue", - "//ortools/base:hash", + "@com_google_protobuf_cc//:protobuf", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/hash", + "@com_google_absl//absl/memory", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", + "@com_google_absl//absl/time", +# "//third_party/kdtree", + "//ortools/graph", "//ortools/base:int_type_indexed_vector", "//ortools/base:map_util", "//ortools/base:small_map", "//ortools/base:small_ordered_set", "//ortools/base:stl_util", - "//ortools/base:strings", - "//ortools/constraint_solver:cp", - "//ortools/graph", + "//ortools/base:hash", + "//ortools/base:murmur", + "//ortools/glop:lp_solver", "//ortools/graph:christofides", "//ortools/graph:connectivity", "//ortools/graph:linear_assignment", + "//ortools/graph:min_cost_flow", + "//ortools/lp_data", + "//ortools/lp_data:base", + "//ortools/sat:theta_tree", "//ortools/util:bitset", + "//ortools/util:optional_boolean_cc_proto", "//ortools/util:range_query_function", "//ortools/util:saturated_arithmetic", "//ortools/util:sorted_interval_list", - "@com_google_protobuf_cc//:protobuf", + "//ortools/base:adjustable_priority_queue", + "//ortools/base:protoutil", ], ) diff --git a/ortools/data/BUILD b/ortools/data/BUILD new file mode 100644 index 00000000000..c225fcf3f1e --- /dev/null +++ b/ortools/data/BUILD @@ -0,0 +1,51 @@ +package(default_visibility = ["//visibility:public"]) + +proto_library( + name = "jobshop_scheduling_proto", + srcs = ["jobshop_scheduling.proto"], + deps = [ + "@com_google_protobuf//:wrappers_proto", + ], +) + +cc_proto_library( + name = "jobshop_scheduling_cc_proto", + deps = [":jobshop_scheduling_proto"], +) + +cc_library( + name = "jobshop_scheduling_parser", + srcs = ["jobshop_scheduling_parser.cc"], + hdrs = ["jobshop_scheduling_parser.h"], + deps = [ + ":jobshop_scheduling_cc_proto", + "//ortools/base", + "//ortools/base:filelineiter", + "@com_google_absl//absl/strings", + "@com_google_protobuf//:protobuf", + ], +) + +proto_library( + name = "rcpsp_proto", + srcs = ["rcpsp.proto"], +) + +cc_proto_library( + name = "rcpsp_cc_proto", + deps = [":rcpsp_proto"], +) + +cc_library( + name = "rcpsp_parser", + srcs = ["rcpsp_parser.cc"], + hdrs = ["rcpsp_parser.h"], + visibility = ["//visibility:public"], + deps = [ + ":rcpsp_cc_proto", + "//ortools/base", + "//ortools/base:file", + "//ortools/base:filelineiter", + "@com_google_absl//absl/strings", + ], +) diff --git a/ortools/data/jobshop_scheduling_parser.cc b/ortools/data/jobshop_scheduling_parser.cc index 1488777c1c6..da5c0880ccc 100644 --- a/ortools/data/jobshop_scheduling_parser.cc +++ b/ortools/data/jobshop_scheduling_parser.cc @@ -18,6 +18,7 @@ #include "absl/strings/numbers.h" #include "absl/strings/str_split.h" #include "google/protobuf/wrappers.pb.h" +#include "ortools/base/commandlineflags.h" #include "ortools/base/filelineiter.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" diff --git a/ortools/flatzinc/BUILD b/ortools/flatzinc/BUILD index 34f0af51d73..e51a4d5f66f 100644 --- a/ortools/flatzinc/BUILD +++ b/ortools/flatzinc/BUILD @@ -19,22 +19,15 @@ cc_library( "//ortools/base:hash", "//ortools/base:map_util", "//ortools/base:stl_util", - "//ortools/base:strings", - "//ortools/util:iterators", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", + "//ortools/graph:iterators", "//ortools/util:string_array", ], ) -#cc_test( -# name = "model_test", -# size = "small", -# srcs = ["model_test.cc"], -# deps = [ -# ":model", -# "//@gtest//:main", -# ], -#) - cc_library( name = "parser_yacc_lib", srcs = ["parser.tab.cc"], @@ -44,15 +37,15 @@ cc_library( "parser_util.h", ], copts = [ - # "-Xclang-only=-Wno-implicit-fallthrough", "$(STACK_FRAME_UNLIMITED)", # parser.tab.cc ], deps = [ ":model", "//ortools/base", "//ortools/base:map_util", + "//ortools/base:mathutil", "//ortools/base:stl_util", - "//ortools/base:strings", + "@com_google_absl//absl/strings", "//ortools/util:string_array", ], ) @@ -61,12 +54,13 @@ cc_library( name = "parser_lex_lib", srcs = ["parser.yy.cc"], copts = [ - # "-Xclang-only=-Wno-implicit-fallthrough", "-Wno-unused-function", # parser.yy.cc ], deps = [ ":parser_yacc_lib", "//ortools/base", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", ], ) @@ -81,24 +75,6 @@ cc_library( ], ) -#cc_test( -# name = "parser_test", -# size = "small", -# srcs = ["parser_test.cc"], -# data = [ -# "testdata/M12.fzn", -# "testdata/alpha.fzn", -# "testdata/golomb.fzn", -# ], -# deps = [ -# ":model", -# ":parser_lib", -# "//@gtest//:main", -# "//ortools/base:file", -# "//ortools/base:file:path", -# ], -#) - cc_library( name = "presolve", srcs = ["presolve.cc"], @@ -109,26 +85,13 @@ cc_library( "//ortools/base", "//ortools/base:hash", "//ortools/base:map_util", - "//ortools/base:strings", + "@com_google_absl//absl/strings", "//ortools/graph:cliques", "//ortools/util:saturated_arithmetic", "//ortools/util:vector_map", ], ) -#cc_test( -# name = "presolve_test", -# size = "small", -# srcs = ["presolve_test.cc"], -# deps = [ -# ":model", -# ":presolve", -# "//@gtest//:main", -# "//ortools/base:file", -# "//ortools/base:file:path", -# ], -#) - cc_library( name = "checker", srcs = ["checker.cc"], @@ -139,7 +102,8 @@ cc_library( "//ortools/base", "//ortools/base:hash", "//ortools/base:map_util", - "//ortools/base:strings", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/strings", ], ) @@ -182,7 +146,7 @@ cc_library( deps = [ ":logging", "//ortools/base", - "//ortools/base:mutex", + "@com_google_absl//absl/synchronization", "//ortools/constraint_solver:cp", ], ) @@ -269,8 +233,9 @@ cc_library( ":model", ":solver", "//ortools/base", - "//ortools/base:strings", "//ortools/base:map_util", + "@com_google_absl//absl/strings", + "//ortools/base:threadpool", "//ortools/sat:cp_constraints", "//ortools/sat:cp_model_cc_proto", "//ortools/sat:cp_model_solver", @@ -284,8 +249,10 @@ cc_library( "//ortools/sat:optimization", "//ortools/sat:sat_solver", "//ortools/sat:table", + "//ortools/util:sigint", ], ) + cc_binary( name = "fz", srcs = ["fz.cc"], diff --git a/ortools/flatzinc/fz.cc b/ortools/flatzinc/fz.cc index b2b19708f63..2289ff14b9e 100644 --- a/ortools/flatzinc/fz.cc +++ b/ortools/flatzinc/fz.cc @@ -33,7 +33,7 @@ #include "ortools/flatzinc/model.h" #include "ortools/flatzinc/parser.h" #include "ortools/flatzinc/presolve.h" -#include "ortools/flatzinc/reporting.h" +//#include "ortools/flatzinc/reporting.h" DEFINE_int32(time_limit, 0, "time limit in ms."); DEFINE_bool(all_solutions, false, "Search for all solutions."); diff --git a/ortools/glop/BUILD b/ortools/glop/BUILD index e6cbdfbdcb8..78b3363a06e 100644 --- a/ortools/glop/BUILD +++ b/ortools/glop/BUILD @@ -1,4 +1,176 @@ -package(default_visibility = ["//visibility:public"]) +package( + default_visibility = ["//visibility:public"], +) + +# Floating-point code in this directory must not be compiled with +# dangerous optimizations. For example do not assume that FP expressions +# are associative. This is what -fno-fast-math is for. +SAFE_FP_CODE = ["-fno-fast-math"] + +# Revised Simplex LP solver. + +cc_library( + name = "revised_simplex", + srcs = ["revised_simplex.cc"], + hdrs = ["revised_simplex.h"], + copts = SAFE_FP_CODE, + deps = [ + ":basis_representation", + ":dual_edge_norms", + ":entering_variable", + ":initial_basis", + ":parameters_cc_proto", + ":primal_edge_norms", + ":reduced_costs", + ":status", + ":update_row", + ":variable_values", + ":variables_info", + "//ortools/base", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", + "//ortools/lp_data", + "//ortools/lp_data:base", + "//ortools/lp_data:lp_print_utils", + "//ortools/lp_data:lp_utils", + "//ortools/lp_data:matrix_utils", + "//ortools/lp_data:sparse_row", + "//ortools/util:fp_utils", + "//ortools/util:random_engine", + "//ortools/util:time_limit", + ], +) + +# Update row. + +cc_library( + name = "update_row", + srcs = ["update_row.cc"], + hdrs = ["update_row.h"], + copts = SAFE_FP_CODE, + deps = [ + ":basis_representation", + ":parameters_cc_proto", + ":variables_info", + "//ortools/base", + "//ortools/lp_data:base", + "//ortools/lp_data:lp_utils", + "//ortools/util:stats", + ], +) + +# Variables info. + +cc_library( + name = "variables_info", + srcs = ["variables_info.cc"], + hdrs = ["variables_info.h"], + copts = SAFE_FP_CODE, + deps = [ + "//ortools/base", + "//ortools/lp_data:base", + "//ortools/lp_data:sparse", + ], +) + +# LU factorization of sparse matrices. + +cc_library( + name = "lu_factorization", + srcs = ["lu_factorization.cc"], + hdrs = ["lu_factorization.h"], + copts = SAFE_FP_CODE, + deps = [ + ":markowitz", + ":parameters_cc_proto", + ":status", + "//ortools/lp_data:lp_utils", + "//ortools/lp_data:sparse", + "//ortools/util:stats", + ], +) + +cc_library( + name = "markowitz", + srcs = ["markowitz.cc"], + hdrs = ["markowitz.h"], + copts = SAFE_FP_CODE, + deps = [ + ":parameters_cc_proto", + ":status", + "//ortools/base", + "@com_google_absl//absl/container:inlined_vector", + "//ortools/lp_data:base", + "//ortools/lp_data:lp_utils", + "//ortools/lp_data:sparse", + "//ortools/util:stats", + ], +) + +# Basis representations (Eta and LU). + +cc_library( + name = "basis_representation", + srcs = ["basis_representation.cc"], + hdrs = ["basis_representation.h"], + copts = SAFE_FP_CODE, + deps = [ + ":lu_factorization", + ":parameters_cc_proto", + ":rank_one_update", + ":status", + "//ortools/base", + "//ortools/base:stl_util", + "//ortools/lp_data:base", + "//ortools/lp_data:lp_utils", + "//ortools/lp_data:sparse", + "//ortools/util:stats", + ], +) + +cc_library( + name = "rank_one_update", + hdrs = ["rank_one_update.h"], + copts = SAFE_FP_CODE, + deps = [ + ":status", + "//ortools/base", + "//ortools/lp_data:base", + "//ortools/lp_data:lp_utils", + "//ortools/lp_data:sparse", + ], +) + +# Initial basis. + +cc_library( + name = "initial_basis", + srcs = ["initial_basis.cc"], + hdrs = ["initial_basis.h"], + copts = SAFE_FP_CODE, + deps = [ + ":markowitz", + "//ortools/base", + "//ortools/lp_data", + "//ortools/lp_data:base", + "//ortools/lp_data:lp_utils", + "//ortools/lp_data:sparse", + ], +) + +# Function status. + +cc_library( + name = "status", + srcs = ["status.cc"], + hdrs = ["status.h"], + copts = SAFE_FP_CODE, + deps = [ + "//ortools/base", + ], +) + +# Glop parameters. cc_proto_library( name = "parameters_cc_proto", @@ -10,75 +182,152 @@ proto_library( srcs = ["parameters.proto"], ) -SAFE_FP_CODE = ["-fno-fast-math"] +# Dual edge norms. + +cc_library( + name = "dual_edge_norms", + srcs = ["dual_edge_norms.cc"], + hdrs = ["dual_edge_norms.h"], + copts = SAFE_FP_CODE, + deps = [ + ":basis_representation", + ":parameters_cc_proto", + "//ortools/base", + "//ortools/lp_data", + "//ortools/lp_data:base", + "//ortools/lp_data:lp_utils", + "//ortools/util:stats", + ], +) + +# Primal edge norms. -# GLOP library with minimal external dependencies for easier use on -# portable targets (e.g., Android, iOS). -# We define a separate target to: -# * Avoid select(), which doesn't work with blaze query -# * Define ANDROID_JNI, which is necessary for portable build -cc_library( - name = "glop", - srcs = [ - "basis_representation.cc", - "dual_edge_norms.cc", - "entering_variable.cc", - "initial_basis.cc", - "lp_solver.cc", - "lu_factorization.cc", - "markowitz.cc", - "preprocessor.cc", - "primal_edge_norms.cc", - "reduced_costs.cc", - "revised_simplex.cc", - "status.cc", - "update_row.cc", - "variable_values.cc", - "variables_info.cc", - ], - hdrs = [ - "basis_representation.h", - "dual_edge_norms.h", - "entering_variable.h", - "initial_basis.h", - "lp_solver.h", - "lu_factorization.h", - "markowitz.h", - "preprocessor.h", - "primal_edge_norms.h", - "rank_one_update.h", - "reduced_costs.h", - "revised_simplex.h", - "status.h", - "update_row.h", - "variable_values.h", - "variables_info.h", - ], - copts = SAFE_FP_CODE, - visibility = ["//visibility:public"], +cc_library( + name = "primal_edge_norms", + srcs = ["primal_edge_norms.cc"], + hdrs = ["primal_edge_norms.h"], + copts = SAFE_FP_CODE, deps = [ + ":basis_representation", ":parameters_cc_proto", + ":update_row", + ":variables_info", "//ortools/base", - "//ortools/base:hash", + "//ortools/lp_data", + "//ortools/lp_data:base", + "//ortools/lp_data:lp_utils", + "//ortools/util:stats", + ], +) + +cc_library( + name = "reduced_costs", + srcs = ["reduced_costs.cc"], + hdrs = ["reduced_costs.h"], + copts = SAFE_FP_CODE, + deps = [ + ":basis_representation", + ":parameters_cc_proto", + ":primal_edge_norms", + ":status", + ":update_row", + ":variables_info", + "//ortools/base", + "//ortools/lp_data", + "//ortools/lp_data:base", + "//ortools/lp_data:lp_utils", + "//ortools/util:random_engine", + "//ortools/util:stats", "//ortools/base:random", - "//ortools/base:stl_util", - "//ortools/base:strings", - "//ortools/linear_solver:linear_solver_cc_proto", + ], +) + +cc_library( + name = "variable_values", + srcs = ["variable_values.cc"], + hdrs = ["variable_values.h"], + copts = SAFE_FP_CODE, + deps = [ + ":basis_representation", + ":variables_info", + "//ortools/base", + "//ortools/graph:iterators", + "//ortools/lp_data:base", + "//ortools/lp_data:lp_utils", + "//ortools/util:stats", + ], +) + +# Primal pricing rules. + +cc_library( + name = "entering_variable", + srcs = ["entering_variable.cc"], + hdrs = ["entering_variable.h"], + copts = SAFE_FP_CODE, + deps = [ + ":basis_representation", + ":parameters_cc_proto", + ":primal_edge_norms", + ":reduced_costs", + ":status", + ":update_row", + ":variables_info", + "//ortools/base", "//ortools/lp_data", "//ortools/lp_data:base", - "//ortools/lp_data:lp_print_utils", + "//ortools/lp_data:lp_utils", + "//ortools/port:proto_utils", + "//ortools/util:bitset", + "//ortools/base:random", + "//ortools/util:random_engine", + "//ortools/util:stats", + ], +) + +# Preprocessor. + +cc_library( + name = "preprocessor", + srcs = ["preprocessor.cc"], + hdrs = ["preprocessor.h"], + copts = SAFE_FP_CODE, + deps = [ + ":parameters_cc_proto", + ":revised_simplex", + ":status", + "//ortools/base", + "@com_google_absl//absl/strings:str_format", + "//ortools/lp_data", + "//ortools/lp_data:base", + "//ortools/lp_data:lp_data_utils", "//ortools/lp_data:lp_utils", "//ortools/lp_data:matrix_scaler", "//ortools/lp_data:matrix_utils", + ], +) + +# LP Solver. + +cc_library( + name = "lp_solver", + srcs = ["lp_solver.cc"], + hdrs = ["lp_solver.h"], + copts = SAFE_FP_CODE, + deps = [ + ":parameters_cc_proto", + ":preprocessor", + ":status", + "//ortools/base", + "@com_google_absl//absl/strings:strings", + "@com_google_absl//absl/memory", + "@com_google_absl//absl/strings:str_format", + "//ortools/lp_data", + "//ortools/lp_data:base", + "//ortools/lp_data:lp_utils", "//ortools/lp_data:proto_utils", - "//ortools/lp_data:sparse", - "//ortools/lp_data:sparse_row", - "//ortools/util:bitset", - "//ortools/util:file_util", "//ortools/util:fp_utils", - "//ortools/util:iterators", - "//ortools/util:random_engine", - "//ortools/util:stats", "//ortools/util:time_limit", + "//ortools/util:file_util", ], ) diff --git a/ortools/graph/BUILD b/ortools/graph/BUILD index e9b6d071236..f4c64db3941 100644 --- a/ortools/graph/BUILD +++ b/ortools/graph/BUILD @@ -4,8 +4,8 @@ cc_library( name = "graph", hdrs = ["graph.h"], deps = [ + ":iterators", "//ortools/base", - "//ortools/util:iterators", ], ) @@ -23,21 +23,27 @@ cc_library( srcs = ["util.cc"], hdrs = ["util.h"], deps = [ + ":connected_components", ":graph", "//ortools/base:hash", "//ortools/base:map_util", ], ) +cc_library( + name = "iterators", + hdrs = ["iterators.h"], +) + cc_library( name = "io", hdrs = ["io.h"], deps = [ ":graph", + "//ortools/base:filelineiter", "//ortools/base:status", "//ortools/base:statusor", - "//ortools/base:strings", - "//ortools/util:filelineiter", + "@com_google_absl//absl/strings", ], ) @@ -81,7 +87,9 @@ cc_library( # "//ortools/base:int_type_indexed_bitmap", "//ortools/base:int_type_indexed_vector", "//ortools/base:recordio", - "//ortools/base:strings", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/strings", # "//ortools/thread", # "//ortools/util/coding:prefixvarint", ], @@ -112,7 +120,7 @@ cc_library( # deps = [ # "//ortools/base", # "//ortools/base:iterator_adaptors", -# "//ortools/base:strings", +# "@com_google_absl//absl/strings", # "//ortools/thread", # ], #) @@ -126,7 +134,8 @@ cc_library( "//ortools/base:hash", "//ortools/base:int_type", "//ortools/base:int_type_indexed_vector", - "//ortools/base:strings", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/strings", "//ortools/util:time_limit", ], ) @@ -181,7 +190,7 @@ cc_library( ":christofides", ":minimum_spanning_tree", "//ortools/base", - "//ortools/base:strings", + "@com_google_absl//absl/strings", ], ) @@ -196,7 +205,6 @@ cc_library( ], ) - #cc_library( # name = "shortest_paths", # srcs = ["shortest_paths.cc"], @@ -242,6 +250,7 @@ cc_library( ":graph", ":graphs", "//ortools/base", + "@com_google_absl//absl/memory", "//ortools/util:stats", "//ortools/util:zvector", ], @@ -282,13 +291,40 @@ cc_library( deps = [ ":ebert_graph", "//ortools/base", - "//ortools/base:strings", - # "//ortools/testing/production_stub/public:gunit_prod", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", "//ortools/util:permutation", "//ortools/util:zvector", ], ) +cc_library( + name = "connected_components", + srcs = [ + "connected_components.cc", + ], + hdrs = [ + "connected_components.h", + ], + deps = [ + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", + "//ortools/base", + "//ortools/base:map_util", + "//ortools/base:ptr_util", + ], +) + +cc_library( + name = "strongly_connected_components", + hdrs = [ + "strongly_connected_components.h", + ], + deps = [ + "//ortools/base", + ], +) + #cc_library( # name = "biconnected", # srcs = ["biconnected.cc"], diff --git a/ortools/linear_solver/BUILD b/ortools/linear_solver/BUILD index 9d8fc6cb084..7ac54e0b3be 100644 --- a/ortools/linear_solver/BUILD +++ b/ortools/linear_solver/BUILD @@ -1,15 +1,39 @@ package(default_visibility = ["//visibility:public"]) -# If you want to use the GLPK solver, build with '--define USE_GLPK=' (or add -# it to your bazel.rc file). This will download, build and link to GLPK. config_setting( name = "with_glpk", - values = { "define": "USE_GLPK=" } + values = {"define": "USE_GLPK="}, +) + +config_setting( + name = "with_bop", + values = {"define": "USE_BOP="}, +) + +config_setting( + name = "with_cplex", + values = {"define": "USE_CPLEX="}, +) + +config_setting( + name = "with_cbc", + values = {"define": "USE_CBC="}, +) + +config_setting( + name = "with_clp", + values = {"define": "USE_CLP="}, +) + +config_setting( + name = "with_gurobi", + values = {"define": "USE_GUROBI="}, ) proto_library( name = "linear_solver_proto", srcs = ["linear_solver.proto"], + deps = ["//ortools/util:optional_boolean_proto"], ) cc_proto_library( @@ -17,55 +41,86 @@ cc_proto_library( deps = [":linear_solver_proto"], ) +# You can include the interfaces to different solvers by invoking '--define' +# flags. By default only GLOP interface is included. +# +# For instance, if you want to use the GLPK solver, build with +# '--define USE_GLPK=' (or add it to your bazel.rc file). This will download, +# build and link to GLPK. +# +# Currently compiling with '--define USE_BOP=' flag is broken due to the +# circular dependency: +# .-> //ortools/linear_solver:linear_solver +# | //ortools/bop:integral_solver +# | //ortools/bop:bop_solver +# | //ortools/bop:complete_optimizer +# | //ortools/sat:optimization +# `-- //ortools/linear_solver:linear_solver + cc_library( name = "linear_solver", srcs = [ - "bop_interface.cc", - "glop_interface.cc", - "glop_utils.cc", "linear_expr.cc", "linear_solver.cc", "model_exporter.cc", "model_validator.cc", - ] + select({ + "glop_interface.cc", + "glop_utils.cc", + ] + select({ + ":with_bop": ["bop_interface.cc"], + "//conditions:default": [], + }) + select({ + ":with_cbc": ["cbc_interface.cc"], + "//conditions:default": [], + }) + select({ + ":with_clp": ["clp_interface.cc"], + "//conditions:default": [], + }) + select({ + ":with_cplex": ["cplex_interface.cc"], + "//conditions:default": [], + }) + select({ ":with_glpk": ["glpk_interface.cc"], "//conditions:default": [], + }) + select({ + ":with_gurobi": ["gurobi_interface.cc"], + "//conditions:default": [], }), hdrs = [ + "glop_interface.cc", "glop_utils.h", "linear_expr.h", "linear_solver.h", "model_exporter.h", "model_validator.h", ], - copts = [ - "-DUSE_GLOP", - "-DUSE_BOP", - ], defines = [ - "HAVE_CONFIG_H" - ] + select({ - ":with_glpk": ["USE_GLPK"], - "//conditions:default": [], - }), - visibility = ["//visibility:public"], + "USE_GLOP=", + ], deps = [ ":linear_solver_cc_proto", - "//ortools/base:timer", "//ortools/base", - "//ortools/base:file", + "//ortools/base:accurate_sum", + "//ortools/base:canonical_errors", "//ortools/base:hash", "//ortools/base:map_util", + "@com_google_absl//absl/synchronization", + "@com_google_absl//absl/types:optional", + "//ortools/base:status", "//ortools/base:stl_util", - "//ortools/base:random", - "//ortools/bop:bop_parameters_cc_proto", - "//ortools/bop:integral_solver", - "//ortools/glop", + "@com_google_absl//absl/strings", + "//ortools/base:timer", + "//ortools/glop:lp_solver", "//ortools/glop:parameters_cc_proto", - "//ortools/lp_data", + "//ortools/port:file", + "//ortools/port:proto_utils", "//ortools/util:fp_utils", - "//ortools/util:proto_tools", ] + select({ + ":with_bop": [ + "//ortools/bop:bop_parameters_cc_proto", + "//ortools/bop:integral_solver", + ], + "//conditions:default": [], + }) + select({ ":with_glpk": ["@glpk//:glpk"], "//conditions:default": [], }), diff --git a/ortools/lp_data/BUILD b/ortools/lp_data/BUILD index 5e14aa775e9..5492050f153 100644 --- a/ortools/lp_data/BUILD +++ b/ortools/lp_data/BUILD @@ -41,8 +41,9 @@ cc_library( ":base", ":permutation", "//ortools/base", - "//ortools/base:strings", - "//ortools/util:iterators", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", + "//ortools/graph:iterators", "//ortools/util:return_macros", ], ) @@ -56,6 +57,7 @@ cc_library( ":base", ":sparse_vector", "//ortools/base", + "//ortools/base:random", ], ) @@ -86,7 +88,8 @@ cc_library( "//ortools/base:hash", "//ortools/base:int_type", "//ortools/base:int_type_indexed_vector", - "//ortools/base:strings", + "//ortools/base:random", + "@com_google_absl//absl/strings", "//ortools/util:fp_utils", "//ortools/util:return_macros", ], @@ -104,6 +107,9 @@ cc_library( "//ortools/base", "//ortools/base:hash", "//ortools/base:int_type_indexed_vector", + "//ortools/glop:parameters_cc_proto", + "//ortools/glop:revised_simplex", + "//ortools/glop:status", "//ortools/util:fp_utils", ], ) @@ -127,7 +133,6 @@ cc_library( ":base", ":lp_print_utils", ":lp_utils", - ":matrix_scaler", ":matrix_utils", ":permutation", ":sparse", @@ -135,11 +140,26 @@ cc_library( "//ortools/base:hash", "//ortools/base:int_type", "//ortools/base:int_type_indexed_vector", - "//ortools/base:strings", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/strings", + "//ortools/glop:parameters_cc_proto", "//ortools/util:fp_utils", ], ) +cc_library( + name = "lp_data_utils", + srcs = ["lp_data_utils.cc"], + hdrs = ["lp_data_utils.h"], + deps = [ + ":base", + ":lp_data", + ":matrix_scaler", + "//ortools/glop:parameters_cc_proto", + ], +) + cc_library( name = "lp_utils", srcs = ["lp_utils.cc"], @@ -176,7 +196,7 @@ cc_library( # ":base", # ":lp_data", # "//ortools/base", -# "//ortools/base:strings", +# "@com_google_absl//absl/strings", # "//ortools/util/regexp/re2", # ], #) @@ -200,7 +220,8 @@ cc_library( deps = [ ":base", "//ortools/base", - "//ortools/base:strings", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", "//ortools/util:rational_approximation", ], ) @@ -229,17 +250,13 @@ cc_library( ":lp_print_utils", "//ortools/base", "//ortools/base:file", - # "//ortools/base:file:path", - "//ortools/base:filelinereader", + "//ortools/base:filelineiter", "//ortools/base:hash", "//ortools/base:int_type", "//ortools/base:int_type_indexed_vector", "//ortools/base:map_util", "//ortools/base:status", - "//ortools/base:strings", - # "//ortools/file/localfile", - # "//ortools/file/memfile", - # "//ortools/file/zipfile", + "@com_google_absl//absl/strings", ], ) @@ -271,6 +288,7 @@ cc_library( "//ortools/algorithms:dynamic_partition", "//ortools/base", "//ortools/base:hash", - "//ortools/base:mutex", + "@com_google_absl//absl/synchronization", + "//ortools/glop:parameters_cc_proto", ], ) diff --git a/ortools/port/BUILD b/ortools/port/BUILD index 9467d0633d4..eff7d398e40 100644 --- a/ortools/port/BUILD +++ b/ortools/port/BUILD @@ -18,3 +18,30 @@ cc_library( "//ortools/base:sysinfo", ], ) + +cc_library( + name = "file", + srcs = [ + "file_nonport.cc", + ], + hdrs = [ + "file.h", + ], + deps = [ + "//ortools/base:file", + "//ortools/base:status", + "@com_google_absl//absl/strings", + ], +) + +cc_library( + name = "proto_utils", + hdrs = [ + "proto_utils.h", + ], + deps = [ + "//ortools/base", + "@com_google_absl//absl/strings", + "@com_google_protobuf_cc//:protobuf", + ], +) diff --git a/ortools/sat/BUILD b/ortools/sat/BUILD index 1e948b0f33b..8f7d084aa2e 100644 --- a/ortools/sat/BUILD +++ b/ortools/sat/BUILD @@ -1,5 +1,6 @@ -# Description: -# Home of SAT solver +# Home of CP/SAT solver (which includes SAT, max-SAT and PB problems). +# + package( default_visibility = ["//visibility:public"], ) @@ -34,6 +35,35 @@ proto_library( srcs = ["cp_model.proto"], ) +cc_library( + name = "cp_model", + srcs = ["cp_model.cc"], + hdrs = ["cp_model.h"], + visibility = ["//visibility:public"], + deps = [ + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/strings:str_format", + "@com_google_absl//absl/types:span", + "//ortools/base:map_util", + "//ortools/sat:cp_model_cc_proto", + "//ortools/sat:cp_model_solver", + "//ortools/sat:cp_model_utils", + "//ortools/sat:model", + "//ortools/util:sorted_interval_list", + ], +) + +cc_library( + name = "model", + hdrs = ["model.h"], + visibility = ["//visibility:public"], + deps = [ + "//ortools/base", + "//ortools/base:map_util", + "//ortools/base:typeid", + ], +) + cc_library( name = "cp_model_utils", srcs = ["cp_model_utils.cc"], @@ -42,11 +72,32 @@ cc_library( deps = [ ":cp_model_cc_proto", "//ortools/base", + "@com_google_absl//absl/container:flat_hash_set", "//ortools/base:stl_util", "//ortools/util:sorted_interval_list", ], ) +cc_library( + name = "synchronization", + srcs = ["synchronization.cc"], + hdrs = ["synchronization.h"], + visibility = ["//visibility:public"], + deps = [ + ":cp_model_loader", + ":cp_model_cc_proto", + ":cp_model_utils", + ":integer", + ":integer_search", + ":model", + ":sat_base", + "//ortools/base", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/synchronization", + "//ortools/util:bitset", + ], +) + cc_library( name = "cp_model_checker", srcs = ["cp_model_checker.cc"], @@ -56,39 +107,135 @@ cc_library( ":cp_model_cc_proto", ":cp_model_utils", "//ortools/base", - "//ortools/base:hash", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/strings", "//ortools/base:map_util", - "//ortools/base:strings", + "//ortools/base:hash", + "//ortools/port:proto_utils", "//ortools/util:saturated_arithmetic", "//ortools/util:sorted_interval_list", ], ) +cc_library( + name = "cp_model_search", + srcs = ["cp_model_search.cc"], + hdrs = ["cp_model_search.h"], + deps = [ + ":cp_model_cc_proto", + ":cp_model_utils", + ":integer", + ":integer_search", + ":model", + ":util", + "//ortools/base", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/strings:str_format", + "//ortools/base:cleanup", + ], +) + +cc_library( + name = "cp_model_objective", + srcs = ["cp_model_objective.cc"], + hdrs = ["cp_model_objective.h"], + deps = [ + ":cp_model_cc_proto", + ":cp_model_utils", + "//ortools/base", + ], +) + cc_library( name = "cp_model_solver", srcs = ["cp_model_solver.cc"], hdrs = ["cp_model_solver.h"], visibility = ["//visibility:public"], deps = [ - ":all_different", - ":cp_model_cc_proto", + ":circuit", + ":clause", ":cp_model_checker", + ":cp_model_expand", + ":cp_model_lns", + ":cp_model_loader", ":cp_model_presolve", + ":cp_model_cc_proto", + ":cp_model_search", + ":cp_model_utils", + ":drat_checker", + ":probing", + ":drat_proof_handler", + ":integer", + ":integer_expr", + ":integer_search", + ":linear_programming_constraint", + ":linear_relaxation", + ":lns", + ":model", + ":optimization", + ":precedences", + ":sat_base", + ":sat_parameters_cc_proto", + ":sat_solver", + ":simplification", + ":synchronization", + "//ortools/base", + "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/memory", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", + "@com_google_absl//absl/synchronization", + "//ortools/base:threadpool", + "//ortools/base:int_type", + "//ortools/base:int_type_indexed_vector", + "//ortools/base:map_util", + "//ortools/graph:connectivity", + "//ortools/port:proto_utils", + "//ortools/util:sorted_interval_list", + "//ortools/util:time_limit", + "//ortools/base:status", + "@com_google_protobuf_cc//:protobuf", + "//ortools/base:file", + ], +) + +cc_library( + name = "cp_model_loader", + srcs = ["cp_model_loader.cc"], + hdrs = ["cp_model_loader.h"], + visibility = ["//visibility:public"], + deps = [ + ":all_different", + ":circuit", + ":cp_constraints", + ":cp_model_cc_proto", ":cp_model_utils", ":cumulative", ":disjunctive", ":integer", + ":integer_expr", ":intervals", - ":linear_programming_constraint", ":model", - ":optimization", + ":pb_constraint", + ":precedences", + ":sat_base", + ":sat_parameters_cc_proto", ":sat_solver", ":table", "//ortools/base", - "//ortools/base:hash", + "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", + "//ortools/base:int_type", + "//ortools/base:int_type_indexed_vector", + "//ortools/base:map_util", "//ortools/base:stl_util", - "//ortools/base:strings", - "//ortools/graph:connectivity", + "//ortools/util:saturated_arithmetic", + "//ortools/util:sorted_interval_list", + "@com_google_protobuf_cc//:protobuf", + "//ortools/base:file", ], ) @@ -96,30 +243,47 @@ cc_library( name = "cp_model_presolve", srcs = ["cp_model_presolve.cc"], hdrs = ["cp_model_presolve.h"], - visibility = ["//visibility:public"], deps = [ - ":cp_model_cc_proto", ":cp_model_checker", + ":cp_model_loader", + ":cp_model_objective", + ":cp_model_cc_proto", ":cp_model_utils", + ":probing", + ":sat_base", + ":sat_parameters_cc_proto", ":simplification", "//ortools/base", - "//ortools/base:hash", + "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/strings", "//ortools/base:map_util", "//ortools/base:stl_util", - "//ortools/base:strings", + "//ortools/base:hash", + "//ortools/base:mathutil", + "//ortools/port:proto_utils", "//ortools/util:affine_relation", "//ortools/util:bitset", "//ortools/util:sorted_interval_list", + "//ortools/util:time_limit", ], ) cc_library( - name = "model", - hdrs = ["model.h"], + name = "cp_model_expand", + srcs = ["cp_model_expand.cc"], + hdrs = ["cp_model_expand.h"], deps = [ + ":cp_model_cc_proto", + ":cp_model_presolve", + ":cp_model_utils", "//ortools/base", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/container:flat_hash_map", "//ortools/base:map_util", - "//ortools/base:typeid", + "//ortools/base:hash", + "//ortools/util:saturated_arithmetic", ], ) @@ -129,16 +293,18 @@ cc_library( deps = [ ":model", "//ortools/base", + "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/strings:str_format", + "@com_google_absl//absl/types:span", "//ortools/base:int_type", "//ortools/base:int_type_indexed_vector", - "//ortools/base:span", - "//ortools/base:strings", "//ortools/util:bitset", ], ) -# W_FLOAT_CONVERSION = "-Xclang-only=-Wfloat-conversion" -W_FLOAT_CONVERSION = "" +# Enable a warning to check for floating point to integer conversions. +# In GCC-4.8, this was "-Wreal-conversion", but was removed in 4.9 +# In Clang, this warning is "-Wfloat-conversion" cc_library( name = "sat_solver", @@ -146,29 +312,75 @@ cc_library( "sat_solver.cc", ], hdrs = ["sat_solver.h"], - copts = [W_FLOAT_CONVERSION], deps = [ ":clause", - ":drat", + ":drat_proof_handler", ":model", ":pb_constraint", + ":restart", ":sat_base", + ":sat_decision", ":sat_parameters_cc_proto", + ":util", "//ortools/base", - "//ortools/base:adjustable_priority_queue", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/strings:str_format", + "@com_google_absl//absl/types:span", "//ortools/base:int_type", "//ortools/base:int_type_indexed_vector", "//ortools/base:map_util", - "//ortools/base:random", "//ortools/base:stl_util", - "//ortools/base:strings", - "//ortools/util:bitset", - "//ortools/util:running_stat", + "//ortools/base:hash", + "//ortools/port:proto_utils", + "//ortools/port:sysinfo", "//ortools/util:saturated_arithmetic", "//ortools/util:stats", "//ortools/util:time_limit", - # "//ortools/util/time:clock", - "@com_google_protobuf_cc//:protobuf", + ], +) + +cc_library( + name = "restart", + srcs = ["restart.cc"], + hdrs = ["restart.h"], + deps = [ + ":model", + ":sat_parameters_cc_proto", + "//ortools/base", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", + "//ortools/util:bitset", + "//ortools/util:running_stat", + ], +) + +cc_library( + name = "probing", + srcs = ["probing.cc"], + hdrs = ["probing.h"], + deps = [ + ":clause", + ":integer", + ":model", + ":sat_solver", + "//ortools/base", + ], +) + +cc_library( + name = "sat_decision", + srcs = ["sat_decision.cc"], + hdrs = ["sat_decision.h"], + deps = [ + ":model", + ":pb_constraint", + ":sat_base", + ":sat_parameters_cc_proto", + ":util", + "//ortools/base", + "//ortools/util:bitset", + "//ortools/util:integer_pq", + "//ortools/util:random_engine", ], ) @@ -176,23 +388,24 @@ cc_library( name = "clause", srcs = ["clause.cc"], hdrs = ["clause.h"], - copts = [W_FLOAT_CONVERSION], deps = [ + ":drat_proof_handler", + ":model", ":sat_base", ":sat_parameters_cc_proto", "//ortools/base", - "//ortools/base:hash", - "//ortools/base:inlined_vector", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/container:inlined_vector", + "@com_google_absl//absl/types:span", + "//ortools/graph:strongly_connected_components", "//ortools/base:int_type", "//ortools/base:int_type_indexed_vector", - "//ortools/base:random", - "//ortools/base:span", "//ortools/base:stl_util", - "//ortools/base:strings", + "//ortools/base:hash", "//ortools/util:bitset", "//ortools/util:random_engine", "//ortools/util:stats", - "//ortools/util:time_limit", ], ) @@ -200,19 +413,23 @@ cc_library( name = "simplification", srcs = ["simplification.cc"], hdrs = ["simplification.h"], - copts = [W_FLOAT_CONVERSION], deps = [ - ":drat", + ":drat_proof_handler", ":sat_base", ":sat_parameters_cc_proto", ":sat_solver", ":util", - "//ortools/algorithms:dynamic_partition", "//ortools/base", + "@com_google_absl//absl/memory", + "@com_google_absl//absl/types:span", + "//ortools/graph:strongly_connected_components", + "//ortools/base:int_type", + "//ortools/base:int_type_indexed_vector", + "//ortools/base:stl_util", + "//ortools/algorithms:dynamic_partition", + "//ortools/util:time_limit", "//ortools/base:adjustable_priority_queue", "//ortools/base:random", - "//ortools/base:stl_util", - "//ortools/base:strongly_connected_components", ], ) @@ -220,11 +437,18 @@ cc_library( name = "pb_constraint", srcs = ["pb_constraint.cc"], hdrs = ["pb_constraint.h"], - copts = [W_FLOAT_CONVERSION], deps = [ ":sat_base", ":sat_parameters_cc_proto", + "//ortools/base", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/strings:str_format", + "@com_google_absl//absl/types:span", + "//ortools/base:int_type", + "//ortools/base:int_type_indexed_vector", "//ortools/base:hash", + "//ortools/base:murmur", + "//ortools/util:bitset", "//ortools/util:saturated_arithmetic", "//ortools/util:stats", ], @@ -234,50 +458,70 @@ cc_library( name = "symmetry", srcs = ["symmetry.cc"], hdrs = ["symmetry.h"], - copts = [W_FLOAT_CONVERSION], deps = [ ":sat_base", + "//ortools/base", + "@com_google_absl//absl/types:span", + "//ortools/base:int_type", + "//ortools/base:int_type_indexed_vector", "//ortools/algorithms:sparse_permutation", - "//ortools/base:hash", "//ortools/util:stats", ], ) -cc_library( - name = "no_cycle", - srcs = ["no_cycle.cc"], - hdrs = ["no_cycle.h"], - copts = [W_FLOAT_CONVERSION], - deps = [ - ":model", - ":sat_base", - ":sat_solver", - "//ortools/base:stl_util", - ], -) - cc_library( name = "integer", srcs = ["integer.cc"], hdrs = ["integer.h"], - copts = [W_FLOAT_CONVERSION], deps = [ ":model", ":sat_base", + ":sat_parameters_cc_proto", ":sat_solver", "//ortools/base", - "//ortools/base:inlined_vector", + "@com_google_absl//absl/base:core_headers", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:inlined_vector", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/types:span", + "//ortools/graph:iterators", "//ortools/base:int_type", + "//ortools/base:int_type_indexed_vector", "//ortools/base:iterator_adaptors", "//ortools/base:map_util", - "//ortools/base:span", "//ortools/base:stl_util", - "//ortools/base:strings", + "//ortools/base:hash", "//ortools/util:bitset", - "//ortools/util:iterators", "//ortools/util:rev", "//ortools/util:saturated_arithmetic", "//ortools/util:sorted_interval_list", + "//ortools/util:time_limit", + ], +) + +cc_library( + name = "integer_search", + srcs = ["integer_search.cc"], + hdrs = ["integer_search.h"], + deps = [ + ":integer", + ":linear_programming_constraint", + ":pseudo_costs", + ":sat_base", + ":sat_decision", + ":sat_solver", + ":util", + ], +) + +cc_library( + name = "pseudo_costs", + srcs = ["pseudo_costs.cc"], + hdrs = ["pseudo_costs.h"], + deps = [ + ":integer", + ":sat_decision", + ":sat_parameters_cc_proto", ], ) @@ -285,15 +529,18 @@ cc_library( name = "intervals", srcs = ["intervals.cc"], hdrs = ["intervals.h"], - copts = [W_FLOAT_CONVERSION], deps = [ ":cp_constraints", ":integer", ":integer_expr", ":model", + ":pb_constraint", ":precedences", ":sat_base", ":sat_solver", + "//ortools/base", + "//ortools/base:int_type", + "//ortools/base:int_type_indexed_vector", "//ortools/util:sort", ], ) @@ -302,13 +549,17 @@ cc_library( name = "precedences", srcs = ["precedences.cc"], hdrs = ["precedences.h"], - copts = [W_FLOAT_CONVERSION], deps = [ + ":cp_constraints", ":integer", ":model", ":sat_base", ":sat_solver", + "//ortools/base", + "@com_google_absl//absl/container:inlined_vector", "//ortools/base:cleanup", + "//ortools/base:int_type", + "//ortools/base:int_type_indexed_vector", "//ortools/base:stl_util", "//ortools/util:bitset", ], @@ -318,12 +569,17 @@ cc_library( name = "integer_expr", srcs = ["integer_expr.cc"], hdrs = ["integer_expr.h"], - copts = [W_FLOAT_CONVERSION], deps = [ ":integer", ":model", ":precedences", ":sat_base", + ":sat_solver", + "//ortools/base", + "@com_google_absl//absl/container:flat_hash_map", + "//ortools/base:int_type", + "//ortools/base:stl_util", + "//ortools/util:sorted_interval_list", ], ) @@ -336,8 +592,14 @@ cc_library( ":model", ":sat_base", ":sat_solver", - "//ortools/base:strongly_connected_components", + "//ortools/base", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", + "//ortools/graph:strongly_connected_components", + "//ortools/base:int_type", + "//ortools/base:map_util", "//ortools/util:sort", + "//ortools/util:sorted_interval_list", ], ) @@ -347,6 +609,8 @@ cc_library( hdrs = ["theta_tree.h"], deps = [ ":integer", + "//ortools/base", + "//ortools/base:int_type", ], ) @@ -354,19 +618,19 @@ cc_library( name = "disjunctive", srcs = ["disjunctive.cc"], hdrs = ["disjunctive.h"], - copts = [W_FLOAT_CONVERSION], deps = [ ":all_different", - ":cp_constraints", ":integer", ":intervals", ":model", ":precedences", ":sat_base", + ":sat_parameters_cc_proto", ":sat_solver", ":theta_tree", + "//ortools/base", + "//ortools/base:int_type", "//ortools/base:iterator_adaptors", - "//ortools/util:stats", ], ) @@ -374,15 +638,14 @@ cc_library( name = "timetable", srcs = ["timetable.cc"], hdrs = ["timetable.h"], - copts = [W_FLOAT_CONVERSION], deps = [ ":integer", ":intervals", - ":model", - ":overload_checker", - ":precedences", ":sat_base", ":sat_solver", + "//ortools/base", + "//ortools/base:int_type", + "//ortools/util:rev", "//ortools/util:sort", ], ) @@ -391,13 +654,11 @@ cc_library( name = "timetable_edgefinding", srcs = ["timetable_edgefinding.cc"], hdrs = ["timetable_edgefinding.h"], - copts = [W_FLOAT_CONVERSION], deps = [ ":integer", ":intervals", - ":model", ":sat_base", - ":sat_solver", + "//ortools/base", "//ortools/base:int_type", "//ortools/util:sort", ], @@ -407,17 +668,21 @@ cc_library( name = "cumulative", srcs = ["cumulative.cc"], hdrs = ["cumulative.h"], - copts = [W_FLOAT_CONVERSION], deps = [ ":disjunctive", ":integer", ":intervals", ":model", ":overload_checker", + ":pb_constraint", + ":precedences", ":sat_base", + ":sat_parameters_cc_proto", ":sat_solver", ":timetable", ":timetable_edgefinding", + "//ortools/base", + "//ortools/base:int_type", ], ) @@ -425,39 +690,85 @@ cc_library( name = "overload_checker", srcs = ["overload_checker.cc"], hdrs = ["overload_checker.h"], - copts = [W_FLOAT_CONVERSION], deps = [ ":integer", ":intervals", - ":model", ":sat_base", ":sat_solver", "//ortools/base", - "//ortools/base:iterator_adaptors", + "//ortools/base:int_type", "//ortools/util:sort", ], ) +#cc_library( +# name = "cumulative_energy", +# srcs = ["cumulative_energy.cc"], +# hdrs = ["cumulative_energy.h"], +# deps = [ +# ":integer", +# ":intervals", +# ":model", +# ":sat_base", +# ":sat_solver", +# ":theta_tree", +# "//ortools/base", +# "//ortools/base:int_type", +# "//ortools/base:iterator_adaptors", +# ], +#) + cc_library( name = "boolean_problem", srcs = ["boolean_problem.cc"], hdrs = ["boolean_problem.h"], - copts = [W_FLOAT_CONVERSION], deps = [ ":boolean_problem_cc_proto", ":cp_model_cc_proto", + ":pb_constraint", + ":sat_base", + ":sat_parameters_cc_proto", ":sat_solver", ":simplification", - "//ortools/algorithms:find_graph_symmetries", - "//ortools/algorithms:sparse_permutation", "//ortools/base", - "//ortools/base:hash", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/strings:str_format", + "//ortools/graph:util", + "//ortools/base:int_type", + "//ortools/base:int_type_indexed_vector", "//ortools/base:map_util", + "//ortools/base:hash", + "//ortools/algorithms:find_graph_symmetries", + "//ortools/algorithms:sparse_permutation", + "//ortools/port:proto_utils", "//ortools/base:status", - "//ortools/base:strings", - "//ortools/graph", "//ortools/graph:io", - "//ortools/graph:util", + ], +) + +cc_library( + name = "linear_relaxation", + srcs = ["linear_relaxation.cc"], + hdrs = ["linear_relaxation.h"], + deps = [ + ":cp_model_loader", + ":integer", + ":linear_programming_constraint", + ":model", + "//ortools/base", + "@com_google_absl//absl/container:flat_hash_set", + "//ortools/base:iterator_adaptors", + ], +) + +cc_library( + name = "linear_constraint", + srcs = ["linear_constraint.cc"], + hdrs = ["linear_constraint.h"], + deps = [ + ":integer", + ":model", + "//ortools/base", ], ) @@ -466,12 +777,56 @@ cc_library( srcs = ["linear_programming_constraint.cc"], hdrs = ["linear_programming_constraint.h"], deps = [ + ":cuts", ":integer", + ":integer_expr", + ":linear_constraint", + ":linear_constraint_manager", ":model", - ":sat_base", "//ortools/base", - "//ortools/glop", + "@com_google_absl//absl/container:flat_hash_map", + "//ortools/graph:strongly_connected_components", + "//ortools/base:int_type", + "//ortools/base:int_type_indexed_vector", + "//ortools/base:map_util", + "//ortools/glop:parameters_cc_proto", + "//ortools/glop:preprocessor", + "//ortools/glop:revised_simplex", + "//ortools/glop:status", "//ortools/lp_data", + "//ortools/lp_data:base", + "//ortools/lp_data:matrix_scaler", + "//ortools/util:rev", + "//ortools/util:saturated_arithmetic", + "//ortools/util:time_limit", + ], +) + +cc_library( + name = "linear_constraint_manager", + srcs = ["linear_constraint_manager.cc"], + hdrs = ["linear_constraint_manager.h"], + deps = [ + ":integer", + ":linear_constraint", + ":model", + ":sat_parameters_cc_proto", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", + ], +) + +cc_library( + name = "cuts", + srcs = ["cuts.cc"], + hdrs = ["cuts.h"], + deps = [ + ":integer", + ":linear_constraint", + ":model", + "//ortools/base", + "//ortools/base:int_type", + "//ortools/algorithms:knapsack_solver_for_cuts", "//ortools/util:time_limit", ], ) @@ -480,17 +835,21 @@ cc_library( name = "lp_utils", srcs = ["lp_utils.cc"], hdrs = ["lp_utils.h"], - copts = [W_FLOAT_CONVERSION], deps = [ ":boolean_problem", ":boolean_problem_cc_proto", ":cp_model_cc_proto", + ":integer", + ":sat_base", ":sat_solver", - "//ortools/base:strings", - "//ortools/glop", + "//ortools/base", + "//ortools/base:int_type", + "//ortools/base:int_type_indexed_vector", + "//ortools/glop:lp_solver", + "//ortools/glop:parameters_cc_proto", "//ortools/linear_solver:linear_solver_cc_proto", "//ortools/lp_data", - "//ortools/lp_data:lp_print_utils", + "//ortools/lp_data:base", "//ortools/util:fp_utils", ], ) @@ -499,18 +858,29 @@ cc_library( name = "optimization", srcs = ["optimization.cc"], hdrs = ["optimization.h"], - copts = [W_FLOAT_CONVERSION], deps = [ ":boolean_problem", + ":boolean_problem_cc_proto", ":encoding", ":integer", ":integer_expr", + ":integer_search", ":model", + ":pb_constraint", + ":sat_base", + ":sat_parameters_cc_proto", ":sat_solver", ":util", "//ortools/base", - "//ortools/base:strings", - "@com_google_protobuf_cc//:protobuf", + "//ortools/base:random", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", + "//ortools/base:int_type", + "//ortools/base:map_util", + "//ortools/port:proto_utils", + "//ortools/util:time_limit", + "//ortools/linear_solver:linear_solver_cc_proto", + "//ortools/linear_solver:linear_solver", ], ) @@ -518,12 +888,14 @@ cc_library( name = "util", srcs = ["util.cc"], hdrs = ["util.h"], - copts = [W_FLOAT_CONVERSION], deps = [ + ":model", + ":sat_base", ":sat_parameters_cc_proto", "//ortools/base", + "//ortools/util:random_engine", "//ortools/base:random", - "//ortools/base:strings", + "@com_google_protobuf_cc//:protobuf", ], ) @@ -531,14 +903,18 @@ cc_library( name = "table", srcs = ["table.cc"], hdrs = ["table.h"], - copts = [W_FLOAT_CONVERSION], deps = [ ":integer", ":model", + ":sat_base", + ":sat_solver", "//ortools/base", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/container:flat_hash_set", + "//ortools/base:int_type", "//ortools/base:map_util", "//ortools/base:stl_util", - "//ortools/base:strings", + "//ortools/util:sorted_interval_list", ], ) @@ -546,27 +922,34 @@ cc_library( name = "cp_constraints", srcs = ["cp_constraints.cc"], hdrs = ["cp_constraints.h"], - copts = [W_FLOAT_CONVERSION], deps = [ ":integer", ":model", + ":sat_base", + ":sat_solver", "//ortools/base", + "@com_google_absl//absl/container:flat_hash_map", + "//ortools/base:int_type", "//ortools/base:map_util", + "//ortools/util:rev", "//ortools/util:sort", - "//ortools/util:sorted_interval_list", ], ) cc_library( - name = "flow_costs", - srcs = ["flow_costs.cc"], - hdrs = ["flow_costs.h"], - copts = ["-DUSE_GLOP"], + name = "circuit", + srcs = ["circuit.cc"], + hdrs = ["circuit.h"], deps = [ ":integer", ":model", ":sat_base", - "//ortools/linear_solver", + ":sat_solver", + "//ortools/base", + "@com_google_absl//absl/container:flat_hash_map", + "//ortools/base:int_type", + "//ortools/base:map_util", + "//ortools/util:rev", ], ) @@ -574,26 +957,129 @@ cc_library( name = "encoding", srcs = ["encoding.cc"], hdrs = ["encoding.h"], - copts = [W_FLOAT_CONVERSION], deps = [ ":boolean_problem_cc_proto", + ":pb_constraint", + ":sat_base", + ":sat_parameters_cc_proto", ":sat_solver", "//ortools/base", - "//ortools/base:strings", + "//ortools/base:int_type", ], ) cc_library( - name = "drat", - srcs = ["drat.cc"], - hdrs = ["drat.h"], - copts = [W_FLOAT_CONVERSION], + name = "cp_model_lns", + srcs = ["cp_model_lns.cc"], + hdrs = ["cp_model_lns.h"], + visibility = ["//visibility:public"], deps = [ - ":model", + ":cp_model_cc_proto", + ":cp_model_utils", + "//ortools/base", + "//ortools/util:random_engine", + "//ortools/util:time_limit", + ], +) + +cc_library( + name = "lns", + hdrs = ["lns.h"], + visibility = ["//visibility:public"], + deps = [ + "//ortools/base", + "//ortools/util:time_limit", + ], +) + +cc_library( + name = "drat_proof_handler", + srcs = ["drat_proof_handler.cc"], + hdrs = ["drat_proof_handler.h"], + deps = [ + ":drat_checker", + ":drat_writer", ":sat_base", "//ortools/base", + "@com_google_absl//absl/memory", + "@com_google_absl//absl/types:span", + "//ortools/base:int_type", + "//ortools/base:int_type_indexed_vector", + "//ortools/base:status", "//ortools/base:file", + ], +) + +cc_library( + name = "drat_checker", + srcs = ["drat_checker.cc"], + hdrs = ["drat_checker.h"], +# data = [ +# "testdata/drup.cnf", +# "testdata/drup.drat", +# ], + deps = [ + ":sat_base", + "//ortools/base", + "@com_google_absl//absl/container:flat_hash_set", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/time", + "@com_google_absl//absl/types:span", "//ortools/base:hash", - "//ortools/base:strings", + "//ortools/base:int_type", + "//ortools/base:int_type_indexed_vector", + "//ortools/base:stl_util", + "//ortools/util:time_limit", + "//ortools/base:status", + ], +) + +cc_library( + name = "drat_writer", + srcs = ["drat_writer.cc"], + hdrs = ["drat_writer.h"], + deps = [ + ":sat_base", + "//ortools/base", + "@com_google_absl//absl/strings:str_format", + "@com_google_absl//absl/types:span", + "//ortools/base:status", + "//ortools/base:file", + ], +) + +cc_library( + name = "cp_model_symmetries", + srcs = ["cp_model_symmetries.cc"], + hdrs = ["cp_model_symmetries.h"], + deps = [ + ":cp_model_cc_proto", + ":cp_model_utils", + "@com_google_protobuf_cc//:protobuf", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/memory", + "//ortools/base:map_util", + "//ortools/base:hash", + "//ortools/algorithms:find_graph_symmetries", + "//ortools/algorithms:sparse_permutation", + ], +) + +cc_library( + name = "swig_helper", + hdrs = ["swig_helper.h"], + visibility = [ + "//ortools/sat/java:__pkg__", + "//ortools/sat/python:__pkg__", + ], + deps = [ + ":cp_model_checker", + ":cp_model_cc_proto", + ":cp_model_solver", + ":model", + ":sat_parameters_cc_proto", + "//ortools/base", + "//ortools/util:sigint", + "//ortools/util:time_limit", ], ) diff --git a/ortools/sat/cp_model_presolve.cc b/ortools/sat/cp_model_presolve.cc index 9429fe7eed8..aaad7712e14 100644 --- a/ortools/sat/cp_model_presolve.cc +++ b/ortools/sat/cp_model_presolve.cc @@ -387,7 +387,7 @@ void PresolveContext::FullyEncodeVariable(int var) { for (int64 v = interval.start; v <= interval.end; ++v) { const int lit = NewBoolVar(); AddImplyInDomain(lit, var, Domain(v)); - AddImplyInDomain(NegatedRef(lit), var, Domain(v).Complement()); + // AddImplyInDomain(NegatedRef(lit), var, Domain(v).Complement()); expanded_variables[var][v] = lit; } } @@ -2326,12 +2326,14 @@ bool PresolveAutomaton(ConstraintProto* ct, PresolveContext* context) { context->UpdateRuleStats("automaton: reduce variable domains"); } + const int true_literal = context->GetOrCreateConstantVar(1); + // Encode reachable states for each time point. std::vector> state_literals(n + 1); for (int time = 0; time < n; ++time) { if (reachable_states[time].size() == 1) { const int64 state = *reachable_states[time].begin(); - state_literals[time][state] = context->GetOrCreateConstantVar(1); + state_literals[time][state] = true_literal; } else if (reachable_states[time].size() == 2) { const int lit = context->NewBoolVar(); auto it = reachable_states[time].begin(); @@ -2345,6 +2347,7 @@ bool PresolveAutomaton(ConstraintProto* ct, PresolveContext* context) { context->working_model->add_constraints()->mutable_bool_or(); BoolArgumentProto* const at_most_one = context->working_model->add_constraints()->mutable_at_most_one(); + for (const int64 state : reachable_states[time]) { const int lit = context->NewBoolVar(); state_literals[time][state] = lit; @@ -2360,20 +2363,12 @@ bool PresolveAutomaton(ConstraintProto* ct, PresolveContext* context) { } // Encode each transition. - for (int time = 0; time + 1 < n; ++time) { - absl::flat_hash_map num_incident_arcs; - for (int t = 0; t < proto.transition_tail_size(); ++t) { - const int64 tail = proto.transition_tail(t); - const int64 label = proto.transition_label(t); - const int64 head = proto.transition_head(t); - - if (!gtl::ContainsKey(reachable_states[time], tail)) continue; - if (!context->DomainContains(vars[time], label)) continue; - if (!gtl::ContainsKey(reachable_states[time + 1], head)) continue; - num_incident_arcs[head]++; - } - - absl::flat_hash_map> heads_per_state_lit; + for (int time = 0; time < n; ++time) { + BoolArgumentProto* const bool_or = + context->working_model->add_constraints()->mutable_bool_or(); + BoolArgumentProto* const at_most_one = + context->working_model->add_constraints()->mutable_at_most_one(); + for (int t = 0; t < proto.transition_tail_size(); ++t) { const int64 tail = proto.transition_tail(t); const int64 label = proto.transition_label(t); @@ -2383,52 +2378,21 @@ bool PresolveAutomaton(ConstraintProto* ct, PresolveContext* context) { if (!context->DomainContains(vars[time], label)) continue; if (!gtl::ContainsKey(reachable_states[time + 1], head)) continue; - const int next_lit = state_literals[time + 1][head]; + CHECK(gtl::ContainsKey(state_literals[time], tail)); + if (time != n - 1) { + CHECK(gtl::ContainsKey(state_literals[time + 1], head)); + } const int tail_lit = state_literals[time][tail]; const int label_lit = context->expanded_variables[vars[time]][label]; - const bool unique = num_incident_arcs[head] == 1; - const int head_lit = unique ? next_lit : context->NewBoolVar(); - if (!unique) { - heads_per_state_lit[next_lit].push_back(head_lit); - } - - context->AddImplication({tail_lit, label_lit}, head_lit); - context->AddImplication(head_lit, {tail_lit, label_lit}); - } - - for (const auto& it : heads_per_state_lit) { - BoolArgumentProto* const bool_or = - context->working_model->add_constraints()->mutable_bool_or(); - bool_or->add_literals(NegatedRef(it.first)); - for (const int lit : it.second) { - bool_or->add_literals(lit); - context->AddImplication(lit, it.first); - } - } - } - - { // Last transition to a final state. - const int last = n - 1; - BoolArgumentProto* const reach_final_state = - context->working_model->add_constraints()->mutable_bool_or(); - - for (int t = 0; t < proto.transition_tail_size(); ++t) { - const int64 tail = proto.transition_tail(t); - const int64 label = proto.transition_label(t); - const int64 head = proto.transition_head(t); - - if (!gtl::ContainsKey(reachable_states[last], tail)) continue; - if (!context->DomainContains(vars[last], label)) continue; - if (!gtl::ContainsKey(reachable_states[last + 1], head)) continue; - - const int tail_lit = state_literals[last][tail]; - const int head_lit = context->NewBoolVar(); - const int label_lit = context->expanded_variables[vars[last]][label]; + const int head_lit = + time == n - 1 ? true_literal : state_literals[time + 1][head]; + const int transition_lit = context->NewBoolVar(); - context->AddImplication({tail_lit, label_lit}, head_lit); - context->AddImplication(head_lit, {tail_lit, label_lit}); + context->AddImplication(transition_lit, {tail_lit, label_lit, head_lit}); + context->AddImplication({tail_lit, label_lit, head_lit}, transition_lit); - reach_final_state->add_literals(head_lit); + bool_or->add_literals(transition_lit); + at_most_one->add_literals(transition_lit); } } @@ -3208,8 +3172,8 @@ bool PresolveOneConstraint(int c, PresolveContext* context) { return PresolveCumulative(ct, context); case ConstraintProto::ConstraintCase::kCircuit: return PresolveCircuit(ct, context); -// case ConstraintProto::ConstraintCase::kAutomaton: -// return PresolveAutomaton(ct, context); + case ConstraintProto::ConstraintCase::kAutomaton: + return PresolveAutomaton(ct, context); default: return false; } diff --git a/ortools/util/BUILD b/ortools/util/BUILD index e0e4ba18be1..329b41460a2 100644 --- a/ortools/util/BUILD +++ b/ortools/util/BUILD @@ -9,17 +9,6 @@ cc_library( ], ) -cc_library( - name = "filelineiter", - hdrs = ["filelineiter.h"], - deps = [ - "//ortools/base", - "//ortools/base:file", - "//ortools/base:status", - "//ortools/base:strings", - ], -) - cc_library( name = "vector_map", hdrs = ["vector_map.h"], @@ -39,6 +28,16 @@ cc_library( deps = ["//ortools/base"], ) +cc_library( + name = "integer_pq", + hdrs = [ + "integer_pq.h", + ], + deps = [ + "//ortools/base", + ], +) + cc_library( name = "cached_log", srcs = ["cached_log.cc"], @@ -53,17 +52,13 @@ cc_library( srcs = ["graph_export.cc"], hdrs = ["graph_export.h"], deps = [ + "@com_google_absl//absl/strings:str_format", "//ortools/base", "//ortools/base:file", "//ortools/base:status", ], ) -cc_library( - name = "iterators", - hdrs = ["iterators.h"], -) - cc_library( name = "zvector", hdrs = ["zvector.h"], @@ -76,22 +71,12 @@ cc_library( deps = ["//ortools/base"], ) -cc_library( - name = "xml_helper", - srcs = ["xml_helper.cc"], - hdrs = ["xml_helper.h"], - deps = [ - "//ortools/base", - "//ortools/base:strings", - ], -) - #cc_library( # name = "step_function", # srcs = ["step_function.cc"], # hdrs = ["step_function.h"], # deps = [ -# "//ortools/base:strings", +# "@com_google_absl//absl/strings", # ":iterators", # "//ortools/base", # ], @@ -103,7 +88,7 @@ cc_library( deps = [ ":bitset", "//ortools/base", - "//ortools/base:strings", + "@com_google_absl//absl/strings", ], ) @@ -114,7 +99,8 @@ cc_library( deps = [ ":saturated_arithmetic", "//ortools/base", - "//ortools/base:strings", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", ], ) @@ -124,7 +110,7 @@ cc_library( hdrs = ["rational_approximation.h"], deps = [ "//ortools/base", - "//ortools/base:strings", + "@com_google_absl//absl/strings", ], ) @@ -135,8 +121,10 @@ cc_library( deps = [ ":saturated_arithmetic", "//ortools/base", - "//ortools/base:span", - "//ortools/base:strings", + "@com_google_absl//absl/container:inlined_vector", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", + "@com_google_absl//absl/types:span", ], ) @@ -162,8 +150,9 @@ cc_library( deps = [ "//ortools/base", "//ortools/base:stl_util", - "//ortools/base:strings", - # "//ortools/base:strings:human_readable", + "@com_google_absl//absl/strings", + "@com_google_absl//absl/strings:str_format", + # "@com_google_absl//absl/strings:human_readable", "//ortools/port:sysinfo", "//ortools/base:timer", "//ortools/port:utf8", @@ -177,7 +166,9 @@ cc_library( deps = [ ":running_stat", "//ortools/base", - "//ortools/base:strings", + "@com_google_absl//absl/container:flat_hash_map", + "@com_google_absl//absl/memory", + "@com_google_absl//absl/strings", "//ortools/base:sysinfo", "//ortools/base:timer", ], @@ -221,7 +212,7 @@ cc_library( srcs = ["file_util.cc"], hdrs = ["file_util.h"], deps = [ - "//ortools/base:strings", + "@com_google_absl//absl/strings", "//ortools/base", "//ortools/base:file", "//ortools/base:hash", @@ -239,7 +230,7 @@ cc_library( srcs = ["proto_tools.cc"], hdrs = ["proto_tools.h"], deps = [ - "//ortools/base:strings", + "@com_google_absl//absl/strings", "//ortools/base", "//ortools/base:file", "//ortools/base:hash", @@ -251,6 +242,16 @@ cc_library( ], ) +proto_library( + name = "optional_boolean_proto", + srcs = ["optional_boolean.proto"], +) + +cc_proto_library( + name = "optional_boolean_cc_proto", + deps = [":optional_boolean_proto"], +) + cc_library( name = "functions_swig_helpers", hdrs = [ @@ -290,7 +291,16 @@ cc_library( deps = [ "//ortools/base", "//ortools/base:map_util", - "//ortools/base:strings", + "@com_google_absl//absl/strings", + ], +) + +cc_library( + name = "sigint", + srcs = ["sigint.cc"], + hdrs = ["sigint.h"], + deps = [ + "//ortools/base", ], ) @@ -309,14 +319,14 @@ cc_library( # hdrs = ["tsplib_parser.h"], # visibility = ["//visibility:public"], # deps = [ -# "//ortools/base:strings", +# "@com_google_absl//absl/strings", # ":filelineiter", # "//ortools/base", # "//ortools/base:file", # "//ortools/base:file:path", # "//ortools/base:map_util", # "//ortools/base:mathutil", -# "///ortools/base:strings", +# "/@com_google_absl//absl/strings", # "//file/zipfile", # "//util/regexp/re2", # ], @@ -328,7 +338,7 @@ cc_library( # hdrs = ["pdtsp_parser.h"], # visibility = ["//visibility:public"], # deps = [ -# "//ortools/base:strings", +# "@com_google_absl//absl/strings", # ":filelineiter", # "//ortools/base", # "//ortools/base:file", @@ -343,26 +353,13 @@ cc_library( # hdrs = ["bp_parser.h"], # visibility = ["//visibility:public"], # deps = [ -# "//ortools/base:strings", +# "@com_google_absl//absl/strings", # ":filelineiter", # "//ortools/base", # "//ortools/base:file", # ], #) -cc_library( - name = "rcpsp_parser", - srcs = ["rcpsp_parser.cc"], - hdrs = ["rcpsp_parser.h"], - visibility = ["//visibility:public"], - deps = [ - ":filelineiter", - "//ortools/base", - "//ortools/base:file", - "//ortools/base:strings", - ], -) - cc_library( name = "sort", hdrs = ["sort.h"],