Google OR-Tools: ortools/flatzinc/parser_util.cc Source File

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

17

18#include <cmath>

19#include <string>

20#include <vector>

21

22#include "absl/strings/string_view.h"

30

34

37 const char* str) {

38 LOG(ERROR) << "Error: " << str << " in line no. " << orfz_get_lineno(scanner);

39 *ok = false;

40}

41

43namespace fz {

44

45

46bool ContainsId(std::vector<Annotation>* annotations, absl::string_view id) {

47 if (annotations != nullptr) {

48 for (int i = 0; i < annotations->size(); ++i) {

51 (*annotations)[i].id == id) {

52 return true;

53 }

54 }

55 }

56 return false;

57}

58

60 for (int i = 0; i < domains.size(); ++i) {

61 if (!domains[i].HasOneValue()) {

62 return false;

63 }

64 }

65 return true;

66}

67

69 const double rounded = std::round(d);

70 const int64_t i = static_cast<int64_t>(rounded);

71 CHECK_LE(std::abs(static_cast<double>(i) - rounded), 1e-9);

72 return i;

73}

74

75

76

77template <class T>

78const T& Lookup(const std::vector<T>& v, int index) {

79

80 CHECK_GE(index, 1);

81 CHECK_LE(index, v.size());

82 return v[index - 1];

83}

84}

85}

const T & Lookup(const std::vector< T > &v, int index)

Definition parser_util.cc:78

bool ContainsId(std::vector< Annotation > *annotations, absl::string_view id)

Definition parser_util.cc:46

int64_t ConvertAsIntegerOrDie(double d)

Definition parser_util.cc:68

bool AllDomainsHaveOneValue(const std::vector< Domain > &domains)

Definition parser_util.cc:59

int orfz_lex(YYSTYPE *, void *scanner)

int orfz_get_lineno(void *scanner)

void orfz_error(operations_research::fz::ParserContext *context, operations_research::fz::Model *model, bool *ok, void *scanner, const char *str)

Definition parser_util.cc:35