@@ -100,9 +100,51 @@ def floyd_warshall(graph: list[list[float]], vertex: int) -> tuple:
100
100
):
101
101
dist [i ][j ] = dist [i ][k ] + dist [k ][j ]
102
102
return dist , vertex
103
-
104
-
103
+
105
104
if __name__ == "__main__" :
106
105
import doctest
107
-
108
106
doctest .testmod ()
107
+
108
+ v = int (input ("Enter number of vertices: " ))
109
+ e = int (input ("Enter number of edges: " ))
110
+
111
+ graph = [[float ("inf" ) for i in range (v )] for j in range (v )]
112
+
113
+ for i in range (v ):
114
+ graph [i ][i ] = 0.0
115
+
116
+ # src and dst are indices that must be within the array size graph[e][v]
117
+ # failure to follow this will result in an error
118
+ for i in range (e ):
119
+ print ("\n Edge " , i + 1 )
120
+ src = int (input ("Enter source:" ))
121
+ dst = int (input ("Enter destination:" ))
122
+ weight = float (input ("Enter weight:" ))
123
+ graph [src ][dst ] = weight
124
+
125
+ floyd_warshall (graph , v )
126
+
127
+ # Example Input
128
+ # Enter number of vertices: 3
129
+ # Enter number of edges: 2
130
+
131
+ # # generated graph from vertex and edge inputs
132
+ # [[inf, inf, inf], [inf, inf, inf], [inf, inf, inf]]
133
+ # [[0.0, inf, inf], [inf, 0.0, inf], [inf, inf, 0.0]]
134
+
135
+ # specify source, destination and weight for edge #1
136
+ # Edge 1
137
+ # Enter source:1
138
+ # Enter destination:2
139
+ # Enter weight:2
140
+
141
+ # specify source, destination and weight for edge #2
142
+ # Edge 2
143
+ # Enter source:2
144
+ # Enter destination:1
145
+ # Enter weight:1
146
+
147
+ # # Expected Output from the vertice, edge and src, dst, weight inputs!!
148
+ # 0 INF INF
149
+ # INF 0 2
150
+ # INF 1 0
0 commit comments