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


Python DiGraph.add_edges_from方法代码示例

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


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

示例1: test_get_rc_chain

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_edges_from [as 别名]
def test_get_rc_chain():
    mock_g = DiGraph()
    mock_g.add_edges_from([('A', 'B', {'RC': 'I'}), ('B', 'C', {'RC': 'S'}),
                           ('C', 'D', {'RC': 'L'}), ('D', 'E', {'RC': 'O'})])
    tp = ['B', 'C', 'D']
    nt.assert_equal(MapGraph._get_rc_chain.im_func(mock_g, 'A', tp, 'E'),
                    'ISLO')
开发者ID:MSenden,项目名称:CoCoTools,代码行数:9,代码来源:test_mapgraph.py

示例2: common_edge_ratio

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_edges_from [as 别名]
def common_edge_ratio(ref_user_connections, eval_user_connections, is_directed=False):
    """ caulcalate the fraction of common edges fraction out of union of two graphs

    Parameters:
    ==========
    ref_user_connections: a list of edges
    eval_user_connections: a list of edges
    is_directed: boolean,
        False (default): edges forms an undirected graph
        True: edges forms a directed graph
    """
    ref_user_connections = _normalize_connections(ref_user_connections, is_directed)
    eval_user_connections = _normalize_connections(eval_user_connections, is_directed)

    if is_directed:
        ref_graph, eval_graph = DiGraph(), DiGraph()
    else:
        ref_graph, eval_graph = Graph(), Graph()

    ref_graph.add_edges_from(ref_user_connections)
    eval_graph.add_edges_from(eval_user_connections)

    ref_edges, eval_edges = ref_graph.edges(), eval_graph.edges()

    tot_common = sum([1 if edge in ref_edges else 0 for edge in eval_edges])
    union_size = len(ref_edges) + len(eval_edges) - tot_common
    return tot_common / union_size
开发者ID:beingzy,项目名称:user_recommender_framework,代码行数:29,代码来源:SocialNetworkEvaluator.py

示例3: test

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_edges_from [as 别名]
    def test():
        bayesian_network = DiGraph()
        edges = [('A', 'C'), ('B', 'C'), ('C', 'D'), ('C', 'E'), ('D', 'F'), ('D', 'G')]
        bayesian_network.add_edges_from(edges)
        for node in bayesian_network.nodes():
            node_object = bayesian_network.node[node]
            #  All the variables are binary
            node_object['values'] = ['0', '1']

        conditional_probabilities = {
                                                'A1': 0.7,
                                                'A0':0.3,
                                                'B1': 0.4,
                                                'B0':0.6,
                                                'C1|A0,B0': 0.1, 'C1|A1,B0': 0.3,
                                                'C1|A0,B1': 0.5, 'C1|A1,B1': 0.9,
                                                'C0|A0,B0': 0.9, 'C0|A1,B0': 0.7,
                                                'C0|A0,B1': 0.5, 'C0|A1,B1': 0.1,
                                                'D1|C0': 0.8, 'D1|C1': 0.3,
                                                'D0|C0': 0.2, 'D0|C1': 0.7,
                                                'E1|C0': 0.2, 'E1|C1': 0.6,
                                                'E0|C0': 0.8, 'E0|C1': 0.4,
                                                'F1|D0': 0.1, 'F1|D1': 0.7,
                                                'F0|D0': 0.9, 'F0|D1': 0.3,
                                                'G1|D0': 0.9, 'G1|D1': 0.4,
                                                'G0|D0': 0.1, 'G0|D1': 0.6
                                     }
        inference = PearlsInference(bayesian_network, conditional_probabilities)
        print '-------------------------------'
        inference.add_evidence(['C', '1'])
        print '----------------------------------'
        inference.add_evidence(['A', '1'])
        pprint(conditional_probabilities)
开发者ID:hbarthwal,项目名称:course_projects,代码行数:35,代码来源:pearls_inference.py

示例4: test_remove_node

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_edges_from [as 别名]
def test_remove_node():
    mock_mapp = DiGraph()
    mock_mapp.add_node('X')
    mock_mapp.add_edges_from([('A', 'B', {'TP': ['X']}),
                              ('B', 'C', {'TP': ['Y']})])
    MapGraph.remove_node.im_func(mock_mapp, 'X')
    nt.assert_equal(mock_mapp.edges(), [('B', 'C')])
开发者ID:MSenden,项目名称:CoCoTools,代码行数:9,代码来源:test_mapgraph.py

示例5: test_missing_edges

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_edges_from [as 别名]
    def test_missing_edges(self):
        """A tournament must not have any pair of nodes without at least
        one edge joining the pair.

        """
        G = DiGraph()
        G.add_edges_from([(0, 1), (1, 2), (2, 3), (3, 0), (1, 3)])
        assert_false(is_tournament(G))
开发者ID:4c656554,项目名称:networkx,代码行数:10,代码来源:test_tournament.py

示例6: test_get_best_is

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_edges_from [as 别名]
def test_get_best_is():
    mock_mapp = DiGraph()
    mock_mapp.add_edges_from([('A-1', 'B-1', {'RC': 'I', 'PDC': 5}),
                              ('A-1', 'B-2', {'RC': 'I', 'PDC': 7}),
                              ('A-1', 'B-3', {'RC': 'S', 'PDC': 5})])
    result = MapGraph._get_best_is.im_func(mock_mapp, 'A-1',
                                           ['B-1', 'B-2', 'B-3'])
    nt.assert_equal(result, ('B-1', 5))
开发者ID:MSenden,项目名称:CoCoTools,代码行数:10,代码来源:test_mapgraph.py

示例7: test_get_worst_pdc

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_edges_from [as 别名]
def test_get_worst_pdc():
    mock_mapp = DiGraph()
    mock_mapp.add_edges_from([('A-1', 'B-1', {'RC': 'L', 'PDC': 5}),
                              ('A-1', 'B-2', {'RC': 'O', 'PDC': 7}),
                              ('A-1', 'B-3', {'RC': 'L', 'PDC': 15})])
    result = MapGraph._get_worst_pdc.im_func(mock_mapp, 'A-1',
                                             ['B-1', 'B-2', 'B-3'])
    nt.assert_equal(result, 15)
开发者ID:MSenden,项目名称:CoCoTools,代码行数:10,代码来源:test_mapgraph.py

示例8: test_get_worst_pdc_in_tp

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_edges_from [as 别名]
def test_get_worst_pdc_in_tp():
    mock_g = DiGraph()
    mock_g.add_edges_from([('A', 'B', {'PDC': 0}), ('B', 'C', {'PDC': 5}),
                           ('C', 'D', {'PDC': 7}), ('D', 'E', {'PDC': 17})])
    tp = ['B', 'C', 'D']
    nt.assert_equal(MapGraph._get_worst_pdc_in_tp.im_func(mock_g, 'A', tp,
                                                             'E'),
                    17)
开发者ID:MSenden,项目名称:CoCoTools,代码行数:10,代码来源:test_mapgraph.py

示例9: add_edges_from

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_edges_from [as 别名]
 def add_edges_from(self,  ebunch):
     temp = self.copy()
     DiGraph.add_edges_from(temp, ebunch)
     if not temp._is_directed_acyclic_graph():
         raise ValueError("Edges %s create a cycle" %(ebunch, ) )
     elif not temp._is_connected():
         raise ValueError("Edges %s create disconnected graph" %(ebunch, ) )
     else:
         DiGraph.add_edges_from(self,  ebunch)
开发者ID:mrkwjc,项目名称:ffnet,代码行数:11,代码来源:graphs.py

示例10: __init__

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_edges_from [as 别名]
 def __init__(self, conec=[],  **kwargs):
     """
     Calls DiGraph constructor and checks if the graph is connected and acyclic
     """
     DiGraph.__init__(self, **kwargs)
     DiGraph.add_edges_from(self, conec)
     #self.add_edges_from(conec)  #copy maximum recursion here
     if not self._is_connected(): raise ValueError("Not connected graph")
     if not self._is_directed_acyclic_graph(): raise ValueError("Not acyclic graph")
开发者ID:mrkwjc,项目名称:ffnet,代码行数:11,代码来源:graphs.py

示例11: test_bidirectional_edges

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_edges_from [as 别名]
    def test_bidirectional_edges(self):
        """A tournament must not have any pair of nodes with greater
        than one edge joining the pair.

        """
        G = DiGraph()
        G.add_edges_from([(0, 1), (1, 2), (2, 3), (3, 0), (1, 3), (0, 2)])
        G.add_edge(1, 0)
        assert_false(is_tournament(G))
开发者ID:4c656554,项目名称:networkx,代码行数:11,代码来源:test_tournament.py

示例12: test_organize_by_rc

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_edges_from [as 别名]
def test_organize_by_rc():
    mock_mapp = DiGraph()
    mock_mapp.add_edges_from([('A-1', 'B-1', {'RC': 'I'}),
                              ('A-1', 'B-2', {'RC': 'L'}),
                              ('A-1', 'C-3', {'RC': 'O'})])
    result = MapGraph._organize_by_rc.im_func(mock_mapp, 'A-1', ['B-1', 'B-2'])
    nt.assert_equal(result, {'IS': ['B-1'], 'LO': ['B-2']})
    result = MapGraph._organize_by_rc.im_func(mock_mapp, 'A-1', ['C-3'])
    nt.assert_equal(result, {'IS': [], 'LO': ['C-3']})
开发者ID:MSenden,项目名称:CoCoTools,代码行数:11,代码来源:test_mapgraph.py

示例13: example_tree

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_edges_from [as 别名]
def example_tree():
    """creates a tree/networkx.DiGraph of a syntactic parse tree"""
    tree = DiGraph()
    tree.add_nodes_from(['S', 'NP-1', 'N-1', 'Jeff', 'VP', 'V', 'ate', 'NP-2', 'D',
                         'the', 'N-2', 'apple'])
    tree.add_edges_from([('S', 'NP-1'), ('NP-1', 'N-1'), ('N-1', 'Jeff'),
                         ('S', 'VP'), ('VP', 'V'), ('V', 'ate'),
                         ('VP', 'NP-2'), ('NP-2', 'D'), ('D', 'the'),
                         ('NP-2', 'N-2'), ('N-2', 'apple')])
    return tree
开发者ID:arne-cl,项目名称:discoursekernels,代码行数:12,代码来源:test_tree.py

示例14: _convert_bfs

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_edges_from [as 别名]
def _convert_bfs(bfs):
    from networkx import DiGraph
    g = DiGraph()
    g.add_edges_from(bfs[NONE])
    bfs[NONE] = g

    for k, v in bfs.items():
        if k is not NONE:
            _convert_bfs(v)

    return bfs
开发者ID:vinci1it2000,项目名称:dispatcher,代码行数:13,代码来源:alg.py

示例15: test_relate_node_to_others

# 需要导入模块: from networkx import DiGraph [as 别名]
# 或者: from networkx.DiGraph import add_edges_from [as 别名]
def test_relate_node_to_others():
    mock_mapp = DiGraph()
    relate = MapGraph._relate_node_to_others.im_func
    nt.assert_equal(relate(mock_mapp, 'A-1', ['A-2', 'A-3', 'A-4']),
                    ([], 'D'))
    mock_mapp.add_edge('A-1', 'A-3', RC='I')
    nt.assert_equal(relate(mock_mapp, 'A-1', ['A-2', 'A-3', 'A-4']),
                    ('A-3', 'I'))
    mock_mapp.add_edges_from([('A-1', 'A-3', {'RC': 'L'}),
                              ('A-1', 'A-4', {'RC': 'L'})])
    nt.assert_equal(relate(mock_mapp, 'A-1', ['A-2', 'A-3', 'A-4']),
                    (['A-3', 'A-4'], 'L'))
开发者ID:MSenden,项目名称:CoCoTools,代码行数:14,代码来源:test_mapgraph.py


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