Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

csps

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

csps

Tools to solve constraint satisfaction problems

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

csps

Tools to solve constraint satisfaction problems: Constraint Satisfaction Problem Solvers.

npm version node >= 10 size < 1k build status zero deps

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";

// Setup your problem
const variables = [
  /* array of strings */
];
const domains = {
  /* var: possible_attributes<string>[] */
};
const neighbors = {
  /* var: neighbors<string>[] */
};
const constraints = (
  var1: string,
  var1Attributes: string[],
  var2: string,
  var2Attributes: string[],
): boolean => {
  // Return true if same variable.
  if (var1 === var2) {
    return true;
  }

  // more constraints that return false...

  // else, return true
  return true;
};

const aCSP = new CSP<string>(variables, domains, neighbors, constraints);

// run min_conflicts on problem
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.

  • Min-conflicts Hill Climbing
  • AC3
  • AC3b
  • AC4
  • Backtracking

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.

Keywords

FAQs

Package last updated on 23 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc