Exemplo n.º 1
0
def draw_networkx_ex():
    G = nx.dodecahedral_graph()
    nx.draw(G)
    plt.show()
    nx.draw_networkx(G, pos=nx.spring_layout(G))
    limits = plt.axis('off')
    plt.show()
    nodes = nx.draw_networkx_nodes(G, pos=nx.spring_layout(G))
    plt.show()
    edges = nx.draw_networkx_edges(G, pos=nx.spring_layout(G))
    plt.show()
    labels = nx.draw_networkx_labels(G, pos=nx.spring_layout(G))
    plt.show()
    edge_labels = nx.draw_networkx_edge_labels(G, pos=nx.spring_layout(G))
    plt.show()
    print("Circular layout")
    nx.draw_circular(G)
    plt.show()
    print("Random layout")
    nx.draw_random(G)
    plt.show()
    print("Spectral layout")
    nx.draw_spectral(G)
    plt.show()
    print("Spring layout")
    nx.draw_spring(G)
    plt.show()
    print("Shell layout")
    nx.draw_shell(G)
    plt.show()
    print("Graphviz")
 def test180_dodecahedralgraph(self):
     """ Dodecahedral graph. """
     g = nx.dodecahedral_graph()
     mate1 = mv.max_cardinality_matching( g )
     mate2 = nx.max_weight_matching( g, True )
     td.showGraph(g, mate1, "test180_dodecahedralgraph")
     self.assertEqual( len(mate1), len(mate2) )
Exemplo n.º 3
0
def draw_networkx_ex():
    G = nx.dodecahedral_graph()
    nx.draw(G)
    plt.show()
    nx.draw_networkx(G, pos=nx.spring_layout(G))
    limits = plt.axis('off')
    plt.show()
    nodes = nx.draw_networkx_nodes(G, pos=nx.spring_layout(G))
    plt.show()
    edges = nx.draw_networkx_edges(G, pos=nx.spring_layout(G))
    plt.show()
    labels = nx.draw_networkx_labels(G, pos=nx.spring_layout(G))
    plt.show()
    edge_labels = nx.draw_networkx_edge_labels(G, pos=nx.spring_layout(G))
    plt.show()
    print("Circular layout")
    nx.draw_circular(G)
    plt.show()
    print("Random layout")
    nx.draw_random(G)
    plt.show()
    print("Spectral layout")
    nx.draw_spectral(G)
    plt.show()
    print("Spring layout")
    nx.draw_spring(G)
    plt.show()
    print("Shell layout")
    nx.draw_shell(G)
    plt.show()
    print("Graphviz")
def test_dodecahedral():
    G = nx.dodecahedral_graph()
    for flow_func in flow_funcs:
        assert_equal(3, nx.node_connectivity(G, flow_func=flow_func),
                     msg=msg.format(flow_func.__name__))
        assert_equal(3, nx.edge_connectivity(G, flow_func=flow_func),
                     msg=msg.format(flow_func.__name__))
Exemplo n.º 5
0
def test_dodecahedral():
    G = nx.dodecahedral_graph()
    for flow_func in flow_funcs:
        assert_equal(3, nx.node_connectivity(G, flow_func=flow_func),
                     msg=msg.format(flow_func.__name__))
        assert_equal(3, nx.edge_connectivity(G, flow_func=flow_func),
                     msg=msg.format(flow_func.__name__))
Exemplo n.º 6
0
    def __init__(self):
        wx.Frame.__init__(self, None, -1)
        self.panel = wx.Panel(self)
        self.fig = plt.figure()
        self.canvas = FigCanvas(self.panel, -1, self.fig)
#        G=nx.house_graph()
        G=nx.dodecahedral_graph()
        edges=nx.draw_networkx_edges(G,pos=nx.spring_layout(G), arrows=False)
#        pos={0:(0,0),
#            1:(1,0),
#            2:(0,1),
#            3:(1,1),
#            4:(0.5,2.0)}

        node4 = nx.draw_networkx_nodes(G,pos,node_size=2000,nodelist=[4], picker=5, label=['4'])
        print node4
        nx.draw_networkx_nodes(G,pos,node_size=3000,nodelist=[0,1,2,3],node_color='b')
        nx.draw_networkx_labels(G, pos)
#        nx.draw_networkx_edges(G,pos,alpha=0.5,width=6)
        plt.axis('off')
        self.vbox = wx.BoxSizer(wx.VERTICAL)
        self.vbox.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        self.toolbar = NavigationToolbar(self.canvas)
        self.vbox.Add(self.toolbar, 0, wx.EXPAND)
        self.panel.SetSizer(self.vbox)
        self.vbox.Fit(self)

        self.fig.canvas.mpl_connect('pick_event', onpick)
        #
        plt.savefig("house_with_colors.png") # save as png
Exemplo n.º 7
0
def create_graph():
    G = nx.dodecahedral_graph()
    for e in G.edges:
        G.remove_edge(*e)
        break
    nx.draw(G)
    plt.show()
    return G
 def test_intersection_array(self):
     b, c = nx.intersection_array(nx.cycle_graph(5))
     assert_equal(b, [2, 1])
     assert_equal(c, [1, 1])
     b, c = nx.intersection_array(nx.dodecahedral_graph())
     assert_equal(b, [3, 2, 1, 1, 1])
     assert_equal(c, [1, 1, 1, 2, 3])
     b, c = nx.intersection_array(nx.icosahedral_graph())
     assert_equal(b, [5, 2, 1])
     assert_equal(c, [1, 2, 5])
Exemplo n.º 9
0
 def test_intersection_array(self):
     b,c=nx.intersection_array(nx.cycle_graph(5))
     assert_equal(b,[2, 1])
     assert_equal(c,[1, 1])
     b,c=nx.intersection_array(nx.dodecahedral_graph())
     assert_equal(b,[3, 2, 1, 1, 1])
     assert_equal(c,[1, 1, 1, 2, 3])
     b,c=nx.intersection_array(nx.icosahedral_graph())
     assert_equal(b,[5, 2, 1])
     assert_equal(c,[1, 2, 5])
Exemplo n.º 10
0
def draw_ex():
    G = nx.dodecahedral_graph()
    nx.draw(G,
            pos=nx.spring_layout(G),
            nodecolor='r',
            edge_color='b',
            with_labels=True,
            data='weight')
    plt.savefig("draw_graph.png")
    plt.show()
Exemplo n.º 11
0
 def test_intersection_array(self):
     b, c = nx.intersection_array(nx.cycle_graph(5))
     assert b == [2, 1]
     assert c == [1, 1]
     b, c = nx.intersection_array(nx.dodecahedral_graph())
     assert b == [3, 2, 1, 1, 1]
     assert c == [1, 1, 1, 2, 3]
     b, c = nx.intersection_array(nx.icosahedral_graph())
     assert b == [5, 2, 1]
     assert c == [1, 2, 5]
Exemplo n.º 12
0
def networkx(request):
    if request.method == "POST":
        if request.session['graphname'] == 'dodecahedral_graph':
            data_network = request.POST.get('dodecahedral_graph')
            G = nx.dodecahedral_graph()
            shells = data_network
            nx.draw(G)
        if request.session['graphname'] == 'lollipop_graph':
            data_network = request.POST.get('lollipop_graph')
            G = nx.dodecahedral_graph()
            shells = data_network
            nx.draw(G)
        if request.session['graphname'] == 'grid_2d_graph':
            data_network = request.POST.get('grid_2d_graph')
            G = nx.dodecahedral_graph()
            shells = data_network
            nx.draw(G)
        if request.session['graphname'] == 'house_graph':
            data_network = request.POST.get('house_graph')
            G = nx.dodecahedral_graph()
            shells = data_network
            nx.draw(G)
        if request.session['graphname'] == 'star_graph':
            data_network = request.POST.get('star_graph')
            G = nx.dodecahedral_graph()
            shells = data_network
            nx.draw(G)
        if request.session['graphname'] == 'cycle_graph':
            data_network = request.POST.get('cycle_graph')
            G = nx.dodecahedral_graph()
            shells = data_network
            nx.draw(G)
        if request.session['graphname'] == 'path_graph':
            data_network = request.POST.get('path_graph')
            G = nx.dodecahedral_graph()
            shells = data_network
            nx.draw(G)
        if request.session['graphname'] == 'petersen_graph':
            data_network = request.POST.get('petersen_graph')
            G = nx.dodecahedral_graph()
            shells = data_network
            nx.draw(G)
        if request.session['graphname'] == 'cubical_graph':
            data_network = request.POST.get('cubical_graph')
            G = nx.dodecahedral_graph()
            shells = data_network
            nx.draw(G)
        return mlt.show()
Exemplo n.º 13
0
def plot_dodecahedral_graph(layout):
    G = nx.dodecahedral_graph()
    pos = layout(G)
    nx.draw_networkx_nodes(G, pos)
    nx.draw_networkx_edges(G, pos)
    ham_cycle = list(zip(range(19), range(1, 20))) + [(19, 0)]
    nx.draw_networkx_edges(G,
                           pos,
                           edgelist=ham_cycle,
                           edge_color='red',
                           width=2)
 def test_is_distance_regular(self):
     assert_true(nx.is_distance_regular(nx.icosahedral_graph()))
     assert_true(nx.is_distance_regular(nx.petersen_graph()))
     assert_true(nx.is_distance_regular(nx.cubical_graph()))
     assert_true(nx.is_distance_regular(nx.complete_bipartite_graph(3, 3)))
     assert_true(nx.is_distance_regular(nx.tetrahedral_graph()))
     assert_true(nx.is_distance_regular(nx.dodecahedral_graph()))
     assert_true(nx.is_distance_regular(nx.pappus_graph()))
     assert_true(nx.is_distance_regular(nx.heawood_graph()))
     assert_true(nx.is_distance_regular(nx.cycle_graph(3)))
     # no distance regular
     assert_false(nx.is_distance_regular(nx.path_graph(4)))
Exemplo n.º 15
0
 def test_is_distance_regular(self):
     assert_true(nx.is_distance_regular(nx.icosahedral_graph()))
     assert_true(nx.is_distance_regular(nx.petersen_graph()))
     assert_true(nx.is_distance_regular(nx.cubical_graph()))
     assert_true(nx.is_distance_regular(nx.complete_bipartite_graph(3,3)))
     assert_true(nx.is_distance_regular(nx.tetrahedral_graph()))
     assert_true(nx.is_distance_regular(nx.dodecahedral_graph()))
     assert_true(nx.is_distance_regular(nx.pappus_graph()))
     assert_true(nx.is_distance_regular(nx.heawood_graph()))
     assert_true(nx.is_distance_regular(nx.cycle_graph(3)))
     # no distance regular
     assert_false(nx.is_distance_regular(nx.path_graph(4)))
Exemplo n.º 16
0
def platonic(n):  # n must be 4, 6, 8, 12 or 20
    # returns the matrix for sp2 platonic solid, with alpha = 0 and beta = -1
    n_int = int(n)
    if n_int == 4:
        s = nx.tetrahedral_graph()
    elif n_int == 6:
        s = nx.cubical_graph()
    elif n_int == 8:
        s = nx.octahedral_graph()
    elif n_int == 12:
        s = nx.dodecahedral_graph()
    elif n_int == 20:
        s = nx.icosahedral_graph()
    else:
        print("n must be equal to 4, 6, 8, 12 or 20")

    M = -nx.adjacency_matrix(s)
    return M.todense()
Exemplo n.º 17
0
	def draw2(self, network):
		"""docstring"""

		edges = self.create_edges(network)
		nodes = self.create_nodes(network)
		labels = self.create_labels(network)

		G = nx.Graph()
		G.add_nodes_from(nodes)
		G.add_edges_from(edges)

		# Draw graph
		pos = nx.shell_layout(G)
		nx.draw(G, node_color='w', with_labels=True)
		G = nx.dodecahedral_graph()
		nx.draw_networkx_labels(G, pos, labels)

		plt.savefig('network.png')
		plt.show()
Exemplo n.º 18
0
def drawing_example():
	import matplotlib.pyplot as plt

	G = nx.petersen_graph()
	plt.subplot(121)
	nx.draw(G, with_labels=True, font_weight='bold')
	plt.subplot(122)
	nx.draw_shell(G, nlist=[range(5, 10), range(5)], with_labels=True, font_weight='bold')
	plt.show()

	options = {
		'node_color': 'black',
		'node_size': 100,
		'width': 3,
	}
	plt.subplot(221)
	nx.draw_random(G, **options)
	plt.subplot(222)
	nx.draw_circular(G, **options)
	plt.subplot(223)
	nx.draw_spectral(G, **options)
	plt.subplot(224)
	nx.draw_shell(G, nlist=[range(5,10), range(5)], **options)
	plt.show()

	G = nx.dodecahedral_graph()
	shells = [[2, 3, 4, 5, 6], [8, 1, 0, 19, 18, 17, 16, 15, 14, 7], [9, 10, 11, 12, 13]]
	nx.draw_shell(G, nlist=shells, **options)
	plt.show()

	# Save drawings to a file.
	nx.draw(G)
	plt.savefig('./path.png')

	# If Graphviz and PyGraphviz or pydot are available on your system,
	# you can also use nx_agraph.graphviz_layout(G) or nx_pydot.graphviz_layout(G) to get the node positions,
	# or write the graph in dot format for further processing.
	pos = nx.nx_agraph.graphviz_layout(G)
	nx.draw(G, pos=pos)
	nx.drawing.nx_pydot.write_dot(G, './file.dot')
Exemplo n.º 19
0
    def shapes(self, radius=10, length=100, strength=0.05, damping=0.01, center=True):
        G = nx.dodecahedral_graph()
        # G = nx.graph_atlas(134)
        # G = nx.graph_atlas(1167)
        # G = nx.truncated_cube_graph()
        # G = nx.truncated_tetrahedron_graph()
        # G = nx.cycle_graph(5)
        # G = nx.circular_ladder_graph(10)
        # G = nx.circulant_graph(10,[1,4,6])
        # G = nx.frucht_graph()
        # G = nx.moebius_kantor_graph()
        # G = nx.random_tree(10, None)
        # G = nx.sudoku_graph(2)
        # G = nx.pappus_graph()
        # G = nx.octahedral_graph()
        G = nx.hypercube_graph(4)

        # dim = (4,4,4)
        # dim = (2,2,6)
        # dim = (3,3,3)
        # dim = (2,2,2,2)
        # dim = (3,3,6)
        # G = nx.grid_graph(dim=dim, periodic=False)
        # G = nx.wheel_graph(40)
        # G = nx.star_graph(21)

        # G = nx.hexagonal_lattice_graph(4,3)
        # G = nx.triangular_lattice_graph(3,4)
        # G = nx.diamond_graph()

        # G = nx.grid_2d_graph(3,4, periodic=False)
        # G = nx.hypercube_graph(2)
        # G = nx.random_geometric_graph(n=8, radius=8, dim=8, p=10)
        balls = self.arrange_from_graph(G, radius, length, strength, damping, center)

        return balls
Exemplo n.º 20
0
# write_json_graph(nx.random_lobster(20, 0.4, 0.6, seed=0), 'random_lobster(20,0_4,0_6).json')
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')
Exemplo n.º 21
0
 def test_dodecahedral(self):
     print '\ndodecahedral:',
     self.g = nx.dodecahedral_graph()
     a = programming_for_tree_decomposition(self.g, True)
     self.t = a.tree_decomposition()
     self.assertTrue(self.__test_all_conditions())
    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())
Exemplo n.º 23
0
def test_dodecahedral():
    G = nx.dodecahedral_graph()
    assert_equal(3, approx.node_connectivity(G))
    assert_equal(3, approx.node_connectivity(G, 0, 5))
Exemplo n.º 24
0
# Step 0:
# install the package networkx
# !pip install networkx

# Step 1: import the package
import networkx as networkx
#import matplotlib.pyplot as plt
from matplotlib import pyplot

# Step 2: open the graph from file or create one

# Create an example graph:
G = networkx.dodecahedral_graph()
#
#G = networkx.gnm_random_graph(20, 40)
G.nodes
G.edges

# Step 3: Choose the Positions of nodes
# Basic choice: random function -assigning random positions to the nodes
#nodes_position=networkx.random_layout(G)
# Other algorithm to position the nodes on the plane:
nodes_position = networkx.spring_layout(G)
#nodes_position=networkx.circular_layout(G)
# see here for more layouts: https://networkx.github.io/documentation/stable/reference/drawing.html

# Step 4: the plot
pyplot.figure()

networkx.draw(G, pos=nodes_position, node_color='r')  # use spring layout
Exemplo n.º 25
0
def test_dodecahedral():
    # Actual coefficient is 0
    G = nx.dodecahedral_graph()
    assert_equal(average_clustering(G, trials=int(len(G) / 2)),
                 nx.average_clustering(G))
Exemplo n.º 26
0
 def draw(self):
     # nx.draw(self.G)
     G = nx.dodecahedral_graph()
     nx.draw(G)
Exemplo n.º 27
0
def test_dodecahedral():
    G = nx.dodecahedral_graph()
    assert 3 == approx.node_connectivity(G)
    assert 3 == approx.node_connectivity(G, 0, 5)
Exemplo n.º 28
0
def test_draw():
    G = nx.dodecahedral_graph()
    nx.draw(G)  # networkx draw()
#    P.draw()    # pylab draw()
    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')
def test_dodecahedral():
    G = nx.dodecahedral_graph()
    for flow_func in flow_funcs:
        errmsg = f"Assertion failed in function: {flow_func.__name__}"
        assert 3 == nx.node_connectivity(G, flow_func=flow_func), errmsg
        assert 3 == nx.edge_connectivity(G, flow_func=flow_func), errmsg
Exemplo n.º 31
0
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')

Exemplo n.º 32
0
        edges += generate_edges_for_complete_graphs(
            [j for j in range(i * cs, (i + 1) * cs)])
        edges += [(i * cs, ((i + 1) * cs) % (nc * cs))]
    G.add_edges_from(edges)
    return G


# Gs = [nx.cycle_graph(10), nx.grid_graph(dim=[5,5]), nx.full_rary_tree(2, 15), nx.complete_graph(20), nx.complete_bipartite_graph(5, 5), nx.dodecahedral_graph(), nx.hypercube_graph(3), block_graph(5,5), build_networkx_graph('input9.txt')]
# for G in Gs:
#   networkx_to_json(G)

Gs = [
    ('path-5', nx.path_graph(5)),
    ('path-10', nx.path_graph(10)),
    ('cycle-10', nx.cycle_graph(10)),
    ('grid-5-5', nx.grid_graph(dim=[5, 5])),
    ('grid-10-6', nx.grid_graph(dim=[10, 6])),
    ('tree-2-3', nx.balanced_tree(2, 3)),
    ('tree-2-4', nx.balanced_tree(2, 4)),
    ('tree-2-5', nx.balanced_tree(2, 5)),
    ('k-5', nx.complete_graph(5)),
    ('k-20', nx.complete_graph(20)),
    ('bipartite-graph-5-5', nx.complete_bipartite_graph(5, 5)),
    ('dodecahedron', nx.dodecahedral_graph()),
    ('cube', nx.hypercube_graph(3)),
    ('block-5-5', block_graph(5, 5)),
    ('input-9', build_networkx_graph('input9.txt')),
]
for name, G in Gs:
    print(name)
    networkx_to_json_2(G, name)
Exemplo n.º 33
0
def test_dodecahedral():
    G = nx.dodecahedral_graph()
    assert_equal(3, approx.node_connectivity(G))
    assert_equal(3, approx.node_connectivity(G, 0, 5))
Exemplo n.º 34
0
def test_dodecahedral():
    # Actual coefficient is 0
    G = nx.dodecahedral_graph()
    assert (average_clustering(G, trials=int(len(G) / 2)) ==
                 nx.average_clustering(G))
Exemplo n.º 35
0
def test_dodecahedral():
    G = nx.dodecahedral_graph()
    assert_equal(3, nx.node_connectivity(G))
    assert_equal(3, nx.edge_connectivity(G))
Exemplo n.º 36
0
def DodecahedralGraph():
    """
    Returns a Dodecahedral graph (with 20 nodes)

    The dodecahedral graph is cubic symmetric, so the spring-layout
    algorithm will be very effective for display. It is dual to the
    icosahedral graph.

    PLOTTING: The Dodecahedral graph should be viewed in 3 dimensions.
    We chose to use the default spring-layout algorithm here, so that
    multiple iterations might yield a different point of reference for
    the user. We hope to add rotatable, 3-dimensional viewing in the
    future. In such a case, a string argument will be added to select
    the flat spring-layout over a future implementation.

    EXAMPLES: Construct and show a Dodecahedral graph

    ::

        sage: g = graphs.DodecahedralGraph()
        sage: g.show() # long time

    Create several dodecahedral graphs in a Sage graphics array They
    will be drawn differently due to the use of the spring-layout
    algorithm

    ::

        sage: g = []
        sage: j = []
        sage: for i in range(9):
        ...    k = graphs.DodecahedralGraph()
        ...    g.append(k)
        ...
        sage: for i in range(3):
        ...    n = []
        ...    for m in range(3):
        ...        n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False))
        ...    j.append(n)
        ...
        sage: G = sage.plot.graphics.GraphicsArray(j)
        sage: G.show() # long time
    """
    import networkx
    G = networkx.dodecahedral_graph()

    pos = {}
    r1 = 7
    r2 = 4.7
    r3 = 3.8
    r4 = 1.5

    for i,v in enumerate([19,0,1,2,3]):
        i = i + .25
        pos[v] = (r1*cos(i*2*pi/5),r1*sin(i*2*pi/5))

    for i,v in enumerate([18,10,8,6,4]):
        i = i + .25
        pos[v] = (r2*cos(i*2*pi/5),r2*sin(i*2*pi/5))

    for i,v in enumerate([17,11,9,7,5]):
        i = i - .25
        pos[v] = (r3*cos(i*2*pi/5),r3*sin(i*2*pi/5))

    for i,v in enumerate([12,13,14,15,16]):
        i = i + .75
        pos[v] = (r4*cos(i*2*pi/5),r4*sin(i*2*pi/5))

    return graph.Graph(G, name="Dodecahedron", pos=pos)

# https://networkx.github.io/documentation/networkx-1.9.1/reference/algorithms.operators.html

import networkx as nx
import matplotlib.pyplot as plt
import numpy

numpy.random.seed(121)

G = nx.dodecahedral_graph()
edge_labels = nx.draw_networkx_edge_labels(G ,pos=nx.spring_layout(G))

nx.draw( G )
plt.show()
Exemplo n.º 38
0
def DodecahedralGraph():
    """
    Returns a Dodecahedral graph (with 20 nodes)

    The dodecahedral graph is cubic symmetric, so the spring-layout
    algorithm will be very effective for display. It is dual to the
    icosahedral graph.

    PLOTTING: The Dodecahedral graph should be viewed in 3 dimensions.
    We chose to use the default spring-layout algorithm here, so that
    multiple iterations might yield a different point of reference for
    the user. We hope to add rotatable, 3-dimensional viewing in the
    future. In such a case, a string argument will be added to select
    the flat spring-layout over a future implementation.

    EXAMPLES: Construct and show a Dodecahedral graph

    ::

        sage: g = graphs.DodecahedralGraph()
        sage: g.show() # long time

    Create several dodecahedral graphs in a Sage graphics array They
    will be drawn differently due to the use of the spring-layout
    algorithm

    ::

        sage: g = []
        sage: j = []
        sage: for i in range(9):
        ....:     k = graphs.DodecahedralGraph()
        ....:     g.append(k)
        sage: for i in range(3):
        ....:     n = []
        ....:     for m in range(3):
        ....:         n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False))
        ....:     j.append(n)
        sage: G = graphics_array(j)
        sage: G.show() # long time
    """
    import networkx
    G = networkx.dodecahedral_graph()

    pos = {}
    r1 = 7
    r2 = 4.7
    r3 = 3.8
    r4 = 1.5

    for i, v in enumerate([19, 0, 1, 2, 3]):
        i = i + .25
        pos[v] = (r1 * cos(i * 2 * pi / 5), r1 * sin(i * 2 * pi / 5))

    for i, v in enumerate([18, 10, 8, 6, 4]):
        i = i + .25
        pos[v] = (r2 * cos(i * 2 * pi / 5), r2 * sin(i * 2 * pi / 5))

    for i, v in enumerate([17, 11, 9, 7, 5]):
        i = i - .25
        pos[v] = (r3 * cos(i * 2 * pi / 5), r3 * sin(i * 2 * pi / 5))

    for i, v in enumerate([12, 13, 14, 15, 16]):
        i = i + .75
        pos[v] = (r4 * cos(i * 2 * pi / 5), r4 * sin(i * 2 * pi / 5))

    return Graph(G, name="Dodecahedron", pos=pos)
Exemplo n.º 39
0
def draw_ex():
    G = nx.dodecahedral_graph()
    nx.draw(G, pos=nx.spring_layout(G), nodecolor='r', edge_color='b', with_labels=True, data='weight')
    plt.savefig("draw_graph.png")
    plt.show()
Exemplo n.º 40
0
        pass
    if verify_planar_necessary_condition(G):
        six = True

    return one, two, three, four, five, six


### DO NOT TURN IN AN ASSIGNMENT WITH ANYTHING BELOW HERE MODIFIED ###
if __name__ == '__main__':
    G1 = nx.Graph()
    G1.add_edges_from([(1, 2), (2, 3), (3, 4), (4, 5), (2, 6)])
    G2 = nx.Graph()
    G2.add_edges_from([(1, 2), (2, 3), (3, 4), (4, 5), (3, 6)])
    K_5 = nx.complete_graph(5)
    K_3_5 = nx.complete_bipartite_graph(3, 5)
    planar_graph = nx.dodecahedral_graph()
    print("#######################################")
    print("Welcome to Coding 3: Graph Theory!")
    print("#######################################")
    print()

    print("---------------------------------------")
    print("PART A: Basics in Graph theory")
    print("---------------------------------------")
    print("Part (a)")
    print("---------------------------------------")
    print("Test Case 1: ")
    student_ans_1 = graph_properties(G1)
    print("Test Case 1 (Your Answer):", student_ans_1)
    print("Test Case 1 (Correct Answer):", (6, 5, [1, 1, 1, 2, 2, 3]))
    print()
Exemplo n.º 41
0
'''
Created on Nov 27, 2012

@author: Nguyen Huu Hiep
'''

import pylab as P #
import networkx as nx
import matplotlib.pyplot as plt


G = nx.dodecahedral_graph()
pos = nx.spring_layout(G)

nx.draw(G, pos)  # networkx draw()
#P.draw()    # pylab draw()

plt.savefig("fig/dodecahedral_graph.png") # save as png
plt.show() # display
Exemplo n.º 42
0
def drawing_tutorial():
    import matplotlib.pyplot as plt

    G = nx.petersen_graph()
    plt.subplot(121)
    nx.draw(G, with_labels=True, font_weight='bold')
    plt.subplot(122)
    nx.draw_shell(G,
                  nlist=[range(5, 10), range(5)],
                  with_labels=True,
                  font_weight='bold')
    plt.show()

    options = {
        'node_color': 'black',
        'node_size': 100,
        'width': 3,
    }
    plt.subplot(221)
    nx.draw_random(G, **options)
    plt.subplot(222)
    #nx.draw_planar(G, **options)
    nx.draw_circular(G, **options)
    plt.subplot(223)
    nx.draw_spectral(G, **options)
    #nx.draw_spring(G, **options)
    #nx.draw_kamada_kawai(G, **options)
    plt.subplot(224)
    nx.draw_shell(G, nlist=[range(5, 10), range(5)], **options)
    plt.show()

    G = nx.dodecahedral_graph()
    shells = [[2, 3, 4, 5, 6], [8, 1, 0, 19, 18, 17, 16, 15, 14, 7],
              [9, 10, 11, 12, 13]]
    nx.draw_shell(G, nlist=shells, **options)
    plt.show()

    # Save drawings to a file.
    nx.draw(G)
    plt.savefig('./path.png')

    # If Graphviz and PyGraphviz or pydot are available on your system,
    # you can also use nx_agraph.graphviz_layout(G) or nx_pydot.graphviz_layout(G) to get the node positions,
    # or write the graph in dot format for further processing.
    pos = nx.nx_agraph.graphviz_layout(
        G)  # e.g.) pos = {1: (10, 10), 2: (30, 20)}.
    nx.draw(G, pos=pos)
    nx.drawing.nx_pydot.write_dot(G, './file.dot')

    #--------------------
    G = nx.complete_graph(15)

    #pos = nx.get_node_attributes(G, 'pos')
    #pos = nx.nx_agraph.graphviz_layout(G)
    #pos = nx.drawing.nx_pydot.graphviz_layout(G)
    #pos = nx.drawing.nx_pydot.pydot_layout(G)
    #pos = nx.random_layout(G)
    #pos = nx.planar_layout(G)
    #pos = nx.circular_layout(G)
    pos = nx.spectral_layout(G)
    #pos = nx.spiral_layout(G)
    #pos = nx.spring_layout(G)
    #pos = nx.shell_layout(G)
    #pos = nx.kamada_kawai_layout(G)
    #pos = nx.rescale_layout(G)
    #pos = nx.rescale_layout_dict(G)
    #pos = nx.bipartite_layout(G)
    #pos = nx.multipartite_layout(G)

    plt.figure(figsize=(10, 6))
    nx.draw_networkx_nodes(G,
                           pos,
                           node_size=400,
                           alpha=1.0,
                           node_shape='o',
                           node_color='red')
    nx.draw_networkx_edges(G, pos, width=5, alpha=0.8, edge_color='blue')
    #nx.draw_networkx_labels(G, pos, labels=None, font_size=12, font_color='k', font_family='sans-serif', font_weight='normal')
    #nx.draw_networkx_edge_labels(G, pos, edge_labels=None, label_pos=0.5, font_size=12, font_color='k', font_family='sans-serif', font_weight='normal')
    plt.tight_layout()
    plt.axis('off')
    #plt.savefig('./graph_drawing_1.svg')

    plt.figure(figsize=(10, 6))
    #nx.draw(G, pos, ax=None)
    #nx.draw(G, pos, labels=node_labels, **options)
    #nx.draw(G, pos, labels=nx.get_node_attributes(G, 'node_labels'), **options)
    nx.draw_networkx(G, pos, arrows=None, with_labels=True)
    plt.tight_layout()
    plt.axis('off')
    #plt.savefig('./graph_drawing_2.svg')

    plt.show()
Exemplo n.º 43
0
def test_dodecahedral():
    G = nx.dodecahedral_graph()
    assert_equal(3, nx.node_connectivity(G))
    assert_equal(3, nx.edge_connectivity(G))
Exemplo n.º 44
0
    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__':
    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