{"id":15316263,"url":"https://github.com/charkour/csps","last_synced_at":"2025-04-15T02:20:45.375Z","repository":{"id":48890020,"uuid":"302955229","full_name":"charkour/csps","owner":"charkour","description":"🛠️ Tools to solve constraint satisfaction problems","archived":false,"fork":false,"pushed_at":"2021-07-26T21:15:18.000Z","size":4355,"stargazers_count":8,"open_issues_count":12,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T14:11:09.490Z","etag":null,"topics":["aima","constraint-satisfaction-problems","min-conflicts","typescript"],"latest_commit_sha":null,"homepage":"https://charkour.github.io/csps","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/charkour.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-10T17:29:43.000Z","updated_at":"2024-05-05T08:21:21.000Z","dependencies_parsed_at":"2022-09-16T04:12:10.180Z","dependency_job_id":null,"html_url":"https://github.com/charkour/csps","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charkour%2Fcsps","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charkour%2Fcsps/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charkour%2Fcsps/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charkour%2Fcsps/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/charkour","download_url":"https://codeload.github.com/charkour/csps/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248819389,"owners_count":21166472,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aima","constraint-satisfaction-problems","min-conflicts","typescript"],"created_at":"2024-10-01T08:53:41.145Z","updated_at":"2025-04-15T02:20:45.341Z","avatar_url":"https://github.com/charkour.png","language":"TypeScript","readme":"# csps\n\nTools to solve [constraint satisfaction problems](https://en.wikipedia.org/wiki/Constraint_satisfaction_problem): **C**onstraint **S**atisfaction **P**roblem **S**olvers.\n\n[![npm version](https://img.shields.io/npm/v/csps.svg)](https://www.npmjs.com/package/csps)\n![node \u003e= 10](https://img.shields.io/badge/node-%3E%3D10-blue.svg?cacheSeconds=2592000)\n[![size \u003c 1k](https://img.shields.io/bundlephobia/minzip/csps.svg)](https://www.npmjs.com/package/csps)\n[![build status](https://img.shields.io/github/workflow/status/charkour/csps/CI.svg)](https://github.com/charkour/csps)\n[![zero deps](https://img.shields.io/david/charkour/csps)](https://www.npmjs.com/package/csps)\n[![downloads](https://img.shields.io/npm/dt/csps.svg)](https://www.npmjs.com/package/csps)\n\n\u003e Inspired by [Russell and Norvig's \"Artificial Intelligence - A Modern Approach\" Python code](https://github.com/aimacode/aima-python) and modified under the MIT license.\n\n## Background\n\nA 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).\n\nSome 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.\n\n## Installation and Example Usage\n\ninstall:\n\n```sh\nnpm i csps\n```\n\nindex.ts:\n\n```ts\nimport { CSP, min_conflicts } from \"csps\";\n\n// define the attributes on your variable\ninterface VariableAttributes {\n  // {[key: string]: string}\n}\n\n// Setup your problem\nconst variables = [\n  /* array of strings */\n];\nconst domains = {\n  /* var: possible_attributes (type: VariableAttributes[]) */\n};\nconst neighbors = {\n  /* var: neighbors (type: \u003cstring\u003e[]) */\n};\nconst constraints = (\n  var1: string,\n  var1Attributes: VariableAttributes[],\n  var2: string,\n  var2Attributes: VariableAttributes[],\n): boolean =\u003e {\n  // Return true if same variable.\n  if (var1 === var2) {\n    return true;\n  }\n\n  // more constraints that return false...\n\n  // else, return true\n  return true;\n};\n\nconst aCSP = new CSP\u003cVariableAttributes\u003e(variables, domains, neighbors, constraints);\n\n// run min_conflicts on problem\nconst res = min_conflicts(aCSP);\nconsole.log(res);\n// {\n//   var1: { attr1: 'value1', attr2: 'value1', attr3: 'value1' },\n//   var2: { attr1: 'value2', attr2: 'value2', attr3: 'value2' },\n//   var3: { attr1: 'value3', attr2: 'value3', attr3: 'value3' },\n// } // or something similar.\n```\n\n### Demo\n\nView the [example](https://github.com/charkour/csps/tree/main/example) for more in-depth example code.\n\n## API\n\n### Search Functions\n\nCurrently, Min-conflicts Hill Climbing is the only search function supported.\n\n- [x] Min-conflicts Hill Climbing\n- [ ] AC3\n- [ ] AC3b\n- [ ] AC4\n- [ ] Backtracking\n\nPlease view the [docs](https://charkour.github.io/csps/) to see the full API.\n\n## Contributing\n\nPlease feel free to create issues or make PRs.\n\n## Acknowledgements\n\n- Thank you to Russell and Norvig for their _AIMA_ textbook and code.\n- Thank you to TSDX, TypeDoc, and other open source packages that made this package possible.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharkour%2Fcsps","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcharkour%2Fcsps","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharkour%2Fcsps/lists"}