Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/crillab/pblib-rs
Rust safe bindings for pblib.
https://github.com/crillab/pblib-rs
Last synced: 3 months ago
JSON representation
Rust safe bindings for pblib.
- Host: GitHub
- URL: https://github.com/crillab/pblib-rs
- Owner: crillab
- License: gpl-3.0
- Created: 2023-12-04T10:59:13.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2023-12-04T11:24:52.000Z (11 months ago)
- Last Synced: 2024-05-22T21:32:14.750Z (6 months ago)
- Language: C++
- Size: 5.13 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-rust-formalized-reasoning - pblib-rs - rs) - safe bindings for [pblib](https://github.com/master-keying/pblib). (Projects / Libraries)
README
# pblib-rs
Rust safe bindings for pblib.
The source code of pblib is taken from the fork maintained by Radomír Černoch [on Github](https://github.com/master-keying/pblib).
This crate currently provides bindings to a partial set of the initial library functions.
See the original documentation (that can be retrieved from the fork's README page) if you need more information on the encodings.The entry point of the API is the `PB2CNF` structure.
You should begin by taking a look at its documentation is you want to use pblib-rs.## TL;DR
Cardinality constraints:
```rust
use pblib_rs::PB2CNF;// we encode x1 + x2 + x3 >= 2
let literals = vec![1, 2, 3];
let pb2cnf = PB2CNF::new();
// the threshold is 2 and the first variable not in use is 4
let encoding = pb2cnf.encode_at_least_k(literals, 2, 4);
println!("the encoding uses {} variables", encoding.next_free_var_id() - 4);
println!("the encoding uses {} clauses", encoding.clauses().len());
encoding.clauses().iter().enumerate().for_each(|(i,c)| println!("clause {i} is {:?}", c));
```Pseudo-Boolean constraints:
```rust
use pblib_rs::PB2CNF;// we encode 8*x1 + 4*x2 + 2*x3 + 1*x4 >= 6
let weights = vec![8, 4, 2, 1];
let literals = vec![1, 2, 3, 4];
let pb2cnf = PB2CNF::new();
// the threshold is 6 and the first variable not in use is 5
let encoding = pb2cnf.encode_geq(weights.clone(), literals, 6, 5);
println!("the encoding uses {} variables", encoding.next_free_var_id() - 4);
println!("the encoding uses {} clauses", encoding.clauses().len());
encoding.clauses().iter().enumerate().for_each(|(i,c)| println!("clause {i} is {:?}", c));
```## License
pblib-rs is developed at CRIL (Univ. Artois & CNRS).
It is made available under the terms of the GNU Lesser GPLv3 license.