3#include <clingo/app.hh>
4#include <clingo/ast.hh>
6#include <clingo/theory.h>
38 using value_type = std::pair<Symbol, std::variant<int, double, Symbol>>;
82 assignment_->theory_->
self, assignment_->thread_id_, &init_, &index_, &has_value_));
84 current_ = assignment_->
at(index_);
89 TheoryAssignment
const *assignment_ =
nullptr;
92 bool has_value_ =
true;
94 static_assert(std::input_iterator<iterator>);
95 static_assert(std::sentinel_for<sentinel, iterator>);
102 : theory_{
theory}, thread_id_{thread_id} {}
112 return found ? std::optional{index} : std::nullopt;
119 [[
nodiscard]]
auto at(
size_t index)
const -> std::pair<Symbol, std::variant<int, double, Symbol>> {
126 throw std::out_of_range{
"invalid index"};
128 switch (
value.type) {
130 return {std::move(sym),
value.int_number};
134 return {std::move(sym),
value.double_number};
138 return {std::move(sym),
Symbol{
value.symbol,
false}};
142 throw std::logic_error{
"invalid symbol type"};
182 if (theory_.
destroy !=
nullptr) {
203 auto *fun =
static_cast<F *
>(data);
Node capturing expressions in logic programs.
Definition ast.hh:273
A program to add statements to.
Definition ast.hh:809
The main control class for grounding and solving logic programs.
Definition control.hh:179
The main library class for managing global information and logging.
Definition core.hh:471
Class to provide an mutable view of a model.
Definition solve.hh:256
Object to add command-line options.
Definition app.hh:17
Class modeling a mutable view on a statistics entry.
Definition stats.hh:106
Class modeling a symbol in Clingo.
Definition symbol.hh:68
Iterator type for the theory assignment.
Definition theory.hh:33
std::pair< Symbol, std::variant< int, double, Symbol > > value_type
The value type of the iterator, which is a pair of a symbol and its value.
Definition theory.hh:38
iterator()=default
The default constructor for the iterator.
auto operator++() -> iterator &
Increment the iterator to the next value.
Definition theory.hh:64
auto operator*() const -> reference
Get the current value of the iterator.
Definition theory.hh:59
friend auto operator==(iterator const &a, sentinel const &b) -> bool
Check whether their are still values in the assignment.
Definition theory.hh:77
std::input_iterator_tag iterator_category
The iterator category.
Definition theory.hh:36
value_type & reference
The reference type of the iterator.
Definition theory.hh:44
iterator(TheoryAssignment const &assignment)
Constructor for the iterator.
Definition theory.hh:49
value_type * pointer
The pointer type of the iterator.
Definition theory.hh:42
std::ptrdiff_t difference_type
The difference type of the iterator.
Definition theory.hh:40
auto operator++(int) -> iterator
Increment the iterator to the next value (postfix).
Definition theory.hh:70
Class to represent a theory assignment.
Definition theory.hh:28
auto begin() const -> iterator
Get an iterator pointing to the first element of the theory assignment.
Definition theory.hh:150
auto at(size_t index) const -> std::pair< Symbol, std::variant< int, double, Symbol > >
Get the symbol value pair at the given index in the theory assignment.
Definition theory.hh:119
TheoryAssignment(clingo_theory_t const *theory, uint32_t thread_id)
Construct a theory assignment from its C representation and a thread id.
Definition theory.hh:101
static auto end() -> sentinel
Get sentinel marking the end of the theory assignment.
Definition theory.hh:154
auto lookup(Symbol const &sym) const -> std::optional< size_t >
Lookup a symbol in the theory assignment.
Definition theory.hh:108
Theory class to represent a theory in Clingo.
Definition theory.hh:162
friend auto c_cast(Theory const &x) -> clingo_theory_t const *
Get the underlying C representation of the theory.
Definition theory.hh:175
void model(Model model) const
Incorporate theory symbols into the model.
Definition theory.hh:253
void validate_options() const
Validate previously parsed the theory options.
Definition theory.hh:277
void stats(Stats step, Stats accu) const
Incorporate statistics from the theory into the solver's statistics.
Definition theory.hh:247
void prepare(Control const &ctl) const
Prepare the theory for solving.
Definition theory.hh:192
void configure(std::string_view key, std::string_view value) const
Configure the theory with the given key and value.
Definition theory.hh:287
void register_theory(Control const &ctl) const
Register the theory with the control object.
Definition theory.hh:261
void register_options(Options const &opts) const
Add theory related options to the given options object.
Definition theory.hh:270
void rewrite(Library const &lib, Control const &ctl, std::string_view str) const
Rewrite the given program using the theory's rewrite function.
Definition theory.hh:216
void rewrite(Library const &lib, Control const &ctl, StringSpan files) const
Rewrite the programs in the files using the theory's rewrite function.
Definition theory.hh:228
Theory(Theory &&other)=delete
Disable copy and move operations for the Theory class.
~Theory()
Destructor for the Theory class.
Definition theory.hh:181
void rewrite(AST::Node const &stm, F fun) const
Rewrite the given AST node using the theory's rewrite function.
Definition theory.hh:200
Theory(Library const &lib, bool(*create)(clingo_lib_t *lib, clingo_theory_t *theory))
Constructor for the Theory class.
Definition theory.hh:168
auto assignment(uint32_t thread_id) const -> TheoryAssignment
Get the theory assignment for the given thread id.
Definition theory.hh:239
struct clingo_ast clingo_ast_t
This struct provides a view to nodes in the AST.
Definition ast.h:163
struct clingo_lib clingo_lib_t
A library object storing global information.
Definition core.h:176
uint64_t clingo_symbol_t
Type to represent a symbol.
Definition symbol.h:51
@ clingo_theory_value_type_double
A double value.
Definition theory.h:40
@ clingo_theory_value_type_symbol
A symbol value.
Definition theory.h:42
@ clingo_theory_value_type_int
An integer value.
Definition theory.h:38
auto parse(Library const &lib, std::string_view string, ParseType type=ParseType::statement) -> Node
Parse an expression of the given type.
Definition ast.hh:837
@ tuple
Theory tuples "(t1,...,tn)".
@ symbol
a symbol term, e.g., c
@ value
The configuration entry is a double value.
@ rewrite
Parse and rewrite.
std::span< std::string_view const > StringSpan
A span of string views.
Definition core.hh:423
@ theory
Select symbols added by theory.
Sentinel type for the end of the theory assignment.
Definition theory.hh:31
A struct to hold values assigned by a theory.
Definition theory.h:47
A theory object to extend solving.
Definition theory.h:64
bool(* assignment_get_value)(void *self, uint32_t thread_id, size_t index, clingo_symbol_t *symbol, clingo_theory_value_t *value, bool *has_value)
Get the value assigned to the given index.
Definition theory.h:172
bool(* assignment_next)(void *self, uint32_t thread_id, bool *init, size_t *index, bool *has_value)
Get the next index that has a value.
Definition theory.h:160
bool(* validate_options)(void *self)
Validate the options of the theory.
Definition theory.h:114
bool(* prepare)(void *self, clingo_control_t *control)
Prepare the theory.
Definition theory.h:103
bool(* register_options)(void *self, clingo_options_t *options)
Register the theory's options with the given application options object.
Definition theory.h:109
bool(* register_theory)(void *self, clingo_control_t *control)
Register the theory with the given control object.
Definition theory.h:85
void(* destroy)(void *self)
Destroy the theory.
Definition theory.h:77
bool(* rewrite_ast)(void *self, clingo_ast_t *statement, clingo_theory_ast_callback_t callback, void *data)
Rewrite the given ast for the theory.
Definition theory.h:95
bool(* on_model)(void *self, clingo_model_t *model)
Inform the theory that a model has been found.
Definition theory.h:129
bool(* configure)(void *self, char const *key, size_t key_size, char const *value, size_t value_size)
Configure the theory passing key value pairs.
Definition theory.h:123
bool(* on_stats)(void *self, clingo_stats_t *stats)
Add the theory's statistics to the given maps.
Definition theory.h:135
bool(* lookup_symbol)(void *self, clingo_symbol_t symbol, size_t *index, bool *found)
Get the integer index of a symbol assigned by the theory when a model is found.
Definition theory.h:145
void * self
The userdata for the first value to the callabcks in this struct.
Definition theory.h:176