Google OR-Tools: ortools/util/time_limit.cc Source File

1

2

3

4

5

6

7

8

9

10

11

12

13

15

16#include <algorithm>

17#include <cstdint>

18#include <limits>

19#include <memory>

20#include <string>

21#include <utility>

22

23#include "absl/flags/flag.h"

24#include "absl/log/die_if_null.h"

25#include "absl/log/log.h"

26#include "absl/strings/str_cat.h"

27#include "absl/time/time.h"

28

29ABSL_FLAG(bool, time_limit_use_usertime, false,

30 "If true, rely on the user time in the TimeLimit class. This is "

31 "only recommended for benchmarking on a non-isolated environment.");

32

34

35

38

42 external_boolean_as_limit_(nullptr) {

43 ResetTimers(limit_in_seconds, deterministic_limit);

44}

45

47 std::string buffer = absl::StrCat(

52#ifndef NDEBUG

53 for (const auto& counter : deterministic_counters_) {

54 const std::string& counter_name = counter.first;

55 const double counter_value = counter.second;

56 absl::StrAppend(&buffer, "\n", counter_name, ": ", (counter_value));

57 }

58#endif

59 return buffer;

60}

61

63 double limit_in_seconds,

64 double deterministic_limit)

65 : base_time_limit_(ABSL_DIE_IF_NULL(base_time_limit)),

66 time_limit_(std::min(base_time_limit_->GetTimeLeft(), limit_in_seconds),

67 std::min(base_time_limit_->GetDeterministicTimeLeft(),

68 deterministic_limit)) {

69 if (base_time_limit_->external_boolean_as_limit_ != nullptr) {

70 time_limit_.RegisterExternalBooleanAsLimit(

71 base_time_limit_->external_boolean_as_limit_);

72 }

73}

74

76 base_time_limit_->AdvanceDeterministicTime(

77 time_limit_.GetElapsedDeterministicTime());

78}

79}

~NestedTimeLimit()

Definition time_limit.cc:75

NestedTimeLimit(TimeLimit *base_time_limit, double limit_in_seconds, double deterministic_limit)

Definition time_limit.cc:62

double GetTimeLeft() const

double GetElapsedDeterministicTime() const

double GetDeterministicTimeLeft() const

static const int kHistorySize

static const double kSafetyBufferSeconds

double GetElapsedTime() const

std::string DebugString() const

Definition time_limit.cc:46

ABSL_FLAG(bool, time_limit_use_usertime, false, "If true, rely on the user time in the TimeLimit class. This is " "only recommended for benchmarking on a non-isolated environment.")