Clingo
Loading...
Searching...
No Matches
Ground Program Extension

Add non-ground program representations (ASTs) to logic programs or extend the ground (aspif) program. More...

Typedefs

typedef int clingo_theory_sequence_type_t
 Corresponding type to clingo_theory_sequence_type_e.
 
typedef struct clingo_backend clingo_backend_t
 Handle to the backend to add directives in aspif format.
 

Enumerations

enum  clingo_theory_sequence_type_e { clingo_theory_sequence_type_tuple = 0 , clingo_theory_sequence_type_set = 1 , clingo_theory_sequence_type_list = 2 }
 Enumeration of theory sequence types. More...
 

Functions

CLINGO_VISIBILITY_DEFAULT bool clingo_control_backend (clingo_control_t *control, clingo_backend_t **backend)
 Get a backend object to extend the ground program.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_close (clingo_backend_t *backend)
 Finalize the backend after using it.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_rule (clingo_backend_t *backend, bool choice, clingo_atom_t const *head, size_t head_size, clingo_literal_t const *body, size_t body_size)
 Add a rule to the program.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_weight_rule (clingo_backend_t *backend, bool choice, clingo_atom_t const *head, size_t head_size, clingo_weight_t lower_bound, clingo_weighted_literal_t const *body, size_t body_size)
 Add a weight rule to the program.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_minimize (clingo_backend_t *backend, clingo_weight_t priority, clingo_weighted_literal_t const *literals, size_t size)
 Add a minimize constraint (or weak constraint) to the program.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_project (clingo_backend_t *backend, clingo_atom_t const *atoms, size_t size)
 Add a projection directive.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_external (clingo_backend_t *backend, clingo_atom_t atom, clingo_external_type_t type)
 Add an external statement.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_assume (clingo_backend_t *backend, clingo_literal_t const *literals, size_t size)
 Add an assumption directive.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_heuristic (clingo_backend_t *backend, clingo_atom_t atom, clingo_heuristic_type_t type, int bias, unsigned priority, clingo_literal_t const *condition, size_t size)
 Add a heuristic directive.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_acyc_edge (clingo_backend_t *backend, int node_u, int node_v, clingo_literal_t const *condition, size_t size)
 Add an edge directive.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_add_atom (clingo_backend_t *backend, clingo_symbol_t const *symbol, clingo_atom_t *atom)
 Get a fresh atom to be used in aspif directives.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_theory_term_number (clingo_backend_t *backend, int number, clingo_id_t *term_id)
 Add a numeric theory term.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_theory_term_string (clingo_backend_t *backend, char const *string, size_t size, clingo_id_t *term_id)
 Add a theory term representing a string.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_theory_term_sequence (clingo_backend_t *backend, clingo_theory_sequence_type_t type, clingo_id_t const *arguments, size_t size, clingo_id_t *term_id)
 Add a theory term representing a sequence of theory terms.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_theory_term_function (clingo_backend_t *backend, char const *name, size_t name_size, clingo_id_t const *arguments, size_t arguments_size, clingo_id_t *term_id)
 Add a theory term representing a function.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_theory_term_symbol (clingo_backend_t *backend, clingo_symbol_t symbol, clingo_id_t *term_id)
 Convert the given symbol into a theory term.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_theory_element (clingo_backend_t *backend, clingo_id_t const *tuple, size_t tuple_size, clingo_literal_t const *condition, size_t condition_size, clingo_id_t *element_id)
 Add a theory atom element.
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_theory_atom (clingo_backend_t *backend, clingo_symbol_t name, clingo_id_t const *elements, size_t size, clingo_string_t *operator_name, clingo_id_t right_hand_side_id, clingo_atom_t const *atom_in, clingo_atom_t *atom_out)
 Add a theory atom without a guard.
 

Detailed Description

Add non-ground program representations (ASTs) to logic programs or extend the ground (aspif) program.

For an example about ground logic programs, see backend.c. For an example about non-ground logic programs, see ast.c and the Abstract Syntax Trees module.

Enumeration Type Documentation

◆ clingo_theory_sequence_type_e

Enumeration of theory sequence types.

Enumerator
clingo_theory_sequence_type_tuple 

Theory tuples "(t1,...,tn)".

clingo_theory_sequence_type_set 

Theory sets "{t1,...,tn}".

clingo_theory_sequence_type_list 

Theory lists "[t1,...,tn]".

Function Documentation

◆ clingo_backend_acyc_edge()

CLINGO_VISIBILITY_DEFAULT bool clingo_backend_acyc_edge ( clingo_backend_t backend,
int  node_u,
int  node_v,
clingo_literal_t const *  condition,
size_t  size 
)

Add an edge directive.

Parameters
[in]backendthe target backend
[in]node_uthe start vertex of the edge
[in]node_vthe end vertex of the edge
[in]conditionthe condition under which the edge is part of the graph
[in]sizethe number of atoms in the condition
Returns
wether the call was successful

◆ clingo_backend_add_atom()

CLINGO_VISIBILITY_DEFAULT bool clingo_backend_add_atom ( clingo_backend_t backend,
clingo_symbol_t const *  symbol,
clingo_atom_t atom 
)

Get a fresh atom to be used in aspif directives.

Parameters
[in]backendthe target backend
[in]symboloptional symbol to associate the atom with
[out]atomthe resulting atom
Returns
wether the call was successful

◆ clingo_backend_assume()

CLINGO_VISIBILITY_DEFAULT bool clingo_backend_assume ( clingo_backend_t backend,
clingo_literal_t const *  literals,
size_t  size 
)

Add an assumption directive.

Parameters
[in]backendthe target backend
[in]literalsthe literals to assume (positive literals are true and negative literals false for the next solve call)
[in]sizethe number of atoms
Returns
wether the call was successful

◆ clingo_backend_close()

CLINGO_VISIBILITY_DEFAULT bool clingo_backend_close ( clingo_backend_t backend)

Finalize the backend after using it.

Parameters
[in]backendthe target backend
Returns
wether the call was successful

◆ clingo_backend_external()

CLINGO_VISIBILITY_DEFAULT bool clingo_backend_external ( clingo_backend_t backend,
clingo_atom_t  atom,
clingo_external_type_t  type 
)

Add an external statement.

Parameters
[in]backendthe target backend
[in]atomthe external atom
[in]typethe type of the external statement
Returns
wether the call was successful

◆ clingo_backend_heuristic()

CLINGO_VISIBILITY_DEFAULT bool clingo_backend_heuristic ( clingo_backend_t backend,
clingo_atom_t  atom,
clingo_heuristic_type_t  type,
int  bias,
unsigned  priority,
clingo_literal_t const *  condition,
size_t  size 
)

Add a heuristic directive.

Parameters
[in]backendthe target backend
[in]atomthe target atom
[in]typethe type of the heuristic modification
[in]biasthe heuristic bias
[in]prioritythe heuristic priority
[in]conditionthe condition under which to apply the heuristic modification
[in]sizethe number of atoms in the condition
Returns
wether the call was successful

◆ clingo_backend_minimize()

CLINGO_VISIBILITY_DEFAULT bool clingo_backend_minimize ( clingo_backend_t backend,
clingo_weight_t  priority,
clingo_weighted_literal_t const *  literals,
size_t  size 
)

Add a minimize constraint (or weak constraint) to the program.

Parameters
[in]backendthe target backend
[in]prioritythe priority of the constraint
[in]literalsthe weighted literals whose sum to minimize
[in]sizethe number of weighted literals
Returns
wether the call was successful

◆ clingo_backend_project()

CLINGO_VISIBILITY_DEFAULT bool clingo_backend_project ( clingo_backend_t backend,
clingo_atom_t const *  atoms,
size_t  size 
)

Add a projection directive.

Parameters
[in]backendthe target backend
[in]atomsthe atoms to project on
[in]sizethe number of atoms
Returns
wether the call was successful

◆ clingo_backend_rule()

CLINGO_VISIBILITY_DEFAULT bool clingo_backend_rule ( clingo_backend_t backend,
bool  choice,
clingo_atom_t const *  head,
size_t  head_size,
clingo_literal_t const *  body,
size_t  body_size 
)

Add a rule to the program.

Parameters
[in]backendthe target backend
[in]choicedetermines if the head is a choice or a disjunction
[in]headthe head atoms
[in]head_sizethe number of atoms in the head
[in]bodythe body literals
[in]body_sizethe number of literals in the body
Returns
wether the call was successful

◆ clingo_backend_theory_atom()

CLINGO_VISIBILITY_DEFAULT bool clingo_backend_theory_atom ( clingo_backend_t backend,
clingo_symbol_t  name,
clingo_id_t const *  elements,
size_t  size,
clingo_string_t operator_name,
clingo_id_t  right_hand_side_id,
clingo_atom_t const *  atom_in,
clingo_atom_t atom_out 
)

Add a theory atom without a guard.

If the theory atom does not exist yet, the atom receives a fresh program atom, if atom_id is NULL; or *atom_in, otherwise. Note that value zero can be used to mark program directives. The ouput paramater atom_out is set to the final value.

Parameters
[in]backendthe target backend
[in]namethe symbol representing the name
[in]elementsan array of element ids for the theory atom's elements
[in]sizethe number of elements
[in]operator_namethe (optional) right-hand-side operator
[in]right_hand_side_idthe term id of the right-hand-side
[in]atom_inthe atom as described above
[out]atom_outthe final program atom of the theory atom
Returns
wether the call was successful

◆ clingo_backend_theory_element()

CLINGO_VISIBILITY_DEFAULT bool clingo_backend_theory_element ( clingo_backend_t backend,
clingo_id_t const *  tuple,
size_t  tuple_size,
clingo_literal_t const *  condition,
size_t  condition_size,
clingo_id_t element_id 
)

Add a theory atom element.

Parameters
[in]backendthe target backend
[in]tuplethe array of term ids representing the tuple
[in]tuple_sizethe size of the tuple
[in]conditionan array of program literals representing the condition
[in]condition_sizethe size of the condition
[out]element_idthe resulting element id
Returns
wether the call was successful

◆ clingo_backend_theory_term_function()

CLINGO_VISIBILITY_DEFAULT bool clingo_backend_theory_term_function ( clingo_backend_t backend,
char const *  name,
size_t  name_size,
clingo_id_t const *  arguments,
size_t  arguments_size,
clingo_id_t term_id 
)

Add a theory term representing a function.

Parameters
[in]backendthe target backend
[in]namethe name of the function
[in]name_sizethe size of the name
[in]argumentsan array of term ids for the theory terms in the arguments
[in]arguments_sizethe number of arguments
[out]term_idthe resulting term id
Returns
wether the call was successful

◆ clingo_backend_theory_term_number()

CLINGO_VISIBILITY_DEFAULT bool clingo_backend_theory_term_number ( clingo_backend_t backend,
int  number,
clingo_id_t term_id 
)

Add a numeric theory term.

Parameters
[in]backendthe target backend
[in]numberthe value of the term
[out]term_idthe resulting term id
Returns
wether the call was successful

◆ clingo_backend_theory_term_sequence()

CLINGO_VISIBILITY_DEFAULT bool clingo_backend_theory_term_sequence ( clingo_backend_t backend,
clingo_theory_sequence_type_t  type,
clingo_id_t const *  arguments,
size_t  size,
clingo_id_t term_id 
)

Add a theory term representing a sequence of theory terms.

Parameters
[in]backendthe target backend
[in]typethe type of the sequence
[in]argumentsthe term ids of the terms in the sequence
[in]sizethe number of elements of the sequence
[out]term_idthe resulting term id
Returns
wether the call was successful

◆ clingo_backend_theory_term_string()

CLINGO_VISIBILITY_DEFAULT bool clingo_backend_theory_term_string ( clingo_backend_t backend,
char const *  string,
size_t  size,
clingo_id_t term_id 
)

Add a theory term representing a string.

Parameters
[in]backendthe target backend
[in]stringthe value of the term
[in]sizethe size of the string
[out]term_idthe resulting term id
Returns
wether the call was successful

◆ clingo_backend_theory_term_symbol()

CLINGO_VISIBILITY_DEFAULT bool clingo_backend_theory_term_symbol ( clingo_backend_t backend,
clingo_symbol_t  symbol,
clingo_id_t term_id 
)

Convert the given symbol into a theory term.

Parameters
[in]backendthe target backend
[in]symbolthe symbol to convert
[out]term_idthe resulting term id
Returns
wether the call was successful

◆ clingo_backend_weight_rule()

CLINGO_VISIBILITY_DEFAULT bool clingo_backend_weight_rule ( clingo_backend_t backend,
bool  choice,
clingo_atom_t const *  head,
size_t  head_size,
clingo_weight_t  lower_bound,
clingo_weighted_literal_t const *  body,
size_t  body_size 
)

Add a weight rule to the program.

Attention
All weights and the lower bound must be positive.
Parameters
[in]backendthe target backend
[in]choicedetermines if the head is a choice or a disjunction
[in]headthe head atoms
[in]head_sizethe number of atoms in the head
[in]lower_boundthe lower bound of the weight rule
[in]bodythe weighted body literals
[in]body_sizethe number of weighted literals in the body
Returns
wether the call was successful

◆ clingo_control_backend()

CLINGO_VISIBILITY_DEFAULT bool clingo_control_backend ( clingo_control_t *  control,
clingo_backend_t **  backend 
)

Get a backend object to extend the ground program.

The control object itself should not be used until the backend is closed.

Parameters
[in]controlthe control object
[out]backendthe resulting backend
Returns
wether the call was successful