def code(g, permutation=None): """ The code function returns a numerical value associated with a graph. The graph's "code" is used to impose the list ordering on all graphs in an isomorphism class. The code is also used to determine the graph's "canonicity." In this case, the code is simply the integer value of the graph's upper triangle adjacency matrix. This function has the additional capability of applying a permutation to the vertices. This will yield a different code for each distinct permutation that is applied. :param g: A dict which maps vertex numbers to adjacency lists. :param permutation: A list containing a specific ordering/permutation of the vertices in g :return: A number unique number for this graph. """ if permutation is None: permutation = g.keys() bits = "" for i in range(len(permutation)): for j in range(len(permutation)): if j > i: if graph.isAdj(g, permutation[i], permutation[j]): bits += "1" else: bits += "0" return int(bits, 2)
def augmenter(g): """ A python generator which performs a sequence of augmenting operations on the graph parameter, g. In this case, it adds a single edge in all possible ways. :param g: A dict which maps vertex numbers to adjacency lists. """ vertices = g.keys() for pair in combin.k_combinations(vertices, 2): if not graph.isAdj(g, pair[0], pair[1]): new_graph = deepcopy(g) new_graph[pair[0]].append(pair[1]) new_graph[pair[1]].append(pair[0]) yield new_graph