def complete(self, match): if not SubgraphPattern.complete(self, match): return False if self.strong: # If the ring is not strong, return False if self.size%2 == 0: # even ring for i in xrange(self.size/2): node1_start = match.forward[i] node1_stop = match.forward[i+self.size/2] paths = list(self.graph.iter_shortest_paths(node1_start, node1_stop)) if len(paths) != 2: #print "Even ring must have two paths between opposite nodes" return False for path in paths: if len(path) != self.size/2+1: #print "Paths between opposite nodes must half the size of the ring+1" return False else: # odd ring for i in xrange(self.size/2+1): node1_start = match.forward[i] node1_stop = match.forward[i+self.size/2] paths = list(self.graph.iter_shortest_paths(node1_start, node1_stop)) if len(paths) > 1: return False if len(paths[0]) != self.size/2+1: return False node1_stop = match.forward[i+self.size/2+1] paths = list(self.graph.iter_shortest_paths(node1_start, node1_stop)) if len(paths) > 1: return False if len(paths[0]) != self.size/2+1: return False return True
def check_next_match(self, match, new_relations): if not SubgraphPattern.check_next_match(self, match, new_relations): return False if self.strong: # can this ever become a strong ring? node1_start = match.forward[self.subgraph.central_node] for node1 in new_relations.itervalues(): paths = list(self.graph.iter_shortest_paths(node1, node1_start)) if self.size % 2 == 0 and len(match) == self.size: if len(paths) != 2: #print "NRingPattern.check_next_match: not strong a.1" return False for path in paths: if len(path) != len(match)/2+1: #print "NRingPattern.check_next_match: not strong a.2" return False else: if len(paths) != 1: #print "NRingPattern.check_next_match: not strong b.1" return False if len(paths[0]) != (len(match)+1)/2: #print "NRingPattern.check_next_match: not strong b.2" return False #print "RingPattern.check_next_match: no remarks" return True
def __init__(self, size, criteria_sets=None, node_tags={}, strong=False): self.size = size self.strong = strong subgraph = Graph([(i,(i+1)%size) for i in xrange(size)]) SubgraphPattern.__init__(self, subgraph, criteria_sets, node_tags)
def __init__(self, criteria_sets=None, node_tags={}): subgraph = Graph([(0, 1), (0, 2), (0, 3), (0, 4)]) SubgraphPattern.__init__(self, subgraph, criteria_sets, node_tags)