def test_zero_vertex(self): graph = graph_utils.random_graph(10, 0.3) npgraph = graph_utils.graph_to_numpy(graph) degree_vector = all_vertex_degree(npgraph) zero_vertex(npgraph, 4, degree_vector) degree_vector_check = all_vertex_degree(npgraph) assert_equal(degree_vector, degree_vector_check)
def test_algorithm(self): for i in range(10): graph = graph_utils.random_graph(100, 0.1) g1 = graph_utils.graph_to_numpy(graph) g2 = graph_utils.graph_to_numpy(graph) cover_group1 = shaked_algo_impl_v2(g1) cover_group2 = shaked_algo_impl(g2) assert_equal(cover_group1, cover_group2)
def test_by_comparison(self): weights = random_graph(value_generator=lambda: random.randint(1, 1000), vertex_count=20, edge_count=100) fw_result = shortest_distances(weights) for v1, v2 in product(weights.keys(), repeat=2): dijkstra_result = dijkstra.shortest_path(weights, v1, v2)[0] self.assertEqual(fw_result[0][v1][v2], dijkstra_result)
def compare(get_lgraph_a, label_a, get_lgraph_b, label_b): ''' compares two methods on a random graph ''' graph = random_graph(11, 15) tic = time.perf_counter() get_lgraph_a(graph) toc = time.perf_counter() print(f"Finding an ordering with {label_a} took {toc - tic:0.4f} seconds") tic = time.perf_counter() get_lgraph_b(graph) toc = time.perf_counter() print(f"Finding an ordering with {label_b} took {toc - tic:0.4f} seconds")
def stats_for_size(node_count, measurements): ''' pre dany pocet vrcholov vrati array pomerov pre kazdy pocet hran pre kazdy pocet hran je vykonanych `measurement` merani ''' averages = [] for edge_count in range(1, (node_count * (node_count - 1)) // 2 + 1): good_total = 0 bad_total = 0 for _ in range(measurements): graph = random_graph(node_count, edge_count) good, bad = good_order_ratio(graph) good_total += good bad_total += bad ratio = good_total / (good_total + bad_total) averages.append(ratio) return averages
def test_random_graphs(self): for i in range(10): graph = graph_utils.random_graph(100, 0.1) g = graph_utils.graph_to_numpy(graph) cover = degree_minus(g) assert (graph_utils.check_if_legal_vertex_cover(g, cover))