Skip to content

Instantly share code, notes, and snippets.

@szarnyasg
Created February 4, 2021 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szarnyasg/3a1961918f48ed4e5f47d30ae2c72956 to your computer and use it in GitHub Desktop.
Save szarnyasg/3a1961918f48ed4e5f47d30ae2c72956 to your computer and use it in GitHub Desktop.
from igraph import *
import csv
import time
dataset = '/home/szarnyasg/graphs/example-directed'
g = Graph(directed=True)
g.es["weight"] = 1.0
start_time = time.time()
print("================================= Loading ====================================");
with open(dataset + '.e', 'r') as efile:
g = Graph.Read(efile, format='ncol')
print("%.2f seconds" % (time.time() - start_time))
start_time = time.time()
print("=================================== BFS ====================================");
bfs = g.shortest_paths_dijkstra(source = 0, weights=None)
print("%.2f seconds" % (time.time() - start_time))
start_time = time.time()
print("=================================== SSSP ===================================");
sssp = g.shortest_paths_dijkstra(source = 0, weights="weight")
print("%.2f seconds" % (time.time() - start_time))
start_time = time.time()
print("=================================== WCC ====================================");
wcc = g.as_undirected().components()
print("%.2f seconds" % (time.time() - start_time))
# CDLP, LCC, and PR give different results or lack support for some cases
# # different results due to randomized algorithm
# print("=================================== CDLP ===================================");
# print(g.community_label_propagation())
# # directed definition is not supported
# print("=================================== LCC ====================================");
# print(g.as_undirected().transitivity_local_undirected())
# # different results due to fixed-point (eps) approach
# print("==================================== PR ====================================");
# print(g.pagerank())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment