cspsolver 0.3.15

Constraint Satisfaction Problem (CSP) solver
Documentation
# CSP Solver

[![Crates.io](https://img.shields.io/crates/v/cspsolver.svg?color=blue)](https://crates.io/crates/cspsolver)
[![Documentation](https://docs.rs/cspsolver/badge.svg)](https://docs.rs/cspsolver)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

A Constraint Satisfaction Problem (CSP) solver library written in Rust.

## Overview

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.

Type of variables: `float`, `int`, `mixed` (int and float)

Constraints supported include:
- Arithmetic: `+`, `-`, `*`, `/`
- Comparisons: `<`, `<=`, `>`, `>=`, `==`, `!=`
- `all_different`

## Installation

Add this to your `Cargo.toml`:

```toml
[dependencies]
cspsolver = "0.3.15"
```


## Examples

```bash
cargo run --example sudoku
cargo run --example pc_builder
cargo run --example resource_allocation
cargo run --example portfolio_optimization
```

```
๐Ÿงฉ Solving PLATINUM puzzle:
๐Ÿ“Š Puzzle stats: 17 clues given, 64 empty cells

Puzzle:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ ยท ยท ยท โ”‚ ยท ยท ยท โ”‚ ยท ยท ยท โ”‚
โ”‚ ยท ยท ยท โ”‚ ยท ยท 3 โ”‚ ยท 8 5 โ”‚
โ”‚ ยท ยท 1 โ”‚ ยท 2 ยท โ”‚ ยท ยท ยท โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ ยท ยท ยท โ”‚ 5 ยท 7 โ”‚ ยท ยท ยท โ”‚
โ”‚ ยท ยท 4 โ”‚ ยท ยท ยท โ”‚ 1 ยท ยท โ”‚
โ”‚ ยท 9 ยท โ”‚ ยท ยท ยท โ”‚ ยท ยท ยท โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 5 ยท ยท โ”‚ ยท ยท ยท โ”‚ ยท 7 3 โ”‚
โ”‚ ยท ยท 2 โ”‚ ยท 1 ยท โ”‚ ยท ยท ยท โ”‚
โ”‚ ยท ยท ยท โ”‚ ยท 4 ยท โ”‚ ยท ยท 9 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โœ… Solution found in 144330.511ms!
๐Ÿ“Š Statistics: 638 propagations, 54 nodes explored
๐Ÿ” Efficiency: 11.8 propagations/node

Solution:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ 9 8 7 โ”‚ 6 5 4 โ”‚ 3 2 1 โ”‚
โ”‚ 2 4 6 โ”‚ 1 7 3 โ”‚ 9 8 5 โ”‚
โ”‚ 3 5 1 โ”‚ 9 2 8 โ”‚ 7 4 6 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 1 2 8 โ”‚ 5 3 7 โ”‚ 6 9 4 โ”‚
โ”‚ 6 3 4 โ”‚ 8 9 2 โ”‚ 1 5 7 โ”‚
โ”‚ 7 9 5 โ”‚ 4 6 1 โ”‚ 8 3 2 โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ 5 1 9 โ”‚ 2 8 6 โ”‚ 4 7 3 โ”‚
โ”‚ 4 7 2 โ”‚ 3 1 9 โ”‚ 5 6 8 โ”‚
โ”‚ 8 6 3 โ”‚ 7 4 5 โ”‚ 2 1 9 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

```



### Basic Usage

```rust
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);
}
```


## Status

The new implementation follows the design and implementation of [Copper](https://docs.rs/copper/0.1.0/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.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.