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


Python History.add_record方法代码示例

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


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

示例1: __init__

# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import add_record [as 别名]

#.........这里部分代码省略.........
                self.firms.append(firm)
                firm_counter += 1
        firm_count = firm_counter
        # initial worker distribution
        for i in range(workers_count):
            worker = Worker(i)
            self.workers.append(worker)
            firm_id = i % firm_count
            firm = self.firms[firm_id]
            firm.add_worker(worker, firm.current_salary)

        self.history = History(self.steps, self.firms)

        self.firm_actions = [0] * firm_count
        self.firm_results = [0] * firm_count

        self.firm_labormarket_actions = [0] * firm_count
        self.firm_goodmarket_actions = [0] * firm_count

        self.firm_labormarket_results = [0] * firm_count
        self.firm_goodmarket_results = [0] * firm_count

    def manage_firm_actions(self, firm_actions):
        pass

    def manage_sales(self):
        pass

    def manage_job_offers(self):
        pass

    def compute_stats(self):
        self.stats.f = len(self.firms)
        self.stats.price = 0
        self.stats.stock = 0
        self.stats.sales = 0
        self.stats.sold = 0
        self.stats.salary = 0
        employed = 0
        for firm in self.firms:
            self.stats.stock += firm.stock
            self.stats.sold += firm.sold
            self.stats.sales += firm.sales
            employed += len(firm.workers)
            for worker in firm.workers:
                self.stats.salary += worker.salary
        if self.stats.sold > 0:
            self.stats.price = self.stats.sales / self.stats.sold
        else:
            self.stats.price = 0
        if employed > 0:
            self.stats.salary /= employed
        else:
            self.stats.salary = 0
        unemployed = 0
        for worker in self.workers:
            if worker.employer is None:
                unemployed += 1
        if len(self.workers) > 0:
            self.stats.unemployment_rate = unemployed / len(self.workers)
        self.stats.money = self.money
        self.stats.expected_sales_growth = self.config['global']['money_growth']/self.money
        self.stats.expected_sold_growth = 0.05

    def go(self):
        print("It's alive!!")
        birth_rate = self.config['global']['birth_rate']
        money_growth = self.config['global']['money_growth']
        for step in range(self.steps):
            # print("Step:", step)
            for i, firm in enumerate(self.firms):
                # @todo: enable bankrupt
                # if firm.money < self.config['global']['bankrupt_rate']:
                #     firm.bankrupt()
                #     del self.firms[i]
                #     del self.firm_actions[i]
                #     continue
                # print(firm)
                firm.work()
                # print(firm)
                self.firm_goodmarket_actions[firm.id] = firm.decide_price(self.stats)
            self.manage_sales()
            for firm_id, firm_action in enumerate(self.firm_goodmarket_actions):
                firm = self.firms[firm_id]
                firm.apply_goodmarket_result(self.firm_goodmarket_results[firm_id])
                self.history.add_record(step, firm)
            self.compute_stats()
            self.history.add_stats(step, self.stats)  # needs to be rewritten with proper history object in mind
            for j in range(birth_rate):
                worker = Worker(len(self.workers))
                self.workers.append(worker)
            for i, firm in enumerate(self.firms):
                self.firm_labormarket_actions[firm.id] = firm.decide_salary(self.stats)
            self.manage_job_offers()
            for firm_id, firm_action in enumerate(self.firm_labormarket_actions):
                firm = self.firms[firm_id]
                firm.apply_labormarket_result(self.firm_labormarket_results[firm_id])
            self.money += money_growth

        return self.history
开发者ID:urisavka,项目名称:ace,代码行数:104,代码来源:world.py


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