Clingo C API
C API for clingo providing high level functions to control grounding and solving.
Classes | Typedefs | Functions
Program Building

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.

Classes

struct  clingo_weighted_literal
 A Literal with an associated weight. More...
 

Typedefs

typedef struct clingo_backend clingo_backend_t
 Handle to the backend to add directives in aspif format.
 
typedef struct clingo_program_builder clingo_program_builder_t
 Object to build non-ground programs.
 

Functions

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. More...
 
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. More...
 
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. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_project (clingo_backend_t *backend, clingo_atom_t const *atoms, size_t size)
 Add a projection directive. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_external (clingo_backend_t *backend, clingo_atom_t atom, clingo_external_type_t type)
 Add an external statement. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_assume (clingo_backend_t *backend, clingo_literal_t const *literals, size_t size)
 Add an assumption directive. More...
 
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 an heuristic directive. More...
 
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. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_backend_add_atom (clingo_backend_t *backend, clingo_atom_t *atom)
 Get a fresh atom to be used in aspif directives. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_program_builder_begin (clingo_program_builder_t *builder)
 Begin building a program. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_program_builder_add (clingo_program_builder_t *builder, clingo_ast_statement_t const *statement)
 Adds a statement to the program. More...
 
CLINGO_VISIBILITY_DEFAULT bool clingo_program_builder_end (clingo_program_builder_t *builder)
 End building a program. More...
 

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
whether the call was successful; might set one of the following error codes:

◆ clingo_backend_add_atom()

CLINGO_VISIBILITY_DEFAULT bool clingo_backend_add_atom ( clingo_backend_t backend,
clingo_atom_t atom 
)

Get a fresh atom to be used in aspif directives.

Parameters
[in]backendthe target backend
[out]atomthe resulting atom
Returns
whether the call was successful
Examples:
backend.c.

◆ 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
whether the call was successful; might set one of the following error codes:
Examples:
theory-atoms.c.

◆ 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
whether the call was successful; might set one of the following error codes:

◆ 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 an 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
whether the call was successful; might set one of the following error codes:

◆ 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
whether the call was successful; might set one of the following error codes:

◆ 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
whether the call was successful; might set one of the following error codes:

◆ 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
whether the call was successful; might set one of the following error codes:
Examples:
backend.c.

◆ 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
whether the call was successful; might set one of the following error codes:

◆ clingo_program_builder_add()

CLINGO_VISIBILITY_DEFAULT bool clingo_program_builder_add ( clingo_program_builder_t builder,
clingo_ast_statement_t const *  statement 
)

Adds a statement to the program.

Attention
clingo_program_builder_begin() must be called before adding statements and clingo_program_builder_end() must be called after all statements have been added.
Parameters
builderthe target program builder
statementthe statement to add
Returns
whether the call was successful; might set one of the following error codes:
Examples:
ast.c.

◆ clingo_program_builder_begin()

CLINGO_VISIBILITY_DEFAULT bool clingo_program_builder_begin ( clingo_program_builder_t builder)

Begin building a program.

Parameters
builderthe target program builder
Returns
whether the call was successful
Examples:
ast.c.

◆ clingo_program_builder_end()

CLINGO_VISIBILITY_DEFAULT bool clingo_program_builder_end ( clingo_program_builder_t builder)

End building a program.

Parameters
builderthe target program builder
Returns
whether the call was successful
Examples:
ast.c.