Example #1
0
 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)
Example #2
0
    def test_os3e(self):
        '''Validate coverage and availability are reasonable.'''
        link_fail_prob = 0.01
        g = OS3EGraph()
        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"]]
        weighted = False

        '''
        34 nodes
        41 edges
        pfail = 0.01
        p(good) =
            1 * p(success) * p(success) * ... 41 = 0.99 ** 41 =
            0.66228204098398347
        p(1 fail) =
            (41 choose 1) * (p(success) ** (41 - 1)) * p(fail) =
            41 * (0.99 ** 40) * 0.01 =
            0.27427842101356892
        p(2 fail) =
            (41 choose 2) * (p(success) ** (41 - 2)) * (p(fail) ** 2) =
            820 * (0.99 ** 39) * (0.01 ** 2) =
            0.055409782022943221
        p(3 fail) =
            (41 choose 3) * (p(success) ** (41 - 2)) * (p(fail) ** 2) =
            10660 * (0.99 ** 38) * (0.01 ** 3) =
            0.0072760319828107265

        sum (0..1 failures) = 
            0.66228204098398347 + 0.27427842101356892 =
            0.93656046199755238
        error bar = 
            0.063439538002447615

        sum (0..2 failures) =
            0.66228204098398347 + 0.27427842101356892 + 0.055409782022943221 =
            0.99197024402049561
        error bar =
            0.00802

        sum (0..3 failures) =
          0.66228204098398347 + 0.27427842101356892 + 0.055409782022943221 +
              0.0072760319828107265 =
          0.99924627600330629
        error bar = 0.00075
        '''
        exp_coverage = {
            0: 0.66228204098398347,
            1: 0.27427842101356892,
            2: 0.055409782022943221,
            3: 0.0072760319828107265
        }

        def get_coverage(f):
            '''Return expected coverage for given number of failures.'''
            return sum([v for k, v in exp_coverage.iteritems() if k <= f])

        for combo in combos:
            for max_failures in range(3):
                a, c = availability_one_combo(g, combo, apsp, apsp_paths,
                                              weighted, link_fail_prob,
                                              max_failures)
                self.assertTrue(a < 1.0)
                self.assertTrue(c < 1.0)
                self.assertAlmostEqual(get_coverage(max_failures), c)
Example #3
0
# A link of average length should have equivalent failure probability
# to the input prob.
avg_link_fail_prob = sum(distances) / float(g_w.number_of_edges()) * weighted_link_fail_prob
assert abs(link_fail_prob - avg_link_fail_prob) < 0.000001

apsp = nx.all_pairs_shortest_path_length(g)
apsp_paths = nx.all_pairs_shortest_path(g)

apsp_w = nx.all_pairs_dijkstra_path_length(g_w)
apsp_w_paths = nx.all_pairs_dijkstra_path(g_w)

combos = [["Portland"],
          ["Sunnyvale, CA", "Boston"],
          ["Sunnyvale, CA", "Salt Lake City"],
          ["Seattle", "Boston"],
          ["Seattle", "Portland"]]

# These should be roughly equal, given our construction of weighted link
# failure probability.
for combo in combos:
    print "combo: %s" % combo
    for max_failures in range(1, 4):
        print "\tfailures: %s" % max_failures
        a, c = availability_one_combo(g, combo, apsp, apsp_paths,
            False, link_fail_prob, max_failures)

        a_w, c_w = availability_one_combo(g_w, combo, apsp_w,
            apsp_w_paths, True, weighted_link_fail_prob, max_failures)
        print "\t\tunweighted availability, coverage: %0.6f, %0.6f" % (a, c)
        print "\t\t  weighted availability, coverage: %0.6f, %0.6f" % (a_w, c_w)