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


Python networkx.random_geometric_graph方法代码示例

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


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

示例1: test_QueueNetwork_get_queue_data

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import random_geometric_graph [as 别名]
def test_QueueNetwork_get_queue_data(self):

        g = nx.random_geometric_graph(50, 0.5).to_directed()
        q_cls = {1: qt.QueueServer}

        qn = qt.QueueNetwork(g, q_classes=q_cls, seed=17)
        k = np.random.randint(10000, 20000)

        qn.max_agents = 4000
        qn.initialize(queues=range(qn.nE))
        qn.start_collecting_data()
        qn.simulate(n=k)

        data = qn.get_queue_data()
        self.assertEqual(data.shape, (k, 6))
        qn.stop_collecting_data()
        qn.clear_data()

        ans = np.array([q.data == {} for q in qn.edge2queue])
        self.assertTrue(ans.all()) 
开发者ID:djordon,项目名称:queueing-tool,代码行数:22,代码来源:test_network.py

示例2: test_distances

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import random_geometric_graph [as 别名]
def test_distances(self):
        """Tests that pairs of vertices adjacent if and only if they are
        within the prescribed radius.

        """
        # Use the Euclidean metric, the default according to the
        # documentation.
        dist = euclidean
        G = nx.random_geometric_graph(50, 0.25)
        for u, v in combinations(G, 2):
            # Adjacent vertices must be within the given distance.
            if v in G[u]:
                assert_true(dist(G.nodes[u]['pos'], G.nodes[v]['pos']) <= 0.25)
            # Nonadjacent vertices must be at greater distance.
            else:
                assert_false(dist(G.nodes[u]['pos'], G.nodes[v]['pos']) <= 0.25) 
开发者ID:holzschu,项目名称:Carnets,代码行数:18,代码来源:test_geometric.py

示例3: test_node_names

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import random_geometric_graph [as 别名]
def test_node_names(self):
        """Tests using values other than sequential numbers as node IDs.

        """
        import string
        nodes = list(string.ascii_lowercase)
        G = nx.random_geometric_graph(nodes, 0.25)
        assert_equal(len(G), len(nodes))

        dist = euclidean
        for u, v in combinations(G, 2):
            # Adjacent vertices must be within the given distance.
            if v in G[u]:
                assert_true(dist(G.nodes[u]['pos'], G.nodes[v]['pos']) <= 0.25)
            # Nonadjacent vertices must be at greater distance.
            else:
                assert_false(dist(G.nodes[u]['pos'], G.nodes[v]['pos']) <= 0.25) 
开发者ID:holzschu,项目名称:Carnets,代码行数:19,代码来源:test_geometric.py

示例4: test_random_geometric_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import random_geometric_graph [as 别名]
def test_random_geometric_graph(self):
        G=nx.random_geometric_graph(50,0.25)
        assert_equal(len(G),50) 
开发者ID:SpaceGroupUCL,项目名称:qgisSpaceSyntaxToolkit,代码行数:5,代码来源:test_geometric.py

示例5: test_set_types_random

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import random_geometric_graph [as 别名]
def test_set_types_random(self):

        nV = 1200
        nT = np.random.randint(5, 10)
        g = nx.random_geometric_graph(nV, 0.1).to_directed()

        eType = np.random.choice(np.arange(5, 100), size=nT, replace=False)
        prob = np.random.uniform(size=nT)
        prob = prob / sum(prob)

        pType = {eType[k]: prob[k] for k in range(nT)}
        g = qt.set_types_random(g, proportions=pType)

        non_loops = [e for e in g.edges() if e[0] != e[1]]
        mat = [[g.ep(e, 'edge_type') == k for e in non_loops] for k in eType]
        props = (np.array(mat).sum(1) + 0.0) / len(non_loops)
        ps = np.array([pType[k] for k in eType])

        self.assertTrue(np.allclose(props, ps, atol=0.01))

        prob[-1] = 2
        pType = {eType[k]: prob[k] for k in range(nT)}
        with self.assertRaises(ValueError):
            g = qt.set_types_random(g, proportions=pType, seed=10)

        with self.assertRaises(ValueError):
            g = qt.set_types_random(g, loop_proportions=pType, seed=10) 
开发者ID:djordon,项目名称:queueing-tool,代码行数:29,代码来源:test_graph_generation.py

示例6: test_QueueNetwork_blocking

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import random_geometric_graph [as 别名]
def test_QueueNetwork_blocking(self):

        g = nx.random_geometric_graph(100, 0.2).to_directed()
        g = qt.set_types_random(g, proportions={k: 1.0 / 6 for k in range(1, 7)})
        q_cls = {
            1: qt.LossQueue,
            2: qt.QueueServer,
            3: qt.InfoQueue,
            4: qt.ResourceQueue,
            5: qt.ResourceQueue,
            6: qt.QueueServer
        }

        q_arg = {
            3: {'net_size': g.number_of_edges()},
            4: {'num_servers': 500},
            6: {'AgentFactory': qt.GreedyAgent}
        }

        qn = qt.QueueNetwork(g, q_classes=q_cls, q_args=q_arg, seed=17)
        qn.blocking = 'RS'
        self.assertEqual(qn.blocking, 'RS')
        self.assertEqual(qn._blocking, False)

        qn.clear()
        self.assertEqual(qn._initialized, False) 
开发者ID:djordon,项目名称:queueing-tool,代码行数:28,代码来源:test_network.py

示例7: test_QueueNetwork_copy

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import random_geometric_graph [as 别名]
def test_QueueNetwork_copy(self):

        g = nx.random_geometric_graph(100, 0.2).to_directed()
        g = qt.set_types_random(g, proportions={k: 0.2 for k in range(1, 6)})
        q_cls = {
            1: qt.LossQueue,
            2: qt.QueueServer,
            3: qt.InfoQueue,
            4: qt.ResourceQueue,
            5: qt.ResourceQueue
        }

        q_arg = {3: {'net_size': g.number_of_edges()},
                 4: {'num_servers': 500}}

        qn = qt.QueueNetwork(g, q_classes=q_cls, q_args=q_arg, seed=17)
        qn.max_agents = np.infty
        qn.initialize(queues=range(g.number_of_edges()))

        qn.simulate(n=50000)
        qn2 = qn.copy()

        stamp = [(q.num_arrivals, q.time) for q in qn2.edge2queue]
        qn2.simulate(n=25000)

        self.assertFalse(qn.current_time == qn2.current_time)
        self.assertFalse(qn.time == qn2.time)

        ans = []
        for k, q in enumerate(qn2.edge2queue):
            if stamp[k][1] != q.time:
                ans.append(q.time != qn.edge2queue[k].time)

        self.assertTrue(np.array(ans).all()) 
开发者ID:djordon,项目名称:queueing-tool,代码行数:36,代码来源:test_network.py

示例8: test_ResourceQueue_network

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import random_geometric_graph [as 别名]
def test_ResourceQueue_network(self):

        g = nx.random_geometric_graph(100, 0.2).to_directed()
        q_cls = {1: qt.ResourceQueue, 2: qt.ResourceQueue}
        q_arg = {1: {'num_servers': 50}, 2: {'num_servers': 500}}

        qn = qt.QueueNetwork(g, q_classes=q_cls, q_args=q_arg)
        qn.max_agents = 400000
        qn.initialize(queues=range(qn.g.number_of_edges()))
        qn.simulate(n=50000)

        nServ = {1: 50, 2: 500}
        ans = np.array([q.num_servers != nServ[q.edge[3]] for q in qn.edge2queue])
        self.assertTrue(ans.any()) 
开发者ID:djordon,项目名称:queueing-tool,代码行数:16,代码来源:test_queue_server.py

示例9: test_number_of_nodes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import random_geometric_graph [as 别名]
def test_number_of_nodes(self):
        G = nx.random_geometric_graph(50, 0.25, seed=42)
        assert_equal(len(G), 50)
        G = nx.random_geometric_graph(range(50), 0.25, seed=42)
        assert_equal(len(G), 50) 
开发者ID:holzschu,项目名称:Carnets,代码行数:7,代码来源:test_geometric.py

示例10: test_p

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import random_geometric_graph [as 别名]
def test_p(self):
        """Tests for providing an alternate distance metric to the
        generator.

        """
        # Use the L1 metric.
        dist = l1dist
        G = nx.random_geometric_graph(50, 0.25, p=1)
        for u, v in combinations(G, 2):
            # Adjacent vertices must be within the given distance.
            if v in G[u]:
                assert_true(dist(G.nodes[u]['pos'], G.nodes[v]['pos']) <= 0.25)
            # Nonadjacent vertices must be at greater distance.
            else:
                assert_false(dist(G.nodes[u]['pos'], G.nodes[v]['pos']) <= 0.25) 
开发者ID:holzschu,项目名称:Carnets,代码行数:17,代码来源:test_geometric.py

示例11: test_p_dist_default

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import random_geometric_graph [as 别名]
def test_p_dist_default(self):
        """Tests default p_dict = 0.5 returns graph with edge count <= RGG with
           same n, radius, dim and positions

        """
        nodes = 50
        dim = 2
        pos = {v: [random.random() for i in range(dim)] for v in range(nodes)}
        RGG = nx.random_geometric_graph(50, 0.25, pos=pos)
        SRGG = nx.soft_random_geometric_graph(50, 0.25, pos=pos)
        assert_true(len(SRGG.edges()) <= len(RGG.edges())) 
开发者ID:holzschu,项目名称:Carnets,代码行数:13,代码来源:test_geometric.py

示例12: test_number_of_nodes

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import random_geometric_graph [as 别名]
def test_number_of_nodes(self):
        G = nx.random_geometric_graph(50, 0.25)
        assert_equal(len(G), 50)
        G = nx.random_geometric_graph(range(50), 0.25)
        assert_equal(len(G), 50) 
开发者ID:aws-samples,项目名称:aws-kube-codesuite,代码行数:7,代码来源:test_geometric.py

示例13: random_geometric_graph

# 需要导入模块: import networkx [as 别名]
# 或者: from networkx import random_geometric_graph [as 别名]
def random_geometric_graph(N, deg, dia, dim, domain):
    '''
    Parameters of the graph:
    n (int or iterable) – Number of nodes or iterable of nodes

    radius (float) – Distance threshold value

    Average Degree is given by formula: Avg_Deg = (pi*(r^2)*num_nodes)/(l^2)
    Formula for r: avg_deg * l
    where l can be considered a constant where its square can be approximated to 1.04 [ength of square] Empirically Found
    :return: Graph Object
    '''
    strt_time = time()

    l = 1.04

    count = 0
    tolerance = 0.5
    curr_deg_error = float('inf')

    while tolerance < curr_deg_error:

        r = np.round(np.sqrt((deg * l ) / (3.14 * N)), 3)

        G = nx.random_geometric_graph(n=N, radius=r)

        curr_avg_deg = np.mean(list(dict(nx.degree(G)).values()))

        lcc = graph_util.get_lcc_undirected(G)[0]

        curr_deg_error = abs(curr_avg_deg - deg)



        count += 1

        if count == 1000:

            break

    best_G = lcc
    best_diam = nx.algorithms.diameter(best_G)
    best_avg_deg = curr_avg_deg

    end_time = time()

    print('Graph_Name: Random_Geometric_Graph')
    print('Num_Nodes: ', nx.number_of_nodes(best_G), ' Avg_Deg : ', best_avg_deg, ' Diameter: ', best_diam)
    print('TIME: ', end_time - strt_time)
    return best_G, best_avg_deg, best_diam

######################################################################################################################## 
开发者ID:palash1992,项目名称:GEM-Benchmark,代码行数:54,代码来源:graph_gens.py


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