Beispiel #1
0
def test_edmonds_seven():
    g = Graph()
    nodes = [0, 1, 2, 3, 4]
    edges = [(0, 1), (1, 2), (2, 0), (2, 3), (3, 4), (4, 2)]
    for n in nodes:
        g.add_node(n)
    for e in edges:
        g.add_edge(e)
    eq_(len(g.find_a_maximum_matching()), 2)
Beispiel #2
0
def test_edmonds_five():
    g = Graph()
    nodes = [0, 1, 2, 3, 4, 5, 6, 7]
    edges = [(0, 3), (1, 3), (2, 3), (3, 4), (4, 5), (4, 6), (4, 7)]
    for n in nodes:
        g.add_node(n)
    for e in edges:
        g.add_edge(e)
    eq_(len(g.find_a_maximum_matching()), 2)
Beispiel #3
0
def test_edmonds_seven():
    g = Graph()
    nodes = [0, 1, 2, 3]
    edges = [(0, 1), (1, 2), (2, 3), (3, 1)]
    for n in nodes:
        g.add_node(n)
    for e in edges:
        g.add_edge(e)
    ll = g.find_maximally_matchable_edges()
    eq_(len(ll), 2)
    ok_((0, 1) in ll)
    ok_((2, 3) in ll)
Beispiel #4
0
def test_matchable_one():
    g = Graph()
    g.add_node(0)
    g.add_node(1)
    g.add_node(2)
    g.add_node(3)
    g.add_edge((0, 1))
    g.add_edge((1, 2))
    g.add_edge((2, 3))
    ll = g.find_maximally_matchable_edges()
    eq_(len(ll), 2)
    ok_((0, 1) in ll)
    ok_((2, 3) in ll)
Beispiel #5
0
def test_edmonds_one():
    g = Graph()
    g.add_node(0)
    g.add_node(1)
    g.add_edge((0, 1))
    eq_(len(g.find_a_maximum_matching()), 1)
Beispiel #6
0
def test_edmonds_four():
    g = Graph()
    g.add_node(0)
    g.add_node(1)
    g.add_node(2)
    g.add_node(3)
    g.add_edge((0, 1))
    g.add_edge((1, 2))
    g.add_edge((2, 3))
    g.add_edge((0, 3))
    eq_(len(g.find_a_maximum_matching()), 2)
 def get_max_matchable_edges_self(self, ndds=None):
     """Find the set of edges which must be in every maximum matching.
     """
     # Build the simple graph
     g = Graph()
     translate = {}
     for edge in self.es:
         v1 = edge.source()
         v2 = edge.target()
         if v2.index() < v1.index():
             continue
         new_edge = (v1.index(), v2.index())
         if self.edge_exists(v2, v1) or edge.donor().is_altruistic():
             g.add_node(new_edge[0])
             g.add_node(new_edge[1])
             g.add_edge(new_edge)
             translate[new_edge] = edge
     count = len(translate)
     for ndd in ndds:
         for edge in ndd.edges:
             v1 = edge.donor()
             v2 = edge.target()
             new_edge = (v2.index(), count + v1.index())
             g.add_node(new_edge[0])
             g.add_node(new_edge[1])
             g.add_edge(new_edge)
             translate[new_edge] = edge
     # TODO Add NDD edges to this graph!
     matchable = g.find_maximally_matchable_edges()
     LOGGER.info("Found %s maximally matchable edges" % len(matchable))
     return (translate[e] for e in matchable)