当前位置: 首页>>代码示例>>Python>>正文


Python exception.NetworkXError方法代码示例

本文整理汇总了Python中networkx.exception.NetworkXError方法的典型用法代码示例。如果您正苦于以下问题:Python exception.NetworkXError方法的具体用法?Python exception.NetworkXError怎么用?Python exception.NetworkXError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在networkx.exception的用法示例。


在下文中一共展示了exception.NetworkXError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: remove_component

# 需要导入模块: from networkx import exception [as 别名]
# 或者: from networkx.exception import NetworkXError [as 别名]
def remove_component(self, component):
        """
        Removes the specified component from the factor graph.

        :param component: The component to remove.
        :type component: ModelComponent
        """
        if not isinstance(component, ModelComponent):
                raise ModelSpecificationError(
                    "Attempted to remove an object that isn't a ModelComponent.")

        try:
            self.components_graph.remove_node(component)  # implicitly removes edges
        except NetworkXError as e:
            raise ModelSpecificationError("Attempted to remove a node " + str(component) + " that isn't in the graph.")

        if component.name is not None:

            try:
                if getattr(self, component.name) is component:
                    delattr(self, component.name)
            except AttributeError:
                pass

        component.graph = None 
开发者ID:amzn,项目名称:MXFusion,代码行数:27,代码来源:factor_graph.py

示例2: neighbors_iter

# 需要导入模块: from networkx import exception [as 别名]
# 或者: from networkx.exception import NetworkXError [as 别名]
def neighbors_iter(self, n):
        """Return an iterator over all neighbors of node n.

        Examples
        --------
        >>> G = nx.Graph()   # or DiGraph, MultiGraph, MultiDiGraph, etc
        >>> G.add_path([0,1,2,3])
        >>> [n for n in G.neighbors_iter(0)]
        [1]

        Notes
        -----
        It is faster to use the idiom "in G[0]", e.g.

        >>> G = nx.path_graph(4)
        >>> [n for n in G[0]]
        [1]
        """
        try:
            return iter(self.adj[n])
        except KeyError:
            raise NetworkXError("The node %s is not in the graph." % (n,)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:24,代码来源:graph.py

示例3: neighbors_iter

# 需要导入模块: from networkx import exception [as 别名]
# 或者: from networkx.exception import NetworkXError [as 别名]
def neighbors_iter(self, n):
        """Return an iterator over all neighbors of node n.

        Examples
        --------
        >>> G = nx.Graph()   # or DiGraph, MultiGraph, MultiDiGraph, etc
        >>> G.add_path([0,1,2,3])
        >>> [n for n in G.neighbors_iter(0)]
        [1]

        Notes
        -----
        It is faster to use the idiom "in G[0]", e.g.

        >>> G = nx.path_graph(4)
        >>> [n for n in G[0]]
        [1]
        """
        try:
            return iter(self.adj[n])
        except KeyError:
            raise NetworkXError("The node %s is not in the graph."%(n,)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:24,代码来源:timingclasses.py

示例4: neighbors

# 需要导入模块: from networkx import exception [as 别名]
# 或者: from networkx.exception import NetworkXError [as 别名]
def neighbors(self, n):
        """Return a list of the nodes connected to the node n in 
           the dense graph.

        Parameters
        ----------
        n : node
           A node in the graph

        Returns
        -------
        nlist : list
            A list of nodes that are adjacent to n.

        Raises
        ------
        NetworkXError
            If the node n is not in the graph.

        """
        try:
            return list(set(self.adj) - set(self.adj[n]) - set([n]))
        except KeyError:
            raise NetworkXError("The node %s is not in the graph."%(n,)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:26,代码来源:kcomponents.py

示例5: predecessors

# 需要导入模块: from networkx import exception [as 别名]
# 或者: from networkx.exception import NetworkXError [as 别名]
def predecessors(self, n):
        """Returns an iterator over predecessor nodes of n.

        A predecessor of n is a node m such that there exists a directed
        edge from m to n.

        Parameters
        ----------
        n : node
           A node in the graph

        Raises
        -------
        NetworkXError
           If n is not in the graph.

        See Also
        --------
        successors
        """
        try:
            return iter(self._pred[n])
        except KeyError:
            raise NetworkXError("The node %s is not in the digraph." % (n,)) 
开发者ID:holzschu,项目名称:Carnets,代码行数:26,代码来源:digraph.py

示例6: dorogovtsev_goltsev_mendes_graph

# 需要导入模块: from networkx import exception [as 别名]
# 或者: from networkx.exception import NetworkXError [as 别名]
def dorogovtsev_goltsev_mendes_graph(n, create_using=None):
    """Returns the hierarchically constructed Dorogovtsev-Goltsev-Mendes graph.

    n is the generation.
    See: arXiv:/cond-mat/0112143 by Dorogovtsev, Goltsev and Mendes.

    """
    G = empty_graph(0, create_using)
    if G.is_directed():
        raise NetworkXError("Directed Graph not supported")
    if G.is_multigraph():
        raise NetworkXError("Multigraph not supported")

    G.add_edge(0, 1)
    if n == 0:
        return G
    new_node = 2         # next node to be added
    for i in range(1, n + 1):  # iterate over number of generations.
        last_generation_edges = list(G.edges())
        number_of_edges_in_last_generation = len(last_generation_edges)
        for j in range(0, number_of_edges_in_last_generation):
            G.add_edge(new_node, last_generation_edges[j][0])
            G.add_edge(new_node, last_generation_edges[j][1])
            new_node += 1
    return G 
开发者ID:holzschu,项目名称:Carnets,代码行数:27,代码来源:classic.py

示例7: ladder_graph

# 需要导入模块: from networkx import exception [as 别名]
# 或者: from networkx.exception import NetworkXError [as 别名]
def ladder_graph(n, create_using=None):
    """Returns the Ladder graph of length n.

    This is two paths of n nodes, with
    each pair connected by a single edge.

    Node labels are the integers 0 to 2*n - 1.

    """
    G = empty_graph(2 * n, create_using)
    if G.is_directed():
        raise NetworkXError("Directed Graph not supported")
    G.add_edges_from(pairwise(range(n)))
    G.add_edges_from(pairwise(range(n, 2 * n)))
    G.add_edges_from((v, v + n) for v in range(n))
    return G 
开发者ID:holzschu,项目名称:Carnets,代码行数:18,代码来源:classic.py

示例8: __init__

# 需要导入模块: from networkx import exception [as 别名]
# 或者: from networkx.exception import NetworkXError [as 别名]
def __init__(self, graph):
        if not graph.is_multigraph():
            msg = 'Wrong View class. Use DiGraphView.'
            raise NetworkXError(msg)
        self._graph = graph
        self.root_graph = graph
        while hasattr(self.root_graph, '_graph'):
            self.root_graph = self.root_graph._graph
        self.graph = graph.graph
        self._node = graph._node
        if graph.is_directed():
            self._pred = graph._pred
            self._succ = graph._succ
        else:
            self._pred = graph._adj
            self._succ = graph._adj
        self._adj = self._succ 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:19,代码来源:graphviews.py

示例9: data_to_graph6

# 需要导入模块: from networkx import exception [as 别名]
# 或者: from networkx.exception import NetworkXError [as 别名]
def data_to_graph6(data):
    """Convert 6-bit integer sequence to graph6 character sequence."""
    if len(data) > 0 and (min(data) < 0 or max(data) > 63):
        raise NetworkXError("graph6 data units must be within 0..63")
    return ''.join([chr(d+63) for d in data]) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:7,代码来源:graph6.py

示例10: n_to_data

# 需要导入模块: from networkx import exception [as 别名]
# 或者: from networkx.exception import NetworkXError [as 别名]
def n_to_data(n):
    """Convert an integer to one-, four- or eight-unit graph6 sequence."""
    if n < 0:
        raise NetworkXError("Numbers in graph6 format must be non-negative.")
    if n <= 62:
        return [n]
    if n <= 258047:
        return [63, (n>>12) & 0x3f, (n>>6) & 0x3f, n & 0x3f]
    if n <= 68719476735:
        return [63, 63,
            (n>>30) & 0x3f, (n>>24) & 0x3f, (n>>18) & 0x3f,
            (n>>12) & 0x3f, (n>>6) & 0x3f, n & 0x3f]
    raise NetworkXError("Numbers above 68719476735 are not supported by graph6") 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:15,代码来源:graph6.py

示例11: write_sparse6

# 需要导入模块: from networkx import exception [as 别名]
# 或者: from networkx.exception import NetworkXError [as 别名]
def write_sparse6(G, path, nodes=None, header=True):
    """Write graph G to given path in sparse6 format.
    Parameters
    ----------
    G : Graph (undirected)

    path : file or string
       File or filename to write

    nodes: list or iterable
       Nodes are labeled 0...n-1 in the order provided.  If None the ordering
       given by G.nodes() is used.

    header: bool
       If True add '>>sparse6<<' string to head of data

    Raises
    ------
    NetworkXError
        If the graph is directed

    Examples
    --------
    >>> G = nx.Graph([(0, 1), (0, 1), (0, 1)])
    >>> nx.write_sparse6(G, 'test.s6')

    See Also
    --------
    read_sparse6, parse_sparse6, generate_sparse6

    Notes
    -----
    The format does not support edge or node labels.

    References
    ----------
    Sparse6 specification:
    http://cs.anu.edu.au/~bdm/data/formats.txt for details.
    """
    path.write(generate_sparse6(G, nodes=nodes, header=header))
    path.write('\n') 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:43,代码来源:sparse6.py

示例12: remove_edge

# 需要导入模块: from networkx import exception [as 别名]
# 或者: from networkx.exception import NetworkXError [as 别名]
def remove_edge(self, u, v):
        """Remove the edge between u and v.

        Parameters
        ----------
        u, v : nodes
            Remove the edge between nodes u and v.

        Raises
        ------
        NetworkXError
            If there is not an edge between u and v.

        See Also
        --------
        remove_edges_from : remove a collection of edges

        Examples
        --------
        >>> G = nx.Graph()   # or DiGraph, etc
        >>> G.add_path([0,1,2,3])
        >>> G.remove_edge(0,1)
        >>> e = (1,2)
        >>> G.remove_edge(*e) # unpacks e from an edge tuple
        >>> e = (2,3,{'weight':7}) # an edge with attribute data
        >>> G.remove_edge(*e[:2]) # select first part of edge tuple
        """
        try:
            del self.succ[u][v]
            del self.pred[v][u]
        except KeyError:
            raise NetworkXError("The edge %s-%s not in graph."%(u,v)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:34,代码来源:digraph.py

示例13: successors_iter

# 需要导入模块: from networkx import exception [as 别名]
# 或者: from networkx.exception import NetworkXError [as 别名]
def successors_iter(self,n):
        """Return an iterator over successor nodes of n.

        neighbors_iter() and successors_iter() are the same.
        """
        try:
            return iter(self.succ[n])
        except KeyError:
            raise NetworkXError("The node %s is not in the digraph."%(n,)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:11,代码来源:digraph.py

示例14: predecessors_iter

# 需要导入模块: from networkx import exception [as 别名]
# 或者: from networkx.exception import NetworkXError [as 别名]
def predecessors_iter(self,n):
        """Return an iterator over predecessor nodes of n."""
        try:
            return iter(self.pred[n])
        except KeyError:
            raise NetworkXError("The node %s is not in the digraph."%(n,)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:8,代码来源:digraph.py

示例15: remove_edge

# 需要导入模块: from networkx import exception [as 别名]
# 或者: from networkx.exception import NetworkXError [as 别名]
def remove_edge(self, u, v):
        """Remove the edge between u and v.

        Parameters
        ----------
        u, v : nodes
            Remove the edge between nodes u and v.

        Raises
        ------
        NetworkXError
            If there is not an edge between u and v.

        See Also
        --------
        remove_edges_from : remove a collection of edges

        Examples
        --------
        >>> G = nx.Graph()   # or DiGraph, etc
        >>> G.add_path([0,1,2,3])
        >>> G.remove_edge(0,1)
        >>> e = (1,2)
        >>> G.remove_edge(*e) # unpacks e from an edge tuple
        >>> e = (2,3,{'weight':7}) # an edge with attribute data
        >>> G.remove_edge(*e[:2]) # select first part of edge tuple
        """
        try:
            del self.adj[u][v]
            if u != v:  # self-loop needs only one entry removed
                del self.adj[v][u]
        except KeyError:
            raise NetworkXError("The edge %s-%s is not in the graph" % (u, v)) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:35,代码来源:graph.py


注:本文中的networkx.exception.NetworkXError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。