Task to be performed
In this project, we have to find the minimum distance while using the Dijkstra algorithm. To find the minimum distance from starting node to ending node. In this project, we use C++ language for developing a program. In this project contain compilation, an output of the program, planning for the complete solution, workflow, major events states, Dijkstra algorithm, challenges and reflection. The above topics are briefly described below.
To find the shortest path using Dijkstra algorithm programs written by C++. This program is compiled in Dev C++. First, click the Execute tab, then click the Compile. The program is starting to compile when press the Compile button in the Dev C++.
The Shortestpath.cpp is the program name. The compilation time shows the three different types of categories such as compiling a single file, processing C++ source file and Compilation results. The compiling single file describes the filename and compiler name. The filename shows the program path. The E:Shortestpath.cpp is the file path. The processing C++ source file describes the C++ compiler and Command. The Compilation results show the errors, warnings, output file name, compilation time and output size. This program does not show any error and warning message. The compilation time is 0.63 seconds.
The program output contains the source, destination, distance and path. The source is referring to the starting point of the vertex. This program the starting point is 0. The destination refers to the ending point of the vertex. This program ending node is all other nodes. For example, the starting node is 0 the ending node is except source node such as the 1, 2, 3, 4, 5, 6 all nodes are called the destination. The source and destination are used to find the minimum distance between the vertices using a Dijkstra algorithm. The distance refers to the cost of the node. The 0 to 1 vertices cost is 3. The path has referred the location of the vertices. The 0 to 3 path is 0 1 4 3. It is the shortest path of the 0 to 3 vertices. The path is used to find the minimum distance
The program is implemented to find the minimum distance between the vertices using the Dijkstra algorithm. The undirected graph used in this program for finding the minimum distance. The graph has the vertex and edge. The bidirectional format used in this graph. The undirected graph is also called the undirected network.
The C++ Program for Shortest Path
In this program, the workflow is the source and destination is printed first. Next, find the destination. Then calculate the shortest path from source to all vertices. The graph is based on the number of vertexes. For example, the vertex is 7 the matrix has the seven rows and seven columns. Once developed the program compile the program. After compilation shows the errors when the error in this program otherwise it does not show any error. The compilation is successes, then run the program. The output displayed with the source, destination, distance, and path.
Major Event States
Starting node
In more precisely in graph theory, the undirected graph is a graph, that is a set of vertices linked through the edges, wherever the edges take a direction related to them.
Ending node
In given graph is an undirected graph, here be able to only one edge between every pair of nodes. In every node assists a starting node and the ending node. A sub graph of the graph includes a subset of edges and nodes.
Distance
A distance among the number of the edges in minimum distance between two vertices. This is called geodesic distance. There may be one minimum distance among other than the two vertices.
Path
A path is a curve, an endless injective function as of an intermission of the set of real numbers one or more usually to space for topology and space for metric. A path in a graph which doesn’t take the repeating vertices.
It is for calculating the shortest path from Starting node to sink almost as computation in costly as to manipulate the shortest way from starting node to some other vertex. The solution to be particular in starting node of Shortest Path in graph theory. It is undirected and directed graphs together. In all the edges has necessity weights for non-negative. The graph should be connected
Shortest path using the Dijkstra algorithm
- Initially this is the empty set. To create a Shortest Path tree Set as that preserves the path of vertices contain in the Shortest Path tree that is whose shortest distance from starting node is calculated.
- To allocate a distance of value into all the vertices in a graph input. Modify the distance of all value as infinite. Allocate the distance of value as 0 of source vertex. First, it is selected.
- Although shortest path tree set does not contain all the vertices.
- To choice a vertex 0 while it is not there in the shortest path tree set and it has the smallest value of distance. It contain 0 to the minimum distance tree Set.
- To keep posted, the value of distance for all the neighboring vertices of 0. Keep posted, the value of distance, repeat in excess of the all adjacent vertices. In place of each neighboring vertices, if the sum of the value of distance from the starting node and the edge weight as, is smaller than the valued distance, and then to keep posted the valued distance of (GeeksforGeeks, 2018).
The above program has the read function. This function is used to read the number of vertices, matrices and source from the user. The number of vertices is greater than the 0. All members are matrix is must be the positive distance value. The source vertex is always the positive value of the 0 to the number of vertices -1.
Initialize
This function is used to initialize all data members at the opening of the execution. The distance between the sources to all other nodes. The source is considered as 0. The source to source distance is 0. The source to all other vertices is infinity. The infinity is 999. The initialization is false and procedure I initialized to -1.
Major Event States
Closest node
The getclosestunmarkednode is used to find the nearest node. This function returns the node which is a neighbor from the visited node. If the node is visited then it is searching for another node for a visit. The nearest node finds needs the number of vertices, minimum distance and visited node. The number of the vertex is stored in the numofvertices varia
The minimum distance is used to find the distance of the vertices. The calculateDistance () is the function used to find the vertex with the minimum distance value. This value from the set of the vertex. It does not include in the shortest path tree. The minimum value-initialize use the minimum variable.
Solution
The solution contains the vertex, matrix, source, destination, and path. This program is developed to get the input from the user. First, enter the number of the vertex in the graph. Next, enter the weights for the row of the matrix. Then enter the source vertex. Then display the path of the vertices. Suppose enter the negative input for the weights for the row of the matrix it displays the warning message for entering the positive value. The path does not find it displays any path from source to destination.
Shortest Path
The shortest path is very important for this program. Find the shortest path for all vertices. The shortest path finds use the minimum distance method. The shortest path finds to verify the graph and the parent node. The path function is used to print the shortest path from source to destination. It uses the parent array to print the path.
We specified the output in a single file. We are interested in learning the Dijkstra algorithm and shortest path. The undirected graph used in this program for finding the shortest path between the vertices. First, we learned the Dijkstra algorithm, the shortest path, and undirected graph. The undirected graph contains the vertex and edges. The challenge is finding the minimum distance in the graph of unweighted with the floating point data. But we used the integer data for finding the path in the graph. We print the output has the source, destination, distance, and path. The matrix format, making is small difficult for me. The matrix has the number of rows and number of columns. We used the 7 rows and 7 columns in this program. The Matrix format is
0 |
3 |
4 |
0 |
0 |
0 |
0 |
5 |
0 |
0 |
0 |
7 |
0 |
0 |
10 |
0 |
0 |
9 |
0 |
1 |
0 |
0 |
0 |
6 |
0 |
11 |
0 |
0 |
0 |
8 |
0 |
2 |
0 |
0 |
7 |
0 |
0 |
11 |
0 |
0 |
0 |
10 |
0 |
0 |
0 |
0 |
4 |
3 |
0 |
It is used to find the minimum distance. The values represent the cost of the vertex. The 0 represents the non-cost of the vertex. We got the error while compiling this program.
The error shows the same small mistake. We define the wrong method name. We declared the calculateditance but assign the calculateDistance.
Conclusion
In this project, we have been finding the shortest path of the algorithm is explained and executed successfully. The output of the program has been verified successfully. This project has been implemented while using C++ language. In this project contained compilation, an output of the program, planning for the complete solution, workflow, major events states, Dijkstra algorithm, challenges and reflection. These are explained in a detailed manner.
References
C++, S. (2018). Shortest path algorithm using Dijkstra’s Algorithm in C++. [Online] Stack Overflow. Available at: https://stackoverflow.com/questions/27207419/shortest-path-algorithm-using-dijkstras-algorithm-in-c [Accessed 30 Oct. 2018].
GeeksforGeeks. (2018). Dijsktra’s algorithm. [Online] Available at: https://www.geeksforgeeks.org/dijkstras-shortest-path-algorithm-greedy-algo-7/ [Accessed 30 Oct. 2018].