dReal4
formula_evaluator.h
1 #pragma once
2 
3 #include <memory>
4 #include <ostream>
5 #include <vector>
6 
8 #include "dreal/util/box.h"
9 #include "dreal/util/logging.h"
10 
11 namespace dreal {
12 
13 /// Represents the evaluation result of a constraint given a box.
15  public:
16  enum class Type {
17  VALID, ///< Any point in the box satisfies the constraint.
18  UNSAT, ///< There is no point in the box satisfying the constraint.
19  UNKNOWN, ///< It is unknown. It may indicate that there is a
20  /// point in the box satisfying the constraint.
21  };
22 
23  /// Constructs an FormulaEvaluationResult with @p type and @p evaluation.
24  FormulaEvaluationResult(Type type, const Box::Interval& evaluation);
25 
26  /// Returns the type of this result.
27  Type type() const;
28 
29  /// Returns the interval evaluation of this result.
30  const Box::Interval& evaluation() const;
31 
32  private:
33  Type type_;
34 
35  // Given e₁ rop e₂, it keeps the result of the interval evaluation of (e₁ -
36  // e₂) over a box.
37  Box::Interval evaluation_;
38 };
39 
40 std::ostream& operator<<(std::ostream& os, FormulaEvaluationResult::Type type);
41 std::ostream& operator<<(std::ostream& os,
42  const FormulaEvaluationResult& result);
43 
44 // Forward declaration.
46 
47 /// Class to evaluate a symbolic formula with a box.
49  public:
50  // No default constructor.
51  FormulaEvaluator() = delete;
52 
53  /// Default copy constructor.
54  FormulaEvaluator(const FormulaEvaluator&) = default;
55 
56  /// Default move constructor.
58 
59  /// Default copy assign operator.
60  FormulaEvaluator& operator=(const FormulaEvaluator&) = default;
61 
62  /// Default move assign operator.
63  FormulaEvaluator& operator=(FormulaEvaluator&&) = default;
64 
65  /// Default destruction
66  ~FormulaEvaluator() = default;
67 
68  /// Evaluates the constraint/formula with @p box.
69  FormulaEvaluationResult operator()(const Box& box) const;
70 
71  /// Returns the occurred variables in the formula.
72  const Variables& variables() const;
73 
74  const Formula& formula() const;
75 
76  /// Returns true if the based formula is a simple relational formula which is
77  /// in form of `constant relop variable`.
78  bool is_simple_relational() const;
79 
80  /// Returns true if the based formula is a not-equal formula which is
81  /// in form of `e1 != e2` or `!(e1 == e2)`.
82  bool is_neq() const;
83 
84  private:
85  // Constructs an FormulaEvaluator from `ptr`.
86  explicit FormulaEvaluator(std::shared_ptr<FormulaEvaluatorCell> ptr);
87 
88  std::shared_ptr<FormulaEvaluatorCell> ptr_;
89 
90  friend std::ostream& operator<<(std::ostream& os,
91  const FormulaEvaluator& evaluator);
92 
94 
96  double epsilon,
97  double delta,
98  int number_of_jobs);
99 };
100 
101 /// Creates FormulaEvaluator for a relational formula @p f using @p variables.
103 
104 /// Creates FormulaEvaluator for a universally quantified formula @p f
105 /// using @p variables, @p epsilon, @p delta, and @p number_of_jobs.
107  double delta,
108  int number_of_jobs);
109 
110 std::ostream& operator<<(std::ostream& os, const FormulaEvaluator& evaluator);
111 
112 } // namespace dreal
const Box::Interval & evaluation() const
Returns the interval evaluation of this result.
Definition: formula_evaluator.cc:27
Sum type of symbolic::Expression and symbolic::Formula.
Definition: api.cc:9
Base type for evaluator cell types.
Definition: formula_evaluator_cell.h:13
Type
Definition: formula_evaluator.h:16
FormulaEvaluator make_forall_formula_evaluator(const Formula &f, const double epsilon, const double delta, int number_of_jobs)
Creates FormulaEvaluator for a universally quantified formula f using variables, epsilon, delta, and number_of_jobs.
Definition: formula_evaluator.cc:76
Represents the evaluation result of a constraint given a box.
Definition: formula_evaluator.h:14
Represents a n-dimensional interval vector.
Definition: box.h:17
There is no point in the box satisfying the constraint.
Any point in the box satisfies the constraint.
FormulaEvaluator make_relational_formula_evaluator(const Formula &f)
Creates FormulaEvaluator for a relational formula f using variables.
Definition: formula_evaluator.cc:72
This is the header file that we consolidate Drake&#39;s symbolic classes and expose them inside of dreal ...
Represents a set of variables.
Definition: symbolic_variables.h:25
Class to evaluate a symbolic formula with a box.
Definition: formula_evaluator.h:48
Type type() const
Returns the type of this result.
Definition: formula_evaluator.cc:23
Represents a symbolic form of a first-order logic formula.
Definition: symbolic_formula.h:101
FormulaEvaluationResult(Type type, const Box::Interval &evaluation)
Constructs an FormulaEvaluationResult with type and evaluation.
Definition: formula_evaluator.cc:19