Clingo
|
The main control class for grounding and solving logic programs. More...
#include <control.hh>
Public Types | |
using | Context = std::function< SymbolVector(std::string_view, SymbolSpan)> |
Callbock for injecting symbols into the grounding process. | |
Public Member Functions | |
Control (Library const &lib, StringList arguments) | |
Constructs a control object with the given library and arguments. | |
Control (Library const &lib, StringSpan arguments={}) | |
Constructs a control object with the given library and arguments. | |
Control (clingo_control_t *rep, bool acquire) | |
Constructs a control object from an existing C representation. | |
auto | mode () const -> ControlMode |
Get the control mode. | |
void | write_aspif (std::string_view path, WriteAspifFlags flags=WriteAspifFlags::none) const |
Write the current program to an ASPIF file. | |
void | parse_files (StringSpan files) const |
Parse files with the given paths. | |
void | parse_files (StringList files) const |
Parse files with the given paths. | |
void | parse_string (std::string_view program) const |
Parse a logic program from a string. | |
void | ground (std::optional< PartSpan > parts=std::nullopt, Context ctx=nullptr) const |
Ground the control object with the given parts. | |
void | ground (std::initializer_list< Part > parts, Context ctx=nullptr) const |
Ground the control object with the given parts. | |
auto | base () const -> Base |
Get the base of the program. | |
auto | stats () const -> ConstStats |
Get the statistics of the control object. | |
auto | solve (SolveEventHandler &handler, ProgramLiteralSpan const &assumptions={}, SolveFlags flags=SolveFlags::empty) const -> SolveHandle |
Solve the grounded program with the given assumptions and flags. | |
auto | solve (ProgramLiteralSpan const &assumptions={}, SolveFlags flags=SolveFlags::yield) const -> SolveHandle |
Solve the grounded program with the given assumptions and flags. | |
void | main () const |
Run the default ground and solve flow. | |
void | interrupt () const |
Interrupt the current solve operation. | |
void | discard (DiscardType type) const |
Discard the statements of the given types. | |
auto | buffer () const -> std::string_view |
Get the text buffer of the control object. | |
auto | parts () const -> std::optional< PartVector > |
Get the parts to ground. | |
void | parts (PartList parts) const |
Set the parts to ground. | |
void | parts (std::optional< PartSpan > parts) const |
Set the parts to ground. | |
auto | config () const -> Config |
Get the configuration of the control object. | |
auto | const_map () const -> ConstMap |
Get the constant map of the control object. | |
void | observe (Observer &obs, bool preprocess=true) const |
Inspect the current ground program held by the control object. | |
auto | backend () const -> ProgramBackend |
Get the backend of the control object. | |
template<std::derived_from< Propagator > T> | |
auto | register_propagator (std::unique_ptr< T > propagator) const -> T & |
Register a propagator with the control object. | |
void | join (AST::Program const &prg) const |
Join the given non-ground program to the current control object. | |
Friends | |
auto | c_cast (Control const &ctl) -> clingo_control_t * |
Cast to the C representation of the control object. | |
The main control class for grounding and solving logic programs.
Control objects are reference counted. For example, care must be taken not to store objects by value in registered propagators to avoid reference cycles.
using Clingo::Control::Context = std::function<SymbolVector(std::string_view, SymbolSpan)> |
Callbock for injecting symbols into the grounding process.
The callback takes the name of the function and the parameters as a string view and a span of symbols as arguments and returns a vector of symbols to inject.
|
inlineexplicit |
Constructs a control object with the given library and arguments.
lib | the library to store symbols |
arguments | the command-line arguments to pass to the control object |
|
inlineexplicit |
Constructs a control object with the given library and arguments.
lib | the library to store symbols |
arguments | the command-line arguments to pass to the control object |
|
inlineexplicit |
Constructs a control object from an existing C representation.
For internal use.
rep | the C representation of the control object |
acquire | whether to acquire the control object |
|
inline |
Get the backend of the control object.
Get the base of the program.
|
inline |
Get the text buffer of the control object.
Manually created control objects use this buffer to output statements to if the control mode has been set to parse, rewrite, or ground.
Get the configuration of the control object.
Get the constant map of the control object.
|
inline |
Discard the statements of the given types.
type | the types of statements to discard |
|
inline |
Ground the control object with the given parts.
The given parts determine which program parts are grounded with which paramaters. If no parts are given, the parts given by the parts directive are grounded.
parts | the parts to ground the control object with |
ctx | the context to use for grounding |
|
inline |
Ground the control object with the given parts.
The given parts determine which program parts are grounded with which paramaters. If no parts are given, the parts given by the parts directive are grounded.
parts | the parts to ground the control object with |
ctx | the context to use for grounding |
|
inline |
Interrupt the current solve operation.
This function is thread-safe and can be called from any thread.
|
inline |
Join the given non-ground program to the current control object.
prg | the program to join |
|
inline |
Run the default ground and solve flow.
The flow can be configured by specifying a control mode and the parts to ground.
|
inline |
Get the control mode.
Inspect the current ground program held by the control object.
obs | the observer to use for inspecting the program |
preprocess | whether to preprocess the program before observing |
|
inline |
Parse files with the given paths.
It is also possible to read files in aspif format. However, aspif files must be read before grounding to avoid redefinition errors. Multiple aspif files can be given, for example, in the order they have been output by write_aspif.
files | the paths to the files to parse |
|
inline |
Parse files with the given paths.
It is also possible to read files in aspif format. However, aspif files must be read before grounding to avoid redefinition errors. Multiple aspif files can be given, for example, in the order they have been output by write_aspif.
files | the paths to the files to parse |
|
inline |
Parse a logic program from a string.
program | the logic program to parse |
|
inline |
Get the parts to ground.
If no parts are set, the next call to ground would ground the base part.
Set the parts to ground.
parts | the parts to set |
Set the parts to ground.
Use std::nullopt to ground the base part.
parts | the parts to set |
|
inline |
Register a propagator with the control object.
Can be used to register both propagators with and without heuristics.
propagator | the propagator to register |
|
inline |
Solve the grounded program with the given assumptions and flags.
This function does not take a solve event handler. Instead, the returned solve handle is configured to yield models as they are found.
assumptions | the assumptions to use for solving |
flags | the flags to use for solving |
|
inline |
Solve the grounded program with the given assumptions and flags.
handler | the solve event handler to report events to |
assumptions | the assumptions to use for solving |
flags | the flags to use for solving |
|
inline |
Get the statistics of the control object.
|
inline |
Write the current program to an ASPIF file.
Note that the control object discards previously grounded programs after calls to solve(). Only the part of the program grounded after the last call to solve() or at the beginning are written to the file.
path | the path to the ASPIF file |
flags | the flags to use when writing the ASPIF file |
Cast to the C representation of the control object.
ctl | the control object to cast |