3#include <clingo/core.hh>
4#include <clingo/symbol.hh>
6#include <clingo/backend.h>
31 return Detail::call<clingo_backend_theory_term_number>(backend_.get(),
number);
41 return Detail::call<clingo_backend_theory_term_string>(backend_.get(),
string.data(),
string.size());
49 return Detail::call<clingo_backend_theory_term_symbol>(backend_.get(), c_cast(
symbol));
58 return Detail::call<clingo_backend_theory_term_sequence>(
68 return Detail::call<clingo_backend_theory_term_function>(backend_.get(), name.data(), name.size(),
69 elements.data(), elements.size());
78 return Detail::call<clingo_backend_theory_element>(backend_.get(),
tuple.data(),
tuple.size(), condition.data(),
97 std::optional<std::pair<std::string_view, ProgramId>>
const &guard = std::nullopt)
const
99 auto op =
clingo_string_t{guard ? guard->first.data() :
nullptr, guard ? guard->first.size() : 0};
100 return Detail::call<clingo_backend_theory_atom>(backend_.get(), c_cast(name), elements.data(), elements.size(),
106 friend class ProgramBackend;
112 assert(std::uncaught_exceptions() == 0);
115 if (std::uncaught_exceptions() == 0) {
123 ~TheoryBackend() =
default;
125 std::unique_ptr<clingo_backend_t, Free> backend_;
155 return Detail::call<clingo_backend_add_atom>(backend_.get(),
symbol ? c_cast(&
symbol.value()) :
nullptr);
164 Detail::handle_error(
165 clingo_backend_rule(backend_.get(), choice, head.data(), head.size(), body.data(), body.size()));
176 body.data(), body.size()));
219 bias, priority, condition.data(), condition.size()));
228 Detail::handle_error(
Program backend to add atoms and statements.
Definition backend.hh:132
auto atom(std::optional< Symbol > symbol) const -> ProgramAtom
Create a fresh program atom.
Definition backend.hh:154
void rule(ProgramAtomSpan head, ProgramLiteralSpan body={}, bool choice=false) const
Add a choice or disjunctive ground rule.
Definition backend.hh:163
void project(ProgramAtomSpan atoms) const
Add a project directive to the program.
Definition backend.hh:190
void edge(int node_u, int node_v, ProgramLiteralSpan condition) const
Add an edge directive.
Definition backend.hh:227
void heuristic(ProgramAtom atom, HeuristicType type, int bias, unsigned priority=0, ProgramLiteralSpan condition={}) const
Add a heuristic directive to the program.
Definition backend.hh:216
void weight_rule(ProgramAtomSpan head, Weight lower, WeightedLiteralSpan body, bool choice=false) const
Add a ground weight rule to the program.
Definition backend.hh:174
void close()
Finalize the backend.
Definition backend.hh:145
void external(ProgramAtom atom, ExternalType type) const
Add an external directive to the program.
Definition backend.hh:198
void assume(ProgramLiteralSpan literals) const
Add assumptions to the program.
Definition backend.hh:205
auto theory() const -> TheoryBackend const &
Get the associated theory backend.
Definition backend.hh:235
ProgramBackend(clingo_backend_t *backend)
Create a program atom from its C representation.
Definition backend.hh:139
void minimize(WeightedLiteralSpan literals, Weight priority=0) const
Add a minimize constraint to the program.
Definition backend.hh:183
Class modeling a symbol in Clingo.
Definition symbol.hh:68
Theory backend to build theory atoms.
Definition backend.hh:24
auto element(ProgramIdSpan tuple, ProgramLiteralSpan condition) const -> ProgramId
Add a theory element.
Definition backend.hh:77
auto atom(std::optional< ProgramAtom > atom, Symbol const &name, ProgramIdSpan elements={}, std::optional< std::pair< std::string_view, ProgramId > > const &guard=std::nullopt) const -> ProgramAtom
Add a theory atom.
Definition backend.hh:96
auto function(std::string_view name, ProgramIdSpan elements) const -> ProgramId
Add a theory function.
Definition backend.hh:67
auto number(int number) const -> ProgramId
Add a numeric theory term.
Definition backend.hh:30
auto sequence(TheorySequenceType type, ProgramIdSpan elements) const -> ProgramId
Add a theory term sequence.
Definition backend.hh:57
auto string(std::string_view string) const -> ProgramId
Add a string theory term.
Definition backend.hh:40
auto symbol(Symbol const &symbol) const -> ProgramId
Convert the given symbol into a theory term.
Definition backend.hh:48
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_project(clingo_backend_t *backend, clingo_atom_t const *atoms, size_t size)
Add a projection directive.
struct clingo_backend clingo_backend_t
Handle to the backend to add directives in aspif format.
Definition backend.h:47
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_assume(clingo_backend_t *backend, clingo_literal_t const *literals, size_t size)
Add an assumption directive.
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_rule(clingo_backend_t *backend, bool choice, clingo_atom_t const *head, size_t head_size, clingo_literal_t const *body, size_t body_size)
Add a rule to the program.
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_heuristic(clingo_backend_t *backend, clingo_atom_t atom, clingo_heuristic_type_t type, int bias, unsigned priority, clingo_literal_t const *condition, size_t size)
Add a heuristic directive.
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_weight_rule(clingo_backend_t *backend, bool choice, clingo_atom_t const *head, size_t head_size, clingo_weight_t lower_bound, clingo_weighted_literal_t const *body, size_t body_size)
Add a weight rule to the program.
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_minimize(clingo_backend_t *backend, clingo_weight_t priority, clingo_weighted_literal_t const *literals, size_t size)
Add a minimize constraint (or weak constraint) to the program.
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_acyc_edge(clingo_backend_t *backend, int node_u, int node_v, clingo_literal_t const *condition, size_t size)
Add an edge directive.
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_close(clingo_backend_t *backend)
Finalize the backend after using it.
int clingo_theory_sequence_type_t
Corresponding type to clingo_theory_sequence_type_e.
Definition backend.h:44
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_external(clingo_backend_t *backend, clingo_atom_t atom, clingo_external_type_t type)
Add an external statement.
@ clingo_theory_sequence_type_list
Theory lists "[t1,...,tn]".
Definition backend.h:41
@ clingo_theory_sequence_type_tuple
Theory tuples "(t1,...,tn)".
Definition backend.h:39
@ clingo_theory_sequence_type_set
Theory sets "{t1,...,tn}".
Definition backend.h:40
int clingo_external_type_t
Corresponding type to clingo_external_type_e.
Definition shared.h:32
int clingo_heuristic_type_t
Corresponding type to clingo_heuristic_type_e.
Definition shared.h:22
TheorySequenceType
Enumeration of available theory sequence types.
Definition backend.hh:17
@ tuple
Theory tuples "(t1,...,tn)".
@ list
Theory lists "[t1,...,tn]".
@ set
Theory sets "{t1,...,tn}".
@ symbol
a symbol term, e.g., c
@ number
a number term, e.g., 42
clingo_atom_t ProgramAtom
A program atom.
Definition core.hh:387
std::span< ProgramId const > ProgramIdSpan
A span of program ids.
Definition core.hh:384
HeuristicType
Enumeration of heuristic types.
Definition core.hh:560
std::span< ProgramAtom const > ProgramAtomSpan
A span of program atoms.
Definition core.hh:389
clingo_weight_t Weight
A weight used in sum aggregates and minimize constraints.
Definition core.hh:408
std::span< WeightedLiteral const > WeightedLiteralSpan
A span of weighted literals.
Definition core.hh:415
clingo_id_t ProgramId
A program id used for various kinds of indices.
Definition core.hh:382
std::span< ProgramLiteral const > ProgramLiteralSpan
A span of program literals.
Definition core.hh:394
ExternalType
Enumeration of control modes.
Definition core.hh:552
Struct to capture strings that are not null-terminated.
Definition core.h:91