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


Python networkx.MultiGraph方法代码示例

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


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

示例1: gdf_to_nx

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import MultiGraph [as 别名]
def gdf_to_nx(gdf_network, approach="primal", length="mm_len"):
    """
    Convert LineString GeoDataFrame to networkx.MultiGraph

    Parameters
    ----------
    gdf_network : GeoDataFrame
        GeoDataFrame containing objects to convert
    approach : str, default 'primal'
        Decide wheter genereate ``'primal'`` or ``'dual'`` graph.
    length : str, default mm_len
        name of attribute of segment length (geographical) which will be saved to graph

    Returns
    -------
    networkx.Graph
        Graph

    """
    gdf_network = gdf_network.copy()
    if "key" in gdf_network.columns:
        gdf_network.rename(columns={"key": "__key"}, inplace=True)
    # generate graph from GeoDataFrame of LineStrings
    net = nx.MultiGraph()
    net.graph["crs"] = gdf_network.crs
    gdf_network[length] = gdf_network.geometry.length
    fields = list(gdf_network.columns)

    if approach == "primal":
        _generate_primal(net, gdf_network, fields)

    elif approach == "dual":
        _generate_dual(net, gdf_network, fields)

    else:
        raise ValueError(
            "Approach {} is not supported. Use 'primal' or 'dual'.".format(approach)
        )

    return net 
开发者ID:martinfleis,项目名称:momepy,代码行数:42,代码来源:utils.py

示例2: format_graph_for_json

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import MultiGraph [as 别名]
def format_graph_for_json(graph, raise_errors=True):
    """
    Currently, only supported types for graph are Graph, DiGraph, MultiGraph, and MultiDiGraph. graph must
    be an instance of one of these types, not a class that inherits from one.
    """
    graph_dict = nx.to_dict_of_dicts(graph)
    graph_type = ''

    for key, value in accepted_types.items():
        if type(graph) == key:
            graph_type = value
            break

    if graph_type == '':
        if raise_errors:
            raise TypeError('parameter graph is not of the accepted types.graph is of'
                            'type {}'.format(str(type(graph))))
        else:
            graph_type = 'other'

    return {'graph_type': graph_type, 'graph_dict': graph_dict} 
开发者ID:wardbradt,项目名称:peregrine,代码行数:23,代码来源:drawing.py

示例3: merge

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import MultiGraph [as 别名]
def merge(self, ontologies):
        """
        Merges specified ontology into current ontology
        """
        if self.xref_graph is None:
            self.xref_graph = nx.MultiGraph()
        logger.info("Merging source: {} xrefs: {}".format(self, len(self.xref_graph.edges())))
        for ont in ontologies:
            logger.info("Merging {} into {}".format(ont, self))
            g = self.get_graph()
            srcg = ont.get_graph()
            for n in srcg.nodes():
                g.add_node(n, **srcg.node[n])
            for (o,s,m) in srcg.edges(data=True):
                g.add_edge(o,s,**m)
            if ont.xref_graph is not None:
                for (o,s,m) in ont.xref_graph.edges(data=True):
                    self.xref_graph.add_edge(o,s,**m) 
开发者ID:biolink,项目名称:ontobio,代码行数:20,代码来源:ontol.py

示例4: generate_predicted_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import MultiGraph [as 别名]
def generate_predicted_graph(self, dpids, switch_links, host_links, host_information):
        """Creates the predicted network graph"""
        self.predicted_network_graph = networkx.MultiGraph()
        for dpid in dpids:
            self.predicted_network_graph.add_node(dpid)
        for link in switch_links:
            u, v = link
            self.predicted_network_graph.add_edge(self.dpids[u], self.dpids[v])
        self.host_name_to_index = {}
        for host_id, host_info in host_information.items():
            host_name = host_info['host'].name
            self.host_name_to_index[host_name] = host_id
            self.predicted_network_graph.add_node(host_name)
            links = host_links[host_id]
            for link in links:
                self.predicted_network_graph.add_edge(host_name, self.dpids[link]) 
开发者ID:faucetsdn,项目名称:faucet,代码行数:18,代码来源:mininet_test_watcher.py

示例5: read_dot

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import MultiGraph [as 别名]
def read_dot(path):
    """Return a NetworkX MultiGraph or MultiDiGraph from a dot file on path.

    Parameters
    ----------
    path : filename or file handle

    Returns
    -------
    G : NetworkX multigraph
        A MultiGraph or MultiDiGraph.

    Notes
    -----
    Use G = nx.Graph(read_dot(path)) to return a Graph instead of a MultiGraph.
    """
    import pydotplus
    data = path.read()
    P = pydotplus.graph_from_dot_data(data)
    return from_pydot(P) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:22,代码来源:nx_pydot.py

示例6: test_set_edge_attributes_multi

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import MultiGraph [as 别名]
def test_set_edge_attributes_multi():
    graphs = [nx.MultiGraph(), nx.MultiDiGraph()]
    for G in graphs:
        G = nx.path_graph(3, create_using=G)

        # Test single value
        attr = 'hello'
        vals = 3
        nx.set_edge_attributes(G, attr, vals)
        assert_equal(G[0][1][0][attr], vals)
        assert_equal(G[1][2][0][attr], vals)

        # Test multiple values
        attr = 'hi'
        edges = [(0,1,0), (1,2,0)]
        vals = dict(zip(edges, range(len(edges))))
        nx.set_edge_attributes(G, attr, vals)
        assert_equal(G[0][1][0][attr], 0)
        assert_equal(G[1][2][0][attr], 1) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:21,代码来源:test_function.py

示例7: test_get_edge_attributes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import MultiGraph [as 别名]
def test_get_edge_attributes():
    graphs = [nx.Graph(), nx.DiGraph(), nx.MultiGraph(), nx.MultiDiGraph()]
    for G in graphs:
        G = nx.path_graph(3, create_using=G)
        attr = 'hello'
        vals = 100
        nx.set_edge_attributes(G, attr, vals)
        attrs = nx.get_edge_attributes(G, attr)

        assert_equal(len(attrs), 2)
        if G.is_multigraph():
            keys = [(0,1,0), (1,2,0)]
        else:
            keys = [(0,1), (1,2)]
        for key in keys:
            assert_equal(attrs[key], 100) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:18,代码来源:test_function.py

示例8: __len__

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import MultiGraph [as 别名]
def __len__(self):
        """Return the number of nodes. Use the expression 'len(G)'.

        Returns
        -------
        nnodes : int
            The number of nodes in the graph.

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

        """
        return len(self.node) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:19,代码来源:timingclasses.py

示例9: number_of_nodes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import MultiGraph [as 别名]
def number_of_nodes(self):
        """Return the number of nodes in the graph.

        Returns
        -------
        nnodes : int
            The number of nodes in the graph.

        See Also
        --------
        order, __len__  which are identical

        Examples
        --------
        >>> G = nx.Graph()   # or DiGraph, MultiGraph, MultiDiGraph, etc
        >>> G.add_path([0,1,2])
        >>> len(G)
        3
        """
        return len(self.node) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:22,代码来源:timingclasses.py

示例10: has_node

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import MultiGraph [as 别名]
def has_node(self, n):
        """Return True if the graph contains the node n.

        Parameters
        ----------
        n : node

        Examples
        --------
        >>> G = nx.Graph()   # or DiGraph, MultiGraph, MultiDiGraph, etc
        >>> G.add_path([0,1,2])
        >>> G.has_node(0)
        True

        It is more readable and simpler to use

        >>> 0 in G
        True

        """
        try:
            return n in self.node
        except TypeError:
            return False 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:26,代码来源:timingclasses.py

示例11: neighbors_iter

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import MultiGraph [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

示例12: adjacency_list

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import MultiGraph [as 别名]
def adjacency_list(self):
        """Return an adjacency list representation of the graph.

        The output adjacency list is in the order of G.nodes().
        For directed graphs, only outgoing adjacencies are included.

        Returns
        -------
        adj_list : lists of lists
            The adjacency structure of the graph as a list of lists.

        See Also
        --------
        adjacency_iter

        Examples
        --------
        >>> G = nx.Graph()   # or DiGraph, MultiGraph, MultiDiGraph, etc
        >>> G.add_path([0,1,2,3])
        >>> G.adjacency_list() # in order given by G.nodes()
        [[1], [0, 2], [1, 3], [2]]

        """
        return list(map(list,iter(self.adj.values()))) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:26,代码来源:timingclasses.py

示例13: setUp

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import MultiGraph [as 别名]
def setUp(self):
        super(TestGraphCanvasMultiGraph, self).setUp()

        # Add in some extra edges
        G = nx.MultiGraph(self.input_G)
        G.add_edge('a','c')

        G.add_edge('out',12)
        G.add_edge('out',12)
        G.add_edge('out',12)
        self.input_G = G.copy()

        # Viewer under test
        self.a = nxv.GraphCanvas(G) 
开发者ID:jsexauer,项目名称:networkx_viewer,代码行数:16,代码来源:tests.py

示例14: __init__

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import MultiGraph [as 别名]
def __init__(self, pairs):
        ##self.graph = nx.MultiGraph()
        self.graph = nx.Graph()
        self.graph.add_edges_from(pairs)
        self.lattice_points = self.graph.nodes()
        self.pairs = self.graph.edges()
        
        self.interaction = -1
        self.field = 0
        self.energy = None 
开发者ID:wolverton-research-group,项目名称:qmpy,代码行数:12,代码来源:network.py

示例15: create_multi_exchange_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import MultiGraph [as 别名]
def create_multi_exchange_graph(exchanges: list, digraph=False):
    """
    Returns a MultiGraph representing the markets for each exchange in exchanges. Each edge represents a market.
    Note: does not add edge weights using the ticker's ask and bid prices.
    exchange.load_markets() must have been called for each exchange in exchanges. Will throw a ccxt error if it has not.

    todo: check which error.
    """
    if digraph:
        graph = nx.MultiDiGraph()
    else:
        graph = nx.MultiGraph()

    for exchange in exchanges:
        for market_name in exchange.symbols:
            try:
                base_currency, quote_currency = market_name.split('/')
            # if ccxt returns a market in incorrect format (e.g FX_BTC_JPY on BitFlyer)
            except ValueError:
                continue

            graph.add_edge(base_currency,
                           quote_currency,
                           market_name=market_name,
                           exchange_name=exchange.name.lower())
            if digraph:
                graph.add_edge(quote_currency,
                               base_currency,
                               market_name=market_name,
                               exchange_name=exchange.name.lower())

    return graph 
开发者ID:wardbradt,项目名称:peregrine,代码行数:34,代码来源:multi_exchange.py


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