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


Python Population.num_adults方法代码示例

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


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

示例1: drive

# 需要导入模块: from population import Population [as 别名]
# 或者: from population.Population import num_adults [as 别名]

#.........这里部分代码省略.........
                            food=food.produced_food,
                            kcals=total_kcal,
                            facility_crop=facility.crop_area,
                            facility_personnel=facility.personnel_capacity,
                            air=air.oxygen_consumed(),
                            power=power.power_consumed())

        # Main iteration loop
        for cur_sim_time in range(1, max_sim_time):
            print 'current sim time:', cur_sim_time
            start = time.time()

            # Diasters
            if random.random() <= 0.01:
                #ratio = random.random()/10.0
                #disaster.create_disaster(ratio)
                #print 'DISASTER killed', ratio, 'in:', time.time() - start
                death_from_disaster = random.randint(1,20)
                disaster.create_disaster(death_from_disaster)
                print 'DISASTER killed', death_from_disaster, 'people and', (death_from_disaster+10)*2500.0, 'food in:', time.time() - start
                start = time.time()

            # If enough food, expand facility. Assume 3 month build time
            if food.remaining_food > 2500*10 and (facility.personnel_capacity - population.num_people()) <= 10:
                facility.start_pod_construction(cur_sim_time, 3)
                facility.add_pod(cur_sim_time)

            # Adding newborns
            born_count = 0
            for add_count in range (people_born.get(cur_sim_time % 9, 0)):
                if population.num_people() < facility.personnel_capacity:
                    population.add_person(Person(cur_sim_time, population.get_rand_death_time(cur_sim_time), random.random()))
                    born_count += 1
            print 'added', born_count, 'people in', time.time()-start

            # Removing the dead
            start = time.time()
            people_to_kill = len(population.death_dict.get(cur_sim_time, []))
            population.remove_dead(cur_sim_time)
            print 'removed', people_to_kill, 'people in:', time.time() - start

            # Calculating total kcal
            start = time.time()
            total_kcal = population.kcal_requirements(cur_sim_time)
            print 'completed total kcal in:', time.time() - start

            # Food consumption
            food_delta = food.update_food(total_kcal)
            print 'produced food = ', food.produced_food, '; remaining food = ', food.remaining_food
            # if not enough food
            if food_delta < 0:
                # people who are unfed will die, starting with oldest people
                while (food_delta < 0):
                    food_delta = food_delta + population.people[0].kcal_requirements(cur_sim_time)
                    population.remove_person(0)
                population.generate_death_dict()

            # Calculating how many newborns to be created in 9 months time
            num_people = population.num_people()
            num_adults = population.num_adults(cur_sim_time)
            # newborns based on number of adults. Average US birthrate in 2014: 0.01342 (indexmundi.com)
            people_born[cur_sim_time % 9] = random.randint(np.rint(num_adults*0.01),np.rint(num_adults*0.020))
            print 'total people:', num_people, 'and total adults:', num_adults, 'and total kcal:', total_kcal
            print 'total capacity:', facility.personnel_capacity

            print('-'*100)

            # Record results of the iteration.
            self._write_results(population=num_people,
                                food=food.produced_food,
                                kcals=total_kcal,
                                facility_crop=facility.crop_area,
                                facility_personnel=facility.personnel_capacity,
                                air=air.oxygen_consumed(),
                                power=power.power_consumed())

            # If the visualization option has been selected, plot the results
            # every 10 timesteps.
            if self.vis and cur_sim_time % 10 == 0:

                # Add data for the chart.
                self.vis.add_data(cur_sim_time, {
                    'Population Count': num_people,
                    'Adult Count': num_adults,
                    'Caloric Requirements (Mcal)': total_kcal / 1000.0,
                    'Produced Food (Mcal)': food.produced_food / 1000.0,
                    'Air (kg O2)': air.oxygen_consumed(),
                    'Power Consumption (kWh)': power.power_consumed()
                })

                # Update the chart, re-rendering.
                self.vis.update()

        # If visualization has been selected,
        if self.vis:
            # Save the last rendered chart as a png image.
            self.vis.savefig()

        # Return the results dict.
        return self.results
开发者ID:slugwarz05,项目名称:proj2-code,代码行数:104,代码来源:driver.py


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