def test_simple(self): M = np.array([ [0, 0, 0, 0, 0, 0, 0, 0, 0], [0.25, 0, 0, 0, 0, 0, 0, 0, 0], [0.1, 0, 0, 0, 0, 0, 0, 0, 0], [0.05, 0, 0, 0, 0, 0, 0, 0, 0], [0.1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0.2, 0, 0.05, 0.1, 0.15], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0] ]) expected = np.array([ [0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 1, 1, 0, 1], [0, 0, 0, 0, 0, 0, 0, 1, 0], ]) G = nx.from_numpy_matrix(M, create_using=nx.DiGraph) ut.normalizeGraph(G) expectedG = nx.from_numpy_matrix(expected) ut.normalizeGraph(G) resG = tr.treeToBND(M) N = nx.to_numpy_matrix(resG) np.testing.assert_array_equal(expected, N) dr.printInput(G) dr.printRes(G, resG, expectedG)
def test_simple(self): M = np.array([ [0, 0, 0, 0, 0, 0, 0, 0], [0.1, 0, 0, 0, 0, 0, 0, 0], [0.15, 0, 0, 0, 0, 0, 0, 0], [0.05, 0, 0, 0, 0, 0, 0, 0], [0.1, 0, 0, 0, 0, 0.05, 0.35, 0.2], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0] ]) expected = np.array([ [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 1, 0, 1], [1, 1, 0, 1, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1], [0, 1, 0, 0, 1, 0, 1, 0], ]) G = nx.from_numpy_matrix(M, create_using=nx.DiGraph) ut.normalizeGraph(G) expectedG = nx.from_numpy_matrix(expected) ut.normalizeGraph(G) res = sp.sparseToBND(G) resG, layers = res[0], res[1] N = nx.to_numpy_matrix(resG) dr.printInput(G) dr.printRes(G, resG, expectedG, layers) np.testing.assert_array_equal(expected, N)
return G choice = 1 ### a simple random graph if choice == 0: n = 20 G = randomGraph(n) dr.printInput(G) res = sp.sparseToBND(G) N, layers = res[0], res[1] dr.printRes(G, N, None, layers) ### Several test on random graphs if choice == 1: N, n = 100000, 20 results = [] inputs = [] for i in tqdm(range(N)): G = randomGraph(n) edges = str(G.edges) avgDegree = ev.getAverageDegree(G) n = len(G) res = sp.sparseToBND(G)
print('(1) one single highland graph') print('(2) all highlands graphs with a given number of nodes') choice = int(input('Your choice: ')) ### Simple Test ### if choice == 1: n = int(input('How many nodes ? ')) m = int(input('Degree of the highland nodes ? ')) print(n, m) G = highlands(n, m) dr.printInput(G) res = sp.sparseToBND(G) N = res[0] dr.printRes(G, N, None) ### All tests ### elif choice == 2: n = int(input('How many nodes ? ')) EPLs = np.zeros(n) maxs = np.zeros(n) for m in range(n): _m = m+1 G = highlands(n, _m) res = sp.sparseToBND(G) N = res[0] EPL = ev.getEPL(G, N) _max = ev.getMaxDegree(N) EPLs[m] = EPL
choice = 4 ### Simple Test for one wheel ### if choice == 0: n = 10 center = 0 nodes = np.array([i for i in range(n)]) G = simpleWheel(nodes, center, direction=ut.Direction.OUTGOING) dr.printInput(G) res = sp.sparseToBND(G) dr.printRes(G, res[0], None, res[1]) ### Simple Test for several wheels ### elif choice == 1: n = 10 nodes = np.array([i for i in range(n)]) highOutSubsets = [0] highInSubsets = [5] G = severalWheels(nodes, highOutSubsets, highInSubsets) dr.printInput(G) res = sp.sparseToBND(G) N, layers = res[0], res[1] dr.printRes(G, N, None, layers)