Ejemplo n.º 1
0
    def __init__(
        self,
        molecule1,
        molecule2,
        prematched=[],
        vertex_equality=None,
        edge_equality=None,
    ):

        if vertex_equality is None:
            import operator
            vertex_equality = operator.eq

        if edge_equality is None:
            import operator
            edge_equality = operator.eq

        self.molecule1 = molecule1.atom_for
        self.molecule2 = molecule2.atom_for
        self.best = [[]]
        self.largest = 0

        from graph import maximum_clique

        self.compat_graph = maximum_clique.compatibility_graph(
            first=molecule1.graph,
            second=molecule2.graph,
            vertex_equality=vertex_equality,
            edge_equality=edge_equality)

        self.prematched = prematched

        if self.prematched:
            desc_for_1 = molecule1.descriptor_for
            desc_for_2 = molecule2.descriptor_for
            pairs = set([(desc_for_1[l], desc_for_2[r])
                         for (l, r) in self.prematched])
            vertices = [
                v for v in self.compat_graph.vertices()
                if self.compat_graph.vertex_label(vertex=v) in pairs
            ]

            assert len(vertices) == len(self.prematched)
            neighbours = set(
                self.compat_graph.adjacent_vertices(vertex=vertices[0]))

            for v in vertices[1:]:
                neighbours.intersection_update(
                    self.compat_graph.adjacent_vertices(vertex=v))

            self.compat_graph = maximum_clique.selected_subgraph(
                graph=self.compat_graph,
                vertices=neighbours,
            )

        maximum_clique.rascal(graph=self.compat_graph, callable=self)
Ejemplo n.º 2
0
  def __init__(
    self,
    molecule1,
    molecule2,
    prematched = [],
    vertex_equality = None,
    edge_equality = None,
    ):

    if vertex_equality is None:
      import operator
      vertex_equality = operator.eq

    if edge_equality is None:
      import operator
      edge_equality = operator.eq

    self.molecule1 = molecule1.atom_for
    self.molecule2 = molecule2.atom_for
    self.best = [ [] ]
    self.largest = 0

    from graph import maximum_clique

    self.compat_graph = maximum_clique.compatibility_graph(
      first = molecule1.graph,
      second = molecule2.graph,
      vertex_equality = vertex_equality,
      edge_equality = edge_equality
      )

    self.prematched = prematched

    if self.prematched:
      desc_for_1 = molecule1.descriptor_for
      desc_for_2 = molecule2.descriptor_for
      pairs = set(
        [ ( desc_for_1[ l ], desc_for_2[ r ] ) for ( l, r ) in self.prematched ]
        )
      vertices = [ v for v in self.compat_graph.vertices()
        if self.compat_graph.vertex_label( vertex = v ) in pairs ]

      assert len( vertices ) == len( self.prematched )
      neighbours = set( self.compat_graph.adjacent_vertices( vertex = vertices[0] ) )

      for v in vertices[1:]:
        neighbours.intersection_update( self.compat_graph.adjacent_vertices( vertex = v ) )

      self.compat_graph = maximum_clique.selected_subgraph(
        graph = self.compat_graph,
        vertices = neighbours,
        )

    maximum_clique.rascal( graph = self.compat_graph, callable = self )
  def manipulation(self, g):

    n = {}
    n[ "1,1'" ] = g.add_vertex() # 0
    n[ "1,5'" ] = g.add_vertex() # 1
    n[ "2,2'" ] = g.add_vertex() # 2
    n[ "2,3'" ] = g.add_vertex() # 3
    n[ "3,2'" ] = g.add_vertex() # 4
    n[ "3,3'" ] = g.add_vertex() # 5
    n[ "4,4'" ] = g.add_vertex() # 6
    n[ "5,1'" ] = g.add_vertex() # 7
    n[ "5,5'" ] = g.add_vertex() # 8

    g.add_edge( vertex1 = n[ "1,1'" ], vertex2 = n[ "3,3'" ] )
    g.add_edge( vertex1 = n[ "1,1'" ], vertex2 = n[ "4,4'" ] )
    g.add_edge( vertex1 = n[ "1,1'" ], vertex2 = n[ "5,5'" ] )

    g.add_edge( vertex1 = n[ "1,5'" ], vertex2 = n[ "3,2'" ] )
    g.add_edge( vertex1 = n[ "1,5'" ], vertex2 = n[ "4,4'" ] )
    g.add_edge( vertex1 = n[ "1,5'" ], vertex2 = n[ "5,1'" ] )

    g.add_edge( vertex1 = n[ "2,2'" ], vertex2 = n[ "3,3'" ] )
    g.add_edge( vertex1 = n[ "2,2'" ], vertex2 = n[ "4,4'" ] )
    g.add_edge( vertex1 = n[ "2,2'" ], vertex2 = n[ "5,5'" ] )

    g.add_edge( vertex1 = n[ "2,3'" ], vertex2 = n[ "3,2'" ] )
    g.add_edge( vertex1 = n[ "2,3'" ], vertex2 = n[ "5,1'" ] )

    g.add_edge( vertex1 = n[ "3,2'" ], vertex2 = n[ "5,1'" ] )

    g.add_edge( vertex1 = n[ "3,3'" ], vertex2 = n[ "4,4'" ] )
    g.add_edge( vertex1 = n[ "3,3'" ], vertex2 = n[ "5,5'" ] )

    g.add_edge( vertex1 = n[ "4,4'" ], vertex2 = n[ "5,1'" ] )
    g.add_edge( vertex1 = n[ "4,4'" ], vertex2 = n[ "5,5'" ] )

    a = accumulator()
    maximum_clique.rascal( graph = g, callable = a )
    self.assertEqual(
      set(
        [
          frozenset( [ n[ "1,1'" ], n[ "3,3'" ] , n[ "4,4'" ], n[ "5,5'" ] ] ),
          frozenset( [ n[ "2,2'" ], n[ "3,3'" ] , n[ "4,4'" ], n[ "5,5'" ] ] ),
          ]
        ),
      set( frozenset( m ) for m in a.sent ),
      )
Ejemplo n.º 4
0
    def manipulation(self, g):

        n = {}
        n["1,1'"] = g.add_vertex()  # 0
        n["1,5'"] = g.add_vertex()  # 1
        n["2,2'"] = g.add_vertex()  # 2
        n["2,3'"] = g.add_vertex()  # 3
        n["3,2'"] = g.add_vertex()  # 4
        n["3,3'"] = g.add_vertex()  # 5
        n["4,4'"] = g.add_vertex()  # 6
        n["5,1'"] = g.add_vertex()  # 7
        n["5,5'"] = g.add_vertex()  # 8

        g.add_edge(vertex1=n["1,1'"], vertex2=n["3,3'"])
        g.add_edge(vertex1=n["1,1'"], vertex2=n["4,4'"])
        g.add_edge(vertex1=n["1,1'"], vertex2=n["5,5'"])

        g.add_edge(vertex1=n["1,5'"], vertex2=n["3,2'"])
        g.add_edge(vertex1=n["1,5'"], vertex2=n["4,4'"])
        g.add_edge(vertex1=n["1,5'"], vertex2=n["5,1'"])

        g.add_edge(vertex1=n["2,2'"], vertex2=n["3,3'"])
        g.add_edge(vertex1=n["2,2'"], vertex2=n["4,4'"])
        g.add_edge(vertex1=n["2,2'"], vertex2=n["5,5'"])

        g.add_edge(vertex1=n["2,3'"], vertex2=n["3,2'"])
        g.add_edge(vertex1=n["2,3'"], vertex2=n["5,1'"])

        g.add_edge(vertex1=n["3,2'"], vertex2=n["5,1'"])

        g.add_edge(vertex1=n["3,3'"], vertex2=n["4,4'"])
        g.add_edge(vertex1=n["3,3'"], vertex2=n["5,5'"])

        g.add_edge(vertex1=n["4,4'"], vertex2=n["5,1'"])
        g.add_edge(vertex1=n["4,4'"], vertex2=n["5,5'"])

        a = accumulator()
        maximum_clique.rascal(graph=g, callable=a)
        self.assertEqual(
            set([
                frozenset([n["1,1'"], n["3,3'"], n["4,4'"], n["5,5'"]]),
                frozenset([n["2,2'"], n["3,3'"], n["4,4'"], n["5,5'"]]),
            ]),
            set(frozenset(m) for m in a.sent),
        )