connections_simulation.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:gossip-python 作者: thomai 项目源码 文件源码
def run(self):
        ip_addresses = ['192.168.1.%s' % x for x in range(1, self._number_clients)]
        ports = [x for x in range(1, 2)]
        clients = []
        progress = 0
        for ip_addr in ip_addresses:
            print_progress(progress, self._number_clients, suffix="Running simulation")
            for port in ports:
                progress += 1
                client = Client(ip_addr, port, clients[0] if len(clients) > 0 else None,
                                max_chache_size=self._number_connections_per_client)
                clients.append(client)
                connection = Connection(client, clients[0])
                connection.initiate()

                bootstrapper_connections = clients[0].get_connections()
                for conn in bootstrapper_connections:
                    connection = Connection(client, conn.second_client)
                    connection.initiate()

        graph = networkx.nx.Graph()
        for client in clients:
            logging.error(client.get_ident())
            logging.error(client.get_connection_idents())
            for node in client.get_connections():
                graph.add_edge(node.first_client.get_ident(), node.second_client.get_ident())

        networkx.draw(graph, with_labels=False)
        plt.savefig("path_graph.pdf")
        print("Network is connected: %s" % networkx.is_connected(graph))
        print("Average shortest path length: %s" % networkx.average_shortest_path_length(graph))
        print("Average bipartite clustering coefficent %s" % networkx.average_clustering(graph))
        print("Bipartite clustering coefficent %s" % networkx.clustering(graph))
        print("degree_assortativity_coefficient %s" % networkx.degree_assortativity_coefficient(graph))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号