Exemplo n.º 1
0
def is_graphic(sequence):
    """Return whether or not the input sequence is graphic.

    A sequence of positive integers is said to be a *graphic sequence* if there
    exist a graph whose degree sequence is equal to the input sequence, up to
    ordering.

    Parameters
    ----------
    sequence : list, iterable
        A list or other iterable container of integers.

    Returns
    -------
    bool
        True if the input sequence is graphic. False otherwise.
    """
    hh = gp.HavelHakimi(sequence)
    return hh.is_graphic()
Exemplo n.º 2
0
def havel_hakimi_process(G):
    """Return an instance of the HavelHakimi class initialized with the degree
    sequence of the graph.

    Parameters
    ----------
    G : NetworkX graph
        An undirected graph.

    Returns
    -------
    object
        An instance of the HavelHakimi class initialized with the degree
        sequence of the graph.

    See Also
    --------
    HavelHakimi
    """
    return gp.HavelHakimi(degree_sequence(G))
Exemplo n.º 3
0
def is_graphic(lSequence):
    hh = gp.HavelHakimi(lSequence)
    return hh.is_graphic()
Exemplo n.º 4
0
def havel_hakimi_process(nxGraph):
    return gp.HavelHakimi(degree_sequence(nxGraph))
Exemplo n.º 5
0
 def test_non_integer_values_raises_TypeError(self):
     with pytest.raises(TypeError):
         hh = gp.HavelHakimi([3, 3, 1.5, 1])
Exemplo n.º 6
0
 def test_non_iterable_raises_TypeError(self):
     with pytest.raises(TypeError):
         hh = gp.HavelHakimi(0)
Exemplo n.º 7
0
 def test_initial_sequence(self):
     G = gp.complete_graph(4)
     hh = gp.HavelHakimi(gp.degree_sequence(G))
     assert hh.get_initial_sequence() == [3, 3, 3, 3]
Exemplo n.º 8
0
 def test_depth_of_complete_graph_is_order_minus_1(self):
     for i in range(2, 12):
         G = gp.complete_graph(i)
         hh = gp.HavelHakimi(gp.degree_sequence(G))
         assert hh.depth() == G.order() - 1
Exemplo n.º 9
0
 def test_elimination_sequence_of_complete_graph(self):
     G = gp.complete_graph(4)
     hh = gp.HavelHakimi(gp.degree_sequence(G))
     e = [3, 2, 1, 0]
     assert hh.get_elimination_sequence() == e
Exemplo n.º 10
0
 def test_process_of_compete_graph(self):
     G = gp.complete_graph(4)
     hh = gp.HavelHakimi(gp.degree_sequence(G))
     p = [[3, 3, 3, 3], [2, 2, 2], [1, 1], [0]]
     assert hh.get_process() == p
Exemplo n.º 11
0
 def test_sequence_of_zeros_is_graphic(self):
     hh = gp.HavelHakimi([0, 0, 0, 0, 0])
     assert hh.is_graphic() == True
Exemplo n.º 12
0
 def test_descending_sequence_of_integers_is_not_graphic(self):
     hh = gp.HavelHakimi([5, 4, 3, 2, 1])
     assert hh.is_graphic() == False
Exemplo n.º 13
0
 def test_havel_hakimi_with_integral_floats(self):
     hh = gp.HavelHakimi([1.0, 1.0])
     assert hh.residue() == 1