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;
52 : mbr_{&mbr}, fun_{fun}, sel_{sel} {}
60 void build_(
ULitVec const &lits);
63 ULitVec const &lits) -> std::pair<Instantiator, std::optional<size_t>>;
65 Queue *iqueue_ =
nullptr;
66 std::pmr::monotonic_buffer_resource *mbr_;
67 std::vector<size_t> rec_;
68 std::vector<std::vector<MatcherType>> todos_;
69 std::vector<std::tuple<size_t, size_t, double>> queue_;
71 std::vector<std::tuple<size_t, std::vector<size_t>, std::vector<size_t>>> lit_map_;
73 std::vector<std::vector<size_t>> var_map_;
89 : head_{head ? std::move(std::get<0>(*head)) : nullptr}, node_{node},
90 base_{head ? &std::get<1>(*head) : nullptr},
91 indices_{head ? std::move(std::get<2>(*head)) : std::vector<size_t>{}}, body_{std::move(
body)}, type_{type} {
99 void do_print(std::ostream &out)
const override;
100 [[nodiscard]]
auto do_body() const ->
ULitVec const & override;
101 [[nodiscard]] auto do_important() const ->
VariableSet override;
104 void do_print_head(std::ostream &out) const override;
105 void do_init(
size_t gen) override;
106 [[nodiscard]] auto do_report(EvalContext const &ctx) ->
bool override;
107 void do_propagate(SymbolStore &store, OutputStm &out, Queue &queue) override;
108 [[nodiscard]] auto do_priority() const ->
size_t override {
return std::numeric_limits<size_t>::max(); }
109 [[nodiscard]]
auto do_profile_node() const -> ProfileNodeInternal *
override {
return node_; }
115 ProfileNodeInternal *node_ =
nullptr;
121 std::vector<size_t> indices_;
133 : type_{std::move(type)}, atom_{std::move(atom)}, base_{&base}, indices_{std::move(indices)},
134 body_{std::move(
body)}, node_{node} {
142 void do_print(std::ostream &out)
const override;
143 [[nodiscard]]
auto do_body() const ->
ULitVec const & override;
144 [[nodiscard]] auto do_important() const ->
VariableSet override;
147 void do_print_head(std::ostream &out) const override;
148 void do_init(
size_t gen) override;
149 [[nodiscard]] auto do_report(
EvalContext const &ctx) ->
bool override;
151 [[nodiscard]] auto do_priority() const ->
size_t override {
return std::numeric_limits<size_t>::max(); }
152 [[nodiscard]]
auto do_is_important([[maybe_unused]]
size_t index)
const ->
bool override {
return false; }
153 [[nodiscard]]
auto do_profile_node() const -> ProfileNodeInternal *
override {
return node_; }
155 std::optional<std::pair<Location, UTerm>> type_;
165 std::vector<size_t> indices_;
168 ProfileNodeInternal *node_;
178 : loc_weight_{std::move(loc_weight)}, loc_prio_{prio ? std::move(prio->first) : loc_weight_},
179 weight_{std::move(weight)}, prio_{prio ? std::move(prio->second) : nullptr}, terms_{std::move(terms)},
180 body_{std::move(
body)}, node_{node} {
187 void do_print(std::ostream &out)
const override;
188 [[nodiscard]]
auto do_body() const ->
ULitVec const & override;
189 [[nodiscard]] auto do_important() const ->
VariableSet override;
192 void do_print_head(std::ostream &out) const override;
193 void do_init(
size_t gen) override;
194 [[nodiscard]] auto do_report(
EvalContext const &ctx) ->
bool override;
196 [[nodiscard]] auto do_priority() const ->
size_t override {
return std::numeric_limits<size_t>::max(); }
197 [[nodiscard]]
auto do_profile_node() const -> ProfileNodeInternal *
override {
return node_; }
199 Location loc_weight_;
206 std::optional<Symbol> res_prio_;
208 ProfileNodeInternal *node_;
216 std::optional<std::pair<Location, UTerm>> prio,
Location loc_type,
UTerm type,
218 : loc_weight_{std::move(loc_weight)}, loc_prio_{prio ? std::move(prio->first) : loc_weight_},
219 loc_type_{std::move(loc_type)}, atom_{std::move(atom)}, base_{&base}, weight_{std::move(weight)},
220 prio_{prio ? std::move(prio->second) : nullptr}, type_{std::move(type)}, body_{std::move(
body)}, node_{node} {
227 void do_print(std::ostream &out)
const override;
228 [[nodiscard]]
auto do_body() const ->
ULitVec const & override;
229 [[nodiscard]] auto do_important() const ->
VariableSet override;
232 void do_print_head(std::ostream &out) const override;
233 void do_init(
size_t gen) override;
234 [[nodiscard]] auto do_report(
EvalContext const &ctx) ->
bool override;
236 [[nodiscard]] auto do_priority() const ->
size_t override {
return std::numeric_limits<size_t>::max(); }
237 [[nodiscard]]
auto do_profile_node() const -> ProfileNodeInternal *
override {
return node_; }
239 Location loc_weight_;
248 ProfileNodeInternal *node_;
260 : src_{std::move(src)}, dst_{std::move(dst)}, body_{std::move(
body)}, node_{node} {
267 void do_print(std::ostream &out)
const override;
268 [[nodiscard]]
auto do_body() const ->
ULitVec const & override;
269 [[nodiscard]] auto do_important() const ->
VariableSet override;
272 void do_print_head(std::ostream &out) const override;
273 void do_init(
size_t gen) override;
274 [[nodiscard]] auto do_report(
EvalContext const &ctx) ->
bool override;
276 [[nodiscard]] auto do_priority() const ->
size_t override {
return std::numeric_limits<size_t>::max(); }
277 [[nodiscard]]
auto do_profile_node() const -> ProfileNodeInternal *
override {
return node_; }
282 ProfileNodeInternal *node_;
292 : term_{std::move(term)}, body_{std::move(
body)}, node_{node} {
299 void do_print(std::ostream &out)
const override;
300 [[nodiscard]]
auto do_body() const ->
ULitVec const & override;
301 [[nodiscard]] auto do_important() const ->
VariableSet override;
304 void do_print_head(std::ostream &out) const override;
305 void do_init(
size_t gen) override;
306 [[nodiscard]] auto do_report(
EvalContext const &ctx) ->
bool override;
308 [[nodiscard]] auto do_priority() const ->
size_t override {
return std::numeric_limits<size_t>::max(); }
309 [[nodiscard]]
auto do_profile_node() const -> ProfileNodeInternal *
override {
return node_; }
313 ProfileNodeInternal *node_;
322 : atom_{std::move(atom)}, base_{&base}, body_{std::move(
body)}, node_{node} {
329 void do_print(std::ostream &out)
const override;
330 [[nodiscard]]
auto do_body() const ->
ULitVec const & override;
331 [[nodiscard]] auto do_important() const ->
VariableSet override;
334 void do_print_head(std::ostream &out) const override;
335 void do_init(
size_t gen) override;
336 [[nodiscard]] auto do_report(
EvalContext const &ctx) ->
bool override;
338 [[nodiscard]] auto do_priority() const ->
size_t override {
return std::numeric_limits<size_t>::max(); }
339 [[nodiscard]]
auto do_is_important([[maybe_unused]]
size_t index)
const ->
bool override {
return false; }
340 [[nodiscard]]
auto do_profile_node() const -> ProfileNodeInternal *
override {
return node_; }
345 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:41
Callbacks to notify statements during instantiations.
Definition instantiator.hh:113
Helper class to prepare statements for grounding.
Definition statement.hh:48
Linearizer(std::pmr::monotonic_buffer_resource &mbr, EstimateFunction fun, EstimateSelector sel)
Construct the linearizer.
Definition statement.hh:51
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.
Profile node that can hold children.
Definition profile.hh:156
A queue to process instantiators.
Definition instantiator.hh:225
A statement edge directives.
Definition statement.hh:256
StmEdge(UTerm src, UTerm dst, ULitVec body, ProfileNodeInternal *node)
Construct the statement.
Definition statement.hh:259
A statement capturing normal rules and integrity constraints.
Definition statement.hh:128
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:131
Statement capturing heuristic directives.
Definition statement.hh:212
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:215
Statement capturing project directives.
Definition statement.hh:318
StmProject(UTerm atom, AtomBase &base, ULitVec body, ProfileNodeInternal *node)
Construct the statement.
Definition statement.hh:321
A statement capturing normal rules and integrity constraints.
Definition statement.hh:85
StmRule(AtomSimple head, ULitVec body, RuleType type, ProfileNodeInternal *node)
Construct the statement.
Definition statement.hh:88
A statement for show directives.
Definition statement.hh:288
StmShow(UTerm term, ULitVec body, ProfileNodeInternal *node)
Construct the statement.
Definition statement.hh:291
A statement capturing weak constraints.
Definition statement.hh:173
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:176
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:82
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
EstimateSelector
Selector for which estimates to consider.
Definition core.hh:204
HeuristicType
Available heuristic types.
Definition core.hh:172
EstimateFunction
Function to combine domain size estimates.
Definition core.hh:197
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:250
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:79
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