SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
FormulaEvaluationGraph.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "FormulaEvaluation.h"
4 
6 
7 namespace formula_ds {
8 
9 // using FormulaID = std::size_t;
10 using FormulaID = unsigned;
11 
12 struct TRUE {};
13 struct FALSE {};
14 struct NOT {
16 };
17 struct AND {
18  std::vector<FormulaID> subformulas;
19 };
20 struct OR {
21  std::vector<FormulaID> subformulas;
22 };
23 struct IFF {
24  std::vector<FormulaID> subformulas;
25 };
26 struct XOR {
27  std::vector<FormulaID> subformulas;
28 };
29 struct BOOL {
30  carl::Variable variable;
31 };
32 struct CONSTRAINT {
34 };
35 
36 struct Formula {
37  using Reason = std::vector<std::pair<FormulaID,bool>>;
38  using Reasons = std::vector<Reason>;
39 
40  std::variant<TRUE,FALSE,NOT,AND,OR,IFF,XOR,BOOL,CONSTRAINT> content;
41  boost::container::flat_set<FormulaID> parents;
44 
45  template<typename C>
46  Formula(const C& c) : content(c) {}
47 
48  Valuation valuation() const {
49  if (reasons_true.empty() && reasons_false.empty()) return Valuation::MULTIVARIATE;
50  else if (reasons_true.empty()) return Valuation::FALSE;
51  else if (reasons_false.empty()) return Valuation::TRUE;
52  else return Valuation::UNKNOWN; // conflict
53  }
54 };
55 
56 using FormulaDB = std::vector<Formula>;
57 using VariableToFormula = boost::container::flat_map<carl::Variable, std::vector<FormulaID>>;
58 
59 struct FormulaGraph {
62  boost::container::flat_set<FormulaID> conflicts;
64 
66  void propagate_root(FormulaID id, bool is_true);
67  void propagate_decision(FormulaID id, bool is_true);
68  void add_reasons_true(FormulaID id, const Formula::Reasons& reasons);
69  void add_reasons_false(FormulaID id, const Formula::Reasons& reasons);
71  void backtrack(FormulaID id, bool is_true);
72 };
73 
74 }
75 
77 
78 public:
80 
81 private:
83 
88  boost::container::flat_map<formula_ds::FormulaID, bool> m_decisions;
91 
93  std::size_t m_results;
99 
101 
102 public:
103  GraphEvaluation(cadcells::datastructures::Projections proj, ImplicantOrdering implicant_complexity_ordering, std::size_t results, ConstraintOrdering constraint_complexity_ordering, bool stop_evaluation_on_conflict, bool preprocess, bool postprocess, BooleanExploration boolean_exploration) : m_proj(proj), m_implicant_complexity_ordering(implicant_complexity_ordering), m_results(results), m_constraint_complexity_ordering(constraint_complexity_ordering), m_stop_evaluation_on_conflict(stop_evaluation_on_conflict), m_preprocess(preprocess), m_postprocess(postprocess), m_boolean_exploration(boolean_exploration) {}
104 
105  void set_formula(const FormulaT& f);
106  void extend_valuation(const cadcells::Assignment& ass);
107  void revert_valuation(const cadcells::Assignment& ass);
108  std::vector<boost::container::flat_set<cadcells::datastructures::PolyConstraint>> compute_implicants();
109  Valuation root_valuation() const;
110 };
111 
112 }
Encapsulates all computations on polynomials.
Definition: projections.h:46
std::vector< boost::container::flat_set< cadcells::datastructures::PolyConstraint > > compute_implicants()
boost::container::flat_map< formula_ds::FormulaID, bool > m_decisions
formula_ds::Formula::Reasons explore(formula_ds::FormulaGraph &graph)
GraphEvaluation(cadcells::datastructures::Projections proj, ImplicantOrdering implicant_complexity_ordering, std::size_t results, ConstraintOrdering constraint_complexity_ordering, bool stop_evaluation_on_conflict, bool preprocess, bool postprocess, BooleanExploration boolean_exploration)
cadcells::datastructures::Projections m_proj
void revert_valuation(const cadcells::Assignment &ass)
void extend_valuation(const cadcells::Assignment &ass)
carl::Assignment< RAN > Assignment
Definition: common.h:25
boost::container::flat_map< carl::Variable, std::vector< FormulaID > > VariableToFormula
FormulaT preprocess(const FormulaT &f)
std::function< bool(cadcells::datastructures::Projections &, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &, const boost::container::flat_set< cadcells::datastructures::PolyConstraint > &)> ImplicantOrdering
void postprocess(cadcells::datastructures::Projections &proj, boost::container::flat_set< cadcells::datastructures::PolyConstraint > &i)
std::function< bool(cadcells::datastructures::Projections &, const cadcells::datastructures::PolyConstraint &, const cadcells::datastructures::PolyConstraint &)> ConstraintOrdering
carl::Formula< Poly > FormulaT
Definition: types.h:37
cadcells::datastructures::PolyConstraint constraint
void add_reasons_false(FormulaID id, const Formula::Reasons &reasons)
void add_reasons_true(FormulaID id, const Formula::Reasons &reasons)
std::vector< std::pair< FormulaID, bool > > Reason
std::variant< TRUE, FALSE, NOT, AND, OR, IFF, XOR, BOOL, CONSTRAINT > content
boost::container::flat_set< FormulaID > parents