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);
99 auto fact_lit() -> std::optional<prg_lit_t> {
return do_fact_lit(); }
110 assert(std::ranges::all_of(head, [](
auto const &x) {
return x > 0; }));
111 do_bd_aggr(head, body, bound, choice);
122 assert(std::ranges::all_of(head, [](
auto const &x) {
return x > 0; }));
123 do_rule(head, body, choice);
172 do_heuristic(atom, weight, prio, type, body);
182 do_external(atom, type);
191 assert(std::ranges::all_of(atoms, [](
auto const &x) {
return x > 0; }));
207 virtual void do_preamble(
unsigned major,
unsigned minor,
unsigned revision,
bool incremental) = 0;
208 virtual void do_begin_step() = 0;
209 virtual void do_end_ground() = 0;
210 virtual void do_end_step() = 0;
211 virtual auto do_next_lit() ->
prg_lit_t = 0;
212 virtual auto do_fact_lit() -> std::optional<prg_lit_t> = 0;
224 virtual void do_project(
PrgLitSpan atoms) = 0;
225 virtual void do_assume(
PrgLitSpan literals) = 0;
286 std::optional<std::pair<prg_id_t, prg_id_t>> guard) {
287 assert(atom_or_zero >= 0);
288 do_atom(atom_or_zero, name, elems, guard);
293 virtual void do_str(
prg_id_t id, std::string_view
str) = 0;
298 std::optional<std::pair<prg_id_t, prg_id_t>> guard) = 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:99
void assume(PrgLitSpan literals)
Assume the given literals.
Definition backend.hh:198
void minimize(prg_weight_t priority, WeightedPrgLitSpan body)
Minimize the given weighted literals.
Definition backend.hh:204
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:144
void show_atom(Symbol sym, prg_lit_t lit)
Show the atom with the given symbol and program literal.
Definition backend.hh:152
void rule(PrgLitSpan head, PrgLitSpan body, bool choice)
Add a disjunctive or choice rule.
Definition backend.hh:121
void bd_aggr(PrgLitSpan head, WeightedPrgLitSpan body, int32_t bound, bool choice)
Define a weight constraint.
Definition backend.hh:109
void show_term(Symbol sym, prg_id_t id)
Associate the given symbol with an id.
Definition backend.hh:138
void begin_step()
Start a new step.
Definition backend.hh:74
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:94
void edge(prg_id_t u, prg_id_t v, PrgLitSpan body)
Add an edge for acyclicity checking.
Definition backend.hh:159
void show_term(Symbol sym, PrgLitSpan body)
Show the given symbol if the given condition is true.
Definition backend.hh:130
void external(prg_lit_t atom, ExternalType type)
Declare the given atom as external.
Definition backend.hh:180
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:170
void end_ground()
Finalize the current grounding step.
Definition backend.hh:79
void project(PrgLitSpan atoms)
Project the given atoms.
Definition backend.hh:190
void end_step()
Finalize the current step.
Definition backend.hh:87
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:232
void str(prg_id_t id, std::string_view str)
Add a theory string.
Definition backend.hh:250
void fun(prg_id_t id, prg_id_t name, PrgIdSpan args)
Add a theory function.
Definition backend.hh:259
void tup(prg_id_t id, TheoryTermTupleType type, PrgIdSpan args)
Add a theory tuple.
Definition backend.hh:268
void elem(prg_id_t id, PrgIdSpan terms, PrgLitSpan cond)
Add a theory element.
Definition backend.hh:277
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:285
void num(prg_id_t id, prg_weight_t num)
Add a theory number.
Definition backend.hh:243
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:301
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:229
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