SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
types.h
Go to the documentation of this file.
1 #pragma once
2 
12 #include <carl-formula/formula/functions/PNF.h>
13 
14 #include <boost/container/flat_map.hpp>
15 
16 namespace smtrat::covering_ng {
17 
18 template<typename PropertiesSet>
20 /**
21  * Sorts interval by their lower bounds.
22  */
23 template<typename PropertiesSet>
25  inline constexpr bool operator()(const Interval<PropertiesSet>& a, const Interval<PropertiesSet>& b) const {
26  const auto& cell_a = a->cell();
27  const auto& cell_b = b->cell();
29  }
30 };
31 template<typename PropertiesSet>
32 using IntervalSet = std::set<Interval<PropertiesSet>, IntervalCompare<PropertiesSet>>;
33 
35 
36 template<typename PropertiesSet>
39  std::optional<std::vector<Interval<PropertiesSet>>> m_intervals;
40  std::optional<cadcells::Assignment> m_sample;
41 
43  explicit CoveringResult(Status s) : status(s){}
44  // explicit CoveringResult(std::vector<Interval<PropertiesSet>>& inter) : status(UNSAT), m_intervals(inter) {}
45  // explicit CoveringResult(const cadcells::Assignment& ass) : status(SAT), m_sample(ass) {}
46  CoveringResult(Status s, std::vector<Interval<PropertiesSet>>& inter) : status(s), m_intervals(inter) {}
47  CoveringResult(Status s, std::vector<Interval<PropertiesSet>>&& inter) : status(s), m_intervals(inter) {}
49  CoveringResult(Status s, const std::optional<cadcells::Assignment>& ass) : status(s), m_sample(ass) {}
50  CoveringResult(Status s, const cadcells::Assignment& ass, const std::vector<Interval<PropertiesSet>>& inter) : status(s), m_intervals(inter), m_sample(ass) {}
51  CoveringResult(Status s, const std::optional<cadcells::Assignment>& ass, const std::vector<Interval<PropertiesSet>>& inter) : status(s), m_intervals(inter), m_sample(ass) {}
52 
53  bool is_failed() const {
55  }
56  bool is_failed_projection() const {
58  }
59  bool is_sat() const {
60  return status == Status::SAT;
61  }
62  bool is_unsat() const {
63  return status == Status::UNSAT;
64  }
65  bool is_parameter() const {
66  return status == Status::PARAMETER;
67  }
68  const auto& sample() const {
69  return m_sample;
70  }
71  const auto& intervals() const {
72  assert(m_intervals);
73  return *m_intervals;
74  }
75 };
76 
77 template<typename PropertiesSet>
78 std::ostream& operator<<(std::ostream& os, const CoveringResult<PropertiesSet>& result){
79  switch (result.status) {
80  case Status::SAT:
81  os << "SAT" ;
82  break;
83  case Status::UNSAT:
84  os << "UNSAT" ;
85  break;
86  case Status::FAILED:
87  os << "Failed" ;
88  break;
90  os << "Failed Projection" ;
91  break;
92  case Status::PARAMETER:
93  os << "Parameter" ;
94  break;
95  }
96  return os;
97 }
98 
99 struct ParameterTree {
100  boost::tribool status;
101  std::optional<carl::Variable> variable;
102  std::optional<cadcells::datastructures::SymbolicInterval> interval;
103  std::optional<cadcells::Assignment> sample;
104  std::vector<ParameterTree> children;
105 
106  ParameterTree() : status(boost::indeterminate) {}
107  ParameterTree(bool s) : status(s) {}
108  ParameterTree(const carl::Variable& v, const cadcells::datastructures::SymbolicInterval& i, const cadcells::Assignment& s, std::vector<ParameterTree>&& c) : status(boost::indeterminate), variable(v), interval(i), sample(s), children(std::move(c)) {
109  assert(!children.empty());
110  status = children.begin()->status;
111  for (const auto& child : children) {
112  if (child.status != status) {
113  status = boost::indeterminate;
114  break;
115  }
116  }
117  if (!boost::indeterminate(status)) {
118  children.clear();
119  }
120  }
121  ParameterTree(std::vector<ParameterTree>&& c) : status(boost::indeterminate), children(std::move(c)) {
122  assert(!children.empty());
123  status = children.begin()->status;
124  for (const auto& child : children) {
125  if (child.status != status) {
126  status = boost::indeterminate;
127  break;
128  }
129  }
130  if (!boost::indeterminate(status)) {
131  children.clear();
132  }
133  }
134  ParameterTree(boost::tribool st, const carl::Variable& v, const cadcells::datastructures::SymbolicInterval& i, const cadcells::Assignment& s) : status(st), variable(v), interval(i), sample(s) {
135  assert(!boost::indeterminate(st));
136  }
137 };
138 static std::ostream& operator<<(std::ostream& os, const ParameterTree& tree){
139  os << tree.status;
140  if (tree.variable) {
141  os << " " << *tree.variable << " " << *tree.interval << " " << *tree.sample;
142  }
143  os << " (" << std::endl;
144  for (const auto& child : tree.children) {
145  os << child << std::endl;
146  }
147  os << ")";
148  return os;
149 }
150 
152 private:
153  boost::container::flat_map<carl::Variable, carl::Quantifier> m_var_types;
154 
155 public:
156  [[nodiscard]] const auto& var_types() const {
157  return m_var_types;
158  }
159 
160  /**
161  * Returns the type of the given variable.
162  * @param var The variable.
163  * @return The type of the variable. Returns EXISTS if the variable is not quantified.
164  **/
165  [[nodiscard]] carl::Quantifier var_type(const carl::Variable& var) const{
166  auto it = m_var_types.find(var);
167  if (it == m_var_types.end()) {
168  return carl::Quantifier::FREE;
169  }
170  return it->second;
171  }
172 
173  bool has(const carl::Variable& var) const{
174  return m_var_types.find(var) != m_var_types.end();
175  }
176 
177  void set_var_type(const carl::Variable& var, carl::Quantifier type){
178  m_var_types[var] = type;
179  }
180 
181 };
182 
183 inline std::ostream& operator<<(std::ostream& os, const VariableQuantification& vq) {
184  for (const auto& [var, type] : vq.var_types()) {
185  os << "(" << type << " " << var << ")";
186  }
187  return os;
188 }
189 
190 }
A symbolic interal whose bounds are defined by indexed root expressions.
Definition: roots.h:250
bool has(const carl::Variable &var) const
Definition: types.h:173
void set_var_type(const carl::Variable &var, carl::Quantifier type)
Definition: types.h:177
boost::container::flat_map< carl::Variable, carl::Quantifier > m_var_types
Definition: types.h:153
carl::Quantifier var_type(const carl::Variable &var) const
Returns the type of the given variable.
Definition: types.h:165
int var(Lit p)
Definition: SolverTypes.h:64
bool upper_lt_upper(const DelineationInterval &del1, const DelineationInterval &del2)
Compares the upper bounds of two DelineationIntervals.
Definition: delineation.h:286
bool lower_lt_lower(const DelineationInterval &del1, const DelineationInterval &del2)
Compares the lower bounds of two DelineationIntervals.
Definition: delineation.h:266
bool lower_eq_lower(const DelineationInterval &del1, const DelineationInterval &del2)
Compares the lower bounds of two DelineationIntervals.
Definition: delineation.h:276
std::shared_ptr< SampledDerivation< Properties > > SampledDerivationRef
Definition: derivation.h:25
carl::Assignment< RAN > Assignment
Definition: common.h:25
std::set< Interval< PropertiesSet >, IntervalCompare< PropertiesSet > > IntervalSet
Definition: types.h:32
std::ostream & operator<<(std::ostream &os, const CoveringResult< PropertiesSet > &result)
Definition: types.h:78
cadcells::datastructures::SampledDerivationRef< PropertiesSet > Interval
Definition: types.h:19
QuantifierType type(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
Definition: QEQuery.h:39
const auto & sample() const
Definition: types.h:68
std::optional< std::vector< Interval< PropertiesSet > > > m_intervals
Definition: types.h:39
CoveringResult(Status s, const std::optional< cadcells::Assignment > &ass)
Definition: types.h:49
CoveringResult(Status s, const cadcells::Assignment &ass)
Definition: types.h:48
CoveringResult(Status s, const std::optional< cadcells::Assignment > &ass, const std::vector< Interval< PropertiesSet >> &inter)
Definition: types.h:51
CoveringResult(Status s, const cadcells::Assignment &ass, const std::vector< Interval< PropertiesSet >> &inter)
Definition: types.h:50
CoveringResult(Status s, std::vector< Interval< PropertiesSet >> &&inter)
Definition: types.h:47
const auto & intervals() const
Definition: types.h:71
CoveringResult(Status s, std::vector< Interval< PropertiesSet >> &inter)
Definition: types.h:46
bool is_failed_projection() const
Definition: types.h:56
std::optional< cadcells::Assignment > m_sample
Definition: types.h:40
Sorts interval by their lower bounds.
Definition: types.h:24
constexpr bool operator()(const Interval< PropertiesSet > &a, const Interval< PropertiesSet > &b) const
Definition: types.h:25
ParameterTree(const carl::Variable &v, const cadcells::datastructures::SymbolicInterval &i, const cadcells::Assignment &s, std::vector< ParameterTree > &&c)
Definition: types.h:108
std::vector< ParameterTree > children
Definition: types.h:104
std::optional< cadcells::Assignment > sample
Definition: types.h:103
std::optional< cadcells::datastructures::SymbolicInterval > interval
Definition: types.h:102
ParameterTree(std::vector< ParameterTree > &&c)
Definition: types.h:121
ParameterTree(boost::tribool st, const carl::Variable &v, const cadcells::datastructures::SymbolicInterval &i, const cadcells::Assignment &s)
Definition: types.h:134
std::optional< carl::Variable > variable
Definition: types.h:101