Finding the shortest path using Dijkstra Algorithm, implemented with javascript
Dijkstra Algorithm implemented in Javascript by Group Two members

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/NREG NOFull Name
1201*********Nwachukwu Chibuike A
2201*********Ugwu Johnson O
3201*********Ugwu Kenneth C
4201*********Modili Stephen
5201*********Egenti Marcel C
6201*********Akaluso David C
7201*********Ndubuisi Somtochukwu C
8201*********Ikebude Emeka Stephen
9201*********Ogheneovo Ese
10201*********Okeke Franklin Ikechukwu
11201*********Nze Sandra C
12201*********Ezurike Bright U
13201*********Itubo Stella
14201*********Onuegbu Joy O
15201*********Solomon Charles
16201*********Okwara Nkemdirim Julius
17201*********Oparah Bright U
18201*********Okeke Franklin I
19201*********Umeji Onyedika Augustine
20201*********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

  1. Diagram: This shows the assignment given to us as a network diagram, that is it simply shows the diagram of the assignment
  2. Flowchart: This describes the algorithm used in pictural form, that is the algorithm is implemented using a flowchart
  3. Pseudocode: This shows the algorithm used in english-like statement
  4. Algorithm: This shows the algorithm implemented in JavaScript
  5. 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
  6. Group Members: This shows all members of this group
  7. Documentation: This shows the documentation of the software