def __init__(self,graph, source, sink): self.graph = graph self.source = source self.sink = sink self.double_passage_graph = nx.DiGraph() for n in self.graph.nodes(): for m in self.graph.nodes(): self.double_passage_graph.add_node((n, m)) for v in self.double_passage_graph.nodes_iter(): for w in self.double_passage_graph.nodes_iter(): if self.graph.has_edge(v[0], w[0]) and self.graph.has_edge(v[1], w[1]): self.double_passage_graph.add_edge(v, w) self.double_passage_graph[v][w]['prob'] = self.graph[v[0]][w[0]]['prob'] * self.graph[v[1]][w[1]]['prob'] self.probability = {} self.distributions = {} self.maximum_collisions = get_longest_path_length(self.graph, self.source, self.sink) for n in self.double_passage_graph.nodes_iter(): self.distributions[n] = {} self.probability[n] = 0.0 if self.double_passage_graph.in_degree(n) == 0: for i in xrange(self.maximum_collisions + 1): self.distributions[n][i] = 0.0 self.distributions[(self.source, self.source)][1] = 1.0 self.probability[(self.source, self.source)] = 1.0
def get_sampled_distribution_of_collisions(G, source, sink, number): count = utilities.get_longest_path_length(G, source, sink) collision_dictionary = [0] * (count + 1) for collision in simulate_double_runs(G, source, sink, number): collision_dictionary[collision] = collision_dictionary[collision] + 1 return collision_dictionary
def test_get_longest_path_length(self): self.assertEqual(5, mc.get_longest_path_length(self.path_graph, self.path_graph_sources[0], self.path_graph_sinks[0]), "should return 5 for a path graph with") self.assertEqual(15, mc.get_longest_path_length(s.create_random_dag(15), 0, 14))