def complete(self, match, subject_graph):
size = len(match)<EOL>if match.forward[size-<NUM_LIT:1>] in subject_graph.neighbors[match.forward[size-<NUM_LIT:2>]]:<EOL><INDENT>order = list(range(<NUM_LIT:0>, size, <NUM_LIT:2>)) + list(range(<NUM_LIT:1>, size-<NUM_LIT:1>, <NUM_LIT:2>))[::-<NUM_LIT:1>]<EOL>ok = True<EOL>for i in range(len(order)//<NUM_LIT:2>):<EOL><INDENT>count = len(list(subject_graph.iter_shortest_paths(<EOL>match.forward[order[i]],<EOL>match.forward[order[(i+size//<NUM_LIT:2>)%size]]<EOL>)))<EOL>if count > <NUM_LIT:1>:<EOL><INDENT>ok = False<EOL>break<EOL><DEDENT>count = len(list(subject_graph.iter_shortest_paths(<EOL>match.forward[order[i]],<EOL>match.forward[order[(i+size//<NUM_LIT:2>+<NUM_LIT:1>)%size]]<EOL>)))<EOL>if count > <NUM_LIT:1>:<EOL><INDENT>ok = False<EOL>break<EOL><DEDENT><DEDENT>if ok:<EOL><INDENT>match.ring_vertices = tuple(match.forward[i] for i in order)<EOL>return True<EOL><DEDENT><DEDENT>paths = list(subject_graph.iter_shortest_paths(<EOL>match.forward[size-<NUM_LIT:1>],<EOL>match.forward[size-<NUM_LIT:2>]<EOL>))<EOL>if (size > <NUM_LIT:3> and len(paths) == <NUM_LIT:1> and len(paths[<NUM_LIT:0>]) == <NUM_LIT:3>) or(size == <NUM_LIT:3> and len(paths) == <NUM_LIT:2> and len(paths[<NUM_LIT:0>]) == <NUM_LIT:3>):<EOL><INDENT>path = paths[<NUM_LIT:0>]<EOL>if size == <NUM_LIT:3> and path[<NUM_LIT:1>] == match.forward[<NUM_LIT:0>]:<EOL><INDENT>path = paths[<NUM_LIT:1>]<EOL><DEDENT>match.add_relation(size, path[<NUM_LIT:1>])<EOL>size += <NUM_LIT:1><EOL>order = list(range(<NUM_LIT:0>, size, <NUM_LIT:2>)) + list(range(size-<NUM_LIT:1>, <NUM_LIT:0>, -<NUM_LIT:2>))<EOL>ok = True<EOL>for i in range(len(order)//<NUM_LIT:2>):<EOL><INDENT>count = len(list(subject_graph.iter_shortest_paths(<EOL>match.forward[order[i]],<EOL>match.forward[order[(i+size//<NUM_LIT:2>)%size]]<EOL>)))<EOL>if count != <NUM_LIT:2>:<EOL><INDENT>ok = False<EOL>break<EOL><DEDENT><DEDENT>if ok:<EOL><INDENT>if match.forward[size-<NUM_LIT:1>] < match.forward[<NUM_LIT:0>]:<EOL><INDENT>ok = False<EOL><DEDENT><DEDENT>if not ok:<EOL><INDENT>vertex1 = match.forward[size-<NUM_LIT:1>]<EOL>del match.forward[size-<NUM_LIT:1>]<EOL>del match.reverse[vertex1]<EOL>size -= <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>match.ring_vertices = tuple(match.forward[i] for i in order)<EOL><DEDENT>return ok<EOL><DEDENT>return False<EOL>
Check the completeness of a ring match