dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
GenericFormulaVisitor.h
1
12#pragma once
13
14#include <string>
15
16#include "dlinear/symbolic/symbolic.h"
17#include "dlinear/util/Config.h"
18#include "dlinear/util/Stats.h"
19
20namespace dlinear {
21
29template <class Result, class... Args>
31 public:
33 [[nodiscard]] const IterationStats &stats() const { return stats_; }
35 [[nodiscard]] const Config &config() const { return config_; }
36
37 protected:
43 explicit GenericFormulaVisitor(const Config &config, const std::string &class_name = "GenericFormulaVisitor")
44 : config_{config}, stats_{config.with_timings(), class_name, "Converting"} {}
45 virtual ~GenericFormulaVisitor() = default;
46
47 [[nodiscard]] virtual Result VisitFormula(const Formula &f, Args... args) const {
48 switch (f.get_kind()) {
49 case FormulaKind::False:
50 return VisitFalse(f, args...);
51 case FormulaKind::True:
52 return VisitTrue(f, args...);
53 case FormulaKind::Var:
54 return VisitVariable(f, args...);
55 case FormulaKind::Eq:
56 return VisitEqualTo(f, args...);
57 case FormulaKind::Neq:
58 return VisitNotEqualTo(f, args...);
59 case FormulaKind::Gt:
60 return VisitGreaterThan(f, args...);
61 case FormulaKind::Geq:
62 return VisitGreaterThanOrEqualTo(f, args...);
63 case FormulaKind::Lt:
64 return VisitLessThan(f, args...);
65 case FormulaKind::Leq:
66 return VisitLessThanOrEqualTo(f, args...);
67 case FormulaKind::And:
68 return VisitConjunction(f, args...);
69 case FormulaKind::Or:
70 return VisitDisjunction(f, args...);
71 case FormulaKind::Not:
72 return VisitNegation(f, args...);
73 case FormulaKind::Forall:
74 return VisitForall(f, args...);
75 default:
76 throw std::runtime_error("Unknown formula kind");
77 }
78 }
79 [[nodiscard]] virtual Result VisitFalse(const Formula &f, Args... args) const = 0;
80 [[nodiscard]] virtual Result VisitTrue(const Formula &f, Args... args) const = 0;
81 [[nodiscard]] virtual Result VisitVariable(const Formula &f, Args... args) const = 0;
82 [[nodiscard]] virtual Result VisitEqualTo(const Formula &f, Args... args) const = 0;
83 [[nodiscard]] virtual Result VisitNotEqualTo(const Formula &f, Args... args) const = 0;
84 [[nodiscard]] virtual Result VisitGreaterThan(const Formula &f, Args... args) const = 0;
85 [[nodiscard]] virtual Result VisitGreaterThanOrEqualTo(const Formula &f, Args... args) const = 0;
86 [[nodiscard]] virtual Result VisitLessThan(const Formula &f, Args... args) const = 0;
87 [[nodiscard]] virtual Result VisitLessThanOrEqualTo(const Formula &f, Args... args) const = 0;
88 [[nodiscard]] virtual Result VisitConjunction(const Formula &f, Args... args) const = 0;
89 [[nodiscard]] virtual Result VisitDisjunction(const Formula &f, Args... args) const = 0;
90 [[nodiscard]] virtual Result VisitNegation(const Formula &f, Args... args) const = 0;
91 [[nodiscard]] virtual Result VisitForall(const Formula &f, Args... args) const = 0;
92
93 const Config &config_;
95};
96
97} // namespace dlinear
Simple dataclass used to store the configuration of the program.
Definition Config.h:38
Generic formula visitor implementing the visitor pattern.
const Config & config() const
Get read-only access to the configuration of the FormulaVisitor.
IterationStats stats_
Statistics.
GenericFormulaVisitor(const Config &config, const std::string &class_name="GenericFormulaVisitor")
Construct a new FormulaVisitor object with the given config.
const Config & config_
Configuration.
const IterationStats & stats() const
Get read-only access to the statistics of the FormulaVisitor.
Dataclass collecting statistics about some operation or process.
Definition Stats.h:71
Represents a symbolic form of a first-order logic formula.
Global namespace for the dlinear library.