예제 #1
0
 def calculate(graph):
     deg_seq = gp.degree_sequence(graph)
     valencies = []
     for i in range(0, nx.number_of_nodes(graph)):
         if deg_seq[i] not in valencies:
             valencies.append(deg_seq[i])
     return len(valencies)
예제 #2
0
파일: dsi.py 프로젝트: somacdivad/grinpy
def annihilation_number(G):
    r"""Return the annihilation number of the graph.

    The annihilation number of a graph G is defined as:

    .. math::
        a(G) = \max\{t : \sum_{i=0}^t d_i \leq m\}

    where

    .. math::
        {d_1 \leq d_2 \leq \cdots \leq d_n}

    is the degree sequence of the graph ordered in non-decreasing order and *m*
    is the number of edges in G.

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

    Returns
    -------
    int
        The annihilation number of the graph.
    """
    D = degree_sequence(G)
    D.sort()  # sort in non-decreasing order
    n = len(D)
    m = number_of_edges(G)
    # sum over degrees in the sequence until the sum is larger than the number of edges in the graph
    for i in reversed(range(n + 1)):
        if sum(D[:i]) <= m:
            return i
예제 #3
0
def degree_ranking(Ma):
    G = nx.from_numpy_matrix(Ma)
    deg = np.asarray(gp.degree_sequence(G))
    deg = (np.amax(deg) + 1) - deg  #higher degree comes first
    deg_rank = np.argsort(deg)

    return deg_rank
예제 #4
0
파일: dsi.py 프로젝트: somacdivad/grinpy
def sub_k_domination_number(G, k):
    r"""Return the sub-k-domination number of the graph.

    The *sub-k-domination number* of a graph G with *n* nodes is defined as the
    smallest positive integer t such that the following relation holds:

    .. math::
        t + \frac{1}{k}\sum_{i=0}^t d_i \geq n

    where

    .. math::
        {d_1 \geq d_2 \geq \cdots \geq d_n}

    is the degree sequence of the graph.

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

    k : int
        A positive integer.

    Returns
    -------
    int
        The sub-k-domination number of a graph.

    See Also
    --------
    slater

    Examples
    --------
    >>> G = nx.cycle_graph(4)
    >>> nx.sub_k_domination_number(G, 1)
    True

    References
    ----------
    D. Amos, J. Asplund, B. Brimkov and R. Davila, The sub-k-domination number
    of a graph with applications to k-domination, *arXiv preprint
    arXiv:1611.02379*, (2016)
    """
    # check that k is a positive integer
    if not float(k).is_integer():
        raise TypeError("Expected k to be an integer.")
    k = int(k)
    if k < 1:
        raise ValueError("Expected k to be a positive integer.")
    D = degree_sequence(G)
    D.sort(reverse=True)
    n = len(D)
    for i in range(n + 1):
        if i + (sum(D[:i]) / k) >= n:
            return i
    # if above loop completes, return None
    return None
예제 #5
0
파일: dsi.py 프로젝트: RandyRDavila/grinpy
def annihilation_number(G):
    # TODO: Add documentation
    D = degree_sequence(G)
    D.sort() # sort in non-decreasing order
    m = number_of_edges(G)
    # sum over degrees in the sequence until the sum is larger than the number of edges in the graph
    S = [D[0]]
    while(sum(S) <= m):
        S.append(D[len(S)])
    return len(S) - 1
예제 #6
0
파일: dsi.py 프로젝트: RandyRDavila/grinpy
def sub_total_domination_number(G):
    # TODO: Add documentation
    D = degree_sequence(G)
    D.sort(reverse = True)
    n = len(D)
    for i in range(n + 1):
        if sum(D[:i]) >= n:
            return i
    # if above loop completes, return None (should not occur)
    return None
예제 #7
0
파일: dsi.py 프로젝트: RandyRDavila/grinpy
def sub_k_domination_number(G, k):
    """Return the sub-k-domination number of the graph.

    The *sub-k-domination number* of a graph G with *n* nodes is defined as the
    smallest positive integer t such that the following relation holds:

    .. math::
        t + \frac{1}{k}\sum_{i=0}^t d_i \geq n

    where

    .. math::
        {d_1 \geq d_2 \geq \cdots \geq \d_n}

    is the degree sequence of the graph.

    Parameters
    ----------
    G : graph
        A Networkx graph.

    k : int
        A positive integer.

    Returns
    -------
    sub : int
        The sub-k-domination number of a graph.

    See Also
    --------
    slater

    Examples
    --------
    >>> G = nx.cycle_graph(4)
    >>> nx.sub_k_domination_number(G, 1)
    True

    References
    ----------
    D. Amos, J. Asplund, and R. Davila, The sub-k-domination number of a graph
    with applications to k-domination, *arXiv preprint arXiv:1611.02379*, (2016)
    """
    # TODO: add check that k >= 1 and throw error if not
    D = degree_sequence(G)
    D.sort(reverse = True)
    n = len(D)
    for i in range(n + 1):
        if i + (sum(D[:i]) / k) >= n:
            return i
    # if above loop completes, return None (should not occur)
    return None
예제 #8
0
파일: dsi.py 프로젝트: somacdivad/grinpy
def sub_total_domination_number(G):
    r"""Return the sub-total domination number of the graph.

    The sub-total domination number is defined as:

    .. math::
        sub_{t}(G) = \min\{t : \sum_{i=0}^t d_i \geq n\}

    where

    .. math::
        {d_1 \geq d_2 \geq \cdots \geq d_n}

    is the degree sequence of the graph ordered in non-increasing order and *n*
    is the order of the graph.

    This invariant was defined and investigated by Randy Davila.

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

    Returns
    -------
    int
        The sub-total domination number of the graph.

    References
    ----------
    R. Davila, A note on sub-total domination in graphs. *arXiv preprint
    arXiv:1701.07811*, (2017)
    """
    D = degree_sequence(G)
    D.sort(reverse=True)
    n = len(D)
    for i in range(n + 1):
        if sum(D[:i]) >= n:
            return i
    # if above loop completes, return None
    return None
예제 #9
0
 def calculate(graph):
     sequence = (gp.degree_sequence(graph))
     return sum(sequence) / len(sequence)
예제 #10
0
 def calculate(graph):
     return min(gp.degree_sequence(graph))
예제 #11
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
예제 #12
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]
예제 #13
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
예제 #14
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