![How the Graphs Were Generated](https://data.docslib.org/img/3a60ab92a6e30910dab9bd827208bcff-1.webp)
<p> John Kizhakeparampil</p><p>CSCE 4110</p><p>Term Project</p><p>How the graphs were generated. </p><p>The graphs were generated using a c++ code. The 30 complete directed graphs were created using random number generator. The graphs were created in adjacency matrix format. The total number of nodes on the graph were chosen as a random number between 50 to about 1000. Weights between any two nodes were also assigned as a random number between 1 and 5.</p><p>Finally, the matrix was written to a file to be able to be read later using file stream. The graphs created are text files.</p><p>The first row signifies the number of nodes in the graphs.</p><p>The subsequent rows are in the format</p><p>Node1, Node2, Edge, Weight</p><p>Some explanation about the Dijkstra Code</p><p>Below are the steps we used to find the shortest path from a source to all other vertices. 1) We created an array shortest_path that stores info of vertices included in shortest path tree, i.e., whose minimum distance from source is calculated and finalized. Initially, this is empty.</p><p>2) We then assign distance value to all vertices in the igraph. All other vertices except the source vertex is assigned infinite distance. 3)Then until shortest_path array doesn't include all vertex in graph we do the following:</p><p>We pick a vertex v not present in shortest_path and that has minimum distance value We include that vertex to shortest_path.We also update the distance value of all vertex adjacent to v .For this we iterate through all adjacent vertices of v and then for every adjacent vertex x, if sum of distance value of v(from the source) and weight of edge v-x, is less than the distance value of x, then we update the distance value of vertex x.</p><p>Floyd Code:</p><p>In the first step We initialize the final distance matrix same as the input graph matrix . Then we update the distance matrix by considering all vertices as intermediate vertex. We pick all the vertices one by one and then update all shortest paths which include the picked vertex as an intermediate vertex in the shortest path. </p><p>Let's say we pick vertex number k as an intermediate vertex, then we already have considered vertices {0, 1, 2, .. k-1} as it's intermediate vertices. For every pair (i, j) where I is source vertex and j is destination vertex respectively, there are two possible cases. 1)k may not be an intermediate vertex in shortest path from i to j. In such case we don't modify the distance matrix. 2)If k is an intermediate vertex in shortest path from i to j wee update the value of dist[i][j] = dist[i][k] + dist[k][j].</p><p>Dijkstra’s Algorithm Edsger Dijkstra discovered Dijkstra’s algorithm in 1959. This algorithm solves the single-source shortest-path problem by finding the shortest path between a given source vertex and then towards all other vertices. This algorithm works by first finding the path with the lowest total weight between two vertices, j and k. It then uses the fact that a node r, in the path from j to k implies a minimal path from j to r. In the end, we will have the shortest path from a given vertex to all other vertices in the graph. Dijkstra’s algorithm belongs to a class of algorithms known as greedy algorithms. A greedy algorithm makes the decision that seems the most promising at a given time and then never reconsiders that decision. The time complexity of Dijkstra’s algorithm is dependent upon the internal data structures used for implementing the queue and representing the graph. When using an adjacency list to represent the graph and an unordered array to implement the queue the time complexity is O(n2), where n is the number of vertices in the graph. </p><p>The number of vertices range from 50 to 1000 in 30 different test graphs for algorithm execution and their CPU times are given below which will give us a detailed performance comparison between Dijkstra’s and Floyd Warshall’s algorithms. </p><p>Dijkstra’s algorithm has a running time of O(n2) time.</p><p>Is this table correct? Looks good</p><p>Directed Graph Number Number of nodes in graph Dijkstra CPU Time (secs)</p><p>0 602 4.572 </p><p>1 602 4.888 </p><p>2 602 4.364 </p><p>3 602 4.832 </p><p>4 249 0.420 </p><p>5 249 0.504 6 249 0.412 </p><p>7 249 0.540 </p><p>8 249 0.444 </p><p>9 249 0.620 </p><p>10 249 0.508 </p><p>11 249 0.540 </p><p>12 249 0.444 </p><p>13 249 0.604 </p><p>14 249 0.536 </p><p>15 249 0.532 </p><p>16 249 0.496 </p><p>17 249 0.468 </p><p>18 276 0.608 </p><p>19 276 0.628 </p><p>20 276 0.600 </p><p>21 276 0.616 </p><p>22 276 0.580 </p><p>23 276 0.596 </p><p>24 276 0.568 </p><p>25 276 0.588 </p><p>26 276 0.540 </p><p>27 276 0.556 </p><p>28 276 0.764 </p><p>29 276 0.552 </p><p>Dijkstra’s algorithm Graph Diagram Whenever I try to insert a line dotted graph, I do not see any line.</p><p>What kind of graph diagram for dijkstra should I use? </p><p>I am not sure how we can draw such huge graphs in line dotted form but a directed graph usually looks like below:</p><p>Floyd’s Algorithm Stephen Warshall and Robert Floyd independently discovered Floyd’s algorithm in 1962. This algorithm is sometimes referred to as the Warshall-Floyd algorithm or the Roy-Floyd algorithm. The algorithm finds the shortest path between all the vertices of a given graph. This algorithm works by estimating the shortest path between two vertices and further improving that estimate until it is optimum. Consider a graph G, with Vertices V numbered 1 to n. The algorithm first finds the shortest path from i to j, using only vertices 1 to k, where k<=n. Next, using the previous result the algorithm finds the shortest path from i to j, using vertices 1 to k+1. We continue using this method until k=n, at which time we have the shortest path between all vertices. This algorithm has a time complexity of O(n3), where n is the number of vertices in the graph. </p><p>Floyd-Warshall algorithm has a running time of O(n3) time.</p><p>Is this table also correct? Looks good</p><p>Directed Graph Number Number of nodes in graph Floyd CPU Time (secs)</p><p>0 602 2.428 </p><p>1 602 2.588 </p><p>2 602 2.356 3 602 3.316 </p><p>4 249 0.372 </p><p>5 249 0.412 </p><p>6 249 0.432 </p><p>7 249 0.376 </p><p>8 249 0.308 </p><p>9 249 0.276 </p><p>10 249 0.328 </p><p>11 249 0.312 </p><p>12 249 0.288 </p><p>13 249 0.304 </p><p>14 249 0.268 </p><p>15 249 0.316 </p><p>16 249 0.276 </p><p>17 249 0.316 </p><p>18 276 0.396 </p><p>19 276 0.400 </p><p>20 276 0.388 </p><p>21 276 0.344 </p><p>22 276 0.392 </p><p>23 276 0.376 </p><p>24 276 0.384 </p><p>25 276 0.400 </p><p>26 276 0.340 27 276 0.316 </p><p>28 276 0.364 </p><p>29 276 0.368 </p><p>Floyd-Warshall algorithm Graph Diagram</p><p>Whenever I try to insert a line dotted graph, I do not see any line.</p><p>What kind of graph diagram for Floyd should I use?</p><p>Conclusion: Can you read this and add any to it? Looks good</p><p>Both Floyd-Warshall and Dijkstra's algorithms can be used to find the shortest path between vertices in graphs. The Floyd-Warshall algorithm finds the shortest path between all vertices and is much easier to implement, while Dijkstra's algorithm finds the shortest path between a single vertex and all other vertices.</p><p>According to the experiment tables above, for small values, number of vertices, Dijkstra's algorithm is not worth the effort on implementation. When the number of vertices in a graph increases, the performance of Floyd's algorithm decreases. Therefore, Dijkstra's algorithm is capable when performance is a factor. While, if you will need the shortest path that contains several vertices on the same graph you should consider Dijkstra's algorithm. </p>
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages6 Page
-
File Size-