コード例 #1
0
ファイル: os3e_weighted.py プロジェクト: cnetboy/FSP_Engine
def OS3EWeightedGraph():

    data = {}
    g = OS3EGraph()
    longit = {}
    lat = {}
    # Get locations
    if os.path.isfile(LATLONG_FILE):
        print "Using existing lat/long file"
        data = read_json_file(LATLONG_FILE)
    else:
        print "Generating new lat/long file"
        for n in g.nodes():
            data[n] = get_lat_long(n)
        write_json_file(LATLONG_FILE, data)

    for node in g.nodes():
	latit = float(data[node]["Latitude"])
	lon = float(data[node]["Longitude"])
	lat[node] = latit
	longit[node] = lon	
    nx.set_node_attributes(g,'Latitude',lat)
    nx.set_node_attributes(g,'Longitude',longit)	
	

    # Append weights
    for src, dst in g.edges():
        g[src][dst]["weight"] = dist_in_miles(data, src, dst)
        #print "%s to %s: %s" % (src, dst, g[src][dst]["weight"])

    return g
コード例 #2
0
ファイル: test_metrics.py プロジェクト: sdsd08013/cpp
 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()))
コード例 #3
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)
コード例 #4
0
def OS3EWeightedGraph():

    data = {}
    g = OS3EGraph()

    # Get locations
    if os.path.isfile(LATLONG_FILE):
        print("Using existing lat/long file")
        data = read_json_file(LATLONG_FILE)
    else:
        print("Generating new lat/long file")
        for n in g.nodes():
            data[n] = get_lat_long(n)
        write_json_file(LATLONG_FILE, data)

    # Append weights
    for src, dst in g.edges():
        g[src][dst]["weight"] = dist_in_miles(data, src, dst)
        #print "%s to %s: %s" % (src, dst, g[src][dst]["weight"])

    return g
コード例 #5
0
ファイル: os3e_test.py プロジェクト: sdsd08013/cpp
#!/usr/bin/env python
import cc
from topo.os3e import OS3EGraph

g = OS3EGraph()

link_fail_prob = 0.01
print "OS3E"
print "sssp: %03f" % cc.compute(g, link_fail_prob, 0, 1, 'sssp')
print "any: %03f" % cc.compute(g, link_fail_prob, 0, 1, 'any')
コード例 #6
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)