• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python networkx.all_pairs_node_connectivity函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_cycles

 def test_cycles(self):
     K_undir = nx.all_pairs_node_connectivity(self.cycle)
     for source in K_undir:
         for target, k in K_undir[source].items():
             assert_true(k == 2)
     K_dir = nx.all_pairs_node_connectivity(self.directed_cycle)
     for source in K_dir:
         for target, k in K_dir[source].items():
             assert_true(k == 1)
开发者ID:AmesianX,项目名称:networkx,代码行数:9,代码来源:test_connectivity.py


示例2: test_paths

 def test_paths(self):
     K_undir = nx.all_pairs_node_connectivity(self.path)
     for source in K_undir:
         for target, k in K_undir[source].items():
             assert_true(k == 1)
     K_dir = nx.all_pairs_node_connectivity(self.directed_path)
     for source in K_dir:
         for target, k in K_dir[source].items():
             if source < target:
                 assert_true(k == 1)
             else:
                 assert_true(k == 0)
开发者ID:AmesianX,项目名称:networkx,代码行数:12,代码来源:test_connectivity.py


示例3: set_connectivity

        def set_connectivity(data):    
            df = data.copy()
            df['DateOfDeparture'] = pd.to_datetime(df['DateOfDeparture'])
            df['month'] = df['DateOfDeparture'].dt.week.astype(str)
            df['year'] = df['DateOfDeparture'].dt.year.astype(str)
            df['arr_dep'] = df[['Departure','Arrival']].apply(lambda x: '-'.join(x),axis=1)

            G = nx.Graph()
            connectivity = {}

            list_dep_arr = zip(df['Departure'], df['Arrival'])
            G.add_edges_from(list_dep_arr)
            #G.number_of_nodes()
            #G.number_of_edges()
            connectivity = nx.all_pairs_node_connectivity(G)
            for j, jtem in enumerate(connectivity):
                if j==0:
                    a=[jtem]*len(connectivity[jtem])
                    d = pd.DataFrame(connectivity[jtem].items())
                    d = pd.concat([pd.DataFrame(a),d], axis=1)
                    c = d.copy()
                a=[jtem]*len(connectivity[jtem])
                d = pd.DataFrame(connectivity[jtem].items())
                d = pd.concat([pd.DataFrame(a),d], axis=1)
                c = c.append(d)
            c['arr_dep'] = c[c.columns[[0]]].apply(lambda x: '-'.join(x),axis=1)
            connectivity_dep_arr = dict(zip(c['arr_dep'],c[1]))

            df['connectivity'] = df['arr_dep'].map(connectivity_dep_arr)
            return df
开发者ID:GuillaumeCarbajal,项目名称:Air-passengers,代码行数:30,代码来源:feature_extractor.py


示例4: min_connectivity

 def min_connectivity(self, graph):
     apnc = nx.all_pairs_node_connectivity(graph)
     # start with graph diameter; minimum won't be larger than this
     mc = nx.diameter(graph)
     for targets in apnc.itervalues():
         mc = min(min(targets.itervalues()), mc)
     return mc
开发者ID:geistwriter,项目名称:sawtooth-core,代码行数:7,代码来源:stats_utils.py


示例5: test_all_pairs_connectivity_nbunch_iter

 def test_all_pairs_connectivity_nbunch_iter(self):
     G = nx.complete_graph(5)
     nbunch = [0, 2, 3]
     A = dict.fromkeys(nbunch, dict())
     for u, v in itertools.combinations(nbunch, 2):
         A[u][v] = nx.node_connectivity(G, u, v)
     C = nx.all_pairs_node_connectivity(G, nbunch=iter(nbunch))
     assert_equal(sorted((k, sorted(v)) for k, v in A.items()),
                  sorted((k, sorted(v)) for k, v in C.items()))
开发者ID:qinyushuang,项目名称:networkx,代码行数:9,代码来源:test_connectivity.py


示例6: test_all_pairs_connectivity_nbunch

 def test_all_pairs_connectivity_nbunch(self):
     G = nx.complete_graph(5)
     nbunch = [0, 2, 3]
     A = {n: {} for n in nbunch}
     for u, v in itertools.combinations(nbunch, 2):
         A[u][v] = A[v][u] = nx.node_connectivity(G, u, v)
     C = nx.all_pairs_node_connectivity(G, nbunch=nbunch)
     assert_equal(sorted((k, sorted(v)) for k, v in A.items()),
                  sorted((k, sorted(v)) for k, v in C.items()))
开发者ID:AmesianX,项目名称:networkx,代码行数:9,代码来源:test_connectivity.py


示例7: test_all_pairs_connectivity_directed

 def test_all_pairs_connectivity_directed(self):
     G = nx.DiGraph()
     nodes = [0, 1, 2, 3]
     G.add_path(nodes)
     A = dict.fromkeys(G, dict())
     for u, v in itertools.permutations(nodes, 2):
         A[u][v] = nx.node_connectivity(G, u, v)
     C = nx.all_pairs_node_connectivity(G)
     assert_equal(sorted((k, sorted(v)) for k, v in A.items()),
                  sorted((k, sorted(v)) for k, v in C.items()))
开发者ID:qinyushuang,项目名称:networkx,代码行数:10,代码来源:test_connectivity.py


示例8: test_all_pairs_connectivity

 def test_all_pairs_connectivity(self):
     G = nx.Graph()
     nodes = [0, 1, 2, 3]
     nx.add_path(G, nodes)
     A = {n: {} for n in G}
     for u, v in itertools.combinations(nodes,2):
         A[u][v] = A[v][u] = nx.node_connectivity(G, u, v)
     C = nx.all_pairs_node_connectivity(G)
     assert_equal(sorted((k, sorted(v)) for k, v in A.items()),
                  sorted((k, sorted(v)) for k, v in C.items()))
开发者ID:AmesianX,项目名称:networkx,代码行数:10,代码来源:test_connectivity.py


示例9: cal_para_order

def cal_para_order(para_list):
    """
    To record the parameter variable's all fixed order.
    :param para_list: the url's kinds of url's.
    :return: list -> all fixed parameter order.
    """
    result_order = list()

    order_collection = set()
    for order_seg in para_list:
        length = len(order_seg)
        for i in range(length - 1):
            order_collection.add((order_seg[i], order_seg[i + 1]))
    print 'G2:', sorted(list(order_collection))
    g = nx.DiGraph()
    g.add_edges_from(order_collection)
    connectivity_dict = dict([])
    for source_node, connect_dict in nx.all_pairs_node_connectivity(g).items():
        connectivity_dict[source_node] = []
        for target_node, hop in connect_dict.items():
            if hop > 0:
                connectivity_dict[source_node].append(target_node)
    print 'Connectivity_Original:', nx.all_pairs_node_connectivity(g)
    print 'Connectivity_dict:', connectivity_dict
    node_list = g.nodes()
    node_length = len(node_list)
    for i in range(node_length):
        for j in range(i + 1, node_length):
            node_1 = node_list[i]
            node_2 = node_list[j]
            connect_1_2 = node_2 in connectivity_dict[node_1]
            connect_2_1 = node_1 in connectivity_dict[node_2]
            if connect_1_2 and not connect_2_1:
                result_order.append((node_1, node_2))
            elif connect_2_1 and not connect_1_2:
                result_order.append((node_2, node_1))
            else:
                continue

    return result_order
开发者ID:Lancert9,项目名称:WUA,代码行数:40,代码来源:paraOrder.py


示例10: __cal_variable_order_rule

    def __cal_variable_order_rule(variable_order_set):
        """
        To record the parameter variable's all fixed order.

        :param variable_order_set: set((v1, v2, v3), (v3, v4), ...)
        :return: set((v1, v2), (v1, v3), ...)
        """
        result_order = set()

        order_collection = set()
        for order_seg in variable_order_set:
            for i in range(len(order_seg) - 1):
                order_collection.add((order_seg[i], order_seg[i + 1]))

        g = nx.DiGraph()
        g.add_edges_from(order_collection)
        connectivity_dict = dict([])
        for source_node, connect_dict in nx.all_pairs_node_connectivity(g).items():
            connectivity_dict[source_node] = set()
            for target_node, hop in connect_dict.items():
                if hop > 0:
                    connectivity_dict[source_node].add(target_node)

        node_list = g.nodes()
        node_count = len(node_list)
        for i in range(node_count):
            for j in range(i + 1, node_count):
                node_1 = node_list[i]
                node_2 = node_list[j]
                # if node_1 connect to node_2
                connect_1_2 = node_2 in connectivity_dict[node_1]
                # if node_2 connect to node_1
                connect_2_1 = node_1 in connectivity_dict[node_2]
                if connect_1_2 and not connect_2_1:
                    result_order.add((node_1, node_2))
                elif connect_2_1 and not connect_1_2:
                    result_order.add((node_2, node_1))
                else:
                    continue

        return result_order
开发者ID:Lancert9,项目名称:WUA,代码行数:41,代码来源:HostFeature.py


示例11: test_all_pairs_connectivity_icosahedral

 def test_all_pairs_connectivity_icosahedral(self):
     G = nx.icosahedral_graph()
     C = nx.all_pairs_node_connectivity(G)
     assert_true(all(5 == C[u][v] for u, v in itertools.combinations(G, 2)))
开发者ID:qinyushuang,项目名称:networkx,代码行数:4,代码来源:test_connectivity.py


示例12: test_complete

 def test_complete(self):
     for G in [self.K10, self.K5, self.K20]:
         K = nx.all_pairs_node_connectivity(G)
         for source in K:
             for target, k in K[source].items():
                 assert_true(k == len(G)-1)
开发者ID:AmesianX,项目名称:networkx,代码行数:6,代码来源:test_connectivity.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap