-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
56 lines (43 loc) · 795 Bytes
/
test.js
File metadata and controls
56 lines (43 loc) · 795 Bytes
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
53
54
55
56
const dijkstras = require('./dijkstras');
var g = dijkstras.createGraph();
g.addVertex('A', {
B: 7,
C: 8
});
g.addVertex('B', {
A: 7,
F: 2
});
g.addVertex('C', {
A: 8,
F: 6,
G: 4
});
g.addVertex('D', {
F: 8
});
g.addVertex('E', {
H: 1
});
g.addVertex('F', {
B: 2,
C: 6,
D: 8,
G: 9,
H: 3
});
g.addVertex('G', {
C: 4,
F: 9
});
g.addVertex('H', {
E: 1,
F: 3
});
// operações
var pathStart = 'A';
var pathEnd = 'H';
var shortestPath = g.shortestPath(pathStart, pathEnd);
var distance = g.calcDistance(shortestPath);
console.log('Caminho mais curto de ' + pathStart + ' à ' + pathEnd + ': [ ' + shortestPath.toString().replace(/\,/g, ' => ') + ' ]');
console.log('A distância/peso do caminho é: ' + distance);