Comparing version 1.0.5 to 2.0.0
@@ -1,2 +0,2 @@ | ||
import { LooseObject } from "./interfaces"; | ||
import { CurrentDomain, LooseObject, Variable } from "./interfaces"; | ||
import { Problem } from "./search"; | ||
@@ -41,11 +41,11 @@ /** | ||
* @class CSP | ||
* @extends {Problem<T[]>} | ||
* @template T | ||
* @extends {Problem<Variable[]>} | ||
* @template TAttributes extends object | ||
*/ | ||
export declare class CSP<T extends string> extends Problem<T[]> { | ||
variables: T[]; | ||
domains: LooseObject<T[][]>; | ||
neighbors: LooseObject<T[]>; | ||
constraints: (c1: T, c1Attr: T[], c2: T, c2Attr: T[]) => boolean; | ||
curr_domains: LooseObject<T[][]> | undefined; | ||
export declare class CSP<TAttributes extends object> extends Problem<Variable[]> { | ||
variables: Variable[]; | ||
domains: LooseObject<TAttributes[]>; | ||
neighbors: LooseObject<Variable[]>; | ||
constraints: (c1: Variable, c1Attr: TAttributes, c2: Variable, c2Attr: TAttributes) => boolean; | ||
curr_domains: CurrentDomain<TAttributes> | undefined; | ||
nassigns: number; | ||
@@ -55,11 +55,18 @@ /** | ||
* | ||
* @param {(T[] | undefined)} variables | ||
* @param {LooseObject<T[][]>} domains | ||
* @param {LooseObject<T[]>} neighbors | ||
* @param {(c1: T, c1Attr: T[], c2: T, c2Attr: T[]) => boolean} constraints | ||
* @param {(Variable[] | undefined)} variables | ||
* @param {LooseObject<TAttributes[]>} domains | ||
* @param {LooseObject<Variable[]>} neighbors | ||
* @param {(c1: Variable, c1Attr: TAttributes, c2: Variable, c2Attr: TAttributes) => boolean} constraints | ||
* @memberof CSP | ||
*/ | ||
constructor(variables: T[] | undefined, domains: LooseObject<T[][]>, neighbors: LooseObject<T[]>, constraints: (c1: T, c1Attr: T[], c2: T, c2Attr: T[]) => boolean); | ||
assign: (variable: T, val: T[], assignment: LooseObject<T[]>) => void; | ||
constructor(variables: Variable[] | undefined, domains: LooseObject<TAttributes[]>, neighbors: LooseObject<Variable[]>, constraints: (c1: Variable, c1Attr: TAttributes, c2: Variable, c2Attr: TAttributes) => boolean); | ||
/** | ||
* Add {var: val} to assignment; Discard the old value if any. | ||
* | ||
* @param {Variable} variable | ||
* @param {TAttributes} val | ||
* @param {CurrentDomain<TAttributes>} assignment | ||
*/ | ||
assign: (variable: Variable, val: TAttributes, assignment: CurrentDomain<TAttributes>) => void; | ||
/** | ||
* Remove {var: val} from assignment. | ||
@@ -69,16 +76,16 @@ * DO NOT call this if you are changing a variable to a new value; | ||
* | ||
* @param {T} variable | ||
* @param {LooseObject<T[]>} assignment | ||
* @param {Variable} variable | ||
* @param {CurrentDomain<TAttributes>} assignment | ||
* @memberof CSP | ||
*/ | ||
unassign: (variable: T, assignment: LooseObject<T[]>) => void; | ||
unassign: (variable: Variable, assignment: CurrentDomain<TAttributes>) => void; | ||
/** | ||
* Return the number of conflicts var=val has with other variables. | ||
* | ||
* @param {T} variable | ||
* @param {T[]} val | ||
* @param {LooseObject<T[]>} assignment | ||
* @param {Variable} variable | ||
* @param {TAttributes} val | ||
* @param {CurrentDomain<TAttributes>} assignment | ||
* @memberof CSP | ||
*/ | ||
nconflicts: (variable: T, val: T[], assignment: LooseObject<T[]>) => number; | ||
nconflicts: (variable: Variable, val: TAttributes, assignment: CurrentDomain<TAttributes>) => number; | ||
/** | ||
@@ -88,6 +95,6 @@ * Show a human-readable representation of the CSP. | ||
* | ||
* @param {LooseObject<T[]>} assignment | ||
* @param {CurrentDomain<TAttributes>} assignment | ||
* @memberof CSP | ||
*/ | ||
display: (assignment: LooseObject<T[]>) => void; | ||
display: (assignment: CurrentDomain<TAttributes>) => void; | ||
/** | ||
@@ -97,6 +104,6 @@ * Return a list of variables in current assignment that are in conflict | ||
* | ||
* @param {LooseObject<T[]>} current | ||
* @param {CurrentDomain<TAttributes>>} current | ||
* @memberof CSP | ||
*/ | ||
conflicted_vars: (current: LooseObject<T[]>) => T[]; | ||
conflicted_vars: (current: CurrentDomain<TAttributes>) => string[]; | ||
} |
@@ -120,4 +120,2 @@ 'use strict'; | ||
// Once the attributes is separated into it's own object type. | ||
/** | ||
@@ -161,4 +159,4 @@ * This class describes finite-domain Constraint Satisfaction Problems. | ||
* @class CSP | ||
* @extends {Problem<T[]>} | ||
* @template T | ||
* @extends {Problem<Variable[]>} | ||
* @template TAttributes extends object | ||
*/ | ||
@@ -172,6 +170,6 @@ | ||
* | ||
* @param {(T[] | undefined)} variables | ||
* @param {LooseObject<T[][]>} domains | ||
* @param {LooseObject<T[]>} neighbors | ||
* @param {(c1: T, c1Attr: T[], c2: T, c2Attr: T[]) => boolean} constraints | ||
* @param {(Variable[] | undefined)} variables | ||
* @param {LooseObject<TAttributes[]>} domains | ||
* @param {LooseObject<Variable[]>} neighbors | ||
* @param {(c1: Variable, c1Attr: TAttributes, c2: Variable, c2Attr: TAttributes) => boolean} constraints | ||
* @memberof CSP | ||
@@ -184,3 +182,9 @@ */ | ||
_this = _Problem.call(this, []) || this; | ||
/* Add {var: val} to assignment; Discard the old value if any.*/ | ||
/** | ||
* Add {var: val} to assignment; Discard the old value if any. | ||
* | ||
* @param {Variable} variable | ||
* @param {TAttributes} val | ||
* @param {CurrentDomain<TAttributes>} assignment | ||
*/ | ||
@@ -196,4 +200,4 @@ _this.assign = function (variable, val, assignment) { | ||
* | ||
* @param {T} variable | ||
* @param {LooseObject<T[]>} assignment | ||
* @param {Variable} variable | ||
* @param {CurrentDomain<TAttributes>} assignment | ||
* @memberof CSP | ||
@@ -211,5 +215,5 @@ */ | ||
* | ||
* @param {T} variable | ||
* @param {T[]} val | ||
* @param {LooseObject<T[]>} assignment | ||
* @param {Variable} variable | ||
* @param {TAttributes} val | ||
* @param {CurrentDomain<TAttributes>} assignment | ||
* @memberof CSP | ||
@@ -223,3 +227,3 @@ */ | ||
* | ||
* @param {T} var2 | ||
* @param {Variable} var2 | ||
* @return {*} {boolean} | ||
@@ -239,3 +243,3 @@ */ | ||
* | ||
* @param {LooseObject<T[]>} assignment | ||
* @param {CurrentDomain<TAttributes>} assignment | ||
* @memberof CSP | ||
@@ -252,3 +256,3 @@ */ | ||
* | ||
* @param {LooseObject<T[]>} current | ||
* @param {CurrentDomain<TAttributes>>} current | ||
* @memberof CSP | ||
@@ -310,4 +314,4 @@ */ | ||
* | ||
* @param {any} val | ||
* @returns any | ||
* @param {T} val | ||
* @returns T | ||
*/ | ||
@@ -342,5 +346,5 @@ | ||
* | ||
* @param {CSP<T>} aCSP | ||
* @param {CSP<TAttributes>} aCSP | ||
* @param {number=100000} max_steps | ||
* @returns LooseObject | ||
* @returns CurrentDomain<TAttributes> | undefined | ||
*/ | ||
@@ -371,2 +375,3 @@ | ||
} // If no solution can be found. | ||
// TODO: update this to return the schedule with conflicts. | ||
@@ -380,6 +385,6 @@ | ||
* | ||
* @param {CSP<T>} aCSP | ||
* @param {T} variable | ||
* @param {LooseObject<T[]>} current | ||
* @returns T | ||
* @param {CSP<TAttributes>} aCSP | ||
* @param {Variable} variable | ||
* @param {CurrentDomain<TAttributes>} current | ||
* @returns TAttributes | ||
*/ | ||
@@ -386,0 +391,0 @@ |
@@ -116,4 +116,2 @@ function _inheritsLoose(subClass, superClass) { | ||
// Once the attributes is separated into it's own object type. | ||
/** | ||
@@ -157,4 +155,4 @@ * This class describes finite-domain Constraint Satisfaction Problems. | ||
* @class CSP | ||
* @extends {Problem<T[]>} | ||
* @template T | ||
* @extends {Problem<Variable[]>} | ||
* @template TAttributes extends object | ||
*/ | ||
@@ -168,6 +166,6 @@ | ||
* | ||
* @param {(T[] | undefined)} variables | ||
* @param {LooseObject<T[][]>} domains | ||
* @param {LooseObject<T[]>} neighbors | ||
* @param {(c1: T, c1Attr: T[], c2: T, c2Attr: T[]) => boolean} constraints | ||
* @param {(Variable[] | undefined)} variables | ||
* @param {LooseObject<TAttributes[]>} domains | ||
* @param {LooseObject<Variable[]>} neighbors | ||
* @param {(c1: Variable, c1Attr: TAttributes, c2: Variable, c2Attr: TAttributes) => boolean} constraints | ||
* @memberof CSP | ||
@@ -180,3 +178,9 @@ */ | ||
_this = _Problem.call(this, []) || this; | ||
/* Add {var: val} to assignment; Discard the old value if any.*/ | ||
/** | ||
* Add {var: val} to assignment; Discard the old value if any. | ||
* | ||
* @param {Variable} variable | ||
* @param {TAttributes} val | ||
* @param {CurrentDomain<TAttributes>} assignment | ||
*/ | ||
@@ -192,4 +196,4 @@ _this.assign = function (variable, val, assignment) { | ||
* | ||
* @param {T} variable | ||
* @param {LooseObject<T[]>} assignment | ||
* @param {Variable} variable | ||
* @param {CurrentDomain<TAttributes>} assignment | ||
* @memberof CSP | ||
@@ -207,5 +211,5 @@ */ | ||
* | ||
* @param {T} variable | ||
* @param {T[]} val | ||
* @param {LooseObject<T[]>} assignment | ||
* @param {Variable} variable | ||
* @param {TAttributes} val | ||
* @param {CurrentDomain<TAttributes>} assignment | ||
* @memberof CSP | ||
@@ -219,3 +223,3 @@ */ | ||
* | ||
* @param {T} var2 | ||
* @param {Variable} var2 | ||
* @return {*} {boolean} | ||
@@ -235,3 +239,3 @@ */ | ||
* | ||
* @param {LooseObject<T[]>} assignment | ||
* @param {CurrentDomain<TAttributes>} assignment | ||
* @memberof CSP | ||
@@ -248,3 +252,3 @@ */ | ||
* | ||
* @param {LooseObject<T[]>} current | ||
* @param {CurrentDomain<TAttributes>>} current | ||
* @memberof CSP | ||
@@ -306,4 +310,4 @@ */ | ||
* | ||
* @param {any} val | ||
* @returns any | ||
* @param {T} val | ||
* @returns T | ||
*/ | ||
@@ -338,5 +342,5 @@ | ||
* | ||
* @param {CSP<T>} aCSP | ||
* @param {CSP<TAttributes>} aCSP | ||
* @param {number=100000} max_steps | ||
* @returns LooseObject | ||
* @returns CurrentDomain<TAttributes> | undefined | ||
*/ | ||
@@ -367,2 +371,3 @@ | ||
} // If no solution can be found. | ||
// TODO: update this to return the schedule with conflicts. | ||
@@ -376,6 +381,6 @@ | ||
* | ||
* @param {CSP<T>} aCSP | ||
* @param {T} variable | ||
* @param {LooseObject<T[]>} current | ||
* @returns T | ||
* @param {CSP<TAttributes>} aCSP | ||
* @param {Variable} variable | ||
* @param {CurrentDomain<TAttributes>} current | ||
* @returns TAttributes | ||
*/ | ||
@@ -382,0 +387,0 @@ |
@@ -13,1 +13,5 @@ /** | ||
} | ||
/** Type alias for Variable */ | ||
export declare type Variable = string; | ||
/** Type alias for the current domain */ | ||
export declare type CurrentDomain<T> = LooseObject<T>; |
import { CSP } from "./csp"; | ||
import { LooseObject } from "./interfaces"; | ||
import { CurrentDomain, Variable } from "./interfaces"; | ||
/** | ||
* Solve a CSP by stochastic hill-climbing on the number of conflicts. | ||
* | ||
* @param {CSP<T>} aCSP | ||
* @param {CSP<TAttributes>} aCSP | ||
* @param {number=100000} max_steps | ||
* @returns LooseObject | ||
* @returns CurrentDomain<TAttributes> | undefined | ||
*/ | ||
export declare const min_conflicts: <T extends string>(aCSP: CSP<T>, max_steps?: number) => LooseObject<T[]> | undefined; | ||
export declare const min_conflicts: <TAttributes extends object>(aCSP: CSP<TAttributes>, max_steps?: number) => CurrentDomain<TAttributes> | undefined; | ||
/** | ||
@@ -15,7 +15,7 @@ * Return the value that will give var the least number of conflicts. | ||
* | ||
* @param {CSP<T>} aCSP | ||
* @param {T} variable | ||
* @param {LooseObject<T[]>} current | ||
* @returns T | ||
* @param {CSP<TAttributes>} aCSP | ||
* @param {Variable} variable | ||
* @param {CurrentDomain<TAttributes>} current | ||
* @returns TAttributes | ||
*/ | ||
export declare const min_conflicts_value: <T extends string>(aCSP: CSP<T>, variable: T, current: LooseObject<T[]>) => T[]; | ||
export declare const min_conflicts_value: <TAttributes extends object>(aCSP: CSP<TAttributes>, variable: Variable, current: CurrentDomain<TAttributes>) => TAttributes; |
@@ -21,6 +21,6 @@ /** | ||
* | ||
* @param {any} val | ||
* @returns any | ||
* @param {T} val | ||
* @returns T | ||
*/ | ||
export declare const identity: (val: any) => any; | ||
export declare const identity: <T>(val: T) => T; | ||
/** | ||
@@ -27,0 +27,0 @@ * Return a minimum element of seq; break ties at random. |
@@ -7,3 +7,3 @@ { | ||
"description": "Tools to solve constraint satisfaction problems", | ||
"version": "1.0.5", | ||
"version": "2.0.0", | ||
"license": "MIT", | ||
@@ -60,14 +60,14 @@ "keywords": [ | ||
"devDependencies": { | ||
"@size-limit/preset-small-lib": "^4.9.1", | ||
"@types/jest": "26.0.19", | ||
"@types/seedrandom": "2.4.28", | ||
"@size-limit/preset-small-lib": "4.10.1", | ||
"@types/jest": "26.0.21", | ||
"@types/seedrandom": "2.4.29", | ||
"eledoc": "0.2.1", | ||
"husky": "^4.3.6", | ||
"husky": "4.3.8", | ||
"seedrandom": "3.0.5", | ||
"size-limit": "^4.9.1", | ||
"tsdx": "^0.14.1", | ||
"tslib": "^2.0.3", | ||
"typedoc": "0.20.14", | ||
"typescript": "^4.1.3" | ||
"size-limit": "4.10.1", | ||
"tsdx": "0.14.1", | ||
"tslib": "2.1.0", | ||
"typedoc": "0.20.33", | ||
"typescript": "4.2.3" | ||
} | ||
} |
@@ -9,2 +9,3 @@ # csps | ||
<a href="https://github.com/charkour/csps"><img src="https://img.shields.io/github/workflow/status/charkour/csps/CI.svg" alt="build status"></a> | ||
<a href="https://www.npmjs.com/package/csps"><img src="https://img.shields.io/david/charkour/csps" alt="zero deps"></a> | ||
@@ -91,2 +92,2 @@ > 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. | ||
- Thank you to Russell and Norvig for their _AIMA_ textbook and code. | ||
- Thanks you to TSDX, TypeDoc and other open source packages that made this package possible. | ||
- Thank you to TSDX, TypeDoc, and other open source packages that made this package possible. |
@@ -1,7 +0,4 @@ | ||
import { LooseObject } from "./interfaces"; | ||
import { CurrentDomain, LooseObject, Variable } from "./interfaces"; | ||
import { Problem } from "./search"; | ||
// TODO: Will probably need to separate the T generic param into multiple different ones. | ||
// Once the attributes is separated into it's own object type. | ||
/** | ||
@@ -45,11 +42,11 @@ * This class describes finite-domain Constraint Satisfaction Problems. | ||
* @class CSP | ||
* @extends {Problem<T[]>} | ||
* @template T | ||
* @extends {Problem<Variable[]>} | ||
* @template TAttributes extends object | ||
*/ | ||
export class CSP<T extends string> extends Problem<T[]> { | ||
variables: T[]; | ||
domains: LooseObject<T[][]>; | ||
neighbors: LooseObject<T[]>; | ||
constraints: (c1: T, c1Attr: T[], c2: T, c2Attr: T[]) => boolean; | ||
curr_domains: LooseObject<T[][]> | undefined; | ||
export class CSP<TAttributes extends object> extends Problem<Variable[]> { | ||
variables: Variable[]; | ||
domains: LooseObject<TAttributes[]>; | ||
neighbors: LooseObject<Variable[]>; | ||
constraints: (c1: Variable, c1Attr: TAttributes, c2: Variable, c2Attr: TAttributes) => boolean; | ||
curr_domains: CurrentDomain<TAttributes> | undefined; | ||
nassigns: number; | ||
@@ -60,13 +57,13 @@ | ||
* | ||
* @param {(T[] | undefined)} variables | ||
* @param {LooseObject<T[][]>} domains | ||
* @param {LooseObject<T[]>} neighbors | ||
* @param {(c1: T, c1Attr: T[], c2: T, c2Attr: T[]) => boolean} constraints | ||
* @param {(Variable[] | undefined)} variables | ||
* @param {LooseObject<TAttributes[]>} domains | ||
* @param {LooseObject<Variable[]>} neighbors | ||
* @param {(c1: Variable, c1Attr: TAttributes, c2: Variable, c2Attr: TAttributes) => boolean} constraints | ||
* @memberof CSP | ||
*/ | ||
constructor( | ||
variables: T[] | undefined, | ||
domains: LooseObject<T[][]>, | ||
neighbors: LooseObject<T[]>, | ||
constraints: (c1: T, c1Attr: T[], c2: T, c2Attr: T[]) => boolean, | ||
variables: Variable[] | undefined, | ||
domains: LooseObject<TAttributes[]>, | ||
neighbors: LooseObject<Variable[]>, | ||
constraints: (c1: Variable, c1Attr: TAttributes, c2: Variable, c2Attr: TAttributes) => boolean, | ||
) { | ||
@@ -76,3 +73,3 @@ // const initial: any = []; | ||
this.variables = variables || (Object.keys(domains) as T[]); | ||
this.variables = variables || Object.keys(domains); | ||
this.domains = domains; | ||
@@ -85,4 +82,10 @@ this.neighbors = neighbors; | ||
/* Add {var: val} to assignment; Discard the old value if any.*/ | ||
assign = (variable: T, val: T[], assignment: LooseObject<T[]>) => { | ||
/** | ||
* Add {var: val} to assignment; Discard the old value if any. | ||
* | ||
* @param {Variable} variable | ||
* @param {TAttributes} val | ||
* @param {CurrentDomain<TAttributes>} assignment | ||
*/ | ||
assign = (variable: Variable, val: TAttributes, assignment: CurrentDomain<TAttributes>) => { | ||
assignment[variable] = val; | ||
@@ -97,7 +100,7 @@ this.nassigns += 1; | ||
* | ||
* @param {T} variable | ||
* @param {LooseObject<T[]>} assignment | ||
* @param {Variable} variable | ||
* @param {CurrentDomain<TAttributes>} assignment | ||
* @memberof CSP | ||
*/ | ||
unassign = (variable: T, assignment: LooseObject<T[]>) => { | ||
unassign = (variable: Variable, assignment: CurrentDomain<TAttributes>) => { | ||
if (assignment.hasOwnProperty(variable)) { | ||
@@ -111,15 +114,19 @@ delete assignment[variable]; | ||
* | ||
* @param {T} variable | ||
* @param {T[]} val | ||
* @param {LooseObject<T[]>} assignment | ||
* @param {Variable} variable | ||
* @param {TAttributes} val | ||
* @param {CurrentDomain<TAttributes>} assignment | ||
* @memberof CSP | ||
*/ | ||
nconflicts = (variable: T, val: T[], assignment: LooseObject<T[]>): number => { | ||
nconflicts = ( | ||
variable: Variable, | ||
val: TAttributes, | ||
assignment: CurrentDomain<TAttributes>, | ||
): number => { | ||
/** | ||
* Subclasses may implement this (conflict function) more efficiently | ||
* | ||
* @param {T} var2 | ||
* @param {Variable} var2 | ||
* @return {*} {boolean} | ||
*/ | ||
const conflict = (var2: T): boolean => { | ||
const conflict = (var2: Variable): boolean => { | ||
return ( | ||
@@ -130,3 +137,3 @@ assignment.hasOwnProperty(var2) && !this.constraints(variable, val, var2, assignment[var2]) | ||
return Object.keys(this.neighbors).filter((v: string) => conflict(v as T)).length; | ||
return Object.keys(this.neighbors).filter((v: string) => conflict(v)).length; | ||
}; | ||
@@ -138,6 +145,6 @@ | ||
* | ||
* @param {LooseObject<T[]>} assignment | ||
* @param {CurrentDomain<TAttributes>} assignment | ||
* @memberof CSP | ||
*/ | ||
display = (assignment: LooseObject<T[]>) => { | ||
display = (assignment: CurrentDomain<TAttributes>) => { | ||
console.log(assignment); | ||
@@ -150,7 +157,7 @@ }; | ||
* | ||
* @param {LooseObject<T[]>} current | ||
* @param {CurrentDomain<TAttributes>>} current | ||
* @memberof CSP | ||
*/ | ||
conflicted_vars = (current: LooseObject<T[]>) => { | ||
return this.variables.filter((variable: T) => { | ||
conflicted_vars = (current: CurrentDomain<TAttributes>) => { | ||
return this.variables.filter((variable: Variable) => { | ||
return this.nconflicts(variable, current[variable], current) > 0; | ||
@@ -157,0 +164,0 @@ }); |
@@ -13,1 +13,7 @@ /** | ||
} | ||
/** Type alias for Variable */ | ||
export type Variable = string; | ||
/** Type alias for the current domain */ | ||
export type CurrentDomain<T> = LooseObject<T>; |
/* Min-conflicts hill-climbing search for CSPs functions */ | ||
import { CSP } from "./csp"; | ||
import { LooseObject } from "./interfaces"; | ||
import { CurrentDomain, Variable } from "./interfaces"; | ||
import { argmin_random_tie, random_choice } from "./utils"; | ||
@@ -10,15 +10,15 @@ | ||
* | ||
* @param {CSP<T>} aCSP | ||
* @param {CSP<TAttributes>} aCSP | ||
* @param {number=100000} max_steps | ||
* @returns LooseObject | ||
* @returns CurrentDomain<TAttributes> | undefined | ||
*/ | ||
export const min_conflicts = <T extends string>( | ||
aCSP: CSP<T>, | ||
export const min_conflicts = <TAttributes extends object>( | ||
aCSP: CSP<TAttributes>, | ||
max_steps: number = 100000, | ||
): LooseObject<T[]> | undefined => { | ||
): CurrentDomain<TAttributes> | undefined => { | ||
// Generate a complete assignment for all variables (probably with conflicts) | ||
let current: LooseObject<T[]> = {}; | ||
let current: CurrentDomain<TAttributes> = {}; | ||
aCSP.variables.forEach(variable => { | ||
const val = min_conflicts_value<T>(aCSP, variable as T, current); | ||
aCSP.assign(variable as T, val, current); | ||
const val = min_conflicts_value<TAttributes>(aCSP, variable, current); | ||
aCSP.assign(variable, val, current); | ||
}); | ||
@@ -37,2 +37,3 @@ | ||
// If no solution can be found. | ||
// TODO: update this to return the schedule with conflicts. | ||
return undefined; | ||
@@ -45,14 +46,14 @@ }; | ||
* | ||
* @param {CSP<T>} aCSP | ||
* @param {T} variable | ||
* @param {LooseObject<T[]>} current | ||
* @returns T | ||
* @param {CSP<TAttributes>} aCSP | ||
* @param {Variable} variable | ||
* @param {CurrentDomain<TAttributes>} current | ||
* @returns TAttributes | ||
*/ | ||
export const min_conflicts_value = <T extends string>( | ||
aCSP: CSP<T>, | ||
variable: T, | ||
current: LooseObject<T[]>, | ||
): T[] => { | ||
const num_conflicts = (val: T[]) => aCSP.nconflicts(variable, val, current); | ||
export const min_conflicts_value = <TAttributes extends object>( | ||
aCSP: CSP<TAttributes>, | ||
variable: Variable, | ||
current: CurrentDomain<TAttributes>, | ||
): TAttributes => { | ||
const num_conflicts = (val: TAttributes) => aCSP.nconflicts(variable, val, current); | ||
return argmin_random_tie(aCSP.domains[variable], num_conflicts); | ||
}; |
@@ -32,6 +32,6 @@ /** | ||
* | ||
* @param {any} val | ||
* @returns any | ||
* @param {T} val | ||
* @returns T | ||
*/ | ||
export const identity = (val: any): any => val; | ||
export const identity = <T>(val: T): T => val; | ||
@@ -38,0 +38,0 @@ /** |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
104156
1298
92