-
Notifications
You must be signed in to change notification settings - Fork 77
/
Graph.ts
48 lines (33 loc) · 1.55 KB
/
Graph.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/********************************************************************************
** Graph
This module contains types for generic graphs.
You should not edit this file.
********************************************************************************/
// An edge in a directed weighted graph
export class Successor<Node> {
action : string;
child : Node;
cost : number;
}
// The minimal interface for a directed weighted graph
export interface Graph<Node> {
successors(node : Node) : Successor<Node>[];
compareNodes : CompareFunction<Node>;
}
// Comparing two elements:
// if a<b then the result should be <0, if a>b then the result should be >0
export interface CompareFunction<T> {
(a: T, b: T): number;
}
// The class for search results: this is what the function 'aStarSearch' should return
// If the search fails: 'status' should be 'failure' or 'timeout'; 'path' should be [] and 'cost' should be negative
// If the search succeeds: 'status' should be 'success'; 'path' should include the goal node, but not the start node
// Note: 'visited' should count all nodes that have been added to the frontier, not only the size of the frontier at return time
export class SearchResult<Node> {
constructor(
public status : 'success' | 'failure' | 'timeout',
public path : Successor<Node>[], // the path found by the search algorithm
public cost : number, // the total cost of the path
public visited : number, // the total number of nodes that have been added to the frontier
) {};
}