Clingo
Loading...
Searching...
No Matches
Grounding and Solving

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.
 
 Grounding
 Interact with a running ground call.
 
 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.
 
 Profile Grounding
 Profile the grounding process.
 

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_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_event_handler_t const *handler, void *data)
 Ground the selected parts of the current (non-ground) logic program.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_control_start_ground (clingo_control_t *control, clingo_part_t const *parts, size_t size, clingo_ground_event_handler_t const *handler, void *data, clingo_ground_handle_t **handle)
 Start grounding a program asynchronously.
 
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.
 

Detailed Description

Functions to control the grounding and solving process.

For an example, see control.c.

Enumeration Type Documentation

◆ clingo_mode_e

The available application modes.

Enumerator
clingo_mode_parse 

parse only

clingo_mode_rewrite 

parse and rewrite

clingo_mode_ground 

parse, rewrite, ground

clingo_mode_solve 

parse, rewrite, ground, and solve

Function Documentation

◆ clingo_const_map_at()

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.

Parameters
[in]mapthe target
[in]indexthe index of the elemnt
[out]namethe name of the constant
[out]symbolthe value of the constant
Returns
whether the call was successful

◆ clingo_const_map_find()

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.

Parameters
[in]mapthe target
[in]namethe name of the constant
[in]name_sizethe size of the name
[out]symbolthe value of the constant
[out]foundwhether the constant was found
Returns
whether the call was successful

◆ clingo_const_map_size()

CLINGO_VISIBILITY_DEFAULT bool clingo_const_map_size ( clingo_const_map_t const *  map,
size_t *  size 
)

Get the size of the constant map.

Parameters
[in]mapthe target
[out]sizethe size of the map
Returns
whether the call was successful

◆ clingo_control_acquire()

CLINGO_VISIBILITY_DEFAULT void clingo_control_acquire ( clingo_control_t *  control)

Increment the reference count of the given control object.

Parameters
[in]controlthe target

◆ clingo_control_buffer()

CLINGO_VISIBILITY_DEFAULT bool clingo_control_buffer ( clingo_control_t *  control,
clingo_string_t result 
)

Get the output of the text output.

Note
The control object has to be created passing option --text-buffer.
Parameters
[in]controlthe target
[out]resultthe resulting string
Returns
whether the call was successful

◆ clingo_control_const_map()

CLINGO_VISIBILITY_DEFAULT bool clingo_control_const_map ( clingo_control_t *  control,
clingo_const_map_t const **  map 
)

Get the map of constants.

Parameters
[in]controlthe target
[out]mapthe map of constants
Returns
whether the call was successful

◆ clingo_control_discard()

CLINGO_VISIBILITY_DEFAULT bool clingo_control_discard ( clingo_control_t *  control,
clingo_discard_type_t  type 
)

Discard the statements of the given types.

Parameters
[in]controlthe target control
[in]typewhat to discard

◆ clingo_control_get_parts()

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.

Parameters
[in]controlthe target
[out]partsthe resulting parts
[out]sizethe resulting parts
[out]has_valuethe resulting parts
Returns
whether the call was successful

◆ clingo_control_ground()

CLINGO_VISIBILITY_DEFAULT bool clingo_control_ground ( clingo_control_t *  control,
clingo_part_t const *  parts,
size_t  size,
clingo_ground_event_handler_t const *  handler,
void *  data 
)

Ground the selected parts of the current (non-ground) logic program.

After grounding, logic programs can be solved with clingo_control_solve().

Note
Parts of a logic program without an explicit #program specification are by default put into a program called base without arguments.
See also
clingo_control_start_ground()
Parameters
[in]controlthe target
[in]partsarray of parts to ground
[in]sizesize of the parts array
[in]handlerhandler for grounding events
[in]datauser data for ground_callback
Returns
whether the call was successful
Examples
ast.c, backend.c, and control.c.

◆ clingo_control_interrupt()

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.

Parameters
[in]controlthe target

◆ clingo_control_main()

CLINGO_VISIBILITY_DEFAULT bool clingo_control_main ( clingo_control_t *  control)

Execute the default ground and solve flow after parsing.

Parameters
[in]controlthe target
Returns
whether the call was successful
Examples
app.c.

◆ clingo_control_mode()

CLINGO_VISIBILITY_DEFAULT bool clingo_control_mode ( clingo_control_t *  control,
clingo_mode_t mode 
)

Get the configured mode.

Parameters
[in]controlthe target
[in]modethe mode
Returns
whether the call was successful

◆ clingo_control_new()

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().

Note
Only gringo options (without --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.
Parameters
[in]libclingo library object
[in]argumentsstring array of command line arguments
[in]sizesize of the arguments array
[out]controlresulting control object
Returns
whether the call was successful
Examples
ast.c, backend.c, and control.c.

◆ clingo_control_parse_files()

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.

Parameters
[in]controlthe target
[in]filesthe files to parse
[in]sizethe number of files to parse
Returns
whether the call was successful
Examples
app.c.

◆ clingo_control_parse_string()

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.

Parameters
[in]controlthe target
[in]programstring representation of the program
[in]sizethe size of the program
Returns
whether the call was successful
Examples
backend.c, and control.c.

◆ clingo_control_release()

CLINGO_VISIBILITY_DEFAULT void clingo_control_release ( clingo_control_t *  control)

Decrement the reference count of the given control object and destroy if zero.

Parameters
[in]controlthe target
Examples
ast.c, backend.c, and control.c.

◆ clingo_control_set_parts()

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.

Parameters
[in]controlthe target
[in]partsthe parts to set
[in]sizethe size of the parts
[in]has_valuewhether parts are available
Returns
whether the call was successful
Examples
app.c.

◆ clingo_control_start_ground()

CLINGO_VISIBILITY_DEFAULT bool clingo_control_start_ground ( clingo_control_t *  control,
clingo_part_t const *  parts,
size_t  size,
clingo_ground_event_handler_t const *  handler,
void *  data,
clingo_ground_handle_t **  handle 
)

Start grounding a program asynchronously.

The function returns a handle and immediately starts grounding in the background. The handle can be used to wait for the grounding to finish, get the result, or cancel the grounding. Stopping grounding leaves the program in an unpredictable state. There is currently no way to rollback a partially grounded program.

The returned handle must be released using clingo_ground_handle_close().

See also
clingo_control_ground()
Parameters
[in]controlthe target
[in]partsarray of parts to ground
[in]sizesize of the parts array
[in]handlerhandler for grounding events
[in]datauser data for ground_callback
[out]handlethe resulting ground handle
Returns
whether the call was successful