simulation.py 文件源码

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

项目:multichain-walker-simulation 作者: pimveldhuisen 项目源码 文件源码
def __init__(self, max_time, log_dir, verbose, persistent_walking, directed_walking, block_limit, alpha,
                 teleport_probability):
        self.max_time = max_time
        self.bootstrap = Node(0, self)
        self.nodes = []
        self.event_queue = []
        self.time = 0
        self.block_file = os.path.join(log_dir, 'blocks.dat')
        self.load_balance_file = os.path.join(log_dir, 'load.dat')
        self.ranking_deviation_file = os.path.join(log_dir, 'ranking.dat')
        self.verbose = verbose
        self.persistent_walking = persistent_walking
        self.directed_walking = directed_walking
        self.block_limit = block_limit
        self.alpha = alpha
        self.teleport_probability = teleport_probability
        self.last_progress_print = None

        print "Reading multichain database.."
        database = Database("multichain.db", self.block_limit)
        public_keys = database.get_identities()
        for public_key in public_keys:
            node = Node(public_key, self, self.persistent_walking, self.directed_walking, self.alpha,
                        self.teleport_probability)
            node.add_blocks(database.get_blocks(public_key))
            node.receive_identity(self.bootstrap)
            node.send_identity(self.bootstrap)
            self.nodes.append(node)
            self.add_event(Simulation.initialisation_delay(), node.take_walk_step)
            self.add_event(0, node.update_ranking)

        print "Calculating rankings.."
        # Here rankings are calculated based on the full database, not the individual databases of the nodes
        self.rankings = {}
        for public_key in public_keys:
            self.rankings[str(public_key)] = get_ranking(database, public_key)


        print "Scheduling data gathering.."
        self.log_data_times = range(self.max_time, -60000, -60000)
        print self.log_data_times
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号