Пример #1
0
def important_edge_itr(graph, known_paths):
    """ INTERNAL: A generator which returns a sequence of edges in order
        of descending criticalness."""
    known_edges = set([])
    for path in known_paths:
        for edge in path:
            known_edges.add(edge)

    # Edges which are in the canonical path
    index = graph.latest_index
    canonical_paths = canonical_path_itr(graph, 0, index, MAX_PATH_LEN)

    for path in canonical_paths:
        for edge in path:
            if edge in known_edges:
                continue
            known_edges.add(edge)
            yield edge

    if index == 0:
        return

    # Then add bootstrap paths back to previous indices
    # Favors older edges.
    for upper_index in range(index - 1, FIRST_INDEX, -1):
        canonical_paths = canonical_path_itr(graph, 0, upper_index,
                                             MAX_PATH_LEN)
        for path in canonical_paths:
            for edge in path:
                if edge in known_edges:
                    continue
                known_edges.add(edge)
                yield edge
    return
Пример #2
0
def important_edge_itr(graph, known_paths):
    """ INTERNAL: A generator which returns a sequence of edges in order
        of descending criticalness."""
    known_edges = set([])
    for path in known_paths:
        for edge in path:
            known_edges.add(edge)

    # Edges which are in the canonical path
    index = graph.latest_index
    canonical_paths = canonical_path_itr(graph, 0, index, MAX_PATH_LEN)

    for path in canonical_paths:
        for edge in path:
            if edge in known_edges:
                continue
            known_edges.add(edge)
            yield edge

    if index == 0:
        return

    # Then add bootstrap paths back to previous indices
    # Favors older edges.
    for upper_index in range(index - 1, FIRST_INDEX, - 1):
        canonical_paths = canonical_path_itr(graph, 0, upper_index,
                                             MAX_PATH_LEN)
        for path in canonical_paths:
            for edge in path:
                if edge in known_edges:
                    continue
                known_edges.add(edge)
                yield edge
    return
Пример #3
0
def canonical_path_edges(graph, known_edges, from_index, allowed):
    """ INTERNAL: Returns edges containing from_index from canonical paths. """
    # Steps from canonical paths
    # REDFLAG: fix, efficiency, bound number of path, add alternate edges
    #paths = graph.canonical_paths(graph.latest_index, MAX_PATH_LEN)
    paths = canonical_path_itr(graph, 0, graph.latest_index, MAX_PATH_LEN)

    second = []
    #print "get_update_edges -- after"
    for path in paths:
        # We need the tmp gook because the edges can overlap
        # and we want the most recent ones.
        tmp = []
        for step in path:
            assert not step is None
            if (step_contains(step, from_index + 1)
                    and not step in known_edges):
                tmp.append([
                    step,
                ])

        tmp.sort(graph.cmp_recency)
        for tmp_path in tmp:
            assert len(tmp_path) == 1
            assert not tmp_path[0] is None
            second.append(tmp_path[0])
            known_edges.add(tmp_path[0])
            allowed -= 1
            if allowed <= 0:
                return second

    return second
Пример #4
0
def canonical_path_edges(graph, known_edges, from_index, allowed):
    """ INTERNAL: Returns edges containing from_index from canonical paths. """
    # Steps from canonical paths
    # REDFLAG: fix, efficiency, bound number of path, add alternate edges
    #paths = graph.canonical_paths(graph.latest_index, MAX_PATH_LEN)
    paths = canonical_path_itr(graph, 0, graph.latest_index, MAX_PATH_LEN)

    second = []
    #print "get_update_edges -- after"
    for path in paths:
        # We need the tmp gook because the edges can overlap
        # and we want the most recent ones.
        tmp = []
        for step in path:
            assert not step is None
            if (step_contains(step, from_index + 1) and
                not step in known_edges):
                tmp.append([step, ])

        tmp.sort(graph.cmp_recency)
        for tmp_path in tmp:
            assert len(tmp_path) == 1
            assert not tmp_path[0] is None
            second.append(tmp_path[0])
            known_edges.add(tmp_path[0])
            allowed -= 1
            if allowed <= 0:
                return second

    return second
Пример #5
0
    def _handle_dump_canonical_paths(self, graph):
        """ INTERNAL: Dump the top 20 canonical paths. """
        if not self.parent.params.get('DUMP_CANONICAL_PATHS', False):
            return

        paths = canonical_path_itr(graph, 0, graph.latest_index, MAX_PATH_LEN)
        first_paths = []
        # REDFLAG: Magick number
        while len(first_paths) < 20:
            try:
                first_paths.append(paths.next())
            except StopIteration:
                break

        dump_paths(graph, first_paths, "Canonical paths")
Пример #6
0
    def _handle_dump_canonical_paths(self, graph):
        """ INTERNAL: Dump the top 20 canonical paths. """
        if not self.parent.params.get('DUMP_CANONICAL_PATHS', False):
            return

        paths = canonical_path_itr(graph, 0, graph.latest_index,
                                               MAX_PATH_LEN)
        first_paths = []
        # REDFLAG: Magick number
        while len(first_paths) < 20:
            try:
                first_paths.append(paths.next())
            except StopIteration:
                break

        dump_paths(graph,
                   first_paths,
                   "Canonical paths")