A Constraint Satisfaction Problem (CSP) solver library written in Rust.
The new implementation follows the design and implementation of Copper v0.1.0.
The library is currently in active development. Features and APIs may change as we refine the implementation and add new functionality.
Supported types:
- Int, Float, Mixed
This library provides efficient algorithms and data structures for solving constraint satisfaction problems. CSPs are mathematical problems defined as a set of objects whose state must satisfy a number of constraints or limitations.
Add this to your Cargo.toml
:
[dependencies]
cspsolver = "0.3.5"
cargo run --example pc_builder
cargo run --example resource_allocation
cargo run --example portfolio_optimization
use cspsolver::prelude::*;
fn main() {
// constraint: v0(int) * 1.5 < 5.0
// solving for maximum v0
let mut m = Model::default();
let v0 = m.new_var_int(1, 3);
println!("v0 domain: [1, 3]");
m.less_than(v0.times_pos(float(1.5)), float(5.0));
let solution = m.maximize(v0).unwrap();
let x = match solution[v0] {
Val::ValI(int_val) => int_val,
_ => panic!("Expected integer value"),
};
assert!(x == 3);
println!("Found optimal value: {}", x);
}
This project is licensed under the MIT License - see the LICENSE file for details.