6#include "PlaistedGreenbaumCnfizer.h"
12#include "dlinear/util/Stats.h"
13#include "dlinear/util/Timer.h"
14#include "dlinear/util/exception.h"
22 std::vector<Formula> aux;
23 std::vector<Variable> vars;
24 const Formula head{VisitFormula(g, aux, vars)};
28std::pair<std::vector<Formula>, std::vector<Variable>> PlaistedGreenbaumCnfizer::operator()(
const Formula &f)
const {
32Formula PlaistedGreenbaumCnfizer::VisitForall(
const Formula &f, std::vector<Formula> &aux,
33 std::vector<Variable> &vars)
const {
35 static std::size_t
id{0};
44 const Variables &quantified_variables{get_quantified_variables(f)};
45 const Formula &quantified_formula{get_quantified_formula(f)};
48 for (
const Formula &clause : clauses) {
49 std::set<Formula> new_clause_set{!bvar};
50 if (is_disjunction(clause)) {
51 DLINEAR_ASSERT(
is_clause(clause),
"Must be a clause");
52 std::set<Formula> temp{get_operands(clause)};
53 new_clause_set.insert(temp.begin(), temp.end());
55 new_clause_set.insert(clause);
58 DLINEAR_ASSERT(
is_clause(new_clause),
"Must be a clause");
61 aux.emplace_back(forall(quantified_variables, new_clause));
63 aux.emplace_back(new_clause);
70Formula PlaistedGreenbaumCnfizer::VisitConjunction(
const Formula &f, std::vector<Formula> &aux,
71 std::vector<Variable> &vars)
const {
72 static std::size_t
id{0};
76 for (
const Formula &op : get_operands(f)) {
77 aux.emplace_back(!bvar || VisitFormula(op, aux, vars));
82Formula PlaistedGreenbaumCnfizer::VisitDisjunction(
const Formula &f, std::vector<Formula> &aux,
83 std::vector<Variable> &vars)
const {
84 static std::size_t
id{0};
89 get_operands(f), [
this, &aux, &vars](
const Formula &formula) {
return VisitFormula(formula, aux, vars); })};
95Formula PlaistedGreenbaumCnfizer::VisitNegation(
const Formula &f, std::vector<Formula> &,
96 std::vector<Variable> &)
const {
97 DLINEAR_ASSERT(
is_atomic(get_operand(f)),
"Must be atomic");
void Increase()
Increase the iteration counter by one.
Formula Process(const Formula &f) const
Convert a f into an equivalent formula f' in CNF.
Formula Process(const Formula &f, bool push_negation_into_relationals=false) const
Convert a f into an equivalent formula f' in NNF.
const NaiveCnfizer naive_cnfizer_
Naive CNFizer. Used to transform nested formulas inside universal quantification.
std::pair< std::vector< Formula >, std::vector< Variable > > Process(const Formula &f) const
Convert a f into an equi-satisfiable formula f' in CNF.
Timer & m_timer()
Get read-write access to the timer of the stats.
bool enabled() const
Check whether the stats is enabled.
The TimeGuard wraps a timer object and pauses it when the guard object is destructed.
@ BOOLEAN
A BOOLEAN variable takes a bool value.
Global namespace for the dlinear library.
std::set< Formula > map(const std::set< Formula > &formulas, const std::function< Formula(const Formula &)> &func)
Given formulas = {f₁, ..., fₙ} and a func : Formula → Formula, map(formulas, func) returns a set {fun...
std::set< Formula > get_clauses(const Formula &f)
Returns the set of clauses in f.
Formula make_disjunction(const std::vector< Formula > &formulas)
Make disjunction of formulas.
bool is_clause(const Formula &f)
Check if f is a clause.
bool HaveIntersection(const Variables &variables1, const Variables &variables2)
Check if the intersection of variables1 and variables2 is non-empty.
bool is_atomic(const Formula &f)
Check if f is atomic.