def test_g3(self):
     """
     I = {A : Y,X,Z ; B : X,Y,Z ; C : X,Y,Z ;
          X : A,B,C ; Y : B,A,C ; Z : A,B,C ; }
     """
     G = make_graph(
             [('A', ['Y', 'X', 'Z']), ('B', ['X', 'Y', 'Z']), ('C', ['X', 'Y', 'Z'])],
             [('X', ['A', 'B', 'C']), ('Y', ['B', 'A', 'C']), ('Z', ['A', 'B', 'C'])])
     self.assertTrue(
             is_stable(G, matching_algos.stable_matching_man_woman(graph.copy_graph(G))))
 def test_g1(self):
     """
     I = {a1 : b1 ;
          b1 : a1 ;}
     """
     G = make_graph(
             [('a1', ['b1'])],
             [('b1', ['a1'])])
     self.assertTrue(
             is_stable(G, matching_algos.stable_matching_man_woman(graph.copy_graph(G))))
 def test_g1(self):
     """
     I = {a1 : b1 ;
          b1 : a1 ;}
     """
     G = make_graph([('a1', ['b1'])], [('b1', ['a1'])])
     self.assertTrue(
         is_stable(
             G,
             matching_algos.stable_matching_man_woman(graph.copy_graph(G))))
Exemple #4
0
def main():
    import sys
    import graph_parser
    import matching_algos
    if len(sys.argv) < 2:
        print('usage: {} <graph file>'.format(sys.argv[0]))
    else:
        G = graph_parser.read_graph(sys.argv[1])
        M1 = matching_algos.stable_matching_man_woman(copy_graph(G))
        M2 = matching_algos.popular_matching_man_woman(copy_graph(G))
        print(to_easy_format(G, M1), to_easy_format(G, M2), sep='\n')
 def test_g4(self):
     """
     I = {m1 : w2,w4,w1,w3 ; m2 : w3,w1,w4,w2 ; m3 : w2,w3,w1,w4 ; m4 : w4,w1,w3,w2 ;
          w1 : m2,m1,m4,m3 ; w2 : m4,m3,m1,m2 ; w3 : m1,m4,m3,m2 ; w4 : m2,m1,m4,m3 ;}
     """
     G = make_graph(
             [('m1', ['w2', 'w4', 'w1', 'w3']), ('m2', ['w3', 'w1', 'w4', 'w2']),
              ('m3', ['w2', 'w3', 'w1', 'w4']), ('m4', ['w4', 'w1', 'w3', 'w2'])],
             [('w1', ['m2', 'm1', 'm4', 'm3']), ('w2', ['m4', 'm3', 'm1', 'm2']),
              ('w3', ['m1', 'm4', 'm3', 'm2']), ('w4', ['m2', 'm1', 'm4', 'm3'])])
     self.assertTrue(
             is_stable(G, matching_algos.stable_matching_man_woman(graph.copy_graph(G))))
 def test_g3(self):
     """
     I = {A : Y,X,Z ; B : X,Y,Z ; C : X,Y,Z ;
          X : A,B,C ; Y : B,A,C ; Z : A,B,C ; }
     """
     G = make_graph([('A', ['Y', 'X', 'Z']), ('B', ['X', 'Y', 'Z']),
                     ('C', ['X', 'Y', 'Z'])], [('X', ['A', 'B', 'C']),
                                               ('Y', ['B', 'A', 'C']),
                                               ('Z', ['A', 'B', 'C'])])
     self.assertTrue(
         is_stable(
             G,
             matching_algos.stable_matching_man_woman(graph.copy_graph(G))))
 def test_g4(self):
     """
     I = {m1 : w2,w4,w1,w3 ; m2 : w3,w1,w4,w2 ; m3 : w2,w3,w1,w4 ; m4 : w4,w1,w3,w2 ;
          w1 : m2,m1,m4,m3 ; w2 : m4,m3,m1,m2 ; w3 : m1,m4,m3,m2 ; w4 : m2,m1,m4,m3 ;}
     """
     G = make_graph([('m1', ['w2', 'w4', 'w1', 'w3']),
                     ('m2', ['w3', 'w1', 'w4', 'w2']),
                     ('m3', ['w2', 'w3', 'w1', 'w4']),
                     ('m4', ['w4', 'w1', 'w3', 'w2'])],
                    [('w1', ['m2', 'm1', 'm4', 'm3']),
                     ('w2', ['m4', 'm3', 'm1', 'm2']),
                     ('w3', ['m1', 'm4', 'm3', 'm2']),
                     ('w4', ['m2', 'm1', 'm4', 'm3'])])
     self.assertTrue(
         is_stable(
             G,
             matching_algos.stable_matching_man_woman(graph.copy_graph(G))))