Technical breakdown
Network Diagram
Flowchart
function Dijkstra(Graph,Source):
for each vertex v in Graph:
dist[v] := Infinity
previuos[v] := undefined
dist[source] := 0
Q:= the set of all nodes in Graph
while Q is not empty
u :=node in Q with smallest dist[]
remove u from Q
for each neighbour v of u:
alt := dist[u]+dist_between(u,v)
if alt < dist[v]
dist[v] := alt
previous[v] := u
return dist[],prev[]
// 1. Calculate the distance between any nodes in the dataset, without needing to edit the problem dictionary.
// 2. Prevent algorithm from going back to start node if loops exist in graph (e.g., in problem below)
const problem = {
start: {B: 3, D: 3, E: 1},
B: {C: 2, E: 2, F: 4},
C: {B: 2, D: 2, E: 1, G: 1},
D: {C: 2, E: 2, J: 4},
E: {B: 2, C: 1, D: 2},
F: {B: 4, G: 2, H: 1, finish: 3},
G: {C: 1, F: 2, H: 2, J: 2},
H: {F: 1, G: 2, finish: 3, J: 1},
J: {D: 4, G: 2, H: 1, finish: 3},
finish:{}
};
function log(message) {
const logging = false;
if (logging) {
console.log(message);
}
}
const lowestCostNode = (costs, processed) => {
return Object.keys(costs).reduce((lowest, node) => {
if (lowest === null || costs[node] < costs[lowest]) {
if (!processed.includes(node)) {
lowest = node;
}
}
return lowest;
}, null);
};
// function that returns the minimum cost and path to reach Finish
const dijkstra = (graph, startNodeName, endNodeName) => {
// track the lowest cost to reach each node
let costs = {};
costs[endNodeName] = "Infinity";
costs = Object.assign(costs, graph[startNodeName]);
// track paths
const parents = {endNodeName: null};
for (let child in graph[startNodeName]) {
parents[child] = startNodeName;
}
// track nodes that have already been processed
const processed = [];
let node = lowestCostNode(costs, processed);
while (node) {
let cost = costs[node];
let children = graph[node];
for (let n in children) {
if (String(n) === String(startNodeName)) {
log("WE DON'T GO BACK TO START");
} else {
log("StartNodeName: " + startNodeName);
log("Evaluating cost to node " + n + " (looking from node " + node + ")");
log("Last Cost: " + costs[n]);
let newCost = cost + children[n];
log("New Cost: " + newCost);
if (!costs[n] || costs[n] > newCost) {
costs[n] = newCost;
parents[n] = node;
log("Updated cost und parents");
} else {
log("A shorter path already exists");
}
}
}
processed.push(node);
node = lowestCostNode(costs, processed);
}
//used for getting the full path of the shortest path
//this is done by appending all the elements in the
// parents array and then reversing it
let optimalPath = [endNodeName];
let parent = parents[endNodeName];
while (parent) {
optimalPath.push(parent);
parent = parents[parent];
}
optimalPath.reverse();
const results = {
distance: costs[endNodeName],
path: optimalPath
};
return results;
};
Select the start node and the end node.
Start node: Stop node:Results will be shown here
MEMBERS OF GROUP TWO
| S/N | REG NO | Full Name |
| 1 | 201********* | Nwachukwu Chibuike A |
| 2 | 201********* | Ugwu Johnson O |
| 3 | 201********* | Ugwu Kenneth C |
| 4 | 201********* | Modili Stephen |
| 5 | 201********* | Egenti Marcel C |
| 6 | 201********* | Akaluso David C |
| 7 | 201********* | Ndubuisi Somtochukwu C |
| 8 | 201********* | Ikebude Emeka Stephen |
| 9 | 201********* | Ogheneovo Ese |
| 10 | 201********* | Okeke Franklin Ikechukwu |
| 11 | 201********* | Nze Sandra C |
| 12 | 201********* | Ezurike Bright U |
| 13 | 201********* | Itubo Stella |
| 14 | 201********* | Onuegbu Joy O |
| 15 | 201********* | Solomon Charles |
| 16 | 201********* | Okwara Nkemdirim Julius |
| 17 | 201********* | Oparah Bright U |
| 18 | 201********* | Okeke Franklin I |
| 19 | 201********* | Umeji Onyedika Augustine |
| 20 | 201********* | Anyanwu Grace C |
Documentation Here.
This software is broken into different parts that show different things. It is broken into 7 major part as listed below
- Diagram: This shows the assignment given to us as a network diagram, that is it simply shows the diagram of the assignment
- Flowchart: This describes the algorithm used in pictural form, that is the algorithm is implemented using a flowchart
- Pseudocode: This shows the algorithm used in english-like statement
- Algorithm: This shows the algorithm implemented in JavaScript
- Calculate Shortest distance
What it does : This calculates the shortest distance from node A to any node. It also shows the path it took to arrive at its conclusion.
How to use it : Simply select the start node( which is node A) and then select the stop node (the node you wish to calculate it's shortest distance from A), and then click on the get button. This will show the result in the container below - Group Members: This shows all members of this group
- Documentation: This shows the documentation of the software