示例#1
0
    def test_weak3(self):
        """ 2     456
          / |     |
        3 - 1  -  0 - 789
        """

        # Test that indeed only weakest are removed
        graph = StentGraph()
        graph.add_edge(1, 2, cost=2, ctvalue=50)
        graph.add_edge(2, 3, cost=2, ctvalue=50)
        graph.add_edge(3, 1, cost=2, ctvalue=50)
        #
        graph.add_edge(4, 5, cost=2, ctvalue=50)
        graph.add_edge(5, 6, cost=2, ctvalue=50)
        graph.add_edge(6, 4, cost=2, ctvalue=50)
        #
        graph.add_edge(7, 8, cost=2, ctvalue=50)
        graph.add_edge(8, 9, cost=2, ctvalue=50)
        graph.add_edge(9, 7, cost=2, ctvalue=50)

        # Connect three subgraphs
        graph.add_edge(0, 1, cost=2, ctvalue=50)
        graph.add_edge(0, 4, cost=3, ctvalue=50)  # gets removed
        graph.add_edge(0, 7, cost=2, ctvalue=50)

        # Prune
        prune_weak(graph, 2, 80)
        # Check result
        assert graph.number_of_edges() == 9 + 2
        for e in graph.edges_iter():
            assert e not in [(0, 4)]

        # Connect three subgraphs
        graph.add_edge(0, 1, cost=1, ctvalue=50)
        graph.add_edge(0, 4, cost=1, ctvalue=50)
        graph.add_edge(0, 7, cost=2, ctvalue=50)  # gets removed

        # Prune
        prune_weak(graph, 2, 80)
        # Check result
        assert graph.number_of_edges() == 9 + 2
        for e in graph.edges_iter():
            assert e not in [(0, 7)]

        # Connect three subgraphs
        graph.add_edge(0, 1, cost=3, ctvalue=50)
        graph.add_edge(0, 4, cost=4, ctvalue=90)  # None gets removed
        graph.add_edge(0, 7, cost=3, ctvalue=50)

        # Prune
        prune_weak(graph, 2, 80)
        # Check result
        assert graph.number_of_edges() == 9 + 3
示例#2
0
    def test_weak1(self):
        """ 2
          / | \
        5 - 1 - 3
          \ | /
            4 
        """

        # Test that indeed only weakest are removed
        graph = StentGraph()
        graph.add_edge(1, 2, cost=2, ctvalue=50)
        graph.add_edge(1, 3, cost=3, ctvalue=50)  # gets removed
        graph.add_edge(1, 4, cost=4, ctvalue=50)  # gets removed
        graph.add_edge(1, 5, cost=1, ctvalue=50)
        #
        graph.add_edge(2, 3, cost=1, ctvalue=50)
        graph.add_edge(3, 4, cost=1, ctvalue=50)
        graph.add_edge(4, 5, cost=1, ctvalue=50)
        graph.add_edge(5, 2, cost=1, ctvalue=50)

        prune_weak(graph, 2, 80)

        # Check result
        assert graph.number_of_edges() == 6
        for e in graph.edges_iter():
            assert e not in [(1, 3), (1, 4)]
示例#3
0
    def test_very_weak(self):

        # Create simple graph
        graph = StentGraph()
        graph.add_edge(1, 4, ctvalue=50)
        graph.add_edge(1, 5, ctvalue=40)
        graph.add_edge(1, 2, ctvalue=30)
        graph.add_edge(1, 3, ctvalue=20)

        # Remove weak edges
        th = 35
        prune_very_weak(graph, th)

        # Check result
        assert graph.number_of_edges() == 2
        for (n1, n2) in graph.edges_iter():
            assert graph[n1][n2]['ctvalue'] > th
示例#4
0
    def test_weak2(self):
        """ 2     5
          / |     | \
        3 - 1  -  4 - 6
        """

        # Test that indeed only weakest are removed
        graph = StentGraph()
        graph.add_edge(1, 2, cost=2, ctvalue=50)
        graph.add_edge(2, 3, cost=2, ctvalue=50)
        graph.add_edge(3, 1, cost=2, ctvalue=50)
        #
        graph.add_edge(4, 5, cost=2, ctvalue=50)
        graph.add_edge(5, 6, cost=2, ctvalue=50)
        graph.add_edge(6, 4, cost=2, ctvalue=50)

        # Connect two subgraphs with weaker connection
        graph.add_edge(1, 4, cost=3, ctvalue=50)

        # Prune
        prune_weak(graph, 2, 80)
        # Check result
        assert graph.number_of_edges() == 6
        for e in graph.edges_iter():
            assert e not in [(1, 4)]

        # Again, now with lower cost (stronger connection)
        graph.add_edge(1, 4, cost=1, ctvalue=50)

        # Prune
        prune_weak(graph, 2, 80)
        # Check result
        assert graph.number_of_edges() == 7

        # Again, now with high ct value
        graph.add_edge(1, 4, cost=3, ctvalue=90)

        # Prune
        prune_weak(graph, 2, 80)
        # Check result
        assert graph.number_of_edges() == 7