Sun Mar 12 15:10:13 2023 graph_adj_test(): Python version:3.8.10 Test graph_adj(). graph_adj_degree_test(): graph_adj_degree() computes the degree of the nodes; The graph adjacency matrix: [[0 0 1 0 0 0 1 0 0 1] [0 0 0 0 1 0 0 0 0 1] [1 0 0 0 0 1 0 0 1 0] [0 0 0 0 0 0 1 1 0 0] [0 1 0 0 0 0 0 0 0 0] [0 0 1 0 0 0 0 0 1 0] [1 0 0 1 0 0 0 0 0 0] [0 0 0 1 0 0 0 0 0 1] [0 0 1 0 0 1 0 0 0 0] [1 1 0 0 0 0 0 1 0 0]] The node degrees: [3 2 3 2 1 2 2 2 2 3] graph_adj_distance_from_node_test(): graph_adj_distance_from_node() computes the distance from one node to all other nodes in a graph; The graph adjacency matrix: [[0 0 1 0 0 0 1 0 0 1] [0 0 0 0 1 0 0 0 0 1] [1 0 0 0 0 1 0 0 1 0] [0 0 0 0 0 0 1 1 0 0] [0 1 0 0 0 0 0 0 0 0] [0 0 1 0 0 0 0 0 1 0] [1 0 0 1 0 0 0 0 0 0] [0 0 0 1 0 0 0 0 0 1] [0 0 1 0 0 1 0 0 0 0] [1 1 0 0 0 0 0 1 0 0]] Distance from node 6 [1. 3. 2. 1. 4. 3. 0. 2. 3. 2.] graph_adj_edge_count_test(): graph_adj_edge_count() counts edges in a graph. Adjacency matrix for bush example: [[0 0 0 1 0 0 0] [0 0 0 0 1 0 0] [0 0 0 0 1 0 0] [1 0 0 0 1 1 1] [0 1 1 1 0 0 0] [0 0 0 1 0 0 0] [0 0 0 1 0 0 0]] Number of edges is 6 graph_adj_edge_select_test(): graph_adj_edge_select() selects an edge from a graph defined by an adjacency matrix. Adjacency matrix for bush example [[0 0 0 1 0 0 0] [0 0 0 0 1 0 0] [0 0 0 0 1 0 0] [1 0 0 0 1 1 1] [0 1 1 1 0 0 0] [0 0 0 1 0 0 0] [0 0 0 1 0 0 0]] An edge of this graph extends from node 6 to node 3 graph_adj_is_eulerian_test( ): graph_adj_is_eulerian() determines whether a graph is eulerian. Matrix A: [[0 0 1 0 0 0 1 0 0 1] [0 0 0 0 1 0 0 0 0 1] [1 0 0 0 0 1 0 0 1 0] [0 0 0 0 0 0 1 1 0 0] [0 1 0 0 0 0 0 0 0 0] [0 0 1 0 0 0 0 0 1 0] [1 0 0 1 0 0 0 0 0 0] [0 0 0 1 0 0 0 0 0 1] [0 0 1 0 0 1 0 0 0 0] [1 1 0 0 0 0 0 1 0 0]] circuit_eulerian = False path_eulerian = False Matrix B: [[0 0 1 0 1 0 1 0 0 1] [0 0 0 0 1 0 0 0 0 1] [1 0 0 0 0 1 0 0 1 0] [0 0 0 0 0 0 1 1 0 0] [1 1 0 0 0 0 0 0 0 0] [0 0 1 0 0 0 0 0 1 0] [1 0 0 1 0 0 0 0 0 0] [0 0 0 1 0 0 0 0 0 1] [0 0 1 0 0 1 0 0 0 0] [1 1 0 0 0 0 0 1 0 0]] circuit_eulerian = False path_eulerian = True Matrix C: [[0 0 1 0 1 0 1 0 0 1] [0 0 0 0 1 0 0 0 0 1] [1 0 0 0 0 1 0 0 1 1] [0 0 0 0 0 0 1 1 0 0] [1 1 0 0 0 0 0 0 0 0] [0 0 1 0 0 0 0 0 1 0] [1 0 0 1 0 0 0 0 0 0] [0 0 0 1 0 0 0 0 0 1] [0 0 1 0 0 1 0 0 0 0] [1 1 1 0 0 0 0 1 0 0]] circuit_eulerian = True path_eulerian = True graph_adj_is_nodewise_connected_test( ): A graph is to be checked for nodewise connectedness. graph_adj_is_nodewise_connected_breadth() uses breadth-first search. graph_adj_is_nodewise_connected_depth() uses depth-first search. graph_adj_is_nodewise_connected_walks() counts the walks from node to node. Results for graph A (not connected!) breadth: False depth: False walks: False Results for graph B (connected!) breadth: True depth: True walks: True graph_adj_random_test(): graph_adj_random() returns a random graph, for which the probability of an edge between nodes I and J is PROB. Random graph # 1 node_num = 100 edge_num = 1231 edge_max = 4950 ratio = 0.24868686868686868 prob = 0.25 Random graph # 2 node_num = 100 edge_num = 2492 edge_max = 4950 ratio = 0.5034343434343435 prob = 0.5 Random graph # 3 node_num = 100 edge_num = 3744 edge_max = 4950 ratio = 0.7563636363636363 prob = 0.75 graph_adj_transitive_closure_test(): graph_adj_transitive_closure() finds the transitive closure of a graph; Adjacency matrix A: [[1 0 0 1 1 0 0 0] [0 1 0 0 0 0 0 0] [0 0 1 0 0 0 1 1] [1 0 0 1 1 0 0 0] [1 0 0 1 1 1 0 0] [0 0 0 0 1 1 0 0] [0 0 1 0 0 0 1 0] [0 0 1 0 0 0 0 1]] Adjacency for transitive closure: [[1 0 0 1 1 1 0 0] [0 1 0 0 0 0 0 0] [0 0 1 0 0 0 1 1] [1 0 0 1 1 1 0 0] [1 0 0 1 1 1 0 0] [1 0 0 1 1 1 0 0] [0 0 1 0 0 0 1 1] [0 0 1 0 0 0 1 1]] graph_adj_walks_test( ): Count the walks from node I to node J of any length. Walks for graph A: [[141. 33. 0. 107. 181. 0. 181. 74. 0.] [ 33. 34. 0. 107. 37. 0. 37. 74. 0.] [ 0. 0. 171. 0. 0. 170. 0. 0. 170.] [107. 107. 0. 396. 144. 0. 144. 288. 0.] [181. 37. 0. 144. 252. 0. 251. 107. 0.] [ 0. 0. 170. 0. 0. 171. 0. 0. 170.] [181. 37. 0. 144. 251. 0. 252. 107. 0.] [ 74. 74. 0. 288. 107. 0. 107. 215. 0.] [ 0. 0. 170. 0. 0. 170. 0. 0. 171.]] Graph B: [[0 1 0 1 0 0 0 0 0] [1 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 1] [1 0 0 0 1 0 1 0 0] [0 0 0 1 0 1 0 1 0] [0 0 0 0 1 0 0 0 1] [0 0 0 1 0 0 0 1 0] [0 0 0 0 1 0 1 0 0] [0 0 1 0 0 1 0 0 0]] Walks for graph B: [[156. 34. 10. 121. 266. 58. 208. 87. 68.] [ 34. 35. 10. 121. 48. 58. 39. 87. 10.] [ 10. 10. 24. 58. 31. 54. 17. 48. 23.] [121. 121. 58. 509. 218. 276. 169. 387. 58.] [266. 48. 31. 218. 518. 129. 388. 170. 160.] [ 58. 58. 54. 276. 129. 184. 89. 218. 54.] [208. 39. 17. 169. 388. 89. 300. 130. 106.] [ 87. 87. 48. 387. 170. 218. 130. 301. 48.] [ 68. 10. 23. 58. 160. 54. 106. 48. 78.]] matrix_is_adjacency_test( ): matrix_is_adjacency() requires that a matrix A be: * square * symmetric * zero on the diagonal * only have 0 or 1 as values. Matrix A: [[0 0 1] [0 0 1] [1 1 0] [0 0 1]] matrix_is_adjacency(A) = False Matrix B: [[0 0 1] [1 0 1] [1 1 0]] matrix_is_adjacency(B) = False Matrix C: [[1 0 1] [0 1 1] [1 1 1]] matrix_is_adjacency(C) = False Matrix D: [[0 1 2] [1 0 1] [2 1 0]] matrix_is_adjacency(D) = False Matrix E: [[0 1 1] [1 0 1] [1 1 0]] matrix_is_adjacency(E) = True graph_adj_test(): Normal end of execution. Sun Mar 12 15:10:13 2023