3#include <clingo/core/core.hh>
4#include <clingo/core/symbol.hh>
6#include <clingo/util/small_vector.hh>
46static constexpr auto prg_lit_max = std::numeric_limits<prg_lit_t>::max();
48static constexpr auto prg_lit_min = -prg_lit_max;
65 void preamble(
unsigned major,
unsigned minor,
unsigned revision,
bool incremental) {
66 do_preamble(major, minor, revision, incremental);
70 void end() { do_end(); }
82 auto fact_lit() -> std::optional<prg_lit_t> {
return do_fact_lit(); }
93 assert(std::ranges::all_of(head, [](
auto const &x) {
return x > 0; }));
94 do_bd_aggr(head, body, bound, choice);
105 assert(std::ranges::all_of(head, [](
auto const &x) {
return x > 0; }));
106 do_rule(head, body, choice);
155 do_heuristic(atom, weight, prio, type, body);
165 do_external(atom, type);
174 assert(std::ranges::all_of(atoms, [](
auto const &x) {
return x > 0; }));
190 virtual void do_preamble(
unsigned major,
unsigned minor,
unsigned revision,
bool incremental) = 0;
191 virtual void do_end() = 0;
192 virtual auto do_next_lit() ->
prg_lit_t = 0;
193 virtual auto do_fact_lit() -> std::optional<prg_lit_t> = 0;
205 virtual void do_project(
PrgLitSpan atoms) = 0;
206 virtual void do_assume(
PrgLitSpan literals) = 0;
267 std::optional<std::pair<prg_id_t, prg_id_t>> guard) {
268 assert(atom_or_zero >= 0);
269 do_atom(atom_or_zero, name, elems, guard);
277 virtual void do_str(
prg_id_t id, std::string_view
str) = 0;
282 std::optional<std::pair<prg_id_t, prg_id_t>> guard) = 0;
283 virtual void do_end() = 0;
Abstract class connecting grounder and solver.
Definition backend.hh:54
auto fact_lit() -> std::optional< prg_lit_t >
Get a factual literal if one existis.
Definition backend.hh:82
void assume(PrgLitSpan literals)
Assume the given literals.
Definition backend.hh:181
void minimize(prg_weight_t priority, WeightedPrgLitSpan body)
Minimize the given weighted literals.
Definition backend.hh:187
void show_term(prg_id_t id, PrgLitSpan body)
Show the symbol with the given id if the given condition is true.
Definition backend.hh:127
void show_atom(Symbol sym, prg_lit_t lit)
Show the atom with the given symbol and program literal.
Definition backend.hh:135
void rule(PrgLitSpan head, PrgLitSpan body, bool choice)
Add a disjunctive or choice rule.
Definition backend.hh:104
void bd_aggr(PrgLitSpan head, WeightedPrgLitSpan body, int32_t bound, bool choice)
Define a weight constraint.
Definition backend.hh:92
void show_term(Symbol sym, prg_id_t id)
Associate the given symbol with an id.
Definition backend.hh:121
void preamble(unsigned major, unsigned minor, unsigned revision, bool incremental)
Initialize the backend.
Definition backend.hh:65
auto next_lit() -> prg_lit_t
Return a fresh (positive) literal.
Definition backend.hh:77
void edge(prg_id_t u, prg_id_t v, PrgLitSpan body)
Add an edge for acyclicity checking.
Definition backend.hh:142
void show_term(Symbol sym, PrgLitSpan body)
Show the given symbol if the given condition is true.
Definition backend.hh:113
void external(prg_lit_t atom, ExternalType type)
Declare the given atom as external.
Definition backend.hh:163
virtual ~ProgramBackend()=default
Destroy the backend.
void heuristic(prg_lit_t atom, int32_t weight, int32_t prio, HeuristicType type, PrgLitSpan body)
Add a heuristic directive.
Definition backend.hh:153
void project(PrgLitSpan atoms)
Project the given atoms.
Definition backend.hh:173
void end()
Finalize the current grounding step.
Definition backend.hh:70
Variant-like class to store symbols stored in a symbol store.
Definition symbol.hh:225
Abstract class connecting grounder and theory data.
Definition backend.hh:213
void str(prg_id_t id, std::string_view str)
Add a theory string.
Definition backend.hh:231
void end()
Finalize the theory.
Definition backend.hh:273
void fun(prg_id_t id, prg_id_t name, PrgIdSpan args)
Add a theory function.
Definition backend.hh:240
void tup(prg_id_t id, TheoryTermTupleType type, PrgIdSpan args)
Add a theory tuple.
Definition backend.hh:249
void elem(prg_id_t id, PrgIdSpan terms, PrgLitSpan cond)
Add a theory element.
Definition backend.hh:258
virtual ~TheoryBackend()=default
Destroy the backend.
void atom(prg_lit_t atom_or_zero, prg_id_t name, PrgIdSpan elems, std::optional< std::pair< prg_id_t, prg_id_t > > guard)
Add a theory atom.
Definition backend.hh:266
void num(prg_id_t id, prg_weight_t num)
Add a theory number.
Definition backend.hh:224
int32_t prg_lit_t
A program literal.
Definition backend.hh:27
std::make_signed_t< prg_id_t > prg_sid_t
An signed version of id_t.
Definition backend.hh:22
std::span< prg_lit_t const > PrgLitSpan
A span of program literals.
Definition backend.hh:37
int32_t prg_weight_t
A weight used in weight and minimize constraints.
Definition backend.hh:33
std::vector< std::pair< prg_lit_t, prg_weight_t > > WeightedPrgLitVec
A vector of program literals.
Definition backend.hh:43
int64_t prg_sum_t
Type to represent sums of weights.
Definition backend.hh:35
uint32_t prg_atom_t
A program atom.
Definition backend.hh:31
uint32_t prg_id_t
An id to refer to elements of a logic program.
Definition backend.hh:16
std::span< prg_id_t const > PrgIdSpan
A span of ids.
Definition backend.hh:18
std::unique_ptr< TheoryBackend > UTheoryBackend
A unique pointer for a theory backend.
Definition backend.hh:286
std::vector< prg_id_t > PrgIdVec
A vector of ids.
Definition backend.hh:20
std::vector< prg_lit_t > PrgLitVec
A vector of literals.
Definition backend.hh:39
std::unique_ptr< ProgramBackend > UProgramBackend
A unique pointer for a program backend.
Definition backend.hh:210
std::span< std::pair< prg_lit_t, prg_weight_t > const > WeightedPrgLitSpan
A span of program literals.
Definition backend.hh:41
TheoryTermTupleType
Enumeration of theory term tuple types.
Definition core.hh:165
HeuristicType
Available heuristic types.
Definition core.hh:172
ExternalType
Available external types.
Definition core.hh:177