diff --git a/examples/cpp/dimacs_assignment.cc b/examples/cpp/dimacs_assignment.cc index 29ea802e22..fb2bc31faa 100644 --- a/examples/cpp/dimacs_assignment.cc +++ b/examples/cpp/dimacs_assignment.cc @@ -15,7 +15,7 @@ #include #include #include -#include "ortools/base/hash.h" +#include #include #include diff --git a/examples/cpp/dobble_ls.cc b/examples/cpp/dobble_ls.cc index f43d4a282f..56944f1660 100644 --- a/examples/cpp/dobble_ls.cc +++ b/examples/cpp/dobble_ls.cc @@ -36,6 +36,7 @@ #include "ortools/base/commandlineflags.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/map_util.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/util/bitset.h" diff --git a/examples/cpp/fap_parser.h b/examples/cpp/fap_parser.h index 87976e0264..4f60685077 100644 --- a/examples/cpp/fap_parser.h +++ b/examples/cpp/fap_parser.h @@ -19,7 +19,7 @@ #ifndef OR_TOOLS_EXAMPLES_FAP_PARSER_H_ #define OR_TOOLS_EXAMPLES_FAP_PARSER_H_ -#include "ortools/base/hash.h" +#include #include #include #include diff --git a/examples/cpp/model_util.cc b/examples/cpp/model_util.cc index e55af70e9b..b7a4a60139 100644 --- a/examples/cpp/model_util.cc +++ b/examples/cpp/model_util.cc @@ -19,6 +19,7 @@ #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/file.h" #include "ortools/base/recordio.h" #include "ortools/base/join.h" diff --git a/examples/cpp/network_routing.cc b/examples/cpp/network_routing.cc index 414beb4680..abcb6bb23d 100644 --- a/examples/cpp/network_routing.cc +++ b/examples/cpp/network_routing.cc @@ -26,8 +26,8 @@ // A random problem generator is also included. -#include "ortools/base/hash.h" -#include "ortools/base/hash.h" +#include +#include #include #include #include diff --git a/examples/cpp/pdptw.cc b/examples/cpp/pdptw.cc index 7aa8e507e0..f11ca64ef7 100644 --- a/examples/cpp/pdptw.cc +++ b/examples/cpp/pdptw.cc @@ -41,6 +41,7 @@ #include "ortools/base/callback.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/commandlineflags.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/strtoint.h" #include "ortools/base/file.h" #include "ortools/base/split.h" diff --git a/examples/cpp/sports_scheduling.cc b/examples/cpp/sports_scheduling.cc index 49f339ce78..adacaf1af1 100644 --- a/examples/cpp/sports_scheduling.cc +++ b/examples/cpp/sports_scheduling.cc @@ -60,6 +60,7 @@ #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" diff --git a/examples/cpp/weighted_tardiness_sat.cc b/examples/cpp/weighted_tardiness_sat.cc index 310aa4d93e..da0062bfb8 100644 --- a/examples/cpp/weighted_tardiness_sat.cc +++ b/examples/cpp/weighted_tardiness_sat.cc @@ -17,6 +17,7 @@ #include "ortools/base/commandlineflags.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/logging.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/strtoint.h" #include "ortools/base/timer.h" #include "google/protobuf/text_format.h" diff --git a/ortools/base/base.i b/ortools/base/base.i index 761579a748..76175fc1f4 100644 --- a/ortools/base/base.i +++ b/ortools/base/base.i @@ -43,11 +43,12 @@ } %{ -#include -#include -#include #include +#include #include +#include +#include + #include "ortools/base/basictypes.h" #include "ortools/base/python-swig.h" %} @@ -124,7 +125,7 @@ %typemap(argout) std::vector* OUTPUT, std::set* OUTPUT, - std::unordered_set* OUTPUT { + std::unordered_set* OUTPUT { %append_output(list_output_helper($1, &py_converter)); } %typemap(out) std::vector { @@ -242,11 +243,12 @@ COPY_TYPEMAPS(uint64, Fprint); #ifdef SWIGJAVA %{ -#include -#include -#include #include +#include #include +#include +#include + #include "ortools/base/basictypes.h" %} @@ -366,11 +368,12 @@ COPY_TYPEMAPS(unsigned long long, uint64); #ifdef SWIGCSHARP %include "enumsimple.swg" %{ -#include -#include -#include #include +#include #include +#include +#include + #include "ortools/base/basictypes.h" %} diff --git a/ortools/base/file.cc b/ortools/base/file.cc index 21ef945174..eb5a4f8e48 100644 --- a/ortools/base/file.cc +++ b/ortools/base/file.cc @@ -269,5 +269,4 @@ util::Status Delete(const std::string& path, int flags) { return util::Status(util::error::INVALID_ARGUMENT, StrCat("Could not delete '", path, "'.")); } - } // namespace file diff --git a/ortools/base/file.h b/ortools/base/file.h index 14e9df62a6..0ea655d31d 100644 --- a/ortools/base/file.h +++ b/ortools/base/file.h @@ -142,4 +142,5 @@ void WriteProtoToFileOrDie(const google::protobuf::Message& proto, util::Status Delete(const std::string& path, int flags); } // namespace file + #endif // OR_TOOLS_BASE_FILE_H_ diff --git a/ortools/base/hash.h b/ortools/base/hash.h index 0447290b96..56044a3a38 100644 --- a/ortools/base/hash.h +++ b/ortools/base/hash.h @@ -14,8 +14,6 @@ #ifndef OR_TOOLS_BASE_HASH_H_ #define OR_TOOLS_BASE_HASH_H_ -#include -#include #include #include @@ -110,7 +108,7 @@ inline uint64 Hash64NumWithSeed(uint64 num, uint64 c) { } } // namespace operations_research -// Support a few hash<> operators, in the std namespace. +// Support a few hash<> operators, in the hash namespace. namespace std { template struct hash> { @@ -147,4 +145,5 @@ struct hash> { } // namespace std #endif // SWIG + #endif // OR_TOOLS_BASE_HASH_H_ diff --git a/ortools/base/int_type.h b/ortools/base/int_type.h index d7ba11a7d4..1ba6424ab0 100755 --- a/ortools/base/int_type.h +++ b/ortools/base/int_type.h @@ -145,7 +145,7 @@ #define OR_TOOLS_BASE_INT_TYPE_H_ #include -#include "ortools/base/hash.h" +#include #include #include // NOLINT diff --git a/ortools/base/join.cc b/ortools/base/join.cc index 56d05ca220..d0ea04b184 100644 --- a/ortools/base/join.cc +++ b/ortools/base/join.cc @@ -152,3 +152,4 @@ std::string StrCat(const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, StrAppend(&out, a, b, c, d, e, f, g, h, i, j, k); return out; } + diff --git a/ortools/base/map_util.h b/ortools/base/map_util.h index f77b9cc507..9b52aa18ad 100644 --- a/ortools/base/map_util.h +++ b/ortools/base/map_util.h @@ -78,10 +78,11 @@ const typename Collection::value_type::second_type FindPtrOrNull( return it->second; } -// Change the value associated with a particular key in a map or std::unordered_map. -// If the key is not present in the map the key and value are inserted, -// otherwise the value is updated to be a copy of the value provided. -// True indicates that an insert took place, false indicates an update. +// Change the value associated with a particular key in a map or +// std::unordered_map. If the key is not present in the map the key and value +// are inserted, otherwise the value is updated to be a copy of the value +// provided. True indicates that an insert took place, false indicates an +// update. template bool InsertOrUpdate(Collection* const collection, const Key& key, const Value& value) { @@ -143,9 +144,8 @@ bool FindCopy(const Collection& collection, const Key& key, return true; } -// Test to see if a set, map, std::unordered_set or std::unordered_map -// contains a particular key. -// Returns true if the key is in the collection. +// Test to see if a set, map, std::unordered_set or std::unordered_map contains +// a particular key. Returns true if the key is in the collection. template bool ContainsKey(const Collection& collection, const Key& key) { typename Collection::const_iterator it = collection.find(key); diff --git a/ortools/base/split.cc b/ortools/base/split.cc index 369302e23f..9e194f42a1 100644 --- a/ortools/base/split.cc +++ b/ortools/base/split.cc @@ -87,9 +87,8 @@ std::vector Split(const std::string& full, const char* delim, int f return out; } -std::vector Split(const std::string& full, - const char* delim, - int64 flags) { +std::vector Split(const std::string& full, const char* delim, + int64 flags) { CHECK_EQ(SkipEmpty(), flags); std::vector out; InternalSplitStringUsing(full, delim, &out); diff --git a/ortools/base/split.h b/ortools/base/split.h index 96b208df2c..13b0553666 100644 --- a/ortools/base/split.h +++ b/ortools/base/split.h @@ -34,8 +34,7 @@ std::vector Split(const std::string& full, char delim, int flags); // // Hack: the int64 allow the C++ compiler to distinguish the two functions. It // is possible to implement this more cleanly at the cost of more complexity. -std::vector Split(const std::string& full, - const char* delim, +std::vector Split(const std::string& full, const char* delim, int64 flags); namespace delimiter { @@ -88,5 +87,4 @@ bool SplitStringAndParse(const std::string& source, const std::string& delim, return true; } - #endif // OR_TOOLS_BASE_SPLIT_H_ diff --git a/ortools/base/stl_util.h b/ortools/base/stl_util.h index 92b483765e..348479ef97 100644 --- a/ortools/base/stl_util.h +++ b/ortools/base/stl_util.h @@ -25,7 +25,7 @@ namespace operations_research { // NOTE: for these three functions, we could just implement a DeleteObject // functor and then call for_each() on the range and functor, but this // requires us to pull in all of algorithm.h, which seems expensive. -// For -#include "ortools/base/hash.h" +#include #include "ortools/base/hash.h" #include "ortools/bop/bop_base.h" diff --git a/ortools/bop/bop_portfolio.cc b/ortools/bop/bop_portfolio.cc index 2ddead222f..2aa730d302 100644 --- a/ortools/bop/bop_portfolio.cc +++ b/ortools/bop/bop_portfolio.cc @@ -13,6 +13,7 @@ #include "ortools/bop/bop_portfolio.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/stl_util.h" #include "ortools/bop/bop_fs.h" #include "ortools/bop/bop_lns.h" diff --git a/ortools/constraint_solver/alldiff_cst.cc b/ortools/constraint_solver/alldiff_cst.cc index 15b9c3439e..cfb1af3e77 100644 --- a/ortools/constraint_solver/alldiff_cst.cc +++ b/ortools/constraint_solver/alldiff_cst.cc @@ -22,6 +22,7 @@ #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/util/string_array.h" diff --git a/ortools/constraint_solver/assignment.cc b/ortools/constraint_solver/assignment.cc index 90a54cac56..5e8a468a7d 100644 --- a/ortools/constraint_solver/assignment.cc +++ b/ortools/constraint_solver/assignment.cc @@ -13,7 +13,7 @@ #include -#include "ortools/base/hash.h" +#include #include #include diff --git a/ortools/constraint_solver/collect_variables.cc b/ortools/constraint_solver/collect_variables.cc index 30a8f68206..c925edd46a 100644 --- a/ortools/constraint_solver/collect_variables.cc +++ b/ortools/constraint_solver/collect_variables.cc @@ -13,7 +13,7 @@ #include -#include "ortools/base/hash.h" +#include #include #include @@ -204,7 +204,7 @@ class CollectVariablesVisitor : public ModelParser { std::vector* const secondaries_; std::vector* const sequences_; std::vector* const intervals_; - // These std::unordered_set can't easily hold const IntVar*, because they + // These hash_set can't easily hold const IntVar*, because they // ultimately serve as containers of mutable IntVar. std::unordered_set primary_set_; std::unordered_set secondary_set_; diff --git a/ortools/constraint_solver/constraint_solver.h b/ortools/constraint_solver/constraint_solver.h index 03c9947488..dc18eff876 100644 --- a/ortools/constraint_solver/constraint_solver.h +++ b/ortools/constraint_solver/constraint_solver.h @@ -65,8 +65,8 @@ #define OR_TOOLS_CONSTRAINT_SOLVER_CONSTRAINT_SOLVER_H_ #include -#include "ortools/base/hash.h" -#include "ortools/base/hash.h" +#include +#include #include #include #include @@ -4983,7 +4983,7 @@ class AssignmentContainer { } // The == should be order-independent EnsureMapIsUpToDate(); - // Do not use the std::unordered_map::== operator! It does not just compare content, + // Do not use the hash_map::== operator! It does not just compare content, // but also how the map is hashed (e.g., number of buckets). This is not // what we want. for (const E& element : container.elements_) { diff --git a/ortools/constraint_solver/constraint_solveri.h b/ortools/constraint_solver/constraint_solveri.h index 4928923deb..2d2a419a10 100644 --- a/ortools/constraint_solver/constraint_solveri.h +++ b/ortools/constraint_solver/constraint_solveri.h @@ -54,7 +54,7 @@ #include #include #include -#include "ortools/base/hash.h" +#include #include #include #include diff --git a/ortools/constraint_solver/constraints.cc b/ortools/constraint_solver/constraints.cc index dd7d31492b..f641a6c740 100644 --- a/ortools/constraint_solver/constraints.cc +++ b/ortools/constraint_solver/constraints.cc @@ -21,6 +21,7 @@ #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/join.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" diff --git a/ortools/constraint_solver/default_search.cc b/ortools/constraint_solver/default_search.cc index e24ad8d9b6..24f2a30504 100644 --- a/ortools/constraint_solver/default_search.cc +++ b/ortools/constraint_solver/default_search.cc @@ -14,7 +14,7 @@ #include #include -#include "ortools/base/hash.h" +#include #include #include #include @@ -25,6 +25,7 @@ #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/stl_util.h" #include "ortools/constraint_solver/constraint_solver.h" diff --git a/ortools/constraint_solver/demon_profiler.cc b/ortools/constraint_solver/demon_profiler.cc index 75222afffa..0cee41f43f 100644 --- a/ortools/constraint_solver/demon_profiler.cc +++ b/ortools/constraint_solver/demon_profiler.cc @@ -15,7 +15,7 @@ #include #include #include -#include "ortools/base/hash.h" +#include #include #include #include diff --git a/ortools/constraint_solver/expressions.cc b/ortools/constraint_solver/expressions.cc index 848b0cd71a..25b81ebbe2 100644 --- a/ortools/constraint_solver/expressions.cc +++ b/ortools/constraint_solver/expressions.cc @@ -14,7 +14,7 @@ #include #include -#include "ortools/base/hash.h" +#include #include #include #include diff --git a/ortools/constraint_solver/graph_constraints.cc b/ortools/constraint_solver/graph_constraints.cc index 27abad5641..b24218bae1 100644 --- a/ortools/constraint_solver/graph_constraints.cc +++ b/ortools/constraint_solver/graph_constraints.cc @@ -20,6 +20,7 @@ #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/join.h" #include "ortools/base/join.h" #include "ortools/constraint_solver/constraint_solver.h" diff --git a/ortools/constraint_solver/hybrid.cc b/ortools/constraint_solver/hybrid.cc index 1211a38734..cc3d396b98 100644 --- a/ortools/constraint_solver/hybrid.cc +++ b/ortools/constraint_solver/hybrid.cc @@ -16,7 +16,7 @@ #include #include -#include "ortools/base/hash.h" +#include #include #include "ortools/base/callback.h" #include "ortools/base/commandlineflags.h" diff --git a/ortools/constraint_solver/io.cc b/ortools/constraint_solver/io.cc index 771acec8f6..476dc67972 100644 --- a/ortools/constraint_solver/io.cc +++ b/ortools/constraint_solver/io.cc @@ -15,7 +15,7 @@ #include #include #include -#include "ortools/base/hash.h" +#include #include #include #include diff --git a/ortools/constraint_solver/local_search.cc b/ortools/constraint_solver/local_search.cc index 5bd4e30a7f..77fc1144a0 100644 --- a/ortools/constraint_solver/local_search.cc +++ b/ortools/constraint_solver/local_search.cc @@ -13,8 +13,8 @@ #include -#include "ortools/base/hash.h" -#include "ortools/base/hash.h" +#include +#include #include #include #include @@ -29,6 +29,7 @@ #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" #include "ortools/base/macros.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/join.h" #include "ortools/base/map_util.h" #include "ortools/base/hash.h" diff --git a/ortools/constraint_solver/range_cst.cc b/ortools/constraint_solver/range_cst.cc index bc6545a8c4..bf20e9e983 100644 --- a/ortools/constraint_solver/range_cst.cc +++ b/ortools/constraint_solver/range_cst.cc @@ -18,6 +18,7 @@ #include #include "ortools/base/logging.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solver.h" #include "ortools/constraint_solver/constraint_solveri.h" diff --git a/ortools/constraint_solver/resource.cc b/ortools/constraint_solver/resource.cc index 592c0f2d2d..81452ba26c 100644 --- a/ortools/constraint_solver/resource.cc +++ b/ortools/constraint_solver/resource.cc @@ -22,7 +22,7 @@ // on a set of interval variables. #include -#include "ortools/base/hash.h" +#include #include #include #include diff --git a/ortools/constraint_solver/routing.cc b/ortools/constraint_solver/routing.cc index fad171d859..3360528477 100644 --- a/ortools/constraint_solver/routing.cc +++ b/ortools/constraint_solver/routing.cc @@ -27,6 +27,7 @@ #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/stringprintf.h" #include "google/protobuf/text_format.h" #include "ortools/base/map_util.h" #include "ortools/base/stl_util.h" diff --git a/ortools/constraint_solver/routing.h b/ortools/constraint_solver/routing.h index d0d4d9f757..d1ce0be04b 100644 --- a/ortools/constraint_solver/routing.h +++ b/ortools/constraint_solver/routing.h @@ -1752,7 +1752,7 @@ class SweepArranger { // build delta assigment representing possible extensions to the current // solution and validate them with filters. // The tricky bit comes from using the assignment and filter APIs in a way -// which avoids the lazy creation of internal std::unordered_maps between variables +// which avoids the lazy creation of internal hash_maps between variables // and indices. // Generic filter-based decision builder applied to IntVars. diff --git a/ortools/constraint_solver/sat_constraint.h b/ortools/constraint_solver/sat_constraint.h index c651c1af16..3b20d272b9 100644 --- a/ortools/constraint_solver/sat_constraint.h +++ b/ortools/constraint_solver/sat_constraint.h @@ -28,8 +28,8 @@ #ifndef OR_TOOLS_CONSTRAINT_SOLVER_SAT_CONSTRAINT_H_ #define OR_TOOLS_CONSTRAINT_SOLVER_SAT_CONSTRAINT_H_ -#include "ortools/base/hash.h" -#include "ortools/base/hash.h" +#include +#include #include "ortools/base/map_util.h" #include "ortools/base/hash.h" diff --git a/ortools/constraint_solver/search.cc b/ortools/constraint_solver/search.cc index 2f5aa42980..4f5aa1bbe8 100644 --- a/ortools/constraint_solver/search.cc +++ b/ortools/constraint_solver/search.cc @@ -14,14 +14,14 @@ #include #include -#include "ortools/base/hash.h" +#include #include #include #include #include #include -#include "ortools/base/casts.h" +//#include "ortools/base/casts.h" #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" @@ -3131,7 +3131,7 @@ int64 GuidedLocalSearchPenaltiesTable::Value(const Arc& arc) const { } } -// Sparse GLS penalties implementation using a std::unordered_map to store penalties. +// Sparse GLS penalties implementation using a hash_map to store penalties. class GuidedLocalSearchPenaltiesMap : public GuidedLocalSearchPenalties { public: diff --git a/ortools/constraint_solver/table.cc b/ortools/constraint_solver/table.cc index d17c0c2b3a..6ba296c451 100644 --- a/ortools/constraint_solver/table.cc +++ b/ortools/constraint_solver/table.cc @@ -15,7 +15,7 @@ // This file implements the table constraints. #include -#include "ortools/base/hash.h" +#include #include #include #include diff --git a/ortools/constraint_solver/trace.cc b/ortools/constraint_solver/trace.cc index 20679135bb..53519102d4 100644 --- a/ortools/constraint_solver/trace.cc +++ b/ortools/constraint_solver/trace.cc @@ -14,7 +14,7 @@ #include #include -#include "ortools/base/hash.h" +#include #include #include #include diff --git a/ortools/constraint_solver/tree_monitor.cc b/ortools/constraint_solver/tree_monitor.cc index 2b27cbe6aa..070cae2940 100644 --- a/ortools/constraint_solver/tree_monitor.cc +++ b/ortools/constraint_solver/tree_monitor.cc @@ -13,7 +13,7 @@ #include -#include "ortools/base/hash.h" +#include #include #include #include diff --git a/ortools/constraint_solver/utilities.cc b/ortools/constraint_solver/utilities.cc index 2b2ba42f70..5e5663c3a0 100644 --- a/ortools/constraint_solver/utilities.cc +++ b/ortools/constraint_solver/utilities.cc @@ -12,8 +12,8 @@ // limitations under the License. -#include "ortools/base/hash.h" -#include "ortools/base/hash.h" +#include +#include #include #include "ortools/base/integral_types.h" diff --git a/ortools/constraint_solver/visitor.cc b/ortools/constraint_solver/visitor.cc index 7432ae5863..871722abb2 100644 --- a/ortools/constraint_solver/visitor.cc +++ b/ortools/constraint_solver/visitor.cc @@ -13,8 +13,8 @@ #include -#include "ortools/base/hash.h" -#include "ortools/base/hash.h" +#include +#include #include #include diff --git a/ortools/flatzinc/flatzinc_constraints.cc b/ortools/flatzinc/flatzinc_constraints.cc index ac623da4db..3b75f1ae1b 100644 --- a/ortools/flatzinc/flatzinc_constraints.cc +++ b/ortools/flatzinc/flatzinc_constraints.cc @@ -16,6 +16,7 @@ #include #include "ortools/base/commandlineflags.h" +#include "ortools/base/stringprintf.h" #include "ortools/constraint_solver/constraint_solveri.h" #include "ortools/flatzinc/logging.h" #include "ortools/util/string_array.h" diff --git a/ortools/flatzinc/model.cc b/ortools/flatzinc/model.cc index 18c128fd9c..e93262e2d2 100644 --- a/ortools/flatzinc/model.cc +++ b/ortools/flatzinc/model.cc @@ -17,6 +17,7 @@ #include #include +#include "ortools/base/stringprintf.h" #include "ortools/base/join.h" #include "ortools/base/join.h" #include "ortools/base/map_util.h" diff --git a/ortools/flatzinc/presolve.cc b/ortools/flatzinc/presolve.cc index 42099ef993..4209a63896 100644 --- a/ortools/flatzinc/presolve.cc +++ b/ortools/flatzinc/presolve.cc @@ -17,6 +17,7 @@ #include #include +#include "ortools/base/stringprintf.h" #include "ortools/base/join.h" #include "ortools/base/stringpiece_utils.h" #include "ortools/base/strutil.h" diff --git a/ortools/flatzinc/sat_constraint.cc b/ortools/flatzinc/sat_constraint.cc index 22d84a1f97..9a0fa1b97b 100644 --- a/ortools/flatzinc/sat_constraint.cc +++ b/ortools/flatzinc/sat_constraint.cc @@ -21,6 +21,7 @@ #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/int_type.h" #include "ortools/base/int_type_indexed_vector.h" #include "ortools/base/map_util.h" diff --git a/ortools/flatzinc/sat_fz_solver.cc b/ortools/flatzinc/sat_fz_solver.cc index e83349a3d7..8c37434ae5 100644 --- a/ortools/flatzinc/sat_fz_solver.cc +++ b/ortools/flatzinc/sat_fz_solver.cc @@ -13,8 +13,9 @@ #include "ortools/flatzinc/sat_fz_solver.h" -#include "ortools/base/hash.h" +#include #include +#include "ortools/base/stringprintf.h" #include "ortools/base/timer.h" #include "ortools/base/join.h" #include "ortools/base/map_util.h" diff --git a/ortools/flatzinc/solver.cc b/ortools/flatzinc/solver.cc index 7a35140360..554b68cedd 100644 --- a/ortools/flatzinc/solver.cc +++ b/ortools/flatzinc/solver.cc @@ -18,6 +18,7 @@ #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/join.h" #include "ortools/base/map_util.h" #include "ortools/base/hash.h" diff --git a/ortools/flatzinc/solver_util.cc b/ortools/flatzinc/solver_util.cc index e62da7c116..a7c7f90f97 100644 --- a/ortools/flatzinc/solver_util.cc +++ b/ortools/flatzinc/solver_util.cc @@ -13,6 +13,7 @@ #include "ortools/flatzinc/solver_util.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/join.h" #include "ortools/flatzinc/logging.h" diff --git a/ortools/glop/lp_solver.cc b/ortools/glop/lp_solver.cc index b77d78dd3d..363b14429d 100644 --- a/ortools/glop/lp_solver.cc +++ b/ortools/glop/lp_solver.cc @@ -20,6 +20,7 @@ #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/timer.h" #include "ortools/base/join.h" diff --git a/ortools/graph/astar.cc b/ortools/graph/astar.cc index 826f4fe5b2..dd116044b6 100644 --- a/ortools/graph/astar.cc +++ b/ortools/graph/astar.cc @@ -12,7 +12,8 @@ // limitations under the License. -#include "ortools/base/hash.h" +#include +#include #include #include diff --git a/ortools/graph/cliques.cc b/ortools/graph/cliques.cc index b3b377eebc..f51de1196a 100644 --- a/ortools/graph/cliques.cc +++ b/ortools/graph/cliques.cc @@ -15,7 +15,7 @@ #include "ortools/graph/cliques.h" #include -#include "ortools/base/hash.h" +#include #include #include #include diff --git a/ortools/graph/cliques.h b/ortools/graph/cliques.h index f5d9741776..e2294bfe4d 100644 --- a/ortools/graph/cliques.h +++ b/ortools/graph/cliques.h @@ -25,7 +25,7 @@ #define OR_TOOLS_GRAPH_CLIQUES_H_ #include -#include "ortools/base/hash.h" +#include #include #include diff --git a/ortools/graph/dijkstra.cc b/ortools/graph/dijkstra.cc index e6a065966d..faa5fc5ded 100644 --- a/ortools/graph/dijkstra.cc +++ b/ortools/graph/dijkstra.cc @@ -13,7 +13,7 @@ #include -#include "ortools/base/hash.h" +#include #include #include diff --git a/ortools/graph/shortestpaths.cc b/ortools/graph/shortestpaths.cc index feefe5fac1..4642e38b90 100644 --- a/ortools/graph/shortestpaths.cc +++ b/ortools/graph/shortestpaths.cc @@ -17,7 +17,7 @@ #include #include #include -#include "ortools/base/hash.h" +#include #include #include diff --git a/ortools/graph/util.h b/ortools/graph/util.h index 0828eec263..d68ae304c5 100644 --- a/ortools/graph/util.h +++ b/ortools/graph/util.h @@ -17,8 +17,8 @@ #define OR_TOOLS_GRAPH_UTIL_H_ #include -#include "ortools/base/hash.h" -#include "ortools/base/hash.h" +#include +#include #include #include #include @@ -231,7 +231,7 @@ void RemoveCyclesFromPath(const Graph& graph, std::vector* arc_path) { if (arc_path->empty()) return; // This maps each node to the latest arc in the given path that leaves it. - std::map last_arc_leaving_node; + std::unordered_map last_arc_leaving_node; for (const int arc : *arc_path) last_arc_leaving_node[graph.Tail(arc)] = arc; // Special case for the destination. diff --git a/ortools/linear_solver/__init__.py b/ortools/linear_solver/__init__.py index c97cbc7319..70b8f9c837 100644 --- a/ortools/linear_solver/__init__.py +++ b/ortools/linear_solver/__init__.py @@ -11,5 +11,5 @@ # See the License for the specific language governing permissions and # limitations under the License. import os as _os -__path__.append(_os.path.join(__path__[0], '..', 'gen', 'ortools', 'linear_solver')) +__path__.append(_os.path.join(__path__[0], '..', 'gen', 'ortools', 'linear_solver')) __path__.append(_os.path.join(__path__[0], '..', '..', 'lib')) diff --git a/ortools/linear_solver/cbc_interface.cc b/ortools/linear_solver/cbc_interface.cc index ef4931b94d..e739a611a8 100644 --- a/ortools/linear_solver/cbc_interface.cc +++ b/ortools/linear_solver/cbc_interface.cc @@ -13,7 +13,7 @@ // -#include "ortools/base/hash.h" +#include #include #include #include diff --git a/ortools/linear_solver/clp_interface.cc b/ortools/linear_solver/clp_interface.cc index 5be96d9674..267a8ba325 100644 --- a/ortools/linear_solver/clp_interface.cc +++ b/ortools/linear_solver/clp_interface.cc @@ -14,7 +14,7 @@ // #include -#include "ortools/base/hash.h" +#include #include #include #include diff --git a/ortools/linear_solver/csharp/linear_solver.i b/ortools/linear_solver/csharp/linear_solver.i index c1dd90b95b..1571378106 100644 --- a/ortools/linear_solver/csharp/linear_solver.i +++ b/ortools/linear_solver/csharp/linear_solver.i @@ -212,7 +212,7 @@ class MPSolutionResponse; %unignore operations_research::MPSolverParameters::kDefaultPrimalTolerance; // We want to ignore the CoeffMap class; but since it inherits from some -// hash_map<>, swig complains about an undefined base class. Silence it. +// std::unordered_map<>, swig complains about an undefined base class. Silence it. %warnfilter(401) CoeffMap; %include "ortools/linear_solver/linear_solver.h" diff --git a/ortools/linear_solver/glop_interface.cc b/ortools/linear_solver/glop_interface.cc index edf743985f..bbf4a96697 100644 --- a/ortools/linear_solver/glop_interface.cc +++ b/ortools/linear_solver/glop_interface.cc @@ -12,7 +12,7 @@ // limitations under the License. -#include "ortools/base/hash.h" +#include #include #include #include diff --git a/ortools/linear_solver/glpk_interface.cc b/ortools/linear_solver/glpk_interface.cc index f50bf1e780..e0dbe95fec 100644 --- a/ortools/linear_solver/glpk_interface.cc +++ b/ortools/linear_solver/glpk_interface.cc @@ -17,7 +17,7 @@ #include #include -#include "ortools/base/hash.h" +#include #include #include #include diff --git a/ortools/linear_solver/gurobi_interface.cc b/ortools/linear_solver/gurobi_interface.cc index ff1dc81906..169a09573d 100644 --- a/ortools/linear_solver/gurobi_interface.cc +++ b/ortools/linear_solver/gurobi_interface.cc @@ -15,7 +15,7 @@ #include #include -#include "ortools/base/hash.h" +#include #include #include #include diff --git a/ortools/linear_solver/java/linear_solver.i b/ortools/linear_solver/java/linear_solver.i index dc2c35bee4..ee6c07849d 100644 --- a/ortools/linear_solver/java/linear_solver.i +++ b/ortools/linear_solver/java/linear_solver.i @@ -255,7 +255,7 @@ import java.lang.reflect.*; %unignore operations_research::MPSolverParameters::kDefaultPrimalTolerance; // no test // We want to ignore the CoeffMap class; but since it inherits from some -// hash_map<>, swig complains about an undefined base class. Silence it. +// std::unordered_map<>, swig complains about an undefined base class. Silence it. %warnfilter(401) CoeffMap; %include "ortools/linear_solver/linear_solver.h" diff --git a/ortools/linear_solver/linear_solver.cc b/ortools/linear_solver/linear_solver.cc index 32fc76f51e..efa06a2ca5 100644 --- a/ortools/linear_solver/linear_solver.cc +++ b/ortools/linear_solver/linear_solver.cc @@ -1606,3 +1606,4 @@ int MPSolverParameters::GetIntegerParam(MPSolverParameters::IntegerParam param) } // namespace operations_research + diff --git a/ortools/linear_solver/linear_solver.h b/ortools/linear_solver/linear_solver.h index 3bbcb73719..03a371c879 100644 --- a/ortools/linear_solver/linear_solver.h +++ b/ortools/linear_solver/linear_solver.h @@ -137,8 +137,8 @@ #define OR_TOOLS_LINEAR_SOLVER_LINEAR_SOLVER_H_ #include -#include "ortools/base/hash.h" -#include "ortools/base/hash.h" +#include +#include #include #include #include diff --git a/ortools/linear_solver/model_exporter.cc b/ortools/linear_solver/model_exporter.cc index 99125dc338..a3e7431c1e 100644 --- a/ortools/linear_solver/model_exporter.cc +++ b/ortools/linear_solver/model_exporter.cc @@ -15,6 +15,7 @@ #include #include +#include #include "ortools/base/commandlineflags.h" #include "ortools/base/integral_types.h" diff --git a/ortools/linear_solver/model_exporter.h b/ortools/linear_solver/model_exporter.h index e42969420f..b572dd6a17 100644 --- a/ortools/linear_solver/model_exporter.h +++ b/ortools/linear_solver/model_exporter.h @@ -14,7 +14,7 @@ #ifndef OR_TOOLS_LINEAR_SOLVER_MODEL_EXPORTER_H_ #define OR_TOOLS_LINEAR_SOLVER_MODEL_EXPORTER_H_ -#include "ortools/base/hash.h" +#include #include #include "ortools/base/macros.h" #include "ortools/base/hash.h" diff --git a/ortools/linear_solver/python/linear_solver.i b/ortools/linear_solver/python/linear_solver.i index 9cc498a01a..8a12bec06f 100644 --- a/ortools/linear_solver/python/linear_solver.i +++ b/ortools/linear_solver/python/linear_solver.i @@ -310,7 +310,7 @@ from ortools.linear_solver.linear_solver_natural_api import VariableExpr // TODO(user): unit test kDefaultPrimalTolerance. // We want to ignore the CoeffMap class; but since it inherits from some -// hash_map<>, swig complains about an undefined base class. Silence it. +// std::unordered_map<>, swig complains about an undefined base class. Silence it. %warnfilter(401) CoeffMap; %include "ortools/linear_solver/linear_solver.h" diff --git a/ortools/linear_solver/scip_interface.cc b/ortools/linear_solver/scip_interface.cc index 59cf57f95b..2e7b2bbf3f 100644 --- a/ortools/linear_solver/scip_interface.cc +++ b/ortools/linear_solver/scip_interface.cc @@ -15,7 +15,7 @@ #include #include -#include "ortools/base/hash.h" +#include #include #include #include diff --git a/ortools/lp_data/lp_data.cc b/ortools/lp_data/lp_data.cc index ff0909c55b..02ca21f3b6 100644 --- a/ortools/lp_data/lp_data.cc +++ b/ortools/lp_data/lp_data.cc @@ -16,7 +16,7 @@ #include #include -#include "ortools/base/hash.h" +#include #include #include diff --git a/ortools/lp_data/lp_data.h b/ortools/lp_data/lp_data.h index 410dc45acc..61e2715e09 100644 --- a/ortools/lp_data/lp_data.h +++ b/ortools/lp_data/lp_data.h @@ -25,7 +25,7 @@ #define OR_TOOLS_LP_DATA_LP_DATA_H_ #include // for max -#include "ortools/base/hash.h" +#include #include #include // for std::string #include // for vector @@ -92,10 +92,10 @@ class LinearProgram { // // Note that these ids are NOT copied over by the Populate*() functions. // - // TODO(user): Move these and the two corresponding std::unordered_table into a new + // TODO(user): Move these and the two corresponding hash_table into a new // LinearProgramBuilder class to simplify the code of some functions like // DeleteColumns() here and make the behavior on copy clear? or simply remove - // them as it is almost as easy to maintain a std::unordered_table on the client side. + // them as it is almost as easy to maintain a hash_table on the client side. ColIndex FindOrCreateVariable(const std::string& variable_id); RowIndex FindOrCreateConstraint(const std::string& constraint_id); diff --git a/ortools/lp_data/mps_reader.h b/ortools/lp_data/mps_reader.h index aedf38ba97..273de2930a 100644 --- a/ortools/lp_data/mps_reader.h +++ b/ortools/lp_data/mps_reader.h @@ -26,7 +26,8 @@ #define OR_TOOLS_LP_DATA_MPS_READER_H_ #include // for max -#include "ortools/base/hash.h" +#include +#include #include // for std::string #include // for vector diff --git a/ortools/sat/boolean_problem.cc b/ortools/sat/boolean_problem.cc index 7df48321f0..2dec8e66d5 100644 --- a/ortools/sat/boolean_problem.cc +++ b/ortools/sat/boolean_problem.cc @@ -13,9 +13,10 @@ #include "ortools/sat/boolean_problem.h" -#include "ortools/base/hash.h" +#include #include "ortools/base/commandlineflags.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/join.h" #include "ortools/base/map_util.h" #include "ortools/base/hash.h" diff --git a/ortools/sat/clause.h b/ortools/sat/clause.h index 7b23ece1b0..1e8c81bf5a 100644 --- a/ortools/sat/clause.h +++ b/ortools/sat/clause.h @@ -18,7 +18,7 @@ #define OR_TOOLS_SAT_CLAUSE_H_ #include -#include "ortools/base/hash.h" +#include #include #include #include diff --git a/ortools/sat/drat.cc b/ortools/sat/drat.cc index e08f5f7d0f..07da9122b7 100644 --- a/ortools/sat/drat.cc +++ b/ortools/sat/drat.cc @@ -14,6 +14,7 @@ #include "ortools/sat/drat.h" #include "ortools/base/commandlineflags.h" +#include "ortools/base/stringprintf.h" DEFINE_string( drat_output, "", diff --git a/ortools/sat/integer.cc b/ortools/sat/integer.cc index 6cc9fa8dba..98e5e20368 100644 --- a/ortools/sat/integer.cc +++ b/ortools/sat/integer.cc @@ -421,8 +421,8 @@ IntegerVariable IntegerTrail::AddIntegerVariable( // Copy for the negated variable. var_to_current_lb_interval_index_.Set(NegationOf(var), all_intervals_.size()); -for (int i = domain.size() - 1; i >= 0; --i) { - const ClosedInterval interval = domain[i]; + for (int i = domain.size() - 1; i >= 0; --i) { + const ClosedInterval interval = domain[i]; all_intervals_.push_back({-interval.end, -interval.start}); } InsertOrDie(&var_to_end_interval_index_, NegationOf(var), diff --git a/ortools/sat/integer.h b/ortools/sat/integer.h index 966b683b3e..1a90fbf5e8 100644 --- a/ortools/sat/integer.h +++ b/ortools/sat/integer.h @@ -606,7 +606,7 @@ class IntegerTrail : public SatPropagator { // indices to the current interval of the lower bound, and to the end index // which is exclusive. // - // TODO(user): Avoid using std::unordered_map here and above, a simple vector should + // TODO(user): Avoid using hash_map here and above, a simple vector should // be more efficient. Except if there is really little variables like this. // // TODO(user): We could share the std::vector entry between a diff --git a/ortools/sat/optimization.cc b/ortools/sat/optimization.cc index 96fac1d0a1..236f0f0516 100644 --- a/ortools/sat/optimization.cc +++ b/ortools/sat/optimization.cc @@ -16,6 +16,7 @@ #include #include +#include "ortools/base/stringprintf.h" #include "google/protobuf/descriptor.h" #include "ortools/sat/encoding.h" #include "ortools/sat/util.h" diff --git a/ortools/sat/pb_constraint.cc b/ortools/sat/pb_constraint.cc index f627c83cdf..12029e41b6 100644 --- a/ortools/sat/pb_constraint.cc +++ b/ortools/sat/pb_constraint.cc @@ -13,6 +13,7 @@ #include "ortools/sat/pb_constraint.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/thorough_hash.h" #include "ortools/util/saturated_arithmetic.h" diff --git a/ortools/sat/sat_solver.cc b/ortools/sat/sat_solver.cc index 0d8ec6671c..e12964fcc8 100644 --- a/ortools/sat/sat_solver.cc +++ b/ortools/sat/sat_solver.cc @@ -20,6 +20,7 @@ #include "ortools/base/integral_types.h" #include "ortools/base/logging.h" +#include "ortools/base/stringprintf.h" #include "ortools/base/sysinfo.h" #include "google/protobuf/text_format.h" #include "ortools/base/split.h" diff --git a/ortools/sat/sat_solver.h b/ortools/sat/sat_solver.h index 0202fcf447..6eab08575d 100644 --- a/ortools/sat/sat_solver.h +++ b/ortools/sat/sat_solver.h @@ -19,7 +19,7 @@ #ifndef OR_TOOLS_SAT_SAT_SOLVER_H_ #define OR_TOOLS_SAT_SAT_SOLVER_H_ -#include "ortools/base/hash.h" +#include #include #include #include diff --git a/ortools/util/python/vector.i b/ortools/util/python/vector.i index 9c8be649a7..8929a1c1a8 100644 --- a/ortools/util/python/vector.i +++ b/ortools/util/python/vector.i @@ -66,11 +66,11 @@ namespace operations_research { } %typemap(in,numinputs=0) std::vector* OUTPUT (std::vector temp), - hash_set* OUTPUT (hash_set temp), + std::unordered_set* OUTPUT (std::unordered_set temp), std::set* OUTPUT (std::set temp) { $1 = &temp; } -%typemap(argout) std::vector* OUTPUT, std::set* OUTPUT, hash_set* OUTPUT { +%typemap(argout) std::vector* OUTPUT, std::set* OUTPUT, std::unordered_set* OUTPUT { %append_output(list_output_helper($1, &py_converter)); } %typemap(out) std::vector { diff --git a/ortools/util/rev.h b/ortools/util/rev.h index 3b1a45fd7a..e31dd3f17f 100644 --- a/ortools/util/rev.h +++ b/ortools/util/rev.h @@ -15,7 +15,7 @@ #ifndef OR_TOOLS_UTIL_REV_H_ #define OR_TOOLS_UTIL_REV_H_ -#include "ortools/base/hash.h" +#include #include #include "ortools/base/logging.h" diff --git a/ortools/util/sorted_interval_list.cc b/ortools/util/sorted_interval_list.cc index 5d9750fe89..0c8f782529 100644 --- a/ortools/util/sorted_interval_list.cc +++ b/ortools/util/sorted_interval_list.cc @@ -115,6 +115,7 @@ std::vector IntersectionOfSortedDisjointIntervals( std::vector ComplementOfSortedDisjointIntervals( const std::vector& intervals) { + DCHECK(IntervalsAreSortedAndDisjoint(intervals)); std::vector result; int64 next_start = kint64min; for (const ClosedInterval& interval : intervals) { @@ -130,6 +131,7 @@ std::vector ComplementOfSortedDisjointIntervals( std::vector NegationOfSortedDisjointIntervals( std::vector intervals) { + DCHECK(IntervalsAreSortedAndDisjoint(intervals)); if (intervals.empty()) return intervals; std::reverse(intervals.begin(), intervals.end()); if (intervals.back().end == kint64min) intervals.pop_back(); // corner-case @@ -145,11 +147,11 @@ namespace { // Transforms a sorted list of intervals in a sorted DISJOINT list for which // IntervalsAreSortedAndDisjoint() would return true. -void IntersectionOfSortedIntervals(std::vector* intervals) { +void UnionOfSortedIntervals(std::vector* intervals) { DCHECK(std::is_sorted(intervals->begin(), intervals->end())); int new_size = 0; for (const ClosedInterval& i : *intervals) { - if (new_size > 0 && i.start <= (*intervals)[new_size - 1].end + 1) { + if (new_size > 0 && i.start <= CapAdd((*intervals)[new_size - 1].end, 1)) { (*intervals)[new_size - 1].end = std::max(i.end, (*intervals)[new_size - 1].end); } else { @@ -157,13 +159,27 @@ void IntersectionOfSortedIntervals(std::vector* intervals) { } } intervals->resize(new_size); + DCHECK(IntervalsAreSortedAndDisjoint(*intervals)) << *intervals; } } // namespace +std::vector UnionOfSortedDisjointIntervals( + const std::vector& a, + const std::vector& b) { + DCHECK(IntervalsAreSortedAndDisjoint(a)); + DCHECK(IntervalsAreSortedAndDisjoint(b)); + std::vector result(a.size() + b.size()); + std::merge(a.begin(), a.end(), b.begin(), b.end(), result.begin()); + UnionOfSortedIntervals(&result); + return result; +} + std::vector AdditionOfSortedDisjointIntervals( const std::vector& a, const std::vector& b) { + DCHECK(IntervalsAreSortedAndDisjoint(a)); + DCHECK(IntervalsAreSortedAndDisjoint(b)); std::vector result; for (const ClosedInterval& i : a) { for (const ClosedInterval& j : b) { @@ -171,18 +187,42 @@ std::vector AdditionOfSortedDisjointIntervals( } } std::sort(result.begin(), result.end()); - IntersectionOfSortedIntervals(&result); + UnionOfSortedIntervals(&result); return result; } std::vector MultiplicationOfSortedDisjointIntervals( std::vector intervals, int64 coeff) { + DCHECK(IntervalsAreSortedAndDisjoint(intervals)); const int64 abs_coeff = std::abs(coeff); for (ClosedInterval& i : intervals) { i.start = CapProd(i.start, abs_coeff); i.end = CapProd(i.end, abs_coeff); } - IntersectionOfSortedIntervals(&intervals); + UnionOfSortedIntervals(&intervals); + return coeff > 0 ? intervals : NegationOfSortedDisjointIntervals(intervals); +} + +std::vector PreciseMultiplicationOfSortedDisjointIntervals( + std::vector intervals, int64 coeff, bool* success) { + DCHECK(IntervalsAreSortedAndDisjoint(intervals)); + *success = true; + if (intervals.empty() || coeff == 0) return {}; + const int64 abs_coeff = std::abs(coeff); + if (abs_coeff != 1) { + if (CapSub(intervals.back().end, intervals.front().start) <= 1000) { + std::vector individual_values; + for (ClosedInterval& i : intervals) { + for (int v = i.start; v <= i.end; ++v) { + individual_values.push_back(CapProd(v, abs_coeff)); + } + } + intervals = SortedDisjointIntervalsFromValues(individual_values); + } else { + *success = false; + return {}; + } + } return coeff > 0 ? intervals : NegationOfSortedDisjointIntervals(intervals); } @@ -202,6 +242,7 @@ int64 FloorRatio(int64 value, int64 positive_coeff) { std::vector InverseMultiplicationOfSortedDisjointIntervals( std::vector intervals, int64 coeff) { + DCHECK(IntervalsAreSortedAndDisjoint(intervals)); if (coeff == 0) { return SortedDisjointIntervalsContain(intervals, 0) ? std::vector({{kint64min, kint64max}}) diff --git a/ortools/util/sorted_interval_list.h b/ortools/util/sorted_interval_list.h index ea87107416..8f4d06f53a 100644 --- a/ortools/util/sorted_interval_list.h +++ b/ortools/util/sorted_interval_list.h @@ -78,6 +78,11 @@ bool SortedDisjointIntervalsContain( std::vector IntersectionOfSortedDisjointIntervals( const std::vector& a, const std::vector& b); +// Returns the union of two lists of sorted disjoint intervals in a +// sorted disjoint interval form. +std::vector UnionOfSortedDisjointIntervals( + const std::vector& a, const std::vector& b); + // Returns the domain of x + y given that the domain of x is a and the one of y // is b. std::vector AdditionOfSortedDisjointIntervals( @@ -95,8 +100,15 @@ std::vector NegationOfSortedDisjointIntervals( std::vector intervals); // Returns the domain of x * coeff given the domain of x. +// To avoid an explosion in the size of the returned vector, the first function +// will actually return a super-set of the domain. For instance [1, 100] * 2 +// will be transformed in [2, 200] not [2][4][6]...[200]. The second version +// will try to be exact as long as the result is not too large, and will set +// success to true when this is the case. std::vector MultiplicationOfSortedDisjointIntervals( - std::vector a, int64 coeff); + std::vector intervals, int64 coeff); +std::vector PreciseMultiplicationOfSortedDisjointIntervals( + std::vector intervals, int64 coeff, bool* success); // If x * coeff is in the given intervals, this returns the domain of x. Note // that it is not the same as given the domains of x, return the domain of x / diff --git a/ortools/util/stats.cc b/ortools/util/stats.cc index 4a39ded5ab..499eb69e8c 100644 --- a/ortools/util/stats.cc +++ b/ortools/util/stats.cc @@ -25,7 +25,6 @@ namespace operations_research { -#ifndef ANDROID_JNI std::string MemoryUsage() { static const int64 kDisplayThreshold = 2; static const int64 kKiloByte = 1024; @@ -45,7 +44,6 @@ std::string MemoryUsage() { return StringPrintf("%" GG_LL_FORMAT "d", memory_usage); } } -#endif Stat::Stat(const std::string& name, StatsGroup* group) : name_(name) { group->Register(this); @@ -86,11 +84,7 @@ std::string StatsGroup::StatString() const { for (int i = 0; i < stats_.size(); ++i) { if (!stats_[i]->WorthPrinting()) continue; // We support UTF8 characters in the stat names. -#ifdef ANDROID_JNI - const int size = stats_[i]->Name().length(); -#else const int size = EncodingUtils::UTF8StrLen(stats_[i]->Name()); -#endif longest_name_size = std::max(longest_name_size, size); sorted_stats.push_back(stats_[i]); } @@ -105,11 +99,7 @@ std::string StatsGroup::StatString() const { result += " "; result += sorted_stats[i]->Name(); result.append( -#ifdef ANDROID_JNI - longest_name_size - sorted_stats[i]->Name().length(), -#else longest_name_size - EncodingUtils::UTF8StrLen(sorted_stats[i]->Name()), -#endif ' '); result += " : " + sorted_stats[i]->ValueAsString(); } diff --git a/ortools/util/stats.h b/ortools/util/stats.h index bc1d80afb1..3868949b23 100644 --- a/ortools/util/stats.h +++ b/ortools/util/stats.h @@ -227,13 +227,9 @@ class TimeDistribution : public DistributionStat { // Adds the elapsed time since the last StartTimer() to the distribution and // returns this time in CPU cycles. inline double StopTimerAndAddElapsedTime() { -#ifdef ANDROID_JNI - return 0.0; -#else const double cycles = static_cast(timer_.GetCycles()); AddToDistribution(cycles); return cycles; -#endif } private: diff --git a/ortools/util/time_limit.h b/ortools/util/time_limit.h index 7c7d2f08c0..4bc582f555 100644 --- a/ortools/util/time_limit.h +++ b/ortools/util/time_limit.h @@ -307,12 +307,10 @@ inline TimeLimit::TimeLimit(double limit_in_seconds, double deterministic_limit) deterministic_limit_(deterministic_limit), elapsed_deterministic_time_(0.0), external_boolean_as_limit_(nullptr) { -#ifndef ANDROID_JNI if (FLAGS_time_limit_use_usertime) { user_timer_.Start(); limit_in_seconds_ = limit_in_seconds; } -#endif } inline bool TimeLimit::LimitReached() { @@ -328,7 +326,6 @@ inline bool TimeLimit::LimitReached() { running_max_.Add(std::max(safety_buffer_ns_, current_ns - last_ns_)); last_ns_ = current_ns; if (current_ns + running_max_.GetCurrentMax() >= limit_ns_) { -#ifndef ANDROID_JNI if (FLAGS_time_limit_use_usertime) { // To avoid making many system calls, we only check the user time when // the "absolute" time limit has been reached. Note that the user time @@ -339,7 +336,6 @@ inline bool TimeLimit::LimitReached() { return false; } } -#endif // To ensure that future calls to LimitReached() will return true. limit_ns_ = 0; @@ -352,15 +348,11 @@ inline double TimeLimit::GetTimeLeft() const { if (limit_ns_ == kint64max) return std::numeric_limits::infinity(); const int64 delta_ns = limit_ns_ - base::GetCurrentTimeNanos(); if (delta_ns < 0) return 0.0; -#ifdef ANDROID_JNI - return delta_ns * 1e-9; -#else if (FLAGS_time_limit_use_usertime) { return std::max(limit_in_seconds_ - user_timer_.Get(), 0.0); } else { return delta_ns * 1e-9; } -#endif } } // namespace operations_research diff --git a/ortools/util/tuple_set.h b/ortools/util/tuple_set.h index 758c169ab2..915af73975 100644 --- a/ortools/util/tuple_set.h +++ b/ortools/util/tuple_set.h @@ -35,8 +35,8 @@ #define OR_TOOLS_UTIL_TUPLE_SET_H_ #include -#include "ortools/base/hash.h" -#include "ortools/base/hash.h" +#include +#include #include #include "ortools/base/integral_types.h" diff --git a/ortools/util/vector_map.h b/ortools/util/vector_map.h index 69101c6de9..2ff346c2db 100644 --- a/ortools/util/vector_map.h +++ b/ortools/util/vector_map.h @@ -17,7 +17,7 @@ #ifndef OR_TOOLS_UTIL_VECTOR_MAP_H_ #define OR_TOOLS_UTIL_VECTOR_MAP_H_ -#include "ortools/base/hash.h" +#include #include #include "ortools/base/map_util.h"