def test_absorbing_centrality(): dimension = 4 grid = grid_2d_graph(dimension, dimension, periodic=False).to_undirected() solutions = { (0, 0): 34.7857142857, (0, 1): 22.9285714286, (0, 2): 22.9285714286, (0, 3): 34.7857142857, (1, 0): 22.9285714286, (1, 1): 14.0714285714, (1, 2): 14.0714285714, (1, 3): 22.9285714286, (2, 0): 22.9285714286, (2, 1): 14.0714285714, (2, 2): 14.0714285714, (2, 3): 22.9285714286, (3, 0): 34.7857142857, (3, 1): 22.9285714286, (3, 2): 22.9285714286, (3, 3): 34.7857142857 } for i in range(dimension): for j in range(dimension): assert abs( absorbing_centrality(grid, [(i, j)], epsilon=1e-12) - solutions[(i, j)]) < 1e-5
def __init__(self, width, height): self.width = width self.height = height self.g = grid_2d_graph(width, height) for node, node_data in self.g.nodes(data=True): node_data['barrier'] = False for src, dst, edge_data in self.g.edges(data=True): edge_data['weight'] = min_int self.walls = set() self.boxes = set() self.bombs = {} # mapping from bomb to rounds self.players = set() self.enemies = set() self.boost_remain = 0 self.boost_renew = 0 max_radius = distance((0, 0), (self.width-1, self.height-1)) self.in_boost_sequence = [False] * max_radius self.radii = range(0, max_radius) self.points = list(product(range(self.width), range(self.height))) self.point_bomb_rounds = {p: max_int for p in self.points} self.bomb_ranges_graph = Graph() self.bomb_ranges_sub_graphs = connected_components(self.bomb_ranges_graph)
def test_k_factor1(self): g = gen.grid_2d_graph(4, 4) g_kf = reg.k_factor(g, 2) for edge in g_kf.edges(): assert g.has_edge(edge[0], edge[1]) for _, degree in g_kf.degree(): assert degree == 2
def test_absorbing_centrality(): dimension = 4 grid = grid_2d_graph(dimension, dimension, periodic=False).to_undirected() solutions = { (0, 0): 34.7857142857, (0, 1): 22.9285714286, (0, 2): 22.9285714286, (0, 3): 34.7857142857, (1, 0): 22.9285714286, (1, 1): 14.0714285714, (1, 2): 14.0714285714, (1, 3): 22.9285714286, (2, 0): 22.9285714286, (2, 1): 14.0714285714, (2, 2): 14.0714285714, (2, 3): 22.9285714286, (3, 0): 34.7857142857, (3, 1): 22.9285714286, (3, 2): 22.9285714286, (3, 3): 34.7857142857 } for i in range(dimension): for j in range(dimension): assert abs(absorbing_centrality(grid, [(i, j)], epsilon=1e-12) - solutions[(i, j)]) < 1e-5
def test_k_factor3(self): g = gen.grid_2d_graph(4, 4) with pytest.raises(nx.NetworkXUnfeasible): reg.k_factor(g, 3)