-
Notifications
You must be signed in to change notification settings - Fork 0
/
e2-b.js
66 lines (53 loc) · 904 Bytes
/
e2-b.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const dijkstras = require('./dijkstras');
var g = dijkstras.createGraph();
g.addVertex('A', {
B: 6,
D: 5,
G: 8,
});
g.addVertex('B', {
A: 6,
C: 7,
D: 1
});
g.addVertex('C', {
B: 7,
D: 4,
E: 11,
F: 2
});
g.addVertex('D', {
A: 5,
B: 1,
C: 4,
E: 6,
H: 3
});
g.addVertex('E', {
C: 11,
F: 2,
D: 6,
G: 10,
});
g.addVertex('F', {
E: 2,
C: 2,
H: 4,
});
g.addVertex('G', {
A: 8,
E: 10,
H: 2,
});
g.addVertex('H', {
F: 4,
D: 3,
G: 2,
});
// operações
var pathStart = 'A';
var pathEnd = 'F';
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);