def __init__(self, since_infection_recovery_factor, viral_in_vivo_replication_and_age_factor, viral_decay_factor, choice_location, number_of_infected_people, number_of_people, width, height): list_data = [] with open('./population_pyramid/' + choice_location + '.csv', newline='') as f: reader = csv.reader(f) lista = list(reader) lista = lista[1:] data = [] for entry in lista: prep_entry = {} ages = entry[0].split('-') if len(ages) == 2: prep_entry["age_from"] = ages[0] prep_entry["age_to"] = ages[1] else: prep_entry["age_from"] = ages[0][:-1] prep_entry["age_to"] = str(int(ages[0][:-1]) + 20) prep_entry["male_population"] = entry[1] prep_entry["female_population"] = entry[2] data.append(prep_entry) self.population_pyramid = data people = self.generatePeople(number_of_people) self.startTime = int(round(time.time() * 1000)) self.num_agents = len(people) self.kill_agents = [] self.schedule = RandomActivation(self) self.grid = MultiGrid(width, height, True) self.datacollector = DataCollector({ "deseased_all": get_deseased_all, "infections_current": get_infected_current, "all_infections_including_transient": get_infected_all }) # cr4eate some agents for i in range(len(people)): a = Human(i, self, people[i], viral_decay_factor, viral_in_vivo_replication_and_age_factor, since_infection_recovery_factor) a.type = "human" x = random.randrange(self.grid.width) y = random.randrange(self.grid.height) if random.randrange(number_of_people) < number_of_infected_people: a.infected = True a.viral_loads = [10] self.grid.place_agent(a, (x, y)) self.schedule.add(a) self.running = True
def __init__(self, space_size=32, jobs=30, agents=1, warehouses=1, split=0.4, use_seed=True, seed: int = 42, obstacle_map: str = "maps/random-32-32-20.map", allocation: str = "HungarianMethod", collision=False): if use_seed: self.random.seed(seed) else: self.random.seed(None) self.space_size = space_size self.tasks_left = jobs self.warehouses = [] self.num_agents = agents self.agents = [] self.collision = collision self.allocation_flag = True self.allocator = getattr(sys.modules["task_allocation"], allocation) self.allocation = None self.schedule = RandomActivation(self) self.grid = MultiGrid(space_size, space_size, torus=False) self.obstacle_matrix = generate_map(obstacle_map) self.obstacles = self.__set_obstacle__() self.__set_up__(agents, warehouses, split) self.hidden_tasks = self.__preload_jobs__() # self.available_tasks = self.__add_jobs__(min(2*agents, jobs)) self.available_tasks = self.__add_jobs__(min(10, jobs)) self.task_allocator = None self.score = PrioritisedTaskTime() self.datacollector = DataCollector( { "tasks_left": "tasks_left", "Overall Wait Time": lambda m: m.score.get_score(), "High": lambda m: m.score.get_avg_wait_time().get(1), "Med": lambda m: m.score.get_avg_wait_time().get(2), "Low": lambda m: m.score.get_avg_wait_time().get(3), }, { "x": lambda a: a.pos[0], "y": lambda a: a.pos[1] }, ) self.running = True self.datacollector.collect(self)
def __init__ (self, endophytism = True, ## allow endophyte life style in model run ws = 30, ## initial num of wood endodisp=2.0, ## dispersal of endos decompdisp=10.0, ## dispersal of decomps leafdisp = 4.0, ## how well do leaves disperse leaffall = 1, ## how frequently do leaves disperse numdecomp=1, ## initial number of decomposers numendo=1, ## initial number of endos endoloss=0.05, ## rate of loss of endophyte infect per step newwood = 15, ## total energy added in new logs each step woodfreq = 1, ## how often to put new logs onto the landscape width = 100, ## grid dimensions, only one (squares only) kappa = 0.03, ## average rate of parent tree clusters per unit distance sigma = 3.0, ## variance of child tree clusters, +/- spread of child clusters mu = 2.2, ## average rate of child tree clusters per unit distance nuke = False, ## make landscape, but no agents ): self.endophytism = endophytism self.nwood = ws self.endodisp = endodisp self.decompdisp = decompdisp self.leafdisp = leafdisp self.leaffall = leaffall self.numdecomp = numdecomp self.numendo = numendo self.endoloss = endoloss self.newwood = newwood self.woodfreq = woodfreq self.schedule = RandomActivation(self) self.grid = MultiGrid(width, width, torus = True) self.running = True self.width = width self.kappa = kappa self.sigma = sigma self.mu = mu self.decompspor = 0 ## sporulation events this turn self.endospor = 0 ## sporulation events this turn self.datacollector = DataCollector( model_reporters={ "Endophytes": sumendos, "Endo_subs": Endo_subs, "Decomposers": sumdecomps, "Decomp_subs": Decomp_subs, "Infected_trees": bluetrees, "decompspor_count": decompspor_count, "endospor_count": endospor_count, "Trees": tracktrees, }) ## make initial agents: if not nuke: ## if not a nuclear holocaust where life is devoid self.make_trees() for i in range(self.nwood): self.add_wood() ## no make_woods method self.make_fungi()
def __init__(self, N, width, height): self.width = width self.height = height self.num_agents = N self.schedule = RandomActivation(self) self.heatmap_data = np.zeros((self.height, self.width)) self.grid = MultiGrid(self.width, self.height, True) self.background_cells = [] # Create agent for cell and set its attribute count = 0 # for unique_id for x in range(self.width): for y in range(self.height): # Create cell agent cell_object = CellAgent(count, self) # Place this agent to the correct location of the model's grid self.grid.place_agent(cell_object, (x, y)) cell_object.init_position = (x, y) # Set attribute for each cell self.set_attribute_cell(cell_object, x, y) # Append to the list containing all background cells self.background_cells.append(cell_object) count += 1 # Find all road cells' position as possible runner's initial position self.roads = [ cell.pos for cell in self.background_cells if cell.type == 'road' ] # Create runner agents self.agent_objects = [] for i in range(self.num_agents): runner = RunnerAgent(i, self) # store the inital position as attribte runner.init_position = self.random.choice(self.roads) print('Initial position: ', runner.init_position) self.grid.place_agent(runner, runner.init_position) self.schedule.add(runner) self.agent_objects.append(runner) # update heatmap data x, y = runner.init_position self.heatmap_data[self.height - 1 - y][x] += 1 # Attribute running for visualization self.running = True # Trail entrance point self.trail_entrance_point = [(3, 32), (30, 40)] self.num_agents_complete_running = 0