Exemplo n.º 1
0
 def test_make_small_graph(self):
     d = [
         "adjacencylist", "Bull Graph", 5,
         [[2, 3], [1, 3, 4], [1, 2, 5], [2], [3]]
     ]
     G = nx.make_small_graph(d)
     assert is_isomorphic(G, nx.bull_graph())
Exemplo n.º 2
0
def get_matplotlib_object_that_represents_graph_edges():
    '''
    networkx.drawing.nx_pylab.draw_networkx_edges() returns a matplotlib.collection.LineCollection
    - A graph object and a dictionary of positions are both required arguments to draw_networkx_edges()
    - Optionally, I can provide a list of edges in which case only the provided edges will be drawn
    - Version incompatibilities:
        - networkx==1.11 and matplotlib==2.2.5 draws fine
            - The LineCollection is sneakily autoscaled! This is not standard in matplotlib
        - networkx==1.11 and matplotlib==3.1.3 fails to run successfully
        - networkx==2.4 and matplotlib==2.2.5 draws fine
            - Need to invoke autoscale()
        - networkx==2.4 and matplotlib==3.1.3 draws fine
            - Need to invoke autoscale()
    '''
    fig, ax = plt.subplots()  # Works fine
    g = nx.bull_graph()
    pos = nx_agraph.graphviz_layout(g)
    print(g.edges())  # [(0, 1), (0, 2), (1, 2), (1, 3), (2, 4)]
    lc = nx.drawing.nx_pylab.draw_networkx_edges(g, pos)
    #lc = nx.drawing.nx_pylab.draw_networkx_edges(g, pos, edgelist=[(0, 1)])
    #fig, ax = plt.subplots() # Causes RuntimeError
    lc.set_color(('r', 'g', 'b', 'y', 'c', 'm', 'k'))
    ax.add_collection(lc)
    ax.autoscale()
    plt.show()
Exemplo n.º 3
0
def ego_graphs():
    print("Ego graphs")
    # G = nx.star_graph(7)
    G = nx.bull_graph()
    EG = nx.ego_graph(G, 2)
    draw_graph(G)
    draw_graph(EG)
 def test170_bullgraph(self):
     """ Bull graph. """
     g = nx.bull_graph()
     mate1 = mv.max_cardinality_matching( g )
     mate2 = nx.max_weight_matching( g, True )
     #td.showGraph(g, mate1, "test170_bullgraph")
     self.assertEqual( len(mate1), len(mate2) )
def test_complement():
    null = nx.null_graph()
    empty1 = nx.empty_graph(1)
    empty10 = nx.empty_graph(10)
    K3 = nx.complete_graph(3)
    K5 = nx.complete_graph(5)
    K10 = nx.complete_graph(10)
    P2 = nx.path_graph(2)
    P3 = nx.path_graph(3)
    P5 = nx.path_graph(5)
    P10 = nx.path_graph(10)
    # complement of the complete graph is empty

    G = nx.complement(K3)
    assert nx.is_isomorphic(G, nx.empty_graph(3))
    G = nx.complement(K5)
    assert nx.is_isomorphic(G, nx.empty_graph(5))
    # for any G, G=complement(complement(G))
    P3cc = nx.complement(nx.complement(P3))
    assert nx.is_isomorphic(P3, P3cc)
    nullcc = nx.complement(nx.complement(null))
    assert nx.is_isomorphic(null, nullcc)
    b = nx.bull_graph()
    bcc = nx.complement(nx.complement(b))
    assert nx.is_isomorphic(b, bcc)
Exemplo n.º 6
0
    def test_make_small_graph(self):
        d = ["adjacencylist", "Bull Graph", 5, [[2, 3], [1, 3, 4], [1, 2, 5], [2], [3]]]
        G = nx.make_small_graph(d)
        assert is_isomorphic(G, nx.bull_graph())

        # Test small graph creation error with wrong ltype
        d[0] = "erroneouslist"
        pytest.raises(nx.NetworkXError, nx.make_small_graph, graph_description=d)
 def test_bull(self):
     expected = True
     g = nx.bull_graph()
     for o in enumerate_dfs_ordering_naively(g):
         @spec_order(o)
         def func(g):
             return is_planar(g)
         actual = func(g)
         self.assertEqual(expected, actual)
def network_graph(df):
    result = pd.read_csv(
        'C:/Harshad.Ambekar/personal/github/hackathon-intel-auto/dataset/labels.csv'
    )
    G = nx.bull_graph()
    pos = nx.spring_layout(G)  # positions for all nodes

    # nodes
    nx.draw_networkx_nodes(
        G,
        pos,
        #nodelist=['loginflow','tenantflow','authenflow','authflow'],
        nodelist=[0, 1, 2, 3, 4],
        node_color='b',
        node_size=250,
        alpha=0.8)

    # edges
    nx.draw_networkx_edges(G, pos, width=1.0, alpha=0.5)
    nx.draw_networkx_edges(
        G,
        pos,
        edgelist=[(0, 1), (0, 2), (0, 3), (1, 2), (2, 4)],
        #edgelist=[('loginflow','tenantflow'),('loginflow','authenflow'),('loginflow','authflow')],
        width=4,
        alpha=0.5,
        edge_color='r')
    # some math labels
    labels = {}
    labels[0] = r'$loginflow$'
    labels[1] = r'$tenantflow$'
    labels[2] = r'$authenflow$'
    labels[3] = r'$authflow$'
    labels[4] = r'$usercreation$'
    nx.draw_networkx_labels(G, pos, labels, font_size=8)

    #plt.axis('off')
    #plt.savefig("labels_and_colors.png") # save as png
    #plt.figure(figsize=(4, 3), dpi=70)

    st.pyplot()
Exemplo n.º 9
0
 def test_complete_to_chordal_graph(self):
     fgrg = nx.fast_gnp_random_graph
     test_graphs = [
         nx.barbell_graph(6, 2),
         nx.cycle_graph(15),
         nx.wheel_graph(20),
         nx.grid_graph([10, 4]),
         nx.ladder_graph(15),
         nx.star_graph(5),
         nx.bull_graph(),
         fgrg(20, 0.3, seed=1),
     ]
     for G in test_graphs:
         H, a = nx.complete_to_chordal_graph(G)
         assert nx.is_chordal(H)
         assert len(a) == H.number_of_nodes()
         if nx.is_chordal(G):
             assert G.number_of_edges() == H.number_of_edges()
             assert set(a.values()) == {0}
         else:
             assert len(set(a.values())) == H.number_of_nodes()
Exemplo n.º 10
0
def BullGraph():
    r"""
    Returns a bull graph with 5 nodes.

    A bull graph is named for its shape. It's a triangle with horns.
    This constructor depends on `NetworkX <http://networkx.lanl.gov>`_
    numeric labeling. For more information, see this
    :wikipedia:`Wikipedia article on the bull graph <Bull_graph>`.

    PLOTTING:

    Upon construction, the position dictionary is filled to
    override the spring-layout algorithm. By convention, the bull graph
    is drawn as a triangle with the first node (0) on the bottom. The
    second and third nodes (1 and 2) complete the triangle. Node 3 is
    the horn connected to 1 and node 4 is the horn connected to node
    2.

    ALGORITHM:

    Uses `NetworkX <http://networkx.lanl.gov>`_.

    EXAMPLES:

    Construct and show a bull graph::

        sage: g = graphs.BullGraph(); g
        Bull graph: Graph on 5 vertices
        sage: g.show() # long time

    The bull graph has 5 vertices and 5 edges. Its radius is 2, its
    diameter 3, and its girth 3. The bull graph is planar with chromatic
    number 3 and chromatic index also 3. ::

        sage: g.order(); g.size()
        5
        5
        sage: g.radius(); g.diameter(); g.girth()
        2
        3
        3
        sage: g.chromatic_number()
        3

    The bull graph has chromatic polynomial `x(x - 2)(x - 1)^3` and
    Tutte polynomial `x^4 + x^3 + x^2 y`. Its characteristic polynomial
    is `x(x^2 - x - 3)(x^2 + x - 1)`, which follows from the definition of
    characteristic polynomials for graphs, i.e. `\det(xI - A)`, where
    `x` is a variable, `A` the adjacency matrix of the graph, and `I`
    the identity matrix of the same dimensions as `A`. ::

        sage: chrompoly = g.chromatic_polynomial()
        sage: bool(expand(x * (x - 2) * (x - 1)^3) == chrompoly)
        True
        sage: charpoly = g.characteristic_polynomial()
        sage: M = g.adjacency_matrix(); M
        [0 1 1 0 0]
        [1 0 1 1 0]
        [1 1 0 0 1]
        [0 1 0 0 0]
        [0 0 1 0 0]
        sage: Id = identity_matrix(ZZ, M.nrows())
        sage: D = x*Id - M
        sage: bool(D.determinant() == charpoly)
        True
        sage: bool(expand(x * (x^2 - x - 3) * (x^2 + x - 1)) == charpoly)
        True
    """
    pos_dict = {0: (0, 0), 1: (-1, 1), 2: (1, 1), 3: (-2, 2), 4: (2, 2)}
    import networkx
    G = networkx.bull_graph()
    return graph.Graph(G, pos=pos_dict, name="Bull graph")
Exemplo n.º 11
0
 def test_bull(self):
     print '\nbull:',
     self.g = nx.bull_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.º 13
0
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)
Exemplo n.º 14
0
def BullGraph():
    r"""
    Returns a bull graph with 5 nodes.

    A bull graph is named for its shape. It's a triangle with horns.
    This constructor depends on `NetworkX <http://networkx.lanl.gov>`_
    numeric labeling. For more information, see this
    :wikipedia:`Wikipedia article on the bull graph <Bull_graph>`.

    PLOTTING:

    Upon construction, the position dictionary is filled to
    override the spring-layout algorithm. By convention, the bull graph
    is drawn as a triangle with the first node (0) on the bottom. The
    second and third nodes (1 and 2) complete the triangle. Node 3 is
    the horn connected to 1 and node 4 is the horn connected to node
    2.

    ALGORITHM:

    Uses `NetworkX <http://networkx.lanl.gov>`_.

    EXAMPLES:

    Construct and show a bull graph::

        sage: g = graphs.BullGraph(); g
        Bull graph: Graph on 5 vertices
        sage: g.show() # long time

    The bull graph has 5 vertices and 5 edges. Its radius is 2, its
    diameter 3, and its girth 3. The bull graph is planar with chromatic
    number 3 and chromatic index also 3. ::

        sage: g.order(); g.size()
        5
        5
        sage: g.radius(); g.diameter(); g.girth()
        2
        3
        3
        sage: g.chromatic_number()
        3

    The bull graph has chromatic polynomial `x(x - 2)(x - 1)^3` and
    Tutte polynomial `x^4 + x^3 + x^2 y`. Its characteristic polynomial
    is `x(x^2 - x - 3)(x^2 + x - 1)`, which follows from the definition of
    characteristic polynomials for graphs, i.e. `\det(xI - A)`, where
    `x` is a variable, `A` the adjacency matrix of the graph, and `I`
    the identity matrix of the same dimensions as `A`. ::

        sage: chrompoly = g.chromatic_polynomial()
        sage: bool(expand(x * (x - 2) * (x - 1)^3) == chrompoly)
        True
        sage: charpoly = g.characteristic_polynomial()
        sage: M = g.adjacency_matrix(); M
        [0 1 1 0 0]
        [1 0 1 1 0]
        [1 1 0 0 1]
        [0 1 0 0 0]
        [0 0 1 0 0]
        sage: Id = identity_matrix(ZZ, M.nrows())
        sage: D = x*Id - M
        sage: bool(D.determinant() == charpoly)
        True
        sage: bool(expand(x * (x^2 - x - 3) * (x^2 + x - 1)) == charpoly)
        True
    """
    pos_dict = {0:(0,0), 1:(-1,1), 2:(1,1), 3:(-2,2), 4:(2,2)}
    import networkx
    G = networkx.bull_graph()
    return graph.Graph(G, pos=pos_dict, name="Bull graph")
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.º 16
0
        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__':
    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
Exemplo n.º 17
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.º 18
0
    G1 = nx.erdos_renyi_graph(n=24, p=0.3, seed=seed)

    # some cool graphs
    G2 = nx.star_graph(20)
    G3 = nx.path_graph(30)
    G4 = nx.petersen_graph()
    G5 = nx.dodecahedral_graph()
    G6 = nx.house_graph()
    G7 = nx.moebius_kantor_graph()
    G8 = nx.barabasi_albert_graph(5, 4)
    G9 = nx.heawood_graph()
    G10 = nx.icosahedral_graph()
    G11 = nx.sedgewick_maze_graph()
    G12 = nx.havel_hakimi_graph([1, 1])
    G13 = nx.complete_graph(20)
    G14 = nx.bull_graph()

    G = G1  # choose a graph from the list

    gd.draw_custom(G)
    plt.show()

    #exact cut
    print("Time 'local_consistent_max_cut':" + str(gt.execution_time(mc.local_consistent_max_cut, 1, G)))
    print('Edges cut: ' + str(gc.cut_edges(G)))
    print('\n')
    print("Time 'lazy_local_consistent_max_cut':" + str(gt.execution_time(mc.lazy_local_consistent_max_cut, 1, G)))
    print('Edges cut: ' + str(gc.cut_edges(G)))
    print('\n')

    gd.draw_cut_graph(G)
Exemplo n.º 19
0
        pos = nx.spectral_layout(G)
        break
    elif mode == 14:
        G = nx.truncated_cube_graph()
        pos = nx.spectral_layout(G)
        break
    elif mode == 15:
        G = nx.sedgewick_maze_graph()
        pos = nx.spectral_layout(G)
        break
    elif mode == 16:
        G = nx.pappus_graph()
        pos = nx.spectral_layout(G)
        break
    elif mode == 17:
        G = nx.bull_graph()
        pos = nx.spectral_layout(G)
        break
    elif mode == 18:
        G = nx.krackhardt_kite_graph()
        break
    else:
        print("Please enter a valid number.")

costsChecker = int(input("Cost Mode (0 - random / 1 - cost of 1): "))

# assigns random weights to all of the edges
for (u, v) in G.edges():
    if costsChecker == 0:
        G.edge[u][v]['weight'] = random.randint(0, 500)
    else:
Exemplo n.º 20
0
 def test_bull(self):
     expected = True
     actual = is_planar(nx.bull_graph())
     self.assertEqual(expected, actual)
Exemplo n.º 21
0
    G1 = nx.erdos_renyi_graph(n=24, p=0.3, seed=seed)

    # some cool graphs
    G2 = nx.star_graph(20)
    G3 = nx.path_graph(30)
    G4 = nx.petersen_graph()
    G5 = nx.dodecahedral_graph()
    G6 = nx.house_graph()
    G7 = nx.moebius_kantor_graph()
    G8 = nx.barabasi_albert_graph(5, 4)
    G9 = nx.heawood_graph()
    G10 = nx.icosahedral_graph()
    G11 = nx.sedgewick_maze_graph()
    G12 = nx.havel_hakimi_graph([1, 1])
    G13 = nx.complete_graph(20)
    G14 = nx.bull_graph()

    G = G1  # choose a graph from the list

    gd.draw_custom(G)
    plt.show()

    #exact cut
    print("Time 'local_consistent_max_cut':" +
          str(gt.execution_time(mc.local_consistent_max_cut, 1, G)))
    print('Edges cut: ' + str(gc.cut_edges(G)))
    print('\n')
    print("Time 'lazy_local_consistent_max_cut':" +
          str(gt.execution_time(mc.lazy_local_consistent_max_cut, 1, G)))
    print('Edges cut: ' + str(gc.cut_edges(G)))
    print('\n')