Skip to content

Commit

Permalink
bump abseil to the latest version, adapt the code all around
Browse files Browse the repository at this point in the history
  • Loading branch information
lperron committed Nov 20, 2019
1 parent 3765c97 commit 2ff000a
Show file tree
Hide file tree
Showing 147 changed files with 1,985 additions and 1,110 deletions.
76 changes: 66 additions & 10 deletions makefiles/Makefile.third_party.unix.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ PROTOC_BINARY := $(shell $(WHICH) ${UNIX_PROTOC_BINARY})
GFLAGS_TAG = 2.2.2
GLOG_TAG = 0.4.0
PROTOBUF_TAG = 3.10.0
ABSL_TAG = bf29470
ABSL_TAG = 2103fd9
CBC_TAG = 2.10.3
CGL_TAG = 0.60.2
CLP_TAG = 1.17.3
Expand Down Expand Up @@ -338,7 +338,8 @@ dependencies/install/lib/libabsl.$L: dependencies/sources/abseil-cpp-$(ABSL_TAG)
cd dependencies/sources/abseil-cpp-$(ABSL_TAG) && \
$(SET_COMPILER) $(CMAKE) -H. -Bbuild_cmake \
-DCMAKE_PREFIX_PATH="$(OR_TOOLS_TOP)/dependencies/install" \
-DBUILD_SHARED_LIBS=ON \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_STATIC_LIBS=ON \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DCMAKE_CXX_FLAGS="$(MAC_VERSION)" \
-DBUILD_TESTING=OFF \
Expand All @@ -350,7 +351,7 @@ dependencies/sources/abseil-cpp-$(ABSL_TAG): | dependencies/sources
-$(DELREC) dependencies/sources/abseil-cpp-$(ABSL_TAG)
git clone --quiet https://github.com/abseil/abseil-cpp.git dependencies/sources/abseil-cpp-$(ABSL_TAG)
cd dependencies/sources/abseil-cpp-$(ABSL_TAG) && git reset --hard $(ABSL_TAG)
cd dependencies/sources/abseil-cpp-$(ABSL_TAG) && git apply "$(OR_TOOLS_TOP)/patches/abseil-cpp-$(ABSL_TAG).patch"
# cd dependencies/sources/abseil-cpp-$(ABSL_TAG) && git apply "$(OR_TOOLS_TOP)/patches/abseil-cpp-$(ABSL_TAG).patch"

ABSL_INC = -I$(UNIX_ABSL_DIR)/include
ABSL_SWIG = $(ABSL_INC)
Expand All @@ -366,16 +367,43 @@ $(_ABSL_STATIC_LIB_DIR)libabsl_bad_variant_access.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_city.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_civil_time.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_debugging_internal.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_demangle_internal.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_dynamic_annotations.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_examine_stack.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_exponential_biased.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_failure_signal_handler.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_flags.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_flags_config.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_flags_handle.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_flags_internal.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_flags_marshalling.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_flags_parse.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_flags_program_name.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_flags_registry.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_flags_usage.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_flags_usage_internal.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_graphcycles_internal.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_hash.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_hashtablez_sampler.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_int128.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_leak_check.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_leak_check_disable.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_log_severity.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_malloc_internal.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_optional.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_periodic_sampler.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_random_distributions.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_random_internal_distribution_test_util.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_random_internal_pool_urbg.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_random_internal_randen.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_random_internal_randen_hwaes.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_random_internal_randen_hwaes_impl.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_random_internal_randen_slow.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_random_internal_seed_material.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_random_seed_gen_exception.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_random_seed_sequences.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_raw_hash_set.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_raw_logging_internal.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_scoped_set_env.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_spinlock_wait.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_stacktrace.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_str_format_internal.a \
Expand All @@ -385,12 +413,40 @@ $(_ABSL_STATIC_LIB_DIR)libabsl_symbolize.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_throw_delegate.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_time.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_time_zone.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_base.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_int128.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_synchronization.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_debugging_internal.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_demangle_internal.a \
$(_ABSL_STATIC_LIB_DIR)libabsl_dynamic_annotations.a \

#$(_ABSL_STATIC_LIB_DIR)libabsl_base.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_synchronization.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_bad_any_cast_impl.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_bad_optional_access.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_bad_variant_access.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_city.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_civil_time.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_debugging_internal.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_examine_stack.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_failure_signal_handler.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_graphcycles_internal.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_hash.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_hashtablez_sampler.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_int128.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_leak_check.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_malloc_internal.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_optional.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_raw_hash_set.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_spinlock_wait.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_stacktrace.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_str_format_internal.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_strings.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_strings_internal.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_symbolize.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_throw_delegate.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_time.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_time_zone.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_base.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_int128.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_synchronization.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_debugging_internal.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_demangle_internal.a \
#$(_ABSL_STATIC_LIB_DIR)libabsl_dynamic_annotations.a \
_ABSL_LIB_DIR = $(dir $(wildcard \
$(UNIX_ABSL_DIR)/lib*/libabsl_base.$L \
Expand Down
2 changes: 1 addition & 1 deletion ortools/algorithms/dynamic_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ std::string MergingPartition::DebugString() {
std::sort(part.begin(), part.end());
std::sort(sorted_parts.begin(), sorted_parts.end());
// Note: typically, a lot of elements of "sorted_parts" will be empty,
// but these won't be visible in the std::string that we construct below.
// but these won't be visible in the string that we construct below.
std::string out;
for (const std::vector<int>& part : sorted_parts) {
if (!out.empty()) out += " | ";
Expand Down
12 changes: 6 additions & 6 deletions ortools/algorithms/dynamic_partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
// (aka "elements") into disjoint equivalence classes (aka "parts").
//
// SAFETY:
// Like std::vector<int> crashes when used improperly, these classes are not
// "safe": most of their methods may crash if called with invalid arguments. The
// client code is responsible for using this class properly. A few DCHECKs()
// will help catch bugs, though.
// Like vector<int> crashes when used improperly, these classes are not "safe":
// most of their methods may crash if called with invalid arguments. The client
// code is responsible for using this class properly. A few DCHECKs() will help
// catch bugs, though.

#ifndef OR_TOOLS_ALGORITHMS_DYNAMIC_PARTITION_H_
#define OR_TOOLS_ALGORITHMS_DYNAMIC_PARTITION_H_
Expand Down Expand Up @@ -112,8 +112,8 @@ class DynamicPartition {
// Prerequisite: NumParts() >= original_num_parts.
void UndoRefineUntilNumPartsEqual(int original_num_parts);

// Dump the partition to a std::string. There might be different conventions
// for sorting the parts and the elements inside them.
// Dump the partition to a string. There might be different conventions for
// sorting the parts and the elements inside them.
enum DebugStringSorting {
// Elements are sorted within parts, and parts are then sorted
// lexicographically.
Expand Down
1 change: 0 additions & 1 deletion ortools/algorithms/samples/knapsack.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# [START import]
from __future__ import print_function
from ortools.algorithms import pywrapknapsack_solver

# [END import]


Expand Down
1 change: 0 additions & 1 deletion ortools/algorithms/samples/simple_knapsack_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# [START import]
from __future__ import print_function
from ortools.algorithms import pywrapknapsack_solver

# [END import]


Expand Down
28 changes: 16 additions & 12 deletions ortools/base/adjustable_priority_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define OR_TOOLS_BASE_ADJUSTABLE_PRIORITY_QUEUE_H_

#include <stddef.h>

#include <functional>
#include <list>
#include <vector>
Expand All @@ -28,11 +29,12 @@ class LowerPriorityThan {
public:
explicit LowerPriorityThan(Comparator* compare) : compare_(compare) {}
bool operator()(T* a, T* b) const { return (*compare_)(*a, *b); }

private:
Comparator* compare_;
};

template<typename T, typename Comp = std::less<T> >
template <typename T, typename Comp = std::less<T> >
class AdjustablePriorityQueue {
public:
// The objects references 'c' and 'm' are not required to be alive for the
Expand Down Expand Up @@ -99,14 +101,14 @@ class AdjustablePriorityQueue {
topvec->push_back(elems_[ind]);
int leftchild = 1 + 2 * ind;
if (leftchild < Size()) {
if (!LowerPriorityThan<T, Comp>(&c_)(elems_[leftchild], elems_[ind])) {
need_to_check_children.push_back(leftchild);
}
int rightchild = leftchild + 1;
if (rightchild < Size() &&
!LowerPriorityThan<T, Comp>(&c_)(elems_[rightchild], elems_[ind])) {
need_to_check_children.push_back(rightchild);
}
if (!LowerPriorityThan<T, Comp>(&c_)(elems_[leftchild], elems_[ind])) {
need_to_check_children.push_back(leftchild);
}
int rightchild = leftchild + 1;
if (rightchild < Size() &&
!LowerPriorityThan<T, Comp>(&c_)(elems_[rightchild], elems_[ind])) {
need_to_check_children.push_back(rightchild);
}
}
}
}
Expand All @@ -130,13 +132,15 @@ class AdjustablePriorityQueue {
// priority than its child).
void CheckValid() {
for (int i = 0; i < elems_.size(); ++i) {
int left_child = 1 + 2*i;
int left_child = 1 + 2 * i;
if (left_child < elems_.size()) {
CHECK(!(LowerPriorityThan<T, Comp>(&c_))(elems_[i], elems_[left_child]));
CHECK(
!(LowerPriorityThan<T, Comp>(&c_))(elems_[i], elems_[left_child]));
}
int right_child = left_child + 1;
if (right_child < elems_.size()) {
CHECK(!(LowerPriorityThan<T, Comp>(&c_))(elems_[i], elems_[right_child]));
CHECK(
!(LowerPriorityThan<T, Comp>(&c_))(elems_[i], elems_[right_child]));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ortools/base/encodingutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace EncodingUtils {

// Returns the number of characters of a UTF8-encoded std::string.
// Returns the number of characters of a UTF8-encoded string.
inline int UTF8StrLen(const std::string& utf8_str) {
if (utf8_str.empty()) return 0;
const char* c = utf8_str.c_str();
Expand Down
10 changes: 5 additions & 5 deletions ortools/base/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ class File {
// If read failed, program will exit.
void ReadOrDie(void* const buff, size_t size);

// Reads a line from file to a std::string.
// Reads a line from file to a string.
// Each line must be no more than max_length bytes.
char* ReadLine(char* const output, uint64 max_length);

// Reads the whole file to a std::string, with a maximum length of
// 'max_length'. Returns the number of bytes read.
// Reads the whole file to a string, with a maximum length of 'max_length'.
// Returns the number of bytes read.
int64 ReadToString(std::string* const line, uint64 max_length);

// Writes "size" bytes of buff to file, buff should be pre-allocated.
Expand All @@ -75,10 +75,10 @@ class File {
// If write failed, program will exit.
void WriteOrDie(const void* const buff, size_t size);

// Writes a std::string to file.
// Writes a string to file.
size_t WriteString(const std::string& line);

// Writes a std::string to file and append a "\n".
// Writes a string to file and append a "\n".
bool WriteLine(const std::string& line);

// Closes the file.
Expand Down
3 changes: 1 addition & 2 deletions ortools/base/filelineiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
// * The lines are separated by '\n' (which is removed by default) and have no
// size limits.
// * Consecutive '\n' result in empty lines being produced.
// * If not empty, the std::string after the last '\n' is produced as the last
// line.
// * If not empty, the string after the last '\n' is produced as the last line.
// * Options are available to keep the trailing '\n' for each line, to remove
// carriage-return chararters ('\r'), and to remove blank lines.
//
Expand Down
1 change: 0 additions & 1 deletion ortools/base/int_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@
#include <iosfwd>
#include <ostream> // NOLINT
#include <type_traits>
#include <unordered_map>

#include "absl/strings/string_view.h"
#include "ortools/base/macros.h"
Expand Down
4 changes: 2 additions & 2 deletions ortools/base/jniutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class JNIUtil {
return env->NewStringUTF(cstr);
}

// Creates a null-terminated UTF-8 encoded C std::string from a jstring.
// The returned std::string should be "delete[]"-ed when no longer needed.
// Creates a null-terminated UTF-8 encoded C string from a jstring.
// The returned string should be "delete[]"-ed when no longer needed.
static char* MakeCString(JNIEnv* env, jstring str) {
if (str == NULL) return NULL;
jsize length = env->GetStringUTFLength(str);
Expand Down
1 change: 1 addition & 0 deletions ortools/base/protoutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#ifndef OR_TOOLS_BASE_PROTOUTIL_H_
#define OR_TOOLS_BASE_PROTOUTIL_H_

#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "google/protobuf/duration.pb.h"
#include "ortools/base/status.h"
Expand Down
3 changes: 1 addition & 2 deletions ortools/base/random.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ int32 ACMRandom::HostnamePidTimeSeed() {
}
const int namelen = strlen(name);
for (size_t i = 0; i < sizeof(uint32) * 3; ++i) {
name[namelen + i] =
'\0'; // so we mix 0's once we get to end-of-std::string
name[namelen + i] = '\0'; // so we mix 0's once we get to end-of-string
}
#if defined(__GNUC__)
uint32 a = getpid();
Expand Down
15 changes: 1 addition & 14 deletions ortools/base/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <random>
#include <string>

#include "absl/random/random.h"
#include "ortools/base/basictypes.h"

namespace operations_research {
Expand Down Expand Up @@ -119,18 +120,4 @@ typedef ACMRandom RandomBase;

} // namespace operations_research

namespace absl {
template <typename URBG>
bool Bernoulli(URBG&& urbg, // NOLINT(runtime/references)
double p) {
return std::bernoulli_distribution(p)(urbg);
}

template <typename URGB>
int Uniform(URGB&& urgb, // NOLINT(runtime/references)
int low, int high_excluded) {
return std::uniform_int_distribution<>(low, high_excluded - 1)(urgb);
}
} // namespace absl

#endif // OR_TOOLS_BASE_RANDOM_H_
5 changes: 3 additions & 2 deletions ortools/base/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ struct Status {
return absl::StrCat("ERROR #", error_code_, ": '", error_message_, "'");
}

util::error::Error code() const { return static_cast<util::error::Error>(error_code_); }
util::error::Error code() const {
return static_cast<util::error::Error>(error_code_);
}

std::string error_message() const { return error_message_; }
std::string message() const { return error_message(); }


void IgnoreError() const {}

private:
Expand Down
Loading

0 comments on commit 2ff000a

Please sign in to comment.