def __init__(self, height=20, width=20, visibility = False ,initial_competitors=0, initial_explorers=1, initial_predators=0 , impactTotalVisibility =.3 , impactPartialVisibility = .35, impactParticipants = .0, impactCompetitors= .0, impactPredators= .0 ): ''' Create a new PsyRTS model with the given parameters. Args initial_competitors: Number of units each participant knows initial_explorers: Number of sheep to start with initial_predators: Number of wolves to start with visibility : total or partial visibility ''' super().__init__() self.uid = next(self.id_gen) self.fps = 0 # Set parameters self.height = height self.width = width self.visibility = visibility self.initial_competitors = initial_competitors self.initial_explorers = initial_explorers self.initial_predators = initial_predators self.schedule = RandomActivationByBreed(self) self.grid = MultiGrid(self.height, self.width, torus=False) self.uncertainty = 0.0 self.resources= 0 self.resourcesParticipants =0 self.resourcesCompetitors = 0 self.visitedCells = 0 self.stepsExploring = 0 self.stepsExploiting = 0 #parameters model mu, sigma = impactTotalVisibility, 0.05 # mean and standard deviation tv = np.random.normal(mu, sigma) if tv < 0: tv = 0 # print( "Starting with tv " , tv) mu, sigma = impactPartialVisibility, 0.05 # mean and standard deviation pv = np.random.normal(mu, sigma) if pv < 0: pv = 0 #print("Starting with pv ", pv) self.impactTotalVisibility = tv self.impactPartialVisibility = pv self.impactParticipants = impactParticipants self.impactCompetitors = impactCompetitors self.impactPredators = impactPredators self.TotalCells = next_moves = self.grid.get_neighborhood( (10,10), True, True, 11) locationsResources = [(4,3) , (16,3), (3,10) , (10,10),(17,10) , (16,17),(4,17) ] locationCPCompetitor = (10, 3) locationCPParticipant = (10, 17) self.locationsExploitation =[] for loc in locationsResources:#resources self.locationsExploitation = self.locationsExploitation + self.grid.get_neighborhood(loc, True, True,1) #cfp self.locationsExploitation = self.locationsExploitation + self.grid.get_neighborhood(locationCPParticipant, True, True, 1) #print( "size grid exploiit " + str(len(self.locationsExploitation))) self.locationsExploration = list(set(self.TotalCells) - set(self.locationsExploitation)) #print("size grid explore " + str(len(self.locationsExploration))) locationsParticipants = [(10, 16), (13, 15), (7, 15), ( 8, 15), (12, 15) ] locationsCompetitors = [(10, 4), (13, 5), (7, 5), ( 8, 5), (12, 5) ] locationsPredators = [(10, 10), (13, 10), (7, 10), ( 8, 10), (12, 10) ] self.datacollector = DataCollector( model_reporters={ "Experiment_Synth": track_experiment, "Conditions": track_params, "Step": track_run, "Exploration": exploration , "Exploitation": exploitation, "ResourcesRatio": resourcesRatio, "ProportionEE": proportionEE, "MapExplored": mapExplored, }) #reporto a datos centralplaceparticipant = CentralPlace(self.next_id(), locationCPParticipant, self, True) self.grid.place_agent(centralplaceparticipant, locationCPParticipant) self.schedule.add(centralplaceparticipant) centralplacecompetitor = CentralPlace(self.next_id(), locationCPCompetitor, self, False) self.grid.place_agent(centralplacecompetitor, locationCPCompetitor) self.schedule.add(centralplacecompetitor) # Create competitor: for i in range(self.initial_competitors): sheep = Competitor(self.next_id(), locationsCompetitors[i], self, True, centralplacecompetitor) self.grid.place_agent(sheep, locationsCompetitors[i]) self.schedule.add(sheep) # Create explorers: for i in range(self.initial_explorers): sheep = Participant(self.next_id(), locationsParticipants[i], self, True, centralplaceparticipant) self.grid.place_agent(sheep, locationsParticipants[i]) self.schedule.add(sheep) # Create predators for i in range(self.initial_predators): wolf = Predator(self.next_id(), locationsPredators[i], self, True) self.grid.place_agent(wolf, locationsPredators[i]) self.schedule.add(wolf) for pa in locationsResources: # randrange gives you an integral value irand = randrange(1, 11) #irand = 4 #print("resource con valores {} ". format( irand) ) self.resources = self.resources + irand patch = Resources(self.next_id(), pa, self, irand) self.grid.place_agent(patch, pa) self.schedule.add(patch) for x in range(0,20): for y in range(0, 20): breadcrumb = BreadCrumb(self.next_id(), (x,y), self) self.grid.place_agent(breadcrumb, (x,y)) self.schedule.add(breadcrumb) self.running = True self.datacollector.collect(self)
def __init__(self, density, initial_infected, infection_rate, min_infected, max_infected, mean_infected, min_exposed, max_exposed, mean_exposed, day_steps, day_isolation, detection_rate, width=20): """ """ # square grid height = width self.height = height self.width = width self.density = density self.initial_infected = initial_infected self.infection_rate = infection_rate self.detection_rate = detection_rate self.day_steps = day_steps self.min_exposed = min_exposed * self.day_steps self.max_exposed = max_exposed * self.day_steps self.mean_exposed = mean_exposed * self.day_steps self.min_infected = min_infected * self.day_steps self.max_infected = max_infected * self.day_steps self.mean_infected = mean_infected * self.day_steps self.day_isolation = day_isolation * self.day_steps self.schedule = RandomActivation(self) self.grid = MultiGrid(width, height, torus=True) self.infected = 0 self.exposed = 0 self.susceptible = 0 self.removed = 0 self.contact = 0 self.cuminfected = 0 self.isolated = 0 self.stats = { "infected": [], "exposed": [], "susceptible": [], "removed": [], "isolated": [] } self.datacollector = DataCollector( # Model-level count { "contact": "contact", "infected": "infected", "cuminfected": "cuminfected", "exposed": "exposed", "susceptible": "susceptible", "removed": "removed", "isolated": "isolated", "stats": "stats" }, # For testing purposes, agent's individual x and y { "x": lambda a: a.pos[0], "y": lambda a: a.pos[1] }) # Set up agents # We use a grid iterator that returns # the coordinates of a cell as well as # its contents. (coord_iter) num_agents = 0 num_infected = 0 while num_agents < self.density: #for cell in self.grid.coord_iter(): #x = cell[1] #y = cell[2] # obtaining non-empty cell x = int(self.random.uniform(0, width)) y = int(self.random.uniform(0, height)) while not self.grid.is_cell_empty((x, y)): x = int(self.random.uniform(0, width)) y = int(self.random.uniform(0, height)) if num_agents < self.density and self.random.random() < 0.2: if num_infected < self.initial_infected: agent_type = Infected() num_infected += 1 # generate typical infected lifespan from normal distribution ls = self.random.uniform(self.min_infected, self.max_infected) agent_type.setLifespan(ls) agent_type.set_detected( self.random.uniform(0, 1) < self.detection_rate) else: agent_type = Susceptible() agent = CovidAgent((x, y), self, agent_type) self.grid.place_agent(agent, (x, y)) self.schedule.add(agent) num_agents += 1 #print(str(num_agents)+" agents finally.") self.running = True