def are_equivalent(mat1, mat2): tr1 = oapackage.reduceGraphNauty(mat1, verbose=0) tri1 = inverse_permutation(tr1) mat1_reduced = oapackage.transformGraphMatrix(mat1, tri1) tr2 = oapackage.reduceGraphNauty(mat2, verbose=0) tri2 = inverse_permutation(tr2) mat2_reduced = oapackage.transformGraphMatrix(mat2, tri2) return np.all(mat1_reduced == mat2_reduced)
def reduce_mod_equivalence(candidates, verbose=False): reps = [] reduced_reps = {} for k, cand in enumerate(candidates): tr = oapackage.reduceGraphNauty(cand, verbose=0) tri = inverse_permutation(tr) cand_reduced = oapackage.transformGraphMatrix(cand, tri) cand_reduced_list = tuple(map(tuple, cand_reduced)) if cand_reduced_list not in reduced_reps: reduced_reps[cand_reduced_list] = 1 reps.append(cand) if verbose: print('\t{} reps from {} candidates'.format(len(reps), k + 1)) return reps
def reduce_mod_equivalence_short(candidates, verbose=False): # May offer advantages over standard proc if few candidates # As then cost of array list comparison cheaper than # conversion to tuple for hash lookup reps = [] reduced_reps = [] for k in range(len(candidates)): cand = candidates[k] tr = oapackage.reduceGraphNauty(cand, verbose=0) tri = inverse_permutation(tr) cand_reduced = oapackage.transformGraphMatrix(cand, tri) if not any(np.array_equal(cand_reduced, c) for c in reduced_reps): reduced_reps.append(cand_reduced) reps.append(cand) if verbose: print('\t{} reps for {} candidates'.format(len(reps), k + 1)) return reps
# -*- coding: utf-8 -*- """ Example script to use Nauty from Python """ #%% Load packages import numpy as np import oapackage # define some graph and colors G = np.zeros((5, 5), dtype=int) G[0, 1] = G[0, 2] = G[0, 3] = G[1, 3] = 1 colors = [0, 0, 0, 1, 1] tr = oapackage.reduceGraphNauty(G, colors=colors, verbose=2) Gx = oapackage.transformGraphMatrix(G, tr) print('input graph: ') print(G) print('reduced graph: ') print(Gx)
def test_reduceGraphNauty(self): G = np.zeros((5, 5), dtype=int) G[1, 0] = G[0, 1] = 1 v = oapackage.reduceGraphNauty(G) self.assertTrue(len(v) == G.shape[0])