Пример #1
0
    def allPatterns(cls, motif, k):
        """
        Return all k-patterns from a given vertex set
        """

        if (motif, k) in cls.allPatternLookup:
            patterns = cls.allPatternLookup[(motif, k)]
        else:
            patterns = []
            # iterate over power set of vertices
            vertexSet = motif.nodes
            for v_set in xpowerset(vertexSet):
                # iterate over all possible boundary sizes
                for boundarySize in range(min([k, len(v_set)]) + 1):
                    # iterate over all possible boundaries
                    for boundary in itertools.combinations(
                            v_set, boundarySize):
                        # iterate over all possible boundary mappings
                        for mapping in itertools.permutations(
                                range(k), boundarySize):
                            d = dict(zip(boundary, mapping))
                            kp = cls(v_set, d, motif)
                            if kp.isSeparator():
                                patterns.append(kp)
                                cls.separatorLookup[(kp.vertices, kp.boundary,
                                                     motif)] = kp
            cls.allPatternLookup[(motif, k)] = patterns
        return iter(patterns)
Пример #2
0
    def allPatterns(cls, motif, k):
        """
        Return all k-patterns from a given vertex set
        """

        if (motif, k) in cls.allPatternLookup:
            patterns = cls.allPatternLookup[(motif, k)]
        else:
            patterns = []
            # iterate over power set of vertices
            vertexSet = motif.nodes
            for v_set in xpowerset(vertexSet):
                # iterate over all possible boundary sizes
                for boundarySize in range(min([k, len(v_set)])+1):
                    # iterate over all possible boundaries
                    for boundary in itertools.combinations(v_set,
                                                           boundarySize):
                        # iterate over all possible boundary mappings
                        for mapping in itertools.permutations(range(k),
                                                              boundarySize):
                            d = dict(zip(boundary, mapping))
                            kp = cls(v_set, d, motif)
                            if kp.isSeparator():
                                patterns.append(kp)
                                cls.separatorLookup[(kp.vertices, kp.boundary,
                                                     motif)] = kp
            cls.allPatternLookup[(motif, k)] = patterns
        return iter(patterns)
Пример #3
0
 def allCompatible(self):
     """
     Generator of all patterns that are compatible for joining with this
     pattern
     """
     v_set = self.graph.nodes
     for otherVertices in xpowerset(v_set - self.vertices):
         pattern2 = self.__class__(set(otherVertices) | self.boundaryVertices, self.boundary, self.graph)
         if pattern2.isSeparator():
             yield pattern2
Пример #4
0
 def allCompatible(self):
     """
     Generator of all patterns that are compatible for joining with this
     pattern
     """
     v_set = self.graph.nodes
     for otherVertices in xpowerset(v_set - self.vertices):
         pattern2 = self.__class__(
             set(otherVertices) | self.boundaryVertices, self.boundary,
             self.graph)
         if pattern2.isSeparator():
             yield pattern2
Пример #5
0
    def inverseJoin(self):
        """Generator of all pattern pairs whose joins give this pattern"""
        # Create set of vertices not on the boundary
        nonBoundaryVertices = self.vertices - self.boundaryVertices

        # Iterate over all divisions of boundary vertices into 2 sets
        for v_list in xpowerset(nonBoundaryVertices):
            v_set = set(v_list)
            # print "Inverse join: " + str(v_set)
            pattern2 = self.__class__(v_set | self.boundaryVertices, self.boundary, self.graph)
            pattern3 = self.__class__(self.vertices - v_set, self.boundary, self.graph)
            if pattern2.isSeparator() and pattern3.isSeparator():
                yield (pattern2, pattern3)
Пример #6
0
    def inverseJoin(self, mem_motif=None):
        """Generator of all pattern pairs whose joins give this pattern"""
        # Create set of vertices not on the boundary
        nonBoundaryVertices = self.vertices - self.boundaryVertices

        # Iterate over all divisions of boundary vertices into 2 sets
        for v_list in xpowerset(nonBoundaryVertices):
            v_set = set(v_list)
            # print "Inverse join: " + str(v_set)
            pattern2 = self.__class__(v_set | self.boundaryVertices,
                                      self.boundary, self.graph)
            pattern3 = self.__class__(self.vertices - v_set, self.boundary,
                                      self.graph)
            if pattern2.isSeparator() and pattern3.isSeparator():
                yield (pattern2, pattern3)
Пример #7
0
 def allPatterns(cls, graph, k):
     """Return all k-patterns from a given vertex set"""
     # iterate over power set of vertices
     vertexSet = graph.nodes
     for v_set in xpowerset(vertexSet):
         # iterate over all possible boundary sizes
         for boundarySize in range(min([k, len(v_set)]) + 1):
             # iterate over all possible boundaries
             for boundary in itertools.combinations(v_set, boundarySize):
                 # iterate over all possible boundary mappings
                 for mapping in itertools.permutations(range(k), boundarySize):
                     d = dict(zip(boundary, mapping))
                     kp = cls(v_set, d, graph)
                     if kp.isSeparator():
                         yield kp
Пример #8
0
 def allPatterns(cls, graph, k):
     """Return all k-patterns from a given vertex set"""
     # iterate over power set of vertices
     vertexSet = graph.nodes
     for v_set in xpowerset(vertexSet):
         # iterate over all possible boundary sizes
         for boundarySize in range(min([k, len(v_set)]) + 1):
             # iterate over all possible boundaries
             for boundary in itertools.combinations(v_set, boundarySize):
                 # iterate over all possible boundary mappings
                 for mapping in itertools.permutations(
                         range(k), boundarySize):
                     d = dict(zip(boundary, mapping))
                     kp = cls(v_set, d, graph)
                     if kp.isSeparator():
                         yield kp
Пример #9
0
 def allPatterns(cls, graph, k):
     """Return all k-patterns from a given vertex set"""
     # print [(i, len(j)) for i, j in cls.allPatternLookup.iteritems()]
     if (graph, k) in cls.allPatternLookup:
         patterns = cls.allPatternLookup[(graph, k)]
     else:
         patterns = []
         # iterate over power set of vertices
         vertexSet = graph.nodes
         for v_set in xpowerset(vertexSet):
             # iterate over all possible boundary sizes
             for boundarySize in range(min([k, len(v_set)])+1):
                 # iterate over all possible boundaries
                 for boundary in itertools.combinations(v_set,
                                                        boundarySize):
                     # iterate over all possible boundary mappings
                     for mapping in itertools.permutations(range(k),
                                                           boundarySize):
                         d = dict(zip(boundary, mapping))
                         kp = cls(v_set, d, graph)
                         if kp.isSeparator():
                             patterns.append(kp)
         cls.allPatternLookup[(graph, k)] = patterns
     return iter(patterns)