-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
30 lines (24 loc) · 1005 Bytes
/
index.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
const { DirectedWeightedGraph } = require('./classes')
const { rbfs } = require('./rbfs')
const { nodes, edges, selectedStart, selectedGoals } = require('./data')
let dwg = new DirectedWeightedGraph()
let idxNewEdge = 0
const getNewEdgeId = () => `edge${idxNewEdge++}`
let nodeData = nodes
let edgesWithoutId = edges
let edgeList = {}
edgesWithoutId.forEach(edge => edgeList[getNewEdgeId()] = edge)
function getHeuristicScores() {
let h = {}
Object.values(nodeData).forEach(drawnNodeObj => h[drawnNodeObj.label] = drawnNodeObj.h)
return h
}
function StartRBFS() {
dwg.addNodesFrom(Object.keys(nodeData))
dwg.addEdgesFrom(edgeList)
rbfs(dwg, selectedStart, selectedGoals, getHeuristicScores(), 5)
const startNode = selectedStart == null ? "<NO START>" : `'${selectedStart}'`
const goalNodes = selectedGoals.size == 0 ? "<NO GOAL>" : `{${Array.from(selectedGoals).map(n => `'${n}'`).join(", ")}}`
console.log("From " + startNode + " to " + goalNodes)
}
StartRBFS()