Crates.io | logicng |
lib.rs | logicng |
version | 0.1.0-alpha.3 |
source | src |
created_at | 2023-09-18 08:26:54.322056 |
updated_at | 2023-09-18 13:07:22.297088 |
description | A Library for Creating, Manipulating, and Solving Boolean Formulas |
homepage | https://www.logicng.org/ |
repository | https://github.com/booleworks/logicng-rs |
max_upload_size | |
id | 975681 |
size | 1,256,360 |
THIS IS AN ALPHA VERSION! THE API MAY STILL CHANGE IN SIGNIFICANT WAYS! THE PROGRAM IS NOT FULLY TESTED, DO NOT USE IN PRODUCTION!
This is LogicNG for Rust. The original version of LogicNG is a Java Library for creating, manipulating and solving Boolean and Pseudo-Boolean formulas.
Its main focus lies on memory-efficient data-structures for Boolean formulas and efficient algorithms for manipulating and solving them. The library is designed and most notably used in industrial systems which have to manipulate and solve millions of formulas per day. The Java version of LogicNG is heavily used by the German automotive industry to validate and optimize their product documentation, support the configuration process of vehicles, and compute WLTP values for emission and consumption.
The Rust version of LogicNG currently provides -among others- the following key functionalities:
open_wbo
The most important philosophy of the library is to avoid unnecessary object creation. Therefore formulas can only be generated via formula factories. A formula factory assures that a formula is only created once in memory. If another instance of the same formula is created by the user, the already existing one is returned by the factory. This leads to a small memory footprint and fast execution of algorithms. Formulas can cache the results of algorithms executed on them and since every formula is hold only once in memory it is assured that the same algorithm on the same formula is also executed only once.
If you want a high-level overview of LogicNG and how it is used in many applications in the area of product configuration, you can read our whitepaper.
The following code creates the Boolean Formula A and not (B or not C) programmatically.
use logicng::formulas::FormulaFactory;
let f = FormulaFactory::new();
let a = f.variable("A");
let b = f.variable("B");
let not_c = f.literal("C", false);
let formula = f.and(&[a, f.not(f.or(&[b, not_c]))]);
Alternatively you can just parse the formula from a string:
use logicng::formulas::FormulaFactory;
let f = FormulaFactory::new();
let formula = f.parse("A & ~(B | ~C)").expect("Parsing failed");
Or even shorter:
use logicng::formulas::{FormulaFactory, ToFormula};
let f = FormulaFactory::new();
let formula = "A & ~(B | ~C)".to_formula(&f);
Once you created the formula you can for example convert it to NNF or CNF or solve it with an instance of MiniSat:
use logicng::formulas::{FormulaFactory, ToFormula};
use logicng::solver::minisat::MiniSat;
let f = FormulaFactory::new();
let formula = "A & ~(B | ~C)".to_formula(&f);
let nnf = f.nnf_of(formula);
let cnf = f.cnf_of(formula);
let mut miniSat = MiniSat::new();
let result = miniSat.sat();
Feature | Description |
---|---|
open_wbo |
Activates MaxSAT solving with Open-WBO |
LogicNG for Rust development is funded by the SofDCar project: