def test_theta(self): """Tests that pairs of vertices adjacent if and only if their sum weights exceeds the threshold parameter theta. """ G = nx.thresholded_random_geometric_graph(50, 0.25, 0.1) for u, v in combinations(G, 2): # Adjacent vertices must be within the given distance. if v in G[u]: assert (G.nodes[u]['weight'] + G.nodes[v]['weight']) >= 0.1
def test_theta(self): """Tests that pairs of vertices adjacent if and only if their sum weights exceeds the threshold parameter theta. """ G = nx.thresholded_random_geometric_graph(50, 0.25, 0.1) for u, v in combinations(G, 2): # Adjacent vertices must be within the given distance. if v in G[u]: assert_true((G.nodes[u]['weight'] + G.nodes[v]['weight']) >= 0.1)
def test_p(self): """Tests for providing an alternate distance metric to the generator. """ # Use the L1 metric. def dist(x, y): return sum(abs(a - b) for a, b in zip(x, y)) G = nx.thresholded_random_geometric_graph(50, 0.25, 0.1, p=1) for u, v in combinations(G, 2): # Adjacent vertices must be within the given distance. if v in G[u]: assert dist(G.nodes[u]['pos'], G.nodes[v]['pos']) <= 0.25
def test_p(self): """Tests for providing an alternate distance metric to the generator. """ # Use the L1 metric. def dist(x, y): return sum(abs(a - b) for a, b in zip(x, y)) G = nx.thresholded_random_geometric_graph(50, 0.25, 0.1, p=1) for u, v in combinations(G, 2): # Adjacent vertices must be within the given distance. if v in G[u]: assert_true(dist(G.nodes[u]['pos'], G.nodes[v]['pos']) <= 0.25)
def test_node_names(self): """Tests using values other than sequential numbers as node IDs.""" import string nodes = list(string.ascii_lowercase) G = nx.thresholded_random_geometric_graph(nodes, 0.25, 0.1) assert len(G) == len(nodes) for u, v in combinations(G, 2): # Adjacent vertices must be within the given distance. if v in G[u]: assert math.dist(G.nodes[u]["pos"], G.nodes[v]["pos"]) <= 0.25
def test_distances(self): """Tests that pairs of vertices adjacent if and only if they are within the prescribed radius. """ # Use the Euclidean metric, the default according to the # documentation. G = nx.thresholded_random_geometric_graph(50, 0.25, 0.1) for u, v in combinations(G, 2): # Adjacent vertices must be within the given distance. if v in G[u]: assert math.dist(G.nodes[u]["pos"], G.nodes[v]["pos"]) <= 0.25
def test_distances(self): """Tests that pairs of vertices adjacent if and only if they are within the prescribed radius. """ # Use the Euclidean metric, the default according to the # documentation. def dist(x, y): return sqrt(sum((a - b) ** 2 for a, b in zip(x, y))) G = nx.thresholded_random_geometric_graph(50, 0.25, 0.1) for u, v in combinations(G, 2): # Adjacent vertices must be within the given distance. if v in G[u]: assert dist(G.nodes[u]['pos'], G.nodes[v]['pos']) <= 0.25
def test_distances(self): """Tests that pairs of vertices adjacent if and only if they are within the prescribed radius. """ # Use the Euclidean metric, the default according to the # documentation. def dist(x, y): return sqrt(sum((a - b) ** 2 for a, b in zip(x, y))) G = nx.thresholded_random_geometric_graph(50, 0.25, 0.1) for u, v in combinations(G, 2): # Adjacent vertices must be within the given distance. if v in G[u]: assert_true(dist(G.nodes[u]['pos'], G.nodes[v]['pos']) <= 0.25)
def generate_graph(n_systems, prob=0.076,p=0.4,n_rounds=4000): G = nx.thresholded_random_geometric_graph(n_systems, 0.076, 0.4) remove_extra_neighbors(G,n_rounds) pos = nx.get_node_attributes(G, 'pos') pos = forceatlas2.forceatlas2_networkx_layout(G, pos=pos, edgeWeightInfluence=1.0, jitterTolerance=1.0, scalingRatio=2.0, strongGravityMode=True, gravity=1.0) nx.set_node_attributes(G, pos, 'pos') return G
def test_node_names(self): """Tests using values other than sequential numbers as node IDs. """ import string nodes = list(string.ascii_lowercase) G = nx.thresholded_random_geometric_graph(nodes, 0.25, 0.1) assert_equal(len(G), len(nodes)) def dist(x, y): return sqrt(sum((a - b) ** 2 for a, b in zip(x, y))) for u, v in combinations(G, 2): # Adjacent vertices must be within the given distance. if v in G[u]: assert_true(dist(G.nodes[u]['pos'], G.nodes[v]['pos']) <= 0.25)
def test_node_names(self): """Tests using values other than sequential numbers as node IDs. """ import string nodes = list(string.ascii_lowercase) G = nx.thresholded_random_geometric_graph(nodes, 0.25, 0.1) assert_equal(len(G), len(nodes)) dist = lambda x, y: sqrt(sum((a - b)**2 for a, b in zip(x, y))) for u, v in combinations(G, 2): # Adjacent vertices must be within the given distance. if v in G[u]: assert_true(dist(G.nodes[u]['pos'], G.nodes[v]['pos']) <= 0.25)
def _generate_inital_graph(n_systems, prob=0.076, p=0.4, n_rounds=4000): G = nx.thresholded_random_geometric_graph(n_systems, 0.076, 0.4) remove_extra_neighbors(G, n_rounds) pos = nx.get_node_attributes(G, 'pos') pos = forceatlas2.forceatlas2_networkx_layout(G, pos=pos, edgeWeightInfluence=1.0, jitterTolerance=1.0, scalingRatio=2.0, strongGravityMode=True, gravity=1.0) nx.set_node_attributes(G, pos, 'pos') govt = {} govts = [] for n in G.nodes(): govt[n] = random.choice(['Coalition', 'Korath', 'Hai']) govts.append(govt[n]) nx.set_node_attributes(G, govt, 'govt') return G, govt
def test_number_of_nodes(self): G = nx.thresholded_random_geometric_graph(50, 0.2, 0.1, seed=42) assert len(G) == 50 G = nx.thresholded_random_geometric_graph(range(50), 0.2, 0.1) assert len(G) == 50
def test_number_of_nodes(self): G = nx.thresholded_random_geometric_graph(50, 0.2, 0.1) assert_equal(len(G), 50) G = nx.thresholded_random_geometric_graph(range(50), 0.2, 0.1) assert_equal(len(G), 50)
node_color=colors, node_size=80, cmap=plt.cm.tab10_r) plt.axis('off') plt.savefig('pirate.maps.txt.out.png') plt.show() def distance(p1, p2): px = p1[0] - p2[0] py = p1[1] - p2[1] return math.sqrt(px * px + py * py) pirate_systems = 300 G2 = nx.thresholded_random_geometric_graph(pirate_systems, 0.07, 0.4) pos = nx.get_node_attributes(G2, 'pos') vector = None center = (0.5, 0.5) def unit(p): v = math.sqrt(p[0] * p[0] + p[1] * p[1]) return (p[0] / v, p[1] / v) def vec_scalar_mul(p, s): return (p[0] * s, p[1] * s) def vec_add(p1, p2):