def gen(): g1 = nx.frucht_graph() g2 = nx.LCF_graph(12, [-5, -2, -4, 2, 5, -2, 2, 5, -2, -5, 4, 2], 1) # print(nx.is_isomorphic(g1, g2)) # g1 = nx.cubical_graph() # g2 = nx.LCF_graph(8, [3, -3], 4) return g1, g2
def gen(): # return nx.bull_graph() # 1-connected planar # return nx.chvatal_graph() # 4-connected non-planar # return nx.cubical_graph() # 3-connected planar # return nx.desargues_graph() # 3-connected non-planar # return nx.diamond_graph() # 2-connected planar # return nx.dodecahedral_graph() # 3-connected planar return nx.frucht_graph() # 3-connected planar
def test220_fruchtgraph(self): """ Frucht graph, smallest cubical graph. """ g = nx.frucht_graph() mate1 = mv.max_cardinality_matching( g ) mate2 = nx.max_weight_matching( g, True ) td.showGraph(g, mate1, "test220_fruchtgraph") td.showGraph(g, mate2, "test220_fruchtgraph_edmonds") self.assertEqual( len(mate1), len(mate2) )
def test_find_pyramid(pool : Pool): from pyramid import find_pyramid # Assuming the frame of the pyramid is returned in the order # (a, b0, b1, b2, s0, s1, s2, m0, m1, m2) for i in range(10): # Bipartite graphs and their complements never have pyramids graph = random_bipartite(n1=7, n2=7, p=.5) assert(find_pyramid(graph, pool) is None) assert(find_pyramid(nx.complement(graph), pool) is None) # Pyramid on 6 vertices graph = nx.Graph() graph.add_edges_from([(0, 1), (0, 2), (0, 3), (1, 2), (1, 4), (2, 5), (3, 5), (4, 5)]) assert(find_pyramid(graph, pool) == (5, 2, 0, 1, 2, 3, 4, 2, 0, 1)) # Pyramid on 7 vertices graph = nx.Graph() graph.add_edges_from([(0, 1), (0, 2), (0, 3), (1, 2), (1, 4), (2, 5), (3, 6), (4, 6), (5, 6)]) assert(find_pyramid(graph, pool) == (6, 0, 1, 2, 3, 4, 5, 0, 1, 2)) # Pyramid on 10 vertices graph = nx.Graph() graph.add_edges_from([(0, 1), (0, 8), (0, 9), (1, 2), (2, 3), (3, 4), (3, 5), (4, 6), (5, 7), (6, 8), (7, 9), (8, 9)]) assert(find_pyramid(graph, pool) == (3, 0, 8, 9, 2, 4, 5, 1, 6, 7)) graph = nx.frucht_graph() assert(find_pyramid(graph, pool) is not None) # Not sure we have correct output for the Frucht graph A = np.array([ [0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0], [1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1], [0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0], [1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0], [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1], [0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0], [0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0], [0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0]] ) graph = nx.from_numpy_array(A) assert(find_pyramid(graph, pool)[:7] == (0, 4, 3, 6, 4, 1, 5))
vcl[0], mcl = mcl, vcl[0] for i in xrange(1, len(vcl)): if not mcl.merge(vcl[i]): return None mcl.prune(dfs_height) return mcl def clean_attributes(g): for v in g.nodes(): if 'visited' in g.node[v]: del g.node[v]['visited'] for u, v in g.edges(): if 'visited' in g[u][v]: del g[u][v]['visited'] if __name__ == '__main__': # g = nx.petersen_graph() g = nx.frucht_graph() # g = nx.krackhardt_kite_graph() # g = nx.icosahedral_graph() # g = nx.tutte_graph() # g = nx.chvatal_graph() # g = nx.desargues_graph() print is_planar(g) # from matplotlib import pyplot as plt # nx.draw_networkx(g) # plt.show()
import networkx as nx import matplotlib.pylab as plt from plot_multigraph import plot_multigraph graphs = [ ("bull", nx.bull_graph()), ("chvatal", nx.chvatal_graph()), ("cubical", nx.cubical_graph()), ("desargues", nx.desargues_graph()), ("diamond", nx.diamond_graph()), ("dodecahedral", nx.dodecahedral_graph()), ("frucht", nx.frucht_graph()), ("heawood", nx.heawood_graph()), ("house", nx.house_graph()), ("house_x", nx.house_x_graph()), ("icosahedral", nx.icosahedral_graph()), ("krackhardt_kite", nx.krackhardt_kite_graph()), ("moebius_kantor", nx.moebius_kantor_graph()), ("octahedral", nx.octahedral_graph()), ("pappus", nx.pappus_graph()), ("petersen", nx.petersen_graph()), ("sedgewick_maze", nx.sedgewick_maze_graph()), ("tetrahedral", nx.tetrahedral_graph()), ("truncated_cube", nx.truncated_cube_graph()), ("truncated_tetrahedron", nx.truncated_tetrahedron_graph()), ] plot_multigraph(graphs, 4, 5, node_size=50) plt.savefig('graphs/small.png')
import time import networkx as nx from controller import NaiveRobber, NaiveCop from cop_and_robbers_env import CopRobEnv from graph_utils import Graph networkx_graph = nx.frucht_graph() graph = Graph(networkx_graph) env = CopRobEnv(graph, 2, auto_robber_class=NaiveRobber) robber = NaiveRobber(env) cop = NaiveCop(env) env.render() done = False obs = None while not done: obs, _, done, _ = env.step(cop.act(obs)) if done: break env.render() #obs, _, done, _ = env.step(robber.act(obs)) #env.render() exit() env.render() for act in [[0, 1], [3], [4, 5], [4]]: env.step(act) env.render()
def gen(n): from random import sample, seed return (g := nx.frucht_graph()), sample(g.nodes, n)
write_json_graph(nx.random_lobster(50, 0.6, 0.4, seed=0), 'random_lobster(50,0_6,0_4).json') # write_json_graph(nx.random_lobster(50, 0.4, 0.6, seed=0), 'random_lobster(50,0_4,0_6).json') write_json_graph(nx.random_lobster(100, 0.6, 0.4, seed=0), 'random_lobster(100,0_6,0_4).json') # write_json_graph(nx.random_lobster(100, 0.4, 0.6, seed=0), 'random_lobster(100,0_4,0_6).json') # write_json_graph(nx.lollipop_graph(5, 4), 'lollipop_graph(5,4).json') write_json_graph(nx.lollipop_graph(10, 10), 'lollipop_graph(10,10).json') write_json_graph(nx.lollipop_graph(20, 50), 'lollipop_graph(20,50).json') # write_json_graph(nx.petersen_graph(), 'petersen_graph().json') # write_json_graph(nx.octahedral_graph(), 'octahedral_graph().json') # write_json_graph(nx.pappus_graph(), 'pappus_graph().json') write_json_graph(nx.dodecahedral_graph(), 'dodecahedral_graph().json') write_json_graph(nx.frucht_graph(), 'frucht_graph().json') # write_json_graph(nx.star_graph(10), 'star_graph(50).json') # write_json_graph(nx.star_graph(50), 'star_graph(50).json') # write_json_graph(nx.star_graph(100), 'star_graph(50).json') write_json_graph(nx.ring_of_cliques(5, 70), 'ring_of_cliques(5,80).json') write_json_graph(nx.ring_of_cliques(6, 70), 'ring_of_cliques(6,70).json') # write_json_graph(nx.barbell_graph(3, 4), 'barbell_graph(3,4).json') # write_json_graph(nx.barbell_graph(3, 8), 'barbell_graph(3,8).json') write_json_graph(nx.barbell_graph(5, 2), 'barbell_graph(5,2).json') # write_json_graph(nx.barbell_graph(5, 0), 'barbell_graph(5,0).json') write_json_graph(nx.barbell_graph(50, 20), 'barbell_graph(50,20).json') # write_json_graph(nx.barbell_graph(50, 50), 'barbell_graph(50,50).json')
def test_frucht(self): expected = True actual = is_planar(nx.frucht_graph()) self.assertEqual(expected, actual)
def generate_frucht(params={}): G = nx.frucht_graph() return G, None
if nx.has_path(graph, o, g): break env.reset(graph, o, g, random_weights=(0, 200), make_horizon=MAKE_HORIZON) yield random.seed(2) np.random.seed(1) ENV_QTTY = 10000 from tqdm import trange env = ShortestRouteEnv(nx.frucht_graph(), 0, 5, random_weights=(1, 10)) # Fake RENDER = False def render(env=env, force=False): if force or RENDER: env.render() generator = env_gen(ENV_QTTY) for _ in trange(ENV_QTTY): next(generator) render() if not MAKE_HORIZON:
def gen(): g1 = nx.frucht_graph() g2 = nx.LCF_graph(12, [-5, -2, -4, 2, 5, -2, 2, 5, -2, -5, 4, 2], 1) return g1, g2
def small_graphs(): print("Make small graph") G = nx.make_small_graph( ["adjacencylist", "C_4", 4, [[2, 4], [1, 3], [2, 4], [1, 3]]]) draw_graph(G) G = nx.make_small_graph( ["adjacencylist", "C_4", 4, [[2, 4], [3], [4], []]]) draw_graph(G) G = nx.make_small_graph( ["edgelist", "C_4", 4, [[1, 2], [3, 4], [2, 3], [4, 1]]]) draw_graph(G) print("LCF graph") G = nx.LCF_graph(6, [3, -3], 3) draw_graph(G) G = nx.LCF_graph(14, [5, -5], 7) draw_graph(G) print("Bull graph") G = nx.bull_graph() draw_graph(G) print("Chvátal graph") G = nx.chvatal_graph() draw_graph(G) print("Cubical graph") G = nx.cubical_graph() draw_graph(G) print("Desargues graph") G = nx.desargues_graph() draw_graph(G) print("Diamond graph") G = nx.diamond_graph() draw_graph(G) print("Dodechaedral graph") G = nx.dodecahedral_graph() draw_graph(G) print("Frucht graph") G = nx.frucht_graph() draw_graph(G) print("Heawood graph") G = nx.heawood_graph() draw_graph(G) print("House graph") G = nx.house_graph() draw_graph(G) print("House X graph") G = nx.house_x_graph() draw_graph(G) print("Icosahedral graph") G = nx.icosahedral_graph() draw_graph(G) print("Krackhardt kite graph") G = nx.krackhardt_kite_graph() draw_graph(G) print("Moebius kantor graph") G = nx.moebius_kantor_graph() draw_graph(G) print("Octahedral graph") G = nx.octahedral_graph() draw_graph(G) print("Pappus graph") G = nx.pappus_graph() draw_graph(G) print("Petersen graph") G = nx.petersen_graph() draw_graph(G) print("Sedgewick maze graph") G = nx.sedgewick_maze_graph() draw_graph(G) print("Tetrahedral graph") G = nx.tetrahedral_graph() draw_graph(G) print("Truncated cube graph") G = nx.truncated_cube_graph() draw_graph(G) print("Truncated tetrahedron graph") G = nx.truncated_tetrahedron_graph() draw_graph(G) print("Tutte graph") G = nx.tutte_graph() draw_graph(G)
def gen(): return nx.frucht_graph()
def test_properties_named_small_graphs(self): G = nx.bull_graph() assert G.number_of_nodes() == 5 assert G.number_of_edges() == 5 assert sorted(d for n, d in G.degree()) == [1, 1, 2, 3, 3] assert nx.diameter(G) == 3 assert nx.radius(G) == 2 G = nx.chvatal_graph() assert G.number_of_nodes() == 12 assert G.number_of_edges() == 24 assert list(d for n, d in G.degree()) == 12 * [4] assert nx.diameter(G) == 2 assert nx.radius(G) == 2 G = nx.cubical_graph() assert G.number_of_nodes() == 8 assert G.number_of_edges() == 12 assert list(d for n, d in G.degree()) == 8 * [3] assert nx.diameter(G) == 3 assert nx.radius(G) == 3 G = nx.desargues_graph() assert G.number_of_nodes() == 20 assert G.number_of_edges() == 30 assert list(d for n, d in G.degree()) == 20 * [3] G = nx.diamond_graph() assert G.number_of_nodes() == 4 assert sorted(d for n, d in G.degree()) == [2, 2, 3, 3] assert nx.diameter(G) == 2 assert nx.radius(G) == 1 G = nx.dodecahedral_graph() assert G.number_of_nodes() == 20 assert G.number_of_edges() == 30 assert list(d for n, d in G.degree()) == 20 * [3] assert nx.diameter(G) == 5 assert nx.radius(G) == 5 G = nx.frucht_graph() assert G.number_of_nodes() == 12 assert G.number_of_edges() == 18 assert list(d for n, d in G.degree()) == 12 * [3] assert nx.diameter(G) == 4 assert nx.radius(G) == 3 G = nx.heawood_graph() assert G.number_of_nodes() == 14 assert G.number_of_edges() == 21 assert list(d for n, d in G.degree()) == 14 * [3] assert nx.diameter(G) == 3 assert nx.radius(G) == 3 G = nx.hoffman_singleton_graph() assert G.number_of_nodes() == 50 assert G.number_of_edges() == 175 assert list(d for n, d in G.degree()) == 50 * [7] assert nx.diameter(G) == 2 assert nx.radius(G) == 2 G = nx.house_graph() assert G.number_of_nodes() == 5 assert G.number_of_edges() == 6 assert sorted(d for n, d in G.degree()) == [2, 2, 2, 3, 3] assert nx.diameter(G) == 2 assert nx.radius(G) == 2 G = nx.house_x_graph() assert G.number_of_nodes() == 5 assert G.number_of_edges() == 8 assert sorted(d for n, d in G.degree()) == [2, 3, 3, 4, 4] assert nx.diameter(G) == 2 assert nx.radius(G) == 1 G = nx.icosahedral_graph() assert G.number_of_nodes() == 12 assert G.number_of_edges() == 30 assert (list( d for n, d in G.degree()) == [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) assert nx.diameter(G) == 3 assert nx.radius(G) == 3 G = nx.krackhardt_kite_graph() assert G.number_of_nodes() == 10 assert G.number_of_edges() == 18 assert (sorted( d for n, d in G.degree()) == [1, 2, 3, 3, 3, 4, 4, 5, 5, 6]) G = nx.moebius_kantor_graph() assert G.number_of_nodes() == 16 assert G.number_of_edges() == 24 assert list(d for n, d in G.degree()) == 16 * [3] assert nx.diameter(G) == 4 G = nx.octahedral_graph() assert G.number_of_nodes() == 6 assert G.number_of_edges() == 12 assert list(d for n, d in G.degree()) == 6 * [4] assert nx.diameter(G) == 2 assert nx.radius(G) == 2 G = nx.pappus_graph() assert G.number_of_nodes() == 18 assert G.number_of_edges() == 27 assert list(d for n, d in G.degree()) == 18 * [3] assert nx.diameter(G) == 4 G = nx.petersen_graph() assert G.number_of_nodes() == 10 assert G.number_of_edges() == 15 assert list(d for n, d in G.degree()) == 10 * [3] assert nx.diameter(G) == 2 assert nx.radius(G) == 2 G = nx.sedgewick_maze_graph() assert G.number_of_nodes() == 8 assert G.number_of_edges() == 10 assert sorted(d for n, d in G.degree()) == [1, 2, 2, 2, 3, 3, 3, 4] G = nx.tetrahedral_graph() assert G.number_of_nodes() == 4 assert G.number_of_edges() == 6 assert list(d for n, d in G.degree()) == [3, 3, 3, 3] assert nx.diameter(G) == 1 assert nx.radius(G) == 1 G = nx.truncated_cube_graph() assert G.number_of_nodes() == 24 assert G.number_of_edges() == 36 assert list(d for n, d in G.degree()) == 24 * [3] G = nx.truncated_tetrahedron_graph() assert G.number_of_nodes() == 12 assert G.number_of_edges() == 18 assert list(d for n, d in G.degree()) == 12 * [3] G = nx.tutte_graph() assert G.number_of_nodes() == 46 assert G.number_of_edges() == 69 assert list(d for n, d in G.degree()) == 46 * [3] # Test create_using with directed or multigraphs on small graphs pytest.raises(nx.NetworkXError, nx.tutte_graph, create_using=nx.DiGraph) MG = nx.tutte_graph(create_using=nx.MultiGraph) assert sorted(MG.edges()) == sorted(G.edges())
def test_frucht(self): print '\nfrucht:', self.g = nx.frucht_graph() a = programming_for_tree_decomposition(self.g, True) self.t = a.tree_decomposition() self.assertTrue(self.__test_all_conditions())
if 'visited' in g.node[v]: del g.node[v]['visited'] for u, v in g.edges(): if 'visited' in g[u][v]: del g[u][v]['visited'] if __name__ == '__main__': targets = { 'bull': nx.bull_graph(), # 1-connected planar 'chvatal': nx.chvatal_graph(), # 4-connected non-planar 'cubical': nx.cubical_graph(), # 3-connected planar 'desargues': nx.desargues_graph(), # 3-connected non-planar 'diamond': nx.diamond_graph(), # 2-connected planar 'dodecahedral': nx.dodecahedral_graph(), # 3-connected planar 'frucht': nx.frucht_graph(), # 3-connected planar 'heawood': nx.heawood_graph(), # 3-connected non-planar 'house': nx.house_graph(), # 2-connected planar 'house_x': nx.house_x_graph(), # 2-connected planar 'icosahedral': nx.icosahedral_graph(), # 5-connected planar 'krackhardt': nx.krackhardt_kite_graph(), # 1-connected planar 'moebius': nx.moebius_kantor_graph(), # non-planar 'octahedral': nx.octahedral_graph(), # 4-connected planar 'pappus': nx.pappus_graph(), # 3-connected non-planar 'petersen': nx.petersen_graph(), # 3-connected non-planar 'sedgewick': nx.sedgewick_maze_graph(), # 1-connected planar 'tetrahedral': nx.tetrahedral_graph(), # 3-connected planar 'truncated_cube': nx.truncated_cube_graph(), # 3-conn. planar 'truncated_tetrahedron': nx.truncated_tetrahedron_graph(), # 3-connected planar 'tutte': nx.tutte_graph()
world.add_node(tmpg, edges=[]) # link them up somehow... min_num_links = 2 for tr1 in world.givers: print 'wiring up ', tr1.name n, attempts = 0, 0 while (n < min_num_links) and (attempts < 10): attempts = attempts + 1 tr2 = world.givers[rng.randint(len(world.givers))] isNewEdge = (tr1.add_neighbour(tr2) and tr2.add_neighbour(tr1)) if isNewEdge: print '\t wired up ', tr1.name, ' to ', tr2.name n = n + 1 print tr1.name, ' should be done - let us see: ' tr1.display() print '^^^^^^^^^^^^^^^^ all wired up ^^^^^^^^^^^^^^^^^^^^^^' H = nx.frucht_graph() # nice to use this one or other standards... # Test one trade: #tr = traders[rng.randint(len(traders))] #tr.do_one_gift() print 'doing one season...' world.do_one_season(num_gifts=200, memory_factor=0.8, verbose=False) for tr in world.givers: tr.display() print 'showing the network...' world.display_all_sequences('givers_random_network_example_seq.png') world.show_network('givers_random_network_example.png')
def graph_setting(s): g = nx.frucht_graph() seed(s) for u, v in g.edges: g[u][v]['capacity'] = randint(1, 10) return g