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()
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))
def is_graphic(lSequence): hh = gp.HavelHakimi(lSequence) return hh.is_graphic()
def havel_hakimi_process(nxGraph): return gp.HavelHakimi(degree_sequence(nxGraph))
def test_non_integer_values_raises_TypeError(self): with pytest.raises(TypeError): hh = gp.HavelHakimi([3, 3, 1.5, 1])
def test_non_iterable_raises_TypeError(self): with pytest.raises(TypeError): hh = gp.HavelHakimi(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]
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
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
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
def test_sequence_of_zeros_is_graphic(self): hh = gp.HavelHakimi([0, 0, 0, 0, 0]) assert hh.is_graphic() == True
def test_descending_sequence_of_integers_is_not_graphic(self): hh = gp.HavelHakimi([5, 4, 3, 2, 1]) assert hh.is_graphic() == False
def test_havel_hakimi_with_integral_floats(self): hh = gp.HavelHakimi([1.0, 1.0]) assert hh.residue() == 1