# Minimum Distance Value, From The Set of Vertices # Not Yet Included in Shortest Path Tree
# Minimum Distance Value, From The Set of Vertices # Not Yet Included in Shortest Path Tree
distance from the source node to every other node. Dijkstra’s algorithm gives the shortest
path from source to every other node. We have written a python class Graph, which
contains functions like dijkstra and printSolution which implements the Dijkstra algorithm
and outputs the shortest distance for every node from the source node 0 in a list. The
function inputs the graph as an adjacency matrix and hence the read function provided also
have been changed a bit. The class Graph is as follows:
class Graph():
return min_index
self.dist[src] = 0
sptSet = [False] * self.V
self.printSolution(self.dist)
f = open('facebook_combined.txt', 'r')
g = Graph(4039)
for line in f:
line = line.strip()
nodes = line.split(' ')
g.graph[int(nodes[0])][int(nodes[1])]=1
f.close()
g = Graph(4039)
..
g.dijkstra(0)
class Graph():
return min_index
self.dist[src] = 0
sptSet = [False] * self.V
self.printSolution(self.dist)
os.chdir('/Users/z001ys6/Downloads/Soumojit/PA')
f = open('facebook_combined.txt', 'r')
g = Graph(4039)
for line in f:
line = line.strip()
nodes = line.split(' ')
g.graph[int(nodes[0])][int(nodes[1])]=1
g.graph[int(nodes[1])][int(nodes[0])]=1
f.close()
g.dijkstra(0)
Sample Output:
Average Exposure Time : 2.82941322109433