def test_connected(self): edges_path = os.path.join(cfg.TESTS_IN_DIR, 'two_component_graph.csv') graph = parse(edges_path) comp = connected_components(graph) expected = ({1, 2, 3}, {4, 5, 6}) actual = tuple(comp) self.assertEqual(actual, expected)
def test_shortest_path(self): """ Test shortest path correctness. :return: """ edges_path = os.path.join(cfg.TESTS_IN_DIR, "sssp_graph.csv") graph = parse(edges_path) graph_nx = nx.Graph() graph_nx.add_weighted_edges_from(graph.weighted_edges) # draw_small_graph(graph) shortest_paths, distances = sssp(graph, 1) # The path [1,2,4] has higher distance and should not appear # in shortest paths self.assertEqual(shortest_paths[4], [[1,3,4]])
def test_highest_betweenness(self): """ Test edge with highest betweenness in graph is same as networkx :return: """ edges_path = os.path.join(cfg.TESTS_IN_DIR, "simple_graph.csv") graph = parse(edges_path) graph_nx = nx.Graph() graph_nx.add_weighted_edges_from(graph.weighted_edges) top_edges_cs = get_edges_with_highest_betweenness(graph) betweenness_nx = edge_betweenness_centrality(graph_nx, normalized=False) top_edges_nx = self.get_edges_with_highest_betweenness(betweenness_nx) self.assertEqual(top_edges_cs, top_edges_nx)
def main(): edges_path = DEFAULT_EDGES_FILE if len(sys.argv) < 2 else sys.argv[1] source_header, target_header, weight_header = get_headers(edges_path) before_memory = memory_usage()[0] before_time = time() graph = parse(edges_path, source_header=source_header, target_header=target_header, weight_header=weight_header, edge_limit=cfg.EDGES_LIMIT) elapsed_time = time() - before_time consumed_memory = memory_usage()[0] - before_memory print('Number of edges: {0:,}, Graph Size in Memory (MB): {1:5.2f}, Parsing Time (seconds): {2:10.2}'.format( cfg.EDGES_LIMIT, consumed_memory, elapsed_time )) del graph
__author__ = "Eduardo Hernandez" __email__ = "https://www.linkedin.com/in/eduardohernandezj/" DEFAULT_EDGES_FILE = os.path.join(cfg.BASE_DIR, "sample_files", "girvan_graph.csv") if __name__ == '__main__': edges_path = DEFAULT_EDGES_FILE if len(sys.argv) < 2 else sys.argv[1] source_header, target_header, weight_header = get_headers(edges_path) # Parse with edges limit: graph = parse(edges_path, edge_limit=cfg.EDGES_LIMIT, source_header=source_header, target_header=target_header, weight_header=weight_header) number_of_edges = len(list(graph.edges)) before_time = time() components = girvan_newman(graph, cfg.COMPONENTS_LEVEL) elapsed_time = time() - before_time print( 'Edges: {0};\t\tTarget Level: {1};\t\t\tSequential Computing Time (seconds): {2}\n\n' .format(number_of_edges, cfg.COMPONENTS_LEVEL, elapsed_time))