Question
Can you help me with this project? I only need the implementation and the main driver of the program. C++ only. PROBLEM STATEMENT: Create a
Can you help me with this project? I only need the implementation and the main driver of the program. C++ only.
PROBLEM STATEMENT: Create a graph ADT that will consist of a set of vertices and a set of weighted edges. An enhanced user-friendly version of this program could be used for a variety of applications like managing travel routes for sales, people with vertices representing customer locations and edges representing the travel routes between locations with their associated costs
CODE: The Graph ADT must use an Adjacency List representation for the graph. The included struct and class definitions assume that the STL Vector class (which must be used) is being used for the Graph vertex list, with a linked edge list hanging off each vector cell (for each vertex).
Supply a client program that demonstrates that your Graph ADT class works correctly for both an undirected graph and a directed graph. It should be menu-driven. Input files provided.
Graphs.h
#ifndef GRAPHS_H #define GRAPHS_H
template // V is the vertex class; W is edge weight class struct edgeRep { V name; // Vertex name W weight; // Edge weight };
template struct vertex // Array cell structure for graph { typedef edgeRep edge; V name; // Vertex name int visited; // Used during traversal, Breadth-First or Depth-First List edgelist; // Pointer to edge list };
template class Graph { protected: vertex G[MAX]; // Main graph array for adjacency list representation // protected member functions
public: Graph(); // Constructor // . . . other constructors ~Graph(); // Destructor //Predicates: int isVertex(V& v); // Tests whether v is a vertex in the graph int isUniEdge(V& v1, V& v2); // Tests whether edge in graph int isBiDirEdge(V& v1, V& v2);// Tests whether edge (v1,v2) in graph // The following functions return -1 for failure, non-neg for success int AddVertex(V& v); // Adds vertex with name v to the graph, if v is not already in // graph, and returns the index where the vertex is stored. int DeleteVertex(V& v); // Deletes vertex with name v from the graph, if v is in the graph. // If there are any edges incident on the vertex, these edges // are deleted also. int AddUniEdge(V& v1, V& v2, W& wt); // Adds the directed edge to the graph; adds the vertices // to the graph if the vertices are not already part of the graph int void DeleteUniEdge(V& v1, V& v2); // Deletes the directed edge (any weight) from the graph, if // it is in the graph. The vertices are not deleted from the graph, // only the edge. int AddBiDirEdge(V& v1, V& v2, W& wt); // Adds the bi-directional edge (v1,v2,wt) to the graph; adds the // vertices to the graph if the vertices are not already part of // the graph int DeleteBiDirEdge(V& v1, V& v2); // Deletes the bi-directional edge (v1,v2) (any weight) from the // graph, if it is in the graph. The vertices are not deleted from // the graph, only the edge. void SimplePrintGraph(); // Prints the list of vertices in the graph, and for each vertex, // prints the list of edges in proper parenthesized notation, namely // (v1,v2,wt) or . NOTE: This is not a traversal. double ShortestDistance(V& v1, V& v2) // returns the shortest distance from vertex 1 to vertex 2 // Must implement the Dijkstra code as provided in class void GetGraph(); // Retrieves a graph from a special file and sets up the adjacency // list for the graph. I am supplying 1 such files.The program // will be able to read any graph that is in the same format: // graph node followed by any adjacent nodes with followed by distance/wieigh // to the node.The adjacency entry is terminated by # void BFTraversal(V& v); // Performs Breadth First Traversal with trace information printed void DFTraversal(V& v); //Performs a recursive Depth First Traversal of the graph starting at //specified vertex(parameter); prints trace information.
}
#endif // !GRAPHS_H
graphs2.txt
Atlanta Houston 650 Washington 600 # Austin Dallas 200 Houston 300 # Buffalo New_York 450 Newark 500 # Chicago Denver 550 New_York 950 # Dallas Austin 200 Chicago 1500 # Denver Atlanta 800 Chicago 550 # Houston Atlanta 650 # Newark # New_York Chicago 950 Buffalo 450 # Washington Atlanta 600 Dallas 700 #
graphs3.txt
Atlanta Houston 650 Washington 600 # Austin Dallas 200 Houston 300 # Buffalo New_York 450 Newark 500 # Chicago Denver 550 New_York 950 # Dallas Austin 200 Chicago 1500 # Denver Atlanta 800 Chicago 550 # Houston Atlanta 650 # Newark Atlanta 1100 # New_York Chicago 950 Buffalo 450 # Washington Atlanta 600 Dallas 700 #
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started