csps
Tools to solve constraint satisfaction problems: Constraint Satisfaction Problem Solvers.
Inspired by Russell and Norvig's "Artificial Intelligence - A Modern Approach" Python code and modified under the MIT license.
Background
A CSP is a specific type of problem that is represented by states and a goal state. The factored representation of each problem state consists of a set of variables and a value (set of attributes) for each. The problem is considered solve, when all values for each variable satisfy all constraints (Russell, Norvig 2010).
Some example of CSPs would be Sudoku, crosswords, scheduling, map-coloring, n-queens, zebra puzzle, and many others. The tools in this csps
package help setup and solve CSPs.
Installation and Example Usage
install:
npm i csps
index.ts:
import { CSP, min_conflicts } from "csps";
interface VariableAttributes {
}
const variables = [
];
const domains = {
};
const neighbors = {
};
const constraints = (
var1: string,
var1Attributes: VariableAttributes[],
var2: string,
var2Attributes: VariableAttributes[],
): boolean => {
if (var1 === var2) {
return true;
}
return true;
};
const aCSP = new CSP<VariableAttributes>(variables, domains, neighbors, constraints);
const res = min_conflicts(aCSP);
console.log(res);
Demo
View the example for more in-depth example code.
API
Search Functions
Currently, Min-conflicts Hill Climbing is the only search function supported.
Please view the docs to see the full API.
Contributing
Please feel free to create issues or make PRs.
Acknowledgements
- Thank you to Russell and Norvig for their AIMA textbook and code.
- Thank you to TSDX, TypeDoc, and other open source packages that made this package possible.