3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-08-23 19:47:52 +00:00
z3/src/math/polysat/clause_builder.h
Jakob Rath e005838129 clause_builder should not fail on always-true literals
Otherwise, e.g. when adding axioms, the caller would have to check each literal before adding it.
2022-01-18 10:32:33 +01:00

61 lines
1.8 KiB
C++

/*++
Copyright (c) 2021 Microsoft Corporation
Module Name:
polysat clause builder
Author:
Jakob Rath 2021-04-6
Notes:
Builds a clause from literals and constraints.
Takes care to
- resolve with unit clauses and accumulate their dependencies,
- skip trivial new constraints such as "4 <= 1".
--*/
#pragma once
#include "math/polysat/constraint.h"
#include "math/polysat/types.h"
namespace polysat {
class clause_builder {
solver* m_solver;
sat::literal_vector m_literals;
/// true iff clause contains a literal that is always true
/// (only this specific case of tautology is covered by this flag)
bool m_is_tautology = false;
public:
clause_builder(solver& s);
clause_builder(clause_builder const& s) = delete;
clause_builder(clause_builder&& s) = default;
clause_builder& operator=(clause_builder const& s) = delete;
clause_builder& operator=(clause_builder&& s) = default;
bool empty() const { return m_literals.empty() && !m_is_tautology; }
void reset();
/// Build the clause. This will reset the clause builder so it can be reused.
/// Returns nullptr if the clause is a tautology and should not be added to the solver.
clause_ref build();
void push(sat::literal lit);
void push(signed_constraint c);
void push(inequality const& i) { push(i.as_signed_constraint()); }
/// Push a new constraint. Allocates a boolean variable for the constraint, if necessary.
void push_new(signed_constraint c);
using const_iterator = decltype(m_literals)::const_iterator;
const_iterator begin() const { return m_literals.begin(); }
const_iterator end() const { return m_literals.end(); }
};
}