def test_diamond(self): '''Simple diamond graph w/two equal paths.''' g = nx.Graph() g.add_path(['A', 'B', 'Z', 'C', 'A']) set_unit_weights(g) paths = vertex_disjoint_shortest_pair(g, 'A', 'Z') exp_paths = [['A', 'B', 'Z'], ['A', 'C', 'Z']] compare_path_lists(self, paths, exp_paths)
def test_line(self): '''Check shortest path for line graph.''' # Return the line graph with n nodes, lowest-num node is 0 for i in range(2, 4): g = nx.path_graph(i) set_unit_weights(g) path = BFS(g, 0, i - 1) self.assertTrue(path) self.assertEqual(path[0], 0) self.assertEqual(path[-1], i - 1)
def test_latency_bound(self): '''Ensure fraction of nodes within bound is reasonable.''' g = OS3EGraph() g_unit = set_unit_weights(g.copy()) apsp = dict(nx.all_pairs_shortest_path_length(g)) apsp_paths = dict(nx.all_pairs_shortest_path(g)) path_lens = [] for a in apsp: for b in apsp: path_lens.append(apsp[a][b]) max_path_len = max(path_lens) combos = [["Sunnyvale, CA", "Boston"], ["Portland"], ["Sunnyvale, CA", "Salt Lake City"], ["Seattle", "Boston"], ["Seattle", "Portland"]] for combo in combos: one = fraction_within_latency(g, combo, apsp, max_path_len + 1.0) self.assertEqual(one, 1.0) two = fraction_within_latency(g, combo, apsp, 0.000001) self.assertEqual(two, len(combo) / float(g.number_of_nodes()))
def test_os3e_weighted(self): '''Ensure unit-weighted version of graph yields same availability.''' link_fail_prob = 0.01 g = OS3EGraph() g_unit = set_unit_weights(g.copy()) apsp = nx.all_pairs_shortest_path_length(g) apsp_paths = nx.all_pairs_shortest_path(g) combos = [["Sunnyvale, CA", "Boston"], ["Portland"], ["Sunnyvale, CA", "Salt Lake City"], ["Seattle", "Boston"], ["Seattle", "Portland"]] for combo in combos: for max_failures in range(1, 2): a, c = availability_one_combo(g, combo, apsp, apsp_paths, False, link_fail_prob, max_failures) a_u, c_u = availability_one_combo(g_unit, combo, apsp, apsp_paths, True, link_fail_prob, max_failures) self.assertAlmostEqual(a, a_u) self.assertAlmostEqual(c, c_u)
def test_latency_bound(self): '''Ensure fraction of nodes within bound is reasonable.''' g = OS3EGraph() g_unit = set_unit_weights(g.copy()) apsp = nx.all_pairs_shortest_path_length(g) apsp_paths = nx.all_pairs_shortest_path(g) path_lens = [] for a in apsp: for b in apsp: path_lens.append(apsp[a][b]) max_path_len = max(path_lens) combos = [["Sunnyvale, CA", "Boston"], ["Portland"], ["Sunnyvale, CA", "Salt Lake City"], ["Seattle", "Boston"], ["Seattle", "Portland"]] for combo in combos: one = fraction_within_latency(g, combo, apsp, max_path_len + 1.0) self.assertEqual(one, 1.0) two = fraction_within_latency(g, combo, apsp, 0.000001) self.assertEqual(two, len(combo) / float(g.number_of_nodes()))