bellman = (from, to) => {
const nodesCount = _(graph.nodes).map(n => n['Id epsico']).max()
const dist = new Float32Array(nodesCount)
const pred = new Uint16Array(nodesCount)
const duration = new Float32Array(nodesCount)
for (let i = 0; i < nodesCount; i++) {
dist[i] = Infinity
pred[i] = i
duration[i] = Infinity
}
dist[from] = 0
duration[from] = 0
for (const _node of Object.entries(graph.nodes)) {
for (const edge of graph.edges) {
const edge_duration = edge.longueur * 60 / edge.vmax
if (dist[edge.ido] + edge.longueur < dist[edge.idf]) {
pred[edge.idf] = edge.ido
dist[edge.idf] = dist[edge.ido] + edge.longueur
duration[edge.idf] = duration[edge.ido] + edge_duration
}
if (dist[edge.idf] + edge.longueur < dist[edge.ido]) {
pred[edge.ido] = edge.idf
dist[edge.ido] = dist[edge.idf] + edge.longueur
duration[edge.ido] = duration[edge.idf] + edge_duration
}
}
}
const result = []
let current = to
do {
result.push(current)
current = pred[current]
} while (pred[current] != current)
return {
nodes: result.reverse(),
distance: dist[to],
duration: duration[to],
}
}