3#include <clingo/ground/matcher.hh>
4#include <clingo/ground/statement.hh>
5#include <clingo/ground/term.hh>
6#include <clingo/ground/theory_term.hh>
8#include <clingo/util/macro.hh>
9#include <clingo/util/small_vector.hh>
11#include <memory_resource>
13namespace CppClingo::Ground {
53 [[nodiscard]]
auto elems() const -> std::span<
size_t const>;
56 [[nodiscard]] auto
uid() const -> std::optional<
size_t>;
61 [[nodiscard]] auto
name() const ->
Symbol {
return name_; }
64 [[nodiscard]]
auto rhs() const -> std::optional<
size_t> {
65 if (rhs_ != invalid_offset) {
74 size_t uid_ = invalid_offset;
89 auto add(
Symbol const *sym,
Symbol name, std::optional<size_t> rhs) -> std::pair<AtomMap::iterator, bool>;
92 [[nodiscard]]
auto size() const ->
size_t;
99 [[nodiscard]] auto
nth(
size_t i) const ->
AtomMap::const_iterator;
133 [[nodiscard]] auto size() const ->
size_t;
135 [[nodiscard]] auto span() const -> std::span<
size_t const>;
137 [[nodiscard]] auto hash() const ->
size_t;
145 CLINGO_IGNORE_ZERO_SIZED_ARRAY_B
147 CLINGO_IGNORE_ZERO_SIZED_ARRAY_E
159 : base_{global.size()}, mbr_{&mbr}, global_{std::move(global)}, name_{std::move(name)},
160 guard_{std::move(guard)}, type_{type} {}
174 auto const &get_cond);
182 [[nodiscard]] auto name() const ->
UTerm const &;
193 std::pmr::monotonic_buffer_resource *mbr_;
198 Symbol *atom_key_ =
nullptr;
224 friend auto operator<<(std::ostream &out,
MatchTheory const &m) -> std::ostream &;
230 std::vector<
Symbol> mutable eval_;
242 [[nodiscard]]
auto do_domain() const ->
bool override;
243 [[nodiscard]] auto do_single_pass() const ->
bool override;
244 [[nodiscard]] auto do_matcher(std::pmr::monotonic_buffer_resource &mbr,
MatcherType type,
245 std::vector<
bool> const &bound)
246 -> std::pair<
UMatcher, std::optional<
size_t>> override;
247 [[nodiscard]] auto do_score(std::vector<
bool> const &bound) const ->
double override;
248 void do_print(std::ostream &out) const override;
250 [[nodiscard]] auto do_copy() const ->
ULit override;
251 [[nodiscard]] auto do_hash() const ->
size_t override;
252 [[nodiscard]] auto do_equal_to(
Lit const &other) const ->
bool override;
253 [[nodiscard]] auto do_compare_to(
Lit const &other) const -> std::weak_ordering override;
255 size_t offset_ = invalid_offset;
263 : state_{&state}, tuple_{std::move(tuple)}, body_{std::move(body)} {}
266 [[nodiscard]]
auto do_body() const ->
ULitVec const & override;
267 [[nodiscard]] auto do_important() const ->
VariableSet override;
268 void do_init([[maybe_unused]]
size_t gen) override;
269 [[nodiscard]] auto do_report(
EvalContext const &ctx) ->
bool override;
271 [[nodiscard]] auto do_priority() const ->
size_t override;
272 void do_print_head(std::ostream &out) const override;
273 void do_print(std::ostream &out) const override;
289 [[nodiscard]]
auto do_domain() const ->
bool override;
290 [[nodiscard]] auto do_single_pass() const ->
bool override;
291 [[nodiscard]] auto do_matcher(std::pmr::monotonic_buffer_resource &mbr,
MatcherType type,
292 std::vector<
bool> const &bound)
293 -> std::pair<
UMatcher, std::optional<
size_t>> override;
294 [[nodiscard]] auto do_score(std::vector<
bool> const &bound) const ->
double override;
295 void do_print(std::ostream &out) const override;
297 [[nodiscard]] auto do_copy() const ->
ULit override;
298 [[nodiscard]] auto do_hash() const ->
size_t override;
299 [[nodiscard]] auto do_equal_to(
Lit const &other) const ->
bool override;
300 [[nodiscard]] auto do_compare_to(
Lit const &other) const -> std::weak_ordering override;
314 [[nodiscard]]
auto do_body() const ->
ULitVec const & override;
315 [[nodiscard]] auto do_important() const ->
VariableSet override;
316 void do_init([[maybe_unused]]
size_t gen) override;
317 [[nodiscard]] auto do_report(
EvalContext const &ctx) ->
bool override;
319 [[nodiscard]] auto do_priority() const ->
size_t override;
320 void do_print_head(std::ostream &out) const override;
321 void do_print(std::ostream &out) const override;
Extensible ground representation for theory atoms.
Definition theory_atom.hh:45
auto elems() const -> std::span< size_t const >
Get the theory atom's elements.
auto name() const -> Symbol
Get the name of the atom.
Definition theory_atom.hh:61
auto rhs() const -> std::optional< size_t >
Get the right hand side theory term index.
Definition theory_atom.hh:64
AtomTheory(Symbol name, std::optional< size_t > rhs)
Default construct the atom with an empty set of elements.
Definition theory_atom.hh:48
void add_elem(size_t idx)
Add a new element.
auto uid() const -> std::optional< size_t >
Get the unique id of the theory atom.
The base implementation of an atom base.
Definition base.hh:148
auto contains(Key const &sym, MatcherType type) const -> std::optional< size_t >
Check if the base contains the given atom with in the given generation.
Definition base.hh:160
The base capturing theory atoms encountered during grounding.
Definition theory_atom.hh:79
auto nth(size_t i) const -> AtomMap::const_iterator
Get the i-th atom in the base.
auto add(Symbol const *sym, Symbol name, std::optional< size_t > rhs) -> std::pair< AtomMap::iterator, bool >
Add an atom.
Util::ordered_map< Symbol const *, AtomTheory, Util::array_hash, Util::array_equal_to > AtomMap
Map containing the atoms.
Definition theory_atom.hh:83
auto atoms() -> AtomMap &
Get the underlying atom map.
auto size() const -> size_t
Get the number of derived atoms.
BaseTheory(size_t size)
Construct an empty base.
Definition theory_atom.hh:86
auto index(Symbol const *sym) const -> size_t
Get the atom index of the given symbol.
Context object to capture state used during instantiation.
Definition instantiator.hh:35
Literal to match a theory atom.
Definition theory_atom.hh:282
LitBdTheory(StateTheory &state, Sign sign)
Construct the matcher.
Definition theory_atom.hh:285
Literal to match a theory atom.
Definition theory_atom.hh:235
LitMatchTheory(StateTheory &state)
Construct the matcher.
Definition theory_atom.hh:238
The base class for groundable literals.
Definition literal.hh:34
A term like object used to match theory atoms.
Definition theory_atom.hh:203
MatchTheory(StateTheory &state)
Construct the matcher.
Definition theory_atom.hh:209
auto vars() const -> VariableSet
Get the variables of the matcher.
Symbol const * Key
The key to match against.
Definition theory_atom.hh:206
A queue to process instantiators.
Definition instantiator.hh:206
Keys for aggregate elements storing their tuple and their aggregate index.
Definition theory_atom.hh:116
static void construct(std::pmr::monotonic_buffer_resource &mbr, EvalContext const &ctx, OutputTheory &out, size_t atom_idx, UTheoryTermVec const &terms, ElementKey *&target)
Construct an element key evaluating the given tuple.
ElementKey(ElementKey const &other)=delete
Prevent copying and moving.
ElementKey(priv_tag tag, EvalContext const &ctx, OutputTheory &out, size_t atom_idx, UTheoryTermVec const &terms)
Constructor.
auto terms() const -> UTheoryTermVec const &
Get the terms.
State storing all necessary information to ground theory atoms.
Definition theory_atom.hh:111
auto find_atom(Assignment &ass) -> AtomMap::iterator
Find a previously grounded theory atom.
Util::ordered_map< ElementKey *, Util::small_vector< size_t > > ElementMap
Map capturing the elements of theory atoms.
Definition theory_atom.hh:154
void insert_elem(EvalContext const &ctx, AtomMap::iterator it, UTheoryTermVec const &tuple, ElementKey *&elem_key, auto const &get_cond)
Insert a theory atom element.
BaseTheory::AtomMap AtomMap
Map containing the atoms.
Definition theory_atom.hh:152
auto global() const -> VariableVec const &
Get the global variables of the theory atom.
auto insert_atom(Symbol name, std::optional< size_t > rhs, Assignment &ass) -> std::pair< AtomMap::iterator, bool >
Insert a theory atom.
void print(std::ostream &out)
Print a debug representation of the theory atom.
void output(Logger &log, SymbolStore &store, OutputStm &out) override
Output all previously output theory atoms.
Class to store state for grounding.
Definition base.hh:438
Ground a rule with a theory atom in the head.
Definition theory_atom.hh:308
StmHdTheory(StateTheory &state, ULitVec body)
Construct the statement.
Definition theory_atom.hh:311
Gather theory atom elements.
Definition theory_atom.hh:259
StmTheoryElement(StateTheory &state, UTheoryTermVec tuple, ULitVec body)
Construct the statement.
Definition theory_atom.hh:262
Base class for groundable statements.
Definition statement.hh:17
Simple logger to report message to stderr or via a callback.
Definition logger.hh:63
Interface to output literals.
Definition output.hh:61
Interface to output statements.
Definition output.hh:90
Interface to output literals.
Definition output.hh:20
A store for symbols.
Definition symbol.hh:454
Variant-like class to store symbols stored in a symbol store.
Definition symbol.hh:225
A vector that misuses the begin, end and capacity pointers to store elements.
Definition small_vector.hh:26
std::vector< std::optional< Symbol > > Assignment
Assignment mapping variables to symbols.
Definition symbol.hh:222
Sign
Enumeration of signs (default negation).
Definition core.hh:16
VariableSet::values_container_type VariableVec
A vector of variables.
Definition base.hh:21
Util::ordered_set< size_t > VariableSet
A set of variables.
Definition base.hh:19
MatcherType
Enumeration of matcher types.
Definition instantiator.hh:48
std::unique_ptr< Matcher > UMatcher
A unique pointer to a matcher.
Definition instantiator.hh:100
std::unique_ptr< Lit > ULit
A unique pointer holding a literal.
Definition literal.hh:29
VarSelectMode
Available variable selection modes.
Definition literal.hh:21
std::vector< ULit > ULitVec
A vector of literals.
Definition literal.hh:31
std::vector< UStm > UStmVec
A vector of statements.
Definition statement.hh:44
std::unique_ptr< Term > UTerm
A unique pointer holding a term.
Definition term.hh:33
std::vector< UTheoryTerm > UTheoryTermVec
A vector of theory terms.
Definition theory_term.hh:15
std::optional< std::pair< String, UTheoryTerm > > TheoryRGuard
The right-hand-side of a theory atom.
Definition theory_atom.hh:42
tsl::ordered_map< Key, T, Hash, KeyEqual, Allocator, ValueTypeContainer, IndexType > ordered_map
Alias for ordered maps.
Definition ordered_map.hh:16