/////////////////////////
/// The following is from routing.js
/////////////////////////
var graph = new DirectedGraph(); //Required by connector
var INFINITY = 1 / 0;
var x_path = [];
function route_setup(){
var end_point = parseInt(document.getElementById("end_point").value);
connector();
console.log("crossed conn");
var out = djikstra(graph, '0');
console.log("crossed djikstra");
for (i = 0; i < data.features.length; i++) {
for (j = 0; j < out.shortestPaths[end_point].length; j++) {
if (String(i) == out.shortestPaths[end_point][j]) {
var x_i = i;
x_path.push({
lat: data.features[x_i].geometry.coordinates[1],
lng: data.features[x_i].geometry.coordinates[0]
});
}
}
}
x_path.push({
lat: data.features[end_point].geometry.coordinates[1],
lng: data.features[end_point].geometry.coordinates[0]
});
return x_path;
}
function DirectedGraph() {
this.vertices = {};
this.addVertex = function(name, edges) {
edges = edges || null;
this.vertices[name] = edges;
};
}
function djikstra(graph, startVertex) {
var dist = {};
var prev = {};
var q = {};
var shortestPaths = {};
for (var vertex in graph.vertices) {
dist[vertex] = INFINITY;
prev[vertex] = null;
q[vertex] = graph.vertices[vertex];
shortestPaths[vertex] = [];
}
dist[startVertex] = 0;
while (Object.keys(q).length !== 0) {
var smallest = findSmallest(dist, q);
var smallestNode = graph.vertices[smallest];
//searches for the vertex u in the vertex set Q that has the least dist[smallest] value.
for (var neighbor in smallestNode) {
var alt = dist[smallest] + smallestNode[neighbor];
//smallestNode[neighbor] is the distance between smallest and neighbor
if (alt <...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.