-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes.js
52 lines (45 loc) · 1.12 KB
/
classes.js
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
48
49
50
51
52
class DirectedWeightedGraph {
constructor() {
this.nodes = new Set()
this.edges = {}
this.inEdges = {}
this.outEdges = {}
}
addNodesFrom(nodes) {
for (let i = 0; i < nodes.length; i++) {
const nodeLabel = nodes[i]
this.nodes.add(nodeLabel)
this.inEdges[nodeLabel] = {}
this.outEdges[nodeLabel] = {}
}
}
addEdgesFrom(edges) {
for (let edgeId in edges) {
const [srcNode, dstNode, weight] = edges[edgeId]
this.edges[edgeId] = edges[edgeId]
this.inEdges[dstNode][srcNode] = edgeId
this.outEdges[srcNode][dstNode] = edgeId
}
}
}
class ReconstructionNode {
constructor(node, parentNode, nodeNo) {
this.node = node
this.parentNode = parentNode
this.nodeNo = nodeNo
this.visited = false
}
}
class NodeGraphic {
constructor(id, x, y, label, radius, heuristic) {
this.id = id
this.x = x
this.y = y
this.label = label
this.r = radius
this.h = heuristic
}
}
let idxNewNode = 0
const getNewNodeId = () => `node${idxNewNode++}`
module.exports = { DirectedWeightedGraph, ReconstructionNode, NodeGraphic, getNewNodeId }