Skip to content
Just-HelpfulPublic

About

Rust based generic constraint solving

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

184 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arc3 Constraint Solving

Crate documentation Github homepage Package version Package version

A semi-generic approach to solving Constraint Satisfaction Problems,
with the possibility to optimise based on the implementation of Constraints.

The primary exports of this crate are:

  • System for generic constraint solving
  • the Assignment trait for assigning values to variables
  • the Constraint trait for constraining the values variables can take
  • the Heuristic trait for deciding search order for constraint solving

There's also some common variants of constraints:

  • DiscreteConstraint that covers most forms of discrete constraints
  • MineConstraint that can be used for minesweeper mine solving

Examples

use std::collections::HashSet;
use farc3::prelude::*;

// Construct the two mine constraints:
// 1. 2 mines among tiles 0, 1 and 2
// 2. 1 mine among tiles 1 and 2
let constraint_0 = MineConstraint::new([0, 1, 2], 2);
let constraint_1 = MineConstraint::new([1, 2], 1);

// Construct the constraint system from these 2 constraints
let mut sys = System::from([
  constraint_0,
  constraint_1
]);

// Find all solutions to the system
let sltns: HashSet<_> = sys.solve().collect();

// All solutions should mark tile 0 as a mine
// as only one of 1 and 2 can be a mine
assert_eq!(
  sltns,
  HashSet::from([
    MineAssignment::new(/*safe*/ [1], /*mines*/ [2, 0]),
    MineAssignment::new(/*safe*/ [2], /*mines*/ [1, 0]),
  ])
);

About

Rust based generic constraint solving

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages