SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
cnf.cpp
Go to the documentation of this file.
1 #include "formula_types.h"
2 
3 #include "utils.h"
4 #include <carl-formula/formula/functions/CNF.h>
5 
6 #include "../settings.h"
7 
8 
9 namespace smtrat::analyzer {
10 
11 void analyze_cnf(const FormulaT& f, AnalyzerStatistics& stats) {
12  if (!settings_analyzer().analyze_cnf) return;
13 
14  FormulaT cnf = carl::to_cnf(f, false);
15 
16  std::size_t num_clauses = 0;
17  std::size_t max_clause_size = 0;
18  std::size_t min_clause_size = 0;
19  std::size_t sum_clause_size = 0;
20 
21  if (cnf.is_atom() || (cnf.type() == carl::FormulaType::OR)) {
22  num_clauses = 1;
23  max_clause_size = cnf.size(); // size is 1 for atoms
24  min_clause_size = cnf.size();
25  sum_clause_size = cnf.size();
26  } else {
27  assert(cnf.type() == carl::FormulaType::AND);
28  num_clauses = cnf.size();
29  for (const auto& sub: cnf) {
30  sum_clause_size += sub.size();
31  if (sub.size() > max_clause_size) max_clause_size = sub.size();
32  if (sub.size() < min_clause_size || min_clause_size == 0) min_clause_size = sub.size();
33  }
34  }
35 
36  stats.add("num_clauses", num_clauses);
37  stats.add("max_clause_size", max_clause_size);
38  stats.add("min_clause_size", min_clause_size);
39  stats.add("sum_clause_size", sum_clause_size);
40  stats.add("avg_clause_size", static_cast<float>(sum_clause_size)/static_cast<float>(num_clauses));
41 }
42 
43 }
void analyze_cnf(const FormulaT &f, AnalyzerStatistics &stats)
Definition: cnf.cpp:11
carl::Formula< Poly > FormulaT
Definition: types.h:37
const auto & settings_analyzer()
Definition: settings.h:33
void add(const std::string &key, const T &value)
Definition: statistics.h:10