Question: In C++. In this assignment you are expected to develop code capable of finding the shortest path between two nodes in a given graph, if

In C++. In this assignment you are expected to develop code capable of finding the shortest path between two nodes in a given graph, if such a path exists, using the Floyd Warshall All Pairs Shortest Path Algorithm.

main.cpp - This is the main driver of your program. It is used to call the functions you write to satisfy the assignment requirements. You should not modify this file.

Graph.hpp - This file contains an incomplete C++ class for a graph data structure. This file is where you should write your code to implement your graphing data structure and algorithms.

Makefile - This file can be used to build your program for testing. You should not modify this file.

You will need to complete all empty functions listed in Graph.hpp. You should not modify any functions that have already been completed.

#ifndef _GRAPH_HPP_
#define _GRAPH_HPP_
#include
using namespace std;
#define MAX_NODES 150
/**
@brief Graph object
*/
class Graph{
private:
uint32_t graph[MAX_NODES][MAX_NODES];
public:
Graph();
~Graph();
bool add_path(uint32_t, uint32_t, uint32_t);
void floyd_warshall();
int shortest_path(uint32_t, uint32_t);
uint32_t get_path(uint32_t, uint32_t);
};
/**
@brief Graph object default constructor, initialize
members to default values
*/
Graph::Graph()
{
/* Code here */
}
/**
@brief Graph object destructor,
*/
Graph::~Graph()
{
/* Code here */
}
/**
@brief Add new path to Graph, treating new path
as weighted and directed
@param src - Source graph node
@param dst - Destination graph node
@param weight - Path weight
@return True if success, False if not
*/
bool Graph::add_path(uint32_t src, uint32_t dst, uint32_t weight)
{
/* Code here */
}
/**
@brief Calculate the shortest paths between all nodes
in a given graph using the Floyd Warshall All
Pairs Shortest Path Algorithm
*/
void Graph::floyd_warshall(void)
{
/* Code here */
}
/**
@brief Return the shortest path between two given nodes,
if such a patch exists
@param src - Source graph node
@param dst - Destination graph node
@return - Shortest path distance between src and dst, -1
if there is no path between src and dst
*/
int Graph::shortest_path(uint32_t src, uint32_t dst)
{
/* Code here */
}
/**
@brief Return path between two given nodes, used
for debugging only
@param src - Source graph node
@param dst - Destination graph node
@return - Path value
*/
uint32_t Graph::get_path(uint32_t src, uint32_t dst)
{
uint32_t path = 0;
if (MAX_NODES > src && MAX_NODES > dst)
{
path = graph[src][dst];
}
return (path);
}
#include
#include
#include
#include
#include "Graph.hpp"
using namespace std;
#define NO_PATH -1
int main()
{
Graph g;
int ret;
g.add_path(1,2,3);
g.floyd_warshall();
ret = g.shortest_path(1,2);
if (NO_PATH != ret)
{
cout << "Shortest path between the two nodes is " << ret << "." << endl;
}
else
{
cout << "There is no path between the two nodes." << endl;
}
return 0;
}

#endif /* _GRAPH_HPP_ */

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!