Skip to content

Commit b2d8153

Browse files
committed
update documentation
1 parent 4e5bb85 commit b2d8153

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

README.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
Tools to solve [constraint satisfaction problems](https://en.wikipedia.org/wiki/Constraint_satisfaction_problem): **C**onstraint **S**atisfaction **P**roblem **S**olvers.
44

5-
<a href="https://www.npmjs.com/package/csps"><img src="https://img.shields.io/npm/v/csps.svg" alt="npm version"></a>
6-
<a href="" disabled><img src="https://img.shields.io/badge/node-%3E%3D10-blue.svg?cacheSeconds=2592000" alt="node >= 10"></a>
7-
<a href="https://www.npmjs.com/package/csps"><img src="https://img.shields.io/bundlephobia/minzip/csps.svg" alt="size < 1k"></a>
8-
<a href="https://github.com/charkour/csps"><img src="https://img.shields.io/github/workflow/status/charkour/csps/CI.svg" alt="build status"></a>
9-
<a href="https://www.npmjs.com/package/csps"><img src="https://img.shields.io/david/charkour/csps" alt="zero deps"></a>
10-
[![Downloads](https://img.shields.io/npm/dt/csps.svg)](https://www.npmjs.com/package/csps)
5+
[![npm version](https://img.shields.io/npm/v/csps.svg)](https://www.npmjs.com/package/csps)
6+
![node >= 10](https://img.shields.io/badge/node-%3E%3D10-blue.svg?cacheSeconds=2592000)
7+
[![size < 1k](https://img.shields.io/bundlephobia/minzip/csps.svg)](https://www.npmjs.com/package/csps)
8+
[![build status](https://img.shields.io/github/workflow/status/charkour/csps/CI.svg)](https://github.com/charkour/csps)
9+
[![zero deps](https://img.shields.io/david/charkour/csps)](https://www.npmjs.com/package/csps)
10+
[![downloads](https://img.shields.io/npm/dt/csps.svg)](https://www.npmjs.com/package/csps)
1111

1212
> 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.
1313
@@ -30,21 +30,26 @@ index.ts:
3030
```ts
3131
import { CSP, min_conflicts } from "csps";
3232

33+
// define the attributes on your variable
34+
interface VariableAttributes {
35+
// {[key: string]: string}
36+
}
37+
3338
// Setup your problem
3439
const variables = [
3540
/* array of strings */
3641
];
3742
const domains = {
38-
/* var: possible_attributes<string>[] */
43+
/* var: possible_attributes (type: VariableAttributes[]) */
3944
};
4045
const neighbors = {
41-
/* var: neighbors<string>[] */
46+
/* var: neighbors (type: <string>[]) */
4247
};
4348
const constraints = (
4449
var1: string,
45-
var1Attributes: string[],
50+
var1Attributes: VariableAttributes[],
4651
var2: string,
47-
var2Attributes: string[],
52+
var2Attributes: VariableAttributes[],
4853
): boolean => {
4954
// Return true if same variable.
5055
if (var1 === var2) {
@@ -57,11 +62,16 @@ const constraints = (
5762
return true;
5863
};
5964

60-
const aCSP = new CSP<string>(variables, domains, neighbors, constraints);
65+
const aCSP = new CSP<VariableAttributes>(variables, domains, neighbors, constraints);
6166

6267
// run min_conflicts on problem
6368
const res = min_conflicts(aCSP);
6469
console.log(res);
70+
// {
71+
// var1: { attr1: 'value1', attr2: 'value1', attr3: 'value1' },
72+
// var2: { attr1: 'value2', attr2: 'value2', attr3: 'value2' },
73+
// var3: { attr1: 'value3', attr2: 'value3', attr3: 'value3' },
74+
// } // or something similar.
6575
```
6676

6777
### Demo

test/test_helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const constraints = (
5151
): boolean => {
5252
/*
5353
Constraints for class scheduling
54-
c1 and c2 are tuples in the form (time, room, faculty)
54+
c1 and c2 are objects in the form {time, room, faculty}
5555
returns true if constraints are met.
5656
The constraint that there is only one section of class
5757
is implicit because classes are variables.

0 commit comments

Comments
 (0)