Expand description
§clingo-rs

Rust idiomatic bindings to the clingo library. Clingo version 5.6.2.
§Usage
§Default - dynamic linking
Per default the crate uses the clingo library via dynamic linking.
It is assumed that a clingo dynamic library is installed on the system.
While compile time the environment variable CLINGO_LIBRARY_PATH
must be set. For example:
export CLINGO_LIBRARY_PATH=/scratch/miniconda3/envs/test/lib
And for running the code that dynamically links to clingo make sure to have the clingo library in your LD_LIBRARY_PATH
.
Have a look a at the [clingo Readme}(https://github.com/potassco/clingo#readme) for different ways of obtaining the binary releases of clingo.
§Using static-linking
You can also use the clingo library via static linking. The build system will attempt to compile clingo for static linking on your system. To build clingo for static linking you need the following tools installed:
- a C++14 conforming compiler
- at least GCC version 4.9
- Clang version 3.1 (using either libstdc++ provided by gcc 4.9 or libc++)
- at least MSVC 15.0 (Visual Studio 2017)
- other compilers might work
- the cmake build system
- at least version 3.18 is recommended
- at least version 3.1 is required
The recommended way to use the optional static linking support is as follows.
[dependencies]
clingo = { version = "0.8.0", features = ["static-linking"] }
§Using derive
macro
The crate provides a derive macro to help easing the use of rust data types as facts.
In your Cargo.toml
add:
[dependencies]
clingo = { version = "0.8.0", features = ["derive"] }
In your source write:
use clingo::{ClingoError, FactBase, Symbol, ToSymbol};
#[derive(ToSymbol)]
struct MyPoint {
x: i32,
y: i32,
}
let p = MyPoint { x: 4, y: 2 };
let mut fb = FactBase::new();
fb.insert(&p);
The macro performs a conversion to snake case. This means the corresponing fact for MyPoint{x:4,y:2}
is my_point(4,2)
.
§Examples
cargo run --example=ast 0
cargo run --example=backend 0
cargo run --example=configuration
cargo run --example=control 0
cargo run --example=model 0
cargo run --example=propagator 0
cargo run --example=solve-async 0
cargo run --example=statistics 0
cargo run --example=symbol 0
cargo run --example=symbolic-atoms 0
cargo run --example=theory-atoms 0
cargo run --example=inject-terms 0
cargo run --example=version
§Contribution
How to make a contribution to clingo-rs
?
Any contribution intentionally submitted for inclusion in the work by you, shall be licensed under the terms of the MIT license without any additional terms or conditions.
Modules§
Structs§
- AllModels
- Assignment
- Represents a (partial) assignment of a particular solver.
- Atom
- Unsigned integer type used for aspif atoms.
- Backend
- Handle to the backend to add directives in aspif format.
- Configuration
- Handle for the solver configuration.
- Configuration
Type - Bit flags describing the entries of a configuration.
- Default
Ctx - Default context for the Control.
- External
Error - Fact
Base - Generic
Control - Control object holding grounding and solving state.
- Generic
Solve Handle - Search handle to a solve call.
- Id
- Unsigned integer type used in various places.
- MModel
- Model
- Represents a model.
- Optimal
Models - Options
- Object to add command-line options.
- Part
- Struct used to specify the program parts that have to be grounded.
- Propagate
Control - This object can be used to add clauses and propagate literals while solving.
- Propagate
Init - Object to initialize a user-defined propagator before each solving step.
- Show
Type - Bit flags to select symbols in models.
- Signature
- Represents a predicate signature.
- Solve
Control - Object to add clauses during search.
- Solve
Mode - Bit flags describing solve modes.
- Solve
Result - Bit flags that describes the result of a solve call.
- Solver
Literal - Signed integer type used for solver literals.
- Statistics
- Handle for to the solver statistics.
- Symbol
- Represents a symbol.
- Symbolic
Atom - A symbolic atom in a program.
- Symbolic
Atoms - Container that stores symbolic atoms in a program – the relevant Herbrand base gringo uses to instantiate programs.
- Symbolic
Atoms Iterator - An iterator over symbolic atoms.
- Theory
Atoms - Container that stores theory atoms, elements, and terms of a program.
- Theory
Atoms Iterator - Iterator over theory atoms.
- Weighted
Literal - A Literal with an associated weight.
Enums§
- Clause
Type - Enumeration of clause types determining the lifetime of a clause.
- Clingo
Error - ClingoError in the rust wrapper, like null pointers or failed matches of C enums.
- Error
Code - Enumeration of clingo error codes for
ClingoError::InternalError
. - Error
Type - Enumeration of clingo error types See: set_error()
- External
Type - Enumeration of different external statements.
- Heuristic
Type - Enumeration of different heuristic modifiers.
- Model
Type - Enumeration for the different model types.
- Propagator
Check Mode - Supported check modes for propagators. Note that total checks are subject to the lock when a model is found. This means that information from previously found models can be used to discard assignments in check calls.
- Solve
Event - Enumeration of solve events.
- Statistics
Type - Enumeration for entries of the statistics.
- Symbol
Type - Enumeration of available symbol types.
- Theory
Term Type - Enumeration of theory term types.
- Truth
Value - Represents three-valued truth values.
- Warning
- Enumeration of warning codes.
- Weigth
Constraint Type - Enumeration of weight_constraint_types.
Traits§
- Control
Ctx - An instance of this trait can be registered with a control object to enable logging, custom propagation, observers and function handling.
- From
Symbol - Function
Handler - Ground
Program Observer - An instance of this struct has to be registered with a solver to observe ground directives as they are passed to the solver.
- Logger
- An instance of this trait has to be registered with a solver to implement a custom logging.
- Propagator
- An instance of this trait has to be registered with a solver to implement a custom propagator.
- Solve
Event Handler - ToSymbol
- helper types and traits to simplify conversion from structs to clingo symbols
Functions§
- add_
string - Internalize a string.
- control
- Create a new control object.
- control_
with_ context - Create a new control object with a custom context.
- parse_
term - Parse a term in string form.
- parse_
term_ with_ logger - Parse a term in string form.
- set_
error - Set an error code and message in the active thread.
- version
- Obtain the clingo version.