3#include <clingo/ground/literal.hh>
5#include <clingo/ground/instantiator.hh>
7#include <clingo/core/core.hh>
9#include <memory_resource>
11namespace CppClingo::Ground {
20 [[nodiscard]]
auto body() const ->
ULitVec const & {
return do_body(); }
31 friend auto operator<<(std::ostream &out,
Stm const &stm) -> std::ostream & {
37 virtual void do_print(std::ostream &out)
const = 0;
38 [[nodiscard]]
virtual auto do_body() const ->
ULitVec const & = 0;
39 [[nodiscard]] virtual auto do_important() const ->
VariableSet = 0;
51 Linearizer(std::pmr::monotonic_buffer_resource &mbr) : mbr_{&mbr} {}
59 void build_(
ULitVec const &lits);
62 ULitVec const &lits) -> std::pair<Instantiator, std::optional<size_t>>;
64 Queue *iqueue_ =
nullptr;
65 std::pmr::monotonic_buffer_resource *mbr_;
66 std::vector<size_t> rec_;
67 std::vector<std::vector<MatcherType>> todos_;
68 std::vector<std::tuple<size_t, size_t, double>> queue_;
70 std::vector<std::tuple<size_t, std::vector<size_t>, std::vector<size_t>>> lit_map_;
72 std::vector<std::vector<size_t>> var_map_;
86 : head_{head ? std::move(std::get<0>(*head)) : nullptr}, node_{node},
87 base_{head ? &std::get<1>(*head) : nullptr},
88 indices_{head ? std::move(std::get<2>(*head)) : std::vector<size_t>{}}, body_{std::move(
body)}, type_{type} {
96 void do_print(std::ostream &out)
const override;
97 [[nodiscard]]
auto do_body() const ->
ULitVec const & override;
98 [[nodiscard]] auto do_important() const ->
VariableSet override;
101 void do_print_head(std::ostream &out) const override;
102 void do_init(
size_t gen) override;
103 [[nodiscard]] auto do_report(EvalContext const &ctx) ->
bool override;
104 void do_propagate(SymbolStore &store, OutputStm &out, Queue &queue) override;
105 [[nodiscard]] auto do_priority() const ->
size_t override {
return std::numeric_limits<size_t>::max(); }
106 [[nodiscard]]
auto do_profile_node() const -> ProfileNodeInternal *
override {
return node_; }
112 ProfileNodeInternal *node_ =
nullptr;
118 std::vector<size_t> indices_;
130 : type_{std::move(type)}, atom_{std::move(atom)}, base_{&base}, indices_{std::move(indices)},
131 body_{std::move(
body)}, node_{node} {
139 void do_print(std::ostream &out)
const override;
140 [[nodiscard]]
auto do_body() const ->
ULitVec const & override;
141 [[nodiscard]] auto do_important() const ->
VariableSet override;
144 void do_print_head(std::ostream &out) const override;
145 void do_init(
size_t gen) override;
146 [[nodiscard]] auto do_report(
EvalContext const &ctx) ->
bool override;
148 [[nodiscard]] auto do_priority() const ->
size_t override {
return std::numeric_limits<size_t>::max(); }
149 [[nodiscard]]
auto do_is_important([[maybe_unused]]
size_t index)
const ->
bool override {
return false; }
150 [[nodiscard]]
auto do_profile_node() const -> ProfileNodeInternal *
override {
return node_; }
152 std::optional<std::pair<Location, UTerm>> type_;
162 std::vector<size_t> indices_;
165 ProfileNodeInternal *node_;
175 : loc_weight_{std::move(loc_weight)}, loc_prio_{prio ? std::move(prio->first) : loc_weight_},
176 weight_{std::move(weight)}, prio_{prio ? std::move(prio->second) : nullptr}, terms_{std::move(terms)},
177 body_{std::move(
body)}, node_{node} {
184 void do_print(std::ostream &out)
const override;
185 [[nodiscard]]
auto do_body() const ->
ULitVec const & override;
186 [[nodiscard]] auto do_important() const ->
VariableSet override;
189 void do_print_head(std::ostream &out) const override;
190 void do_init(
size_t gen) override;
191 [[nodiscard]] auto do_report(
EvalContext const &ctx) ->
bool override;
193 [[nodiscard]] auto do_priority() const ->
size_t override {
return std::numeric_limits<size_t>::max(); }
194 [[nodiscard]]
auto do_profile_node() const -> ProfileNodeInternal *
override {
return node_; }
196 Location loc_weight_;
203 std::optional<Symbol> res_prio_;
205 ProfileNodeInternal *node_;
213 std::optional<std::pair<Location, UTerm>> prio,
Location loc_type,
UTerm type,
215 : loc_weight_{std::move(loc_weight)}, loc_prio_{prio ? std::move(prio->first) : loc_weight_},
216 loc_type_{std::move(loc_type)}, atom_{std::move(atom)}, base_{&base}, weight_{std::move(weight)},
217 prio_{prio ? std::move(prio->second) : nullptr}, type_{std::move(type)}, body_{std::move(
body)}, node_{node} {
224 void do_print(std::ostream &out)
const override;
225 [[nodiscard]]
auto do_body() const ->
ULitVec const & override;
226 [[nodiscard]] auto do_important() const ->
VariableSet override;
229 void do_print_head(std::ostream &out) const override;
230 void do_init(
size_t gen) override;
231 [[nodiscard]] auto do_report(
EvalContext const &ctx) ->
bool override;
233 [[nodiscard]] auto do_priority() const ->
size_t override {
return std::numeric_limits<size_t>::max(); }
234 [[nodiscard]]
auto do_profile_node() const -> ProfileNodeInternal *
override {
return node_; }
236 Location loc_weight_;
245 ProfileNodeInternal *node_;
257 : src_{std::move(src)}, dst_{std::move(dst)}, body_{std::move(
body)}, node_{node} {
264 void do_print(std::ostream &out)
const override;
265 [[nodiscard]]
auto do_body() const ->
ULitVec const & override;
266 [[nodiscard]] auto do_important() const ->
VariableSet override;
269 void do_print_head(std::ostream &out) const override;
270 void do_init(
size_t gen) override;
271 [[nodiscard]] auto do_report(
EvalContext const &ctx) ->
bool override;
273 [[nodiscard]] auto do_priority() const ->
size_t override {
return std::numeric_limits<size_t>::max(); }
274 [[nodiscard]]
auto do_profile_node() const -> ProfileNodeInternal *
override {
return node_; }
279 ProfileNodeInternal *node_;
289 : term_{std::move(term)}, body_{std::move(
body)}, node_{node} {
296 void do_print(std::ostream &out)
const override;
297 [[nodiscard]]
auto do_body() const ->
ULitVec const & override;
298 [[nodiscard]] auto do_important() const ->
VariableSet override;
301 void do_print_head(std::ostream &out) const override;
302 void do_init(
size_t gen) override;
303 [[nodiscard]] auto do_report(
EvalContext const &ctx) ->
bool override;
305 [[nodiscard]] auto do_priority() const ->
size_t override {
return std::numeric_limits<size_t>::max(); }
306 [[nodiscard]]
auto do_profile_node() const -> ProfileNodeInternal *
override {
return node_; }
310 ProfileNodeInternal *node_;
319 : atom_{std::move(atom)}, base_{&base}, body_{std::move(
body)}, node_{node} {
326 void do_print(std::ostream &out)
const override;
327 [[nodiscard]]
auto do_body() const ->
ULitVec const & override;
328 [[nodiscard]] auto do_important() const ->
VariableSet override;
331 void do_print_head(std::ostream &out) const override;
332 void do_init(
size_t gen) override;
333 [[nodiscard]] auto do_report(
EvalContext const &ctx) ->
bool override;
335 [[nodiscard]] auto do_priority() const ->
size_t override {
return std::numeric_limits<size_t>::max(); }
336 [[nodiscard]]
auto do_is_important([[maybe_unused]]
size_t index)
const ->
bool override {
return false; }
337 [[nodiscard]]
auto do_profile_node() const -> ProfileNodeInternal *
override {
return node_; }
342 ProfileNodeInternal *node_;
An atom base used to store derivable atoms and associated state.
Definition base.hh:212
Context object to capture state used during instantiation.
Definition instantiator.hh:39
Callbacks to notify statements during instantiations.
Definition instantiator.hh:111
Helper class to prepare statements for grounding.
Definition statement.hh:48
void start(Queue &queue)
Indicate that a new domain is being prepared.
void prepare(InstanceCallback &cb, ULitVec const &body, VariableSet important)
Prepare a statement for grounding.
Linearizer(std::pmr::monotonic_buffer_resource &mbr)
Construct the linearizer.
Definition statement.hh:51
Profile node that can hold children.
Definition profile.hh:155
A queue to process instantiators.
Definition instantiator.hh:222
A statement edge directives.
Definition statement.hh:253
StmEdge(UTerm src, UTerm dst, ULitVec body, ProfileNodeInternal *node)
Construct the statement.
Definition statement.hh:256
A statement capturing normal rules and integrity constraints.
Definition statement.hh:125
StmExternal(Ground::UTerm atom, AtomBase &base, std::vector< size_t > indices, ULitVec body, std::optional< std::pair< Location, UTerm > > type, ProfileNodeInternal *node)
Construct the statement.
Definition statement.hh:128
Statement capturing heuristic directives.
Definition statement.hh:209
StmHeuristic(UTerm atom, AtomBase &base, ULitVec body, Location loc_weight, UTerm weight, std::optional< std::pair< Location, UTerm > > prio, Location loc_type, UTerm type, ProfileNodeInternal *node)
Construct the statement.
Definition statement.hh:212
Statement capturing project directives.
Definition statement.hh:315
StmProject(UTerm atom, AtomBase &base, ULitVec body, ProfileNodeInternal *node)
Construct the statement.
Definition statement.hh:318
A statement capturing normal rules and integrity constraints.
Definition statement.hh:82
StmRule(AtomSimple head, ULitVec body, RuleType type, ProfileNodeInternal *node)
Construct the statement.
Definition statement.hh:85
A statement for show directives.
Definition statement.hh:285
StmShow(UTerm term, ULitVec body, ProfileNodeInternal *node)
Construct the statement.
Definition statement.hh:288
A statement capturing weak constraints.
Definition statement.hh:170
StmWeakConstraint(Location loc_weight, UTerm weight, std::optional< std::pair< Location, UTerm > > prio, UTermVec terms, ULitVec body, ProfileNodeInternal *node)
Construct the statement.
Definition statement.hh:173
Base class for groundable statements.
Definition statement.hh:17
auto important() const -> VariableSet
Get the important variables in the statement.
Definition statement.hh:28
friend auto operator<<(std::ostream &out, Stm const &stm) -> std::ostream &
Print the statement.
Definition statement.hh:31
auto body() const -> ULitVec const &
Get the body of the statement.
Definition statement.hh:20
The Location of an expression in an input source.
Definition location.hh:44
Interface to output statements.
Definition output.hh:90
A store for symbols.
Definition symbol.hh:454
static auto sup() noexcept -> Symbol
Construct the infimum constant (#inf).
std::vector< Symbol > SymbolVec
A vector of symbols.
Definition symbol.hh:220
HeuristicType
Available heuristic types.
Definition core.hh:172
ExternalType
Available external types.
Definition core.hh:177
Util::ordered_set< size_t > VariableSet
A set of variables.
Definition base.hh:19
std::optional< std::tuple< Ground::UTerm, AtomBase &, std::vector< size_t > > > AtomSimple
Represents a simple head literal which is either represented by a symbol term or #false captured by s...
Definition literal.hh:231
std::vector< ULit > ULitVec
A vector of literals.
Definition literal.hh:31
std::vector< UStm > UStmVec
A vector of statements.
Definition statement.hh:45
std::unique_ptr< Stm > UStm
A unique pointer holding a statement.
Definition statement.hh:43
RuleType
Enumeration of available rule types.
Definition statement.hh:76
std::unique_ptr< Term > UTerm
A unique pointer holding a term.
Definition term.hh:34
std::vector< UTerm > UTermVec
A vector of terms.
Definition term.hh:36