Clingo
|
Functions to control the grounding and solving process. More...
Modules | |
Symbolic Atom Inspection | |
Inspection of atoms occurring in ground logic programs. | |
Basic Shared Types | |
Enumerations shared by various modules. | |
Ground Program Inspection | |
Functions and data structures to inspect ground programs. | |
Ground Program Extension | |
Add non-ground program representations (ASTs) to logic programs or extend the ground (aspif) program. | |
Model Inspection | |
Inspection of models and a high-level interface to add constraints during solving. | |
Solving | |
Interact with a running search. | |
Solver Configuration | |
Configuration of search and enumeration algorithms. | |
Statistics | |
Inspect search and problem stats. | |
Theory Propagation | |
Extend the search with propagators for arbitrary theories. | |
Classes | |
struct | clingo_part |
Struct used to specify the program parts that have to be grounded. More... | |
Typedefs | |
typedef struct clingo_control | clingo_control_t |
Control object holding grounding and solving state. | |
typedef int | clingo_mode_t |
The corresponding type to clingo_mode_e. | |
typedef struct clingo_part | clingo_part_t |
Struct used to specify the program parts that have to be grounded. | |
typedef bool(* | clingo_ground_callback_t) (clingo_lib_t *lib, clingo_location_t const *location, char const *name, size_t name_size, clingo_symbol_t const *arguments, size_t arguments_size, void *data, clingo_symbol_callback_t symbol_callback, void *symbol_callback_data) |
Callback function to implement external functions. | |
typedef struct clingo_const_map | clingo_const_map_t |
A map from constantns to their values. | |
typedef unsigned | clingo_discard_type_t |
Corresponding type to clingo_discard_type_e. | |
Enumerations | |
enum | clingo_mode_e { clingo_mode_parse = 0 , clingo_mode_rewrite = 1 , clingo_mode_ground = 2 , clingo_mode_solve = 3 } |
The available application modes. More... | |
enum | clingo_discard_type_e { minimize = 1 , project = 2 } |
Enumeration of discardable statements. | |
Functions | |
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. | |
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. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_const_map_size (clingo_const_map_t const *map, size_t *size) |
Get the size of the constant map. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_control_new (clingo_lib_t *lib, clingo_string_t const *arguments, size_t size, clingo_control_t **control) |
Create a new control object. | |
CLINGO_VISIBILITY_DEFAULT void | clingo_control_acquire (clingo_control_t *control) |
Increment the reference count of the given control object. | |
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_VISIBILITY_DEFAULT bool | clingo_control_mode (clingo_control_t *control, clingo_mode_t *mode) |
Get the configured mode. | |
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 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_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_const_map (clingo_control_t *control, clingo_const_map_t const **map) |
Get the map of constants. | |
CLINGO_VISIBILITY_DEFAULT bool | clingo_control_buffer (clingo_control_t *control, clingo_string_t *result) |
Get the output of the text output. | |
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_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 bool | clingo_control_discard (clingo_control_t *control, clingo_discard_type_t type) |
Discard the statements of the given types. | |
CLINGO_VISIBILITY_DEFAULT void | clingo_control_interrupt (clingo_control_t *control) |
Interrupt the running search. | |
Functions to control the grounding and solving process.
For an example, see control.c.
typedef bool(* clingo_ground_callback_t) (clingo_lib_t *lib, clingo_location_t const *location, char const *name, size_t name_size, clingo_symbol_t const *arguments, size_t arguments_size, void *data, clingo_symbol_callback_t symbol_callback, void *symbol_callback_data) |
Callback function to implement external functions.
If an external function of form @name(parameters)
occurs in a logic program, then this function is called with its location, name, parameters, and a callback to inject symbols as arguments. The callback can be called multiple times; all symbols passed are injected.
If a (non-recoverable) clingo API function fails in this callback, for example, the symbol callback, the callback must return its return code. In case of errors not related to clingo, this function can use clingo_set_error().
[in] | lib | the library object |
[in] | location | location from which the external function was called |
[in] | name | name of the called external function |
[in] | arguments | arguments of the called external function |
[in] | arguments_size | number of arguments |
[in] | data | user data of the callback |
[in] | symbol_callback | function to inject symbols |
[in] | symbol_callback_data | user data for the symbol callback (must be passed untouched) |
The following example implements the external function @f()
returning 42.
typedef struct clingo_part clingo_part_t |
Struct used to specify the program parts that have to be grounded.
Programs may be structured into parts, which can be grounded independently with clingo_control_ground. Program parts are mainly interesting for incremental grounding and multi-shot solving. For single-shot solving, program parts are not needed.
#program
specification are by default put into a program called base
without arguments.enum clingo_mode_e |
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.
[in] | map | the target |
[in] | index | the index of the elemnt |
[out] | name | the name of the constant |
[out] | symbol | the value of the constant |
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.
[in] | map | the target |
[in] | name | the name of the constant |
[in] | name_size | the size of the name |
[out] | symbol | the value of the constant |
[out] | found | whether the constant was found |
CLINGO_VISIBILITY_DEFAULT bool clingo_const_map_size | ( | clingo_const_map_t const * | map, |
size_t * | size | ||
) |
Get the size of the constant map.
[in] | map | the target |
[out] | size | the size of the map |
CLINGO_VISIBILITY_DEFAULT void clingo_control_acquire | ( | clingo_control_t * | control | ) |
Increment the reference count of the given control object.
[in] | control | the target |
CLINGO_VISIBILITY_DEFAULT bool clingo_control_buffer | ( | clingo_control_t * | control, |
clingo_string_t * | result | ||
) |
Get the output of the text output.
--text-buffer
.[in] | control | the target |
[out] | result | the resulting string |
CLINGO_VISIBILITY_DEFAULT bool clingo_control_const_map | ( | clingo_control_t * | control, |
clingo_const_map_t const ** | map | ||
) |
Get the map of constants.
[in] | control | the target |
[out] | map | the map of constants |
CLINGO_VISIBILITY_DEFAULT bool clingo_control_discard | ( | clingo_control_t * | control, |
clingo_discard_type_t | type | ||
) |
Discard the statements of the given types.
[in] | control | the target control |
[in] | type | what to discard |
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.
[in] | control | the target |
[out] | parts | the resulting parts |
[out] | size | the resulting parts |
[out] | has_value | the resulting parts |
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.
After grounding, logic programs can be solved with clingo_control_solve().
#program
specification are by default put into a program called base
without arguments.[in] | control | the target |
[in] | parts | array of parts to ground |
[in] | size | size of the parts array |
[in] | ground_callback | callback to implement external functions |
[in] | data | user data for ground_callback |
CLINGO_VISIBILITY_DEFAULT void clingo_control_interrupt | ( | clingo_control_t * | control | ) |
Interrupt the running search.
It is generally better to use clingo_solve_handle_cancel(). This function is thread-safe.
[in] | control | the target |
CLINGO_VISIBILITY_DEFAULT bool clingo_control_main | ( | clingo_control_t * | control | ) |
Execute the default ground and solve flow after parsing.
[in] | control | the target |
CLINGO_VISIBILITY_DEFAULT bool clingo_control_mode | ( | clingo_control_t * | control, |
clingo_mode_t * | mode | ||
) |
Get the configured mode.
[in] | control | the target |
[in] | mode | the mode |
CLINGO_VISIBILITY_DEFAULT bool clingo_control_new | ( | clingo_lib_t * | lib, |
clingo_string_t const * | arguments, | ||
size_t | size, | ||
clingo_control_t ** | control | ||
) |
Create a new control object.
A control object has to be freed using clingo_control_free().
--output
) and clasp's options are supported as arguments, except basic options such as --help
. Furthermore, a control object is blocked while a search call is active; you must not call any member function during search.[in] | lib | clingo library object |
[in] | arguments | string array of command line arguments |
[in] | size | size of the arguments array |
[out] | control | resulting 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.
[in] | control | the target |
[in] | files | the files to parse |
[in] | size | the number of files to parse |
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.
After extending the logic program, the corresponding program parts are typically grounded with clingo_control_ground.
[in] | control | the target |
[in] | program | string representation of the program |
[in] | size | the size of the program |
CLINGO_VISIBILITY_DEFAULT void clingo_control_release | ( | clingo_control_t * | control | ) |
Decrement the reference count of the given control object and destroy if zero.
[in] | control | the target |
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.
[in] | control | the target |
[in] | parts | the parts to set |
[in] | size | the size of the parts |
[in] | has_value | whether parts are available |