Clingo
Loading...
Searching...
No Matches
control.hh
1#pragma once
2
3#include <clingo/backend.hh>
4#include <clingo/base.hh>
5#include <clingo/config.hh>
6#include <clingo/core.hh>
7#include <clingo/observe.hh>
8#include <clingo/profile.h>
9#include <clingo/propagate.hh>
10#include <clingo/solve.hh>
11#include <clingo/stats.hh>
12#include <clingo/symbol.hh>
13
14#include <clingo/control.h>
15
16#include <cassert>
17#include <optional>
18#include <span>
19#include <variant>
20
21namespace Clingo {
22
23namespace AST {
24
25class Program;
26auto c_cast(Program const &x) -> clingo_program_t *;
27
28} // namespace AST
29
30namespace Detail {
31
32void join(clingo_control_t *ctx, clingo_program_t const *prg);
33
34} // namespace Detail
35
40
42struct Part {
47 Part(std::string name, SymbolVector params = {}) : name{std::move(name)}, params(std::move(params)) {
48 assert(!this->name.empty());
49 }
50
52 std::string name;
55};
57using PartSpan = std::span<Part const>;
59using PartList = std::initializer_list<Part>;
61using PartVector = std::vector<Part>;
62
66class ConstMap {
67 public:
69 using key_type = std::string_view;
73 using value_type = std::pair<key_type, mapped_type>;
75 using size_type = std::size_t;
77 using difference_type = std::ptrdiff_t;
81 using pointer = Detail::ArrowProxy<value_type>;
83 using iterator = Detail::RandomAccessIterator<ConstMap>;
84
88 explicit ConstMap(clingo_const_map_t const *map) : map_{map} {}
89
94 [[nodiscard]] auto contains(key_type name) const -> bool {
95 return Detail::call<clingo_const_map_find>(map_, name.data(), name.size(), nullptr);
96 }
97
102 [[nodiscard]] auto operator[](key_type name) const -> mapped_type {
103 clingo_symbol_t sym = 0;
104 bool found = false;
105 Detail::handle_error(clingo_const_map_find(map_, name.data(), name.size(), &sym, &found));
106 return found ? Symbol{sym, true} : throw std::out_of_range{"key not found"};
107 }
108
113 [[nodiscard]] auto at(size_t index) const -> value_type {
114 clingo_string_t name;
115 clingo_symbol_t sym = 0;
116 Detail::handle_error(clingo_const_map_at(map_, index, &name, &sym));
117 return {{name.data, name.size}, Symbol{sym, true}};
118 }
119
123 [[nodiscard]] auto size() const -> size_type { return Detail::call<clingo_const_map_size>(map_); }
124
128 [[nodiscard]] auto begin() const -> iterator { return iterator{*this, 0}; }
129
133 [[nodiscard]] auto end() const -> iterator { return iterator{*this, size()}; }
134
135 private:
136 clingo_const_map_t const *map_;
137};
138
148
160
169
171enum class DiscardType {
172 minimize = clingo_discard_type_e::minimize,
173 project = clingo_discard_type_e::project,
174};
175
181
202
205using ProfileNode = std::variant<ProfileNodeInternal, ProfileNodeLeaf>;
206
213 ProfileNodeInternal(std::string key, bool nested) : key{std::move(key)}, nested{nested} {}
214
216 std::string key;
218 bool nested;
220 std::vector<ProfileNode> children;
221};
222
228class Control {
229 public:
235 using Context = std::function<SymbolVector(std::string_view, SymbolSpan)>;
236
241 explicit Control(Library const &lib, StringList arguments) : Clingo::Control{lib, StringSpan{arguments}} {}
242
244 explicit Control(Library const &lib, StringSpan arguments = {}) {
245 auto cstrs = Detail::transform(arguments, [](auto const &x) { return clingo_string_t{x.data(), x.size()}; });
246 ctl_.reset(Detail::call<clingo_control_new>(c_cast(lib), cstrs.data(), arguments.size()), false);
247 }
248
255 explicit Control(clingo_control_t *rep, bool acquire) : ctl_{rep, acquire} {}
256
261 [[nodiscard]] friend auto c_cast(Control const &ctl) -> clingo_control_t * { return ctl.ctl_.get(); }
262
266 [[nodiscard]] auto mode() const -> ControlMode {
267 return static_cast<ControlMode>(Detail::call<clingo_control_mode>(ctl_.get()));
268 }
269
278 void write_aspif(std::string_view path, WriteAspifFlags flags = WriteAspifFlags::none) const {
279 Detail::handle_error(clingo_control_write_aspif(ctl_.get(), path.data(), path.size(),
280 static_cast<clingo_write_aspif_mode_t>(flags)));
281 }
282
291 void parse_files(StringSpan files) const {
292 auto cfiles = Detail::transform(files, [](auto const &x) { return clingo_string_t{x.data(), x.size()}; });
293 Detail::handle_error(clingo_control_parse_files(ctl_.get(), cfiles.data(), cfiles.size()));
294 }
295
304 void parse_files(StringList files) const { parse_files(StringSpan{files.begin(), files.end()}); }
305
309 void parse_string(std::string_view program) const {
310 Detail::handle_error(clingo_control_parse_string(ctl_.get(), program.data(), program.size()));
311 }
312
321 void ground(std::optional<PartSpan> parts = std::nullopt, Context ctx = nullptr) const {
322 std::optional<PartVector> default_parts;
323 std::vector<clingo_part_t> c_parts;
324 if (default_parts = !parts ? this->parts() : std::nullopt; default_parts) {
325 parts = default_parts;
326 }
327 if (parts) {
328 c_parts.reserve(parts->size());
329 for (auto const &part : *parts) {
330 c_parts.emplace_back(part.name.data(), part.name.size(), c_cast(part.params.data()),
331 part.params.size());
332 }
333 } else {
334 c_parts.reserve(1);
335 c_parts.emplace_back("base", 4, nullptr, 0);
336 }
337 Detail::handle_error(
338 clingo_control_ground(ctl_.get(), c_parts.data(), c_parts.size(), ctx ? &ctx_ : nullptr, &ctx));
339 }
340
348 void ground(std::initializer_list<Part> parts, Context ctx = nullptr) const {
349 ground(PartSpan{parts}, std::move(ctx));
350 }
351
355 [[nodiscard]] auto base() const -> Base { return Base{Detail::call<clingo_control_base>(ctl_.get())}; }
356
360 [[nodiscard]] auto stats() const -> ConstStats {
361 auto const *stats = Detail::call<clingo_control_stats>(ctl_.get());
362 auto key = Detail::call<clingo_stats_root>(stats);
363 return ConstStats{stats, key};
364 }
365
372 auto profile() -> std::vector<ProfileNode> {
373 struct Builder {
374 static auto internal(size_t depth, char const *key, size_t key_size, bool nested, void *data) -> bool {
375 CLINGO_TRY {
376 auto *self = static_cast<Builder *>(data);
377 assert(depth <= self->stack.size());
378 self->stack.resize(depth);
379 auto node = ProfileNodeInternal{std::string{key, key_size}, nested};
380 if (self->stack.empty()) {
381 self->roots.emplace_back(std::move(node));
382 self->stack.emplace_back(&self->roots.back());
383 } else {
384 auto &children = std::get<ProfileNodeInternal>(*self->stack.back()).children;
385 children.emplace_back(std::move(node));
386 self->stack.emplace_back(&children.back());
387 }
388 }
389 CLINGO_CATCH;
390 }
391 static auto leaf(size_t depth, clingo_profile_data_t *values, clingo_profile_type_t type, void *data)
392 -> bool {
393 CLINGO_TRY {
394 auto *self = static_cast<Builder *>(data);
395 assert(depth <= self->stack.size());
396 self->stack.resize(depth);
397 auto node = ProfileNodeLeaf{static_cast<ProfileType>(type), values->matches, values->instances,
398 values->time_instantiate, values->time_propagate};
399 if (self->stack.empty()) {
400 self->roots.emplace_back(node);
401 } else {
402 std::get<ProfileNodeInternal>(*self->stack.back()).children.emplace_back(node);
403 }
404 }
405 CLINGO_CATCH;
406 }
407
408 std::vector<ProfileNode *> stack;
409 std::vector<ProfileNode> roots;
410 } builder;
411
412 auto visitor = clingo_profile_visitor_t{&Builder::internal, &Builder::leaf};
413 clingo_control_profile(ctl_.get(), &visitor, &builder);
414 return std::move(builder.roots);
415 }
416
423 [[nodiscard]] auto solve(SolveEventHandler &handler, ProgramLiteralSpan const &assumptions = {},
424 SolveFlags flags = SolveFlags::empty) const -> SolveHandle {
425 return solve_(&handler, assumptions, flags);
426 }
427
436 [[nodiscard]] auto solve(ProgramLiteralSpan const &assumptions = {}, SolveFlags flags = SolveFlags::yield) const
437 -> SolveHandle {
438 return solve_(nullptr, assumptions, flags);
439 }
440
445 void main() const { Detail::handle_error(clingo_control_main(ctl_.get())); }
446
450 void interrupt() const { clingo_control_interrupt(ctl_.get()); }
451
455 void discard(DiscardType type) const {
456 Detail::handle_error(clingo_control_discard(ctl_.get(), static_cast<clingo_discard_type_t>(type)));
457 }
458
465 [[nodiscard]] auto buffer() const -> std::string_view {
466 auto [data, size] = Detail::call<clingo_control_buffer>(ctl_.get());
467 return {data, size};
468 }
469
476 [[nodiscard]] auto parts() const -> std::optional<PartVector> {
477 clingo_part_t const *parts = nullptr;
478 size_t size = 0;
479 bool has_value = false;
480 Detail::handle_error(clingo_control_get_parts(ctl_.get(), &parts, &size, &has_value));
481 if (has_value) {
482 return Detail::transform(std::span{parts, size}, [](auto const &part) {
483 auto params = std::span{cpp_cast(part.params), part.params_size};
484 return Part{{part.name, part.name_size}, {params.begin(), params.end()}};
485 });
486 }
487 return std::nullopt;
488 }
489
493 void parts(PartList parts) const { this->parts(std::span{parts.begin(), parts.end()}); }
494
500 void parts(std::optional<PartSpan> parts) const {
501 if (parts) {
502 auto cparts = Detail::transform(*parts, [](auto const &part) {
503 return clingo_part_t{part.name.data(), part.name.size(), c_cast(part.params.data()),
504 part.params.size()};
505 });
506 Detail::handle_error(clingo_control_set_parts(ctl_.get(), cparts.data(), cparts.size(), true));
507 } else {
508 Detail::handle_error(clingo_control_set_parts(ctl_.get(), nullptr, 0, true));
509 }
510 }
511
515 [[nodiscard]] auto config() const -> Config {
516 auto *config = Detail::call<clingo_control_config>(ctl_.get());
517 auto key = Detail::call<clingo_config_root>(config);
518 return Config{config, key};
519 }
520
524 [[nodiscard]] auto const_map() const -> ConstMap {
525 return ConstMap{Detail::call<clingo_control_const_map>(ctl_.get())};
526 }
527
532 void observe(Observer &obs, bool preprocess = true) const { obs.observe(ctl_.get(), preprocess); }
533
537 [[nodiscard]] auto backend() const -> ProgramBackend {
538 return ProgramBackend{Detail::call<clingo_control_backend>(ctl_.get())};
539 }
540
547 template <std::derived_from<Propagator> T> auto register_propagator(std::unique_ptr<T> propagator) const -> T & {
548 assert(propagator != nullptr);
549 auto &res = *propagator;
550 Detail::handle_error(clingo_control_register_propagator(
551 ctl_.get(), std::is_base_of_v<Heuristic, T> ? &Detail::c_heuristic : &Detail::c_propagator,
552 propagator.release()));
553 return res;
554 }
555
559 void join(AST::Program const &prg) const { Detail::join(ctl_.get(), c_cast(prg)); }
560
561 private:
562 friend class Detail::intrusive_handle<Control, clingo_control_t>;
563
564 static auto ctx_([[maybe_unused]] clingo_lib_t *lib, [[maybe_unused]] clingo_location_t const *location,
565 char const *name, size_t name_size, clingo_symbol_t const *arguments, size_t arguments_size,
566 void *data, clingo_symbol_callback_t symbol_callback, void *symbol_callback_data) -> bool {
567 CLINGO_TRY {
568 auto &cb = *static_cast<std::function<SymbolVector(std::string_view, SymbolSpan)> *>(data);
569 auto syms = cb({name, name_size}, {cpp_cast(arguments), arguments_size});
570 auto const *c_syms = c_cast(syms.data());
571 return symbol_callback(c_syms, syms.size(), symbol_callback_data);
572 }
573 CLINGO_CATCH;
574 }
575
576 static auto acquire(clingo_control_t *ptr) { clingo_control_acquire(ptr); }
577
578 static auto release(clingo_control_t *ptr) { clingo_control_release(ptr); }
579
580 [[nodiscard]] auto solve_(SolveEventHandler *handler, ProgramLiteralSpan const &assumptions, SolveFlags flags) const
581 -> SolveHandle {
582 clingo_solve_handle_t *res = nullptr;
583 Detail::handle_error(clingo_control_solve(ctl_.get(), static_cast<clingo_solve_mode_bitset_t>(flags),
584 assumptions.data(), assumptions.size(),
585 handler != nullptr ? &Detail::c_solve_event_handler : nullptr,
586 handler != nullptr ? handler : nullptr, &res));
587 return SolveHandle{res};
588 }
589
590 Detail::intrusive_handle<Control, clingo_control_t> ctl_;
591};
592
594
595} // namespace Clingo
A program to add statements to.
Definition ast.hh:809
A base that maps signatures to atom bases, and captures term and theory bases.
Definition base.hh:607
Class modeling a mutable configuration entry.
Definition config.hh:138
Class to providing a view on the const directives in a logic program.
Definition control.hh:66
auto operator[](key_type name) const -> mapped_type
Get the value of for the given key.
Definition control.hh:102
std::ptrdiff_t difference_type
The difference type.
Definition control.hh:77
std::size_t size_type
The size type.
Definition control.hh:75
Detail::RandomAccessIterator< ConstMap > iterator
The iterator type.
Definition control.hh:83
value_type reference
The reference type.
Definition control.hh:79
auto contains(key_type name) const -> bool
Check if the map contains the given key.
Definition control.hh:94
std::string_view key_type
The key type.
Definition control.hh:69
auto at(size_t index) const -> value_type
Get the key value pair at the given index.
Definition control.hh:113
std::pair< key_type, mapped_type > value_type
The value type.
Definition control.hh:73
Detail::ArrowProxy< value_type > pointer
The pointer type.
Definition control.hh:81
auto begin() const -> iterator
Get an iterator to the beginning of the map.
Definition control.hh:128
ConstMap(clingo_const_map_t const *map)
Construct from the underlying C representation.
Definition control.hh:88
auto end() const -> iterator
Get an iterator to the end of the map.
Definition control.hh:133
auto size() const -> size_type
Get the size of the map.
Definition control.hh:123
Class modeling an immutable view on a statistics entry.
Definition stats.hh:29
The main control class for grounding and solving logic programs.
Definition control.hh:228
auto config() const -> Config
Get the configuration of the control object.
Definition control.hh:515
void discard(DiscardType type) const
Discard the statements of the given types.
Definition control.hh:455
void parts(std::optional< PartSpan > parts) const
Set the parts to ground.
Definition control.hh:500
void observe(Observer &obs, bool preprocess=true) const
Inspect the current ground program held by the control object.
Definition control.hh:532
auto base() const -> Base
Get the base of the program.
Definition control.hh:355
void write_aspif(std::string_view path, WriteAspifFlags flags=WriteAspifFlags::none) const
Write the current program to an ASPIF file.
Definition control.hh:278
Control(Library const &lib, StringSpan arguments={})
Constructs a control object with the given library and arguments.
Definition control.hh:244
auto stats() const -> ConstStats
Get the statistics of the control object.
Definition control.hh:360
void ground(std::initializer_list< Part > parts, Context ctx=nullptr) const
Ground the control object with the given parts.
Definition control.hh:348
auto parts() const -> std::optional< PartVector >
Get the parts to ground.
Definition control.hh:476
auto const_map() const -> ConstMap
Get the constant map of the control object.
Definition control.hh:524
auto solve(ProgramLiteralSpan const &assumptions={}, SolveFlags flags=SolveFlags::yield) const -> SolveHandle
Solve the grounded program with the given assumptions and flags.
Definition control.hh:436
auto register_propagator(std::unique_ptr< T > propagator) const -> T &
Register a propagator with the control object.
Definition control.hh:547
Control(clingo_control_t *rep, bool acquire)
Constructs a control object from an existing C representation.
Definition control.hh:255
void parts(PartList parts) const
Set the parts to ground.
Definition control.hh:493
void interrupt() const
Interrupt the current solve operation.
Definition control.hh:450
void parse_files(StringSpan files) const
Parse files with the given paths.
Definition control.hh:291
friend auto c_cast(Control const &ctl) -> clingo_control_t *
Cast to the C representation of the control object.
Definition control.hh:261
auto backend() const -> ProgramBackend
Get the backend of the control object.
Definition control.hh:537
auto buffer() const -> std::string_view
Get the text buffer of the control object.
Definition control.hh:465
void main() const
Run the default ground and solve flow.
Definition control.hh:445
Control(Library const &lib, StringList arguments)
Constructs a control object with the given library and arguments.
Definition control.hh:241
void parse_files(StringList files) const
Parse files with the given paths.
Definition control.hh:304
auto solve(SolveEventHandler &handler, ProgramLiteralSpan const &assumptions={}, SolveFlags flags=SolveFlags::empty) const -> SolveHandle
Solve the grounded program with the given assumptions and flags.
Definition control.hh:423
void join(AST::Program const &prg) const
Join the given non-ground program to the current control object.
Definition control.hh:559
void ground(std::optional< PartSpan > parts=std::nullopt, Context ctx=nullptr) const
Ground the control object with the given parts.
Definition control.hh:321
auto mode() const -> ControlMode
Get the control mode.
Definition control.hh:266
std::function< SymbolVector(std::string_view, SymbolSpan)> Context
Callbock for injecting symbols into the grounding process.
Definition control.hh:235
auto profile() -> std::vector< ProfileNode >
Obtain the profiling data of the control object.
Definition control.hh:372
void parse_string(std::string_view program) const
Parse a logic program from a string.
Definition control.hh:309
The main library class for managing global information and logging.
Definition core.hh:471
Observer interface to inspect the current ground program.
Definition observe.hh:15
Program backend to add atoms and statements.
Definition backend.hh:132
Interface to handle events during solving.
Definition solve.hh:291
Class to control a running search.
Definition solve.hh:337
Class modeling a symbol in Clingo.
Definition symbol.hh:68
struct clingo_program clingo_program_t
Object to store.
Definition ast.h:493
unsigned clingo_discard_type_t
Corresponding type to clingo_discard_type_e.
Definition control.h:260
CLINGO_VISIBILITY_DEFAULT bool clingo_const_map_find(clingo_const_map_t const *map, char const *name, size_t name_size, clingo_symbol_t *symbol, bool *found)
Get the constant with the given name.
int clingo_mode_t
The corresponding type to clingo_mode_e.
Definition control.h:44
CLINGO_VISIBILITY_DEFAULT bool clingo_control_parse_string(clingo_control_t *control, char const *program, size_t size)
Extend the logic program with the given non-ground logic program in string form.
CLINGO_VISIBILITY_DEFAULT bool clingo_control_get_parts(clingo_control_t *control, clingo_part_t const **parts, size_t *size, bool *has_value)
Get the program parts to ground.
CLINGO_VISIBILITY_DEFAULT bool clingo_control_discard(clingo_control_t *control, clingo_discard_type_t type)
Discard the statements of the given types.
CLINGO_VISIBILITY_DEFAULT bool clingo_const_map_at(clingo_const_map_t const *map, size_t index, clingo_string_t *name, clingo_symbol_t *symbol)
Get the name and value of the contstant at the given index.
struct clingo_const_map clingo_const_map_t
A map from constantns to their values.
Definition control.h:111
CLINGO_VISIBILITY_DEFAULT void clingo_control_acquire(clingo_control_t *control)
Increment the reference count of the given control object.
CLINGO_VISIBILITY_DEFAULT bool clingo_control_parse_files(clingo_control_t *control, clingo_string_t const *files, size_t size)
Extend the logic program with a program in a file.
CLINGO_VISIBILITY_DEFAULT void clingo_control_interrupt(clingo_control_t *control)
Interrupt the running search.
CLINGO_VISIBILITY_DEFAULT bool clingo_control_ground(clingo_control_t *control, clingo_part_t const *parts, size_t size, clingo_ground_callback_t ground_callback, void *data)
Ground the selected parts of the current (non-ground) logic program.
CLINGO_VISIBILITY_DEFAULT bool clingo_control_main(clingo_control_t *control)
Execute the default ground and solve flow after parsing.
CLINGO_VISIBILITY_DEFAULT bool clingo_control_set_parts(clingo_control_t *control, clingo_part_t const *parts, size_t size, bool has_value)
Set the program parts to ground.
CLINGO_VISIBILITY_DEFAULT void clingo_control_release(clingo_control_t *control)
Decrement the reference count of the given control object and destroy if zero.
@ clingo_mode_ground
parse, rewrite, ground
Definition control.h:40
@ clingo_mode_parse
parse only
Definition control.h:38
@ clingo_mode_rewrite
parse and rewrite
Definition control.h:39
@ clingo_mode_solve
parse, rewrite, ground, and solve
Definition control.h:41
struct clingo_lib clingo_lib_t
A library object storing global information.
Definition core.h:171
struct clingo_location clingo_location_t
Represents a source code location marking its beginning and end.
Definition core.h:354
unsigned clingo_write_aspif_mode_t
Corresponding type to clingo_write_aspif_mode_e.
Definition observe.h:30
CLINGO_VISIBILITY_DEFAULT bool clingo_control_write_aspif(clingo_control_t *control, char const *path, size_t size, clingo_write_aspif_mode_t mode)
Write the current logic program in aspif format to a file.
@ clingo_write_aspif_mode_preamble_auto
Write preamble for newly created files.
Definition observe.h:24
@ clingo_write_aspif_mode_symbols
Whether to write symbols in a structured format.
Definition observe.h:27
@ clingo_write_aspif_mode_preamble
Write preamble.
Definition observe.h:23
@ clingo_write_aspif_mode_preprocess
Whether to preprocess the program before writing.
Definition observe.h:26
@ clingo_write_aspif_mode_append
Append to an existing file (or create it).
Definition observe.h:25
CLINGO_VISIBILITY_DEFAULT bool clingo_control_profile(clingo_control_t const *control, clingo_profile_visitor_t const *visit, void *data)
Visit the profiling data of a control object.
int clingo_profile_type_t
Corresponding type to clingo_profile_type_e.
Definition profile.h:36
@ clingo_profile_type_step
indicate per step values
Definition profile.h:32
@ clingo_profile_type_accu
indicate accumulated values
Definition profile.h:33
CLINGO_VISIBILITY_DEFAULT bool clingo_control_register_propagator(clingo_control_t *control, clingo_propagator_t const *propagator, void *data)
Register a custom propagator with the control object.
struct clingo_solve_handle clingo_solve_handle_t
Search handle to a solve call.
Definition solve.h:112
CLINGO_VISIBILITY_DEFAULT bool clingo_control_solve(clingo_control_t *control, clingo_solve_mode_bitset_t mode, clingo_literal_t const *assumptions, size_t assumptions_size, clingo_solve_event_handler_t const *handler, void *data, clingo_solve_handle_t **handle)
Solve the currently grounded logic program enumerating its models.
unsigned clingo_solve_mode_bitset_t
Corresponding type to clingo_solve_mode_e.
Definition solve.h:71
@ clingo_solve_mode_yield
Yield models in calls to clingo_solve_handle_model.
Definition solve.h:67
@ clingo_solve_mode_async
Enable non-blocking search.
Definition solve.h:66
bool(* clingo_symbol_callback_t)(clingo_symbol_t const *symbols, size_t symbols_size, void *data)
Callback function to inject symbols.
Definition symbol.h:60
uint64_t clingo_symbol_t
Type to represent a symbol.
Definition symbol.h:51
@ map
The configuration entry is a map of configurations.
SolveFlags
Enumeration of the flags for solving a logic program.
Definition control.hh:162
DiscardType
Enumeration of the types of statements that can be discarded.
Definition control.hh:171
WriteAspifFlags
Enumeration of the flags for writing ASPIF files.
Definition control.hh:150
std::vector< Part > PartVector
A vector of program parts.
Definition control.hh:61
ControlMode
Enumeration of the control modes.
Definition control.hh:142
ProfileType
Enumeration of the types of profiling data.
Definition control.hh:177
std::span< Part const > PartSpan
A span of program parts.
Definition control.hh:57
std::initializer_list< Part > PartList
An initializer list of program parts.
Definition control.hh:59
std::variant< ProfileNodeInternal, ProfileNodeLeaf > ProfileNode
A profile node that can be either an internal node or a leaf node.
Definition control.hh:205
@ async
Asynchronously solve in the background.
@ yield
Yield models as they are found.
@ empty
Standard event-based solving.
@ project
Discard project statements.
@ minimize
Discard minimize statements.
@ preamble_auto
Write preamble for newly created files.
@ preamble
Write preamble.
@ symbols
Whether to write symbols in a structured format.
@ append
Append to an existing file (or create it).
@ preprocess
Whether to preprocess the program before writing.
@ parse
Parse only.
@ ground
Parse, rewrite, ground.
@ rewrite
Parse and rewrite.
@ solve
Parse, rewrite, ground, and solve.
@ accu
Indicate accumulated profiling data.
@ step
Indicate per step profiling data.
std::span< std::string_view const > StringSpan
A span of string views.
Definition core.hh:423
std::initializer_list< std::string_view const > StringList
A list of string views.
Definition core.hh:425
std::span< ProgramLiteral const > ProgramLiteralSpan
A span of program literals.
Definition core.hh:394
@ release
No longer treat an atom as external.
@ none
The empty set of flags.
Definition propagate.hh:38
std::vector< Symbol > SymbolVector
A vector of symbols.
Definition symbol.hh:42
std::span< Symbol const > SymbolSpan
A span of symbols, which is a view on a contiguous sequence of symbols.
Definition symbol.hh:38
auto cpp_cast(clingo_symbol_t const *sym) -> Symbol const *
Cast a C symbol to its C++ representation.
Definition symbol.hh:52
#define CLINGO_ENABLE_BITSET_ENUM(E,...)
Opt-in macro for enabling bit operations for a given enum type.
Definition enum.hh:18
A program part to provide inputs to program directives.
Definition control.hh:42
std::string name
The name of the part.
Definition control.hh:52
SymbolVector params
The parameters of the part.
Definition control.hh:54
Part(std::string name, SymbolVector params={})
Constructs a program part with the given name and parameters.
Definition control.hh:47
Class to hold profiling data for an expression in a logic program.
Definition control.hh:208
bool nested
Whether times are included in the parent.
Definition control.hh:218
std::vector< ProfileNode > children
The children of the profile node.
Definition control.hh:220
std::string key
The key of the profile node.
Definition control.hh:216
ProfileNodeInternal(std::string key, bool nested)
Constructs a profile internal node with the given key.
Definition control.hh:213
Class to hold profiling data for an expression in a logic program.
Definition control.hh:183
ProfileType type
The type of the profiling data.
Definition control.hh:196
uint64_t time_instantiate
The time spent instantiating the expression.
Definition control.hh:199
uint64_t matches
The number of matches for the expression.
Definition control.hh:197
uint64_t time_propagate
The time spent propagating the expression.
Definition control.hh:200
ProfileNodeLeaf(ProfileType type, uint64_t matches=0, uint64_t instances=0, uint64_t time_instantiate=0, uint64_t time_propagate=0)
Constructs a profile leaf node with the given type and profiling data.
Definition control.hh:191
uint64_t instances
The number of instances of the expression.
Definition control.hh:198
Struct used to specify the program parts that have to be grounded.
Definition control.h:57
char const * name
name of the program part
Definition control.h:58
Per node performance statistics gathered while grounding a logic program.
Definition profile.h:39
uint64_t time_propagate
The time in nanoseconds spent propagating.
Definition profile.h:47
uint64_t time_instantiate
The time in nanoseconds spent instantiating.
Definition profile.h:45
uint64_t matches
The number of matches produced by the instantiator.
Definition profile.h:41
uint64_t instances
The number of instances produced by the instantiator.
Definition profile.h:43
Visitor for profiling data.
Definition profile.h:51
Struct to capture strings that are not null-terminated.
Definition core.h:86
char const * data
pointer to the beginning of the string
Definition core.h:87