Published
Edited
Dec 21, 2019
1 star
Insert cell
Insert cell
Insert cell
Insert cell
{
if(route) {
return route.canvas
}
}
Insert cell
parsed = {
const from = Number(paramètres.departId)
const to = Number(paramètres.arriveId)
return {
from,
to,
}
}
Insert cell
route = {
const from = Number(paramètres.departId)
const to = Number(paramètres.arriveId)
const route = bellman(from, to)
if (from && to) {
return {
canvas: drawPath(route.nodes).canvas,
route,
}
}
}
Insert cell
result = Object()
Insert cell
paramètres
Insert cell
Insert cell
Insert cell
d3 = require("d3-dsv@1")
Insert cell
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
}
// Edges are symetrical
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],
}
}
Insert cell
drawPath = path => {
const context = backgroundMap()
context.beginPath();
let node = graph.nodes[path[0]]
let coord = graph.proj(node.RGI_XX, node.RGI_YY, width)
context.moveTo(coord.x, coord.y)
for (const n of path) {
const node = graph.nodes[n]
const coord = graph.proj(node.RGI_XX, node.RGI_YY, width)
context.lineTo(coord.x, coord.y);
}
context.strokeStyle = '#000080';
context.lineWidth = 3;
context.stroke();
return context
}
Insert cell
_ = require("lodash")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more