def egg_generate(egg_size): egg_start_pos = [ random.randint(0, gv.display_width), random.randint(0, gv.display_height) ] # egg_start_pos = [int(gv.display_width/2), int(gv.display_height/2)] return Egg.Egg(egg_size, egg_start_pos)
def layeggs(self, batchsize) -> None: # Adds normal distribution with avgeggbatch mean number of eggs to the model or fixed number from avgeggbatch # TODO: Optimize by doing total survival calc in one go for i in range(batchsize): # Each offspring has same starting location as egg-laying location a = Egg.Egg(self.model.getid(), self.model) self.model.schedule.add(a) self.model.grid.place_agent(a, self.pos)
def __init__(self, NumMidges, NumDeer, width=100, height=100, mapfile=None, trapfile=None, dps=0.5): Midge.Midge.setdps(dps) Midge.Midge.createdpsarray(dps) self.NumMidges = NumMidges # Starting number of midges self.NumDeer = NumDeer # Starting number of deer self.idcounter = 0 # Global counter for id of agents, increments with every new agent creation self.mapfile = mapfile # Argument passed to decide on which map data to use (must be in CSV format) self.trapfile = trapfile # File used to decide where the traps will be placed, used to replicate data in paper self.running = True # Used for running model in batches self.midges = [ ] # List of all current midges, can set to update every step self.traps = [] # List of all trap agents self.deer = [] # List of all deer agents self.dps = dps # Daily probability of survival for all midges # Time (days) since simulation has begun self.day = 0 # Activates the step function for midges sequentially (no order needed) self.schedule = BaseScheduler(self) # Create a grid model with potential for multiple agents on one cell self.grid = ContinuousSpace(width, height, torus=False) # Open the map file and create a csvreader object to be used by every midge self.mapdata = open(self.mapfile, 'r') self.csvreader = csv.reader(self.mapdata, delimiter=',') # Create a blank map array filled with the generic 'lightgreen' value self.maparray = np.full(shape=(width, height), fill_value=BiomeCell.BiomeCell('lightgreen'), dtype=BiomeCell.BiomeCell) # Add all biome types from the mapfile to the map array with open(self.mapfile, 'r', encoding='utf-8-sig') as csvfile: csvreader = csv.reader(csvfile, delimiter=',') for l in csvreader: x, y = int(l[0]), int(l[1]) self.maparray[x][y] = BiomeCell.BiomeCell(l[2]) # # Adds midges to random location in grid and to queue in scheduler for i in range(self.NumMidges): x = self.random.random() * self.grid.width y = self.random.random() * self.grid.height a = Midge.Midge(self.getid(), self) # Gives midges random probabilities of having fed and are in stages of gonotrophic cycle a.fed = True a.timesincefed = np.random.randint(0, Midge.Midge.gtrclength) self.schedule.add(a) self.grid.place_agent(a, (x, y)) # Adds some eggs to the simulation as well, just to even out the population variability for i in range(10000): x = self.random.random() * (self.grid.width) y = self.random.random() * (self.grid.height) a = Egg.Egg(self.getid(), self) # Gives eggs random age a.age = random.randint(-Egg.Egg.growthtime, Egg.Egg.growthtime) self.schedule.add(a) self.grid.place_agent(a, (x, y)) # # Adds traps to random locations in the grid from the trap location file and to the queue in scheduler # with open(self.trapfile, 'r', encoding='utf-8-sig') as csvfile: # csvreader = csv.reader(csvfile, delimiter=',') # for l in csvreader: # x, y = int(l[0]), int(l[1]) # a = Trap.Trap(self.getid(), self) # self.schedule.add(a) # self.grid.place_agent(a, (x, y)) # Adds deer to random locations in the grid and to queue in scheduler for i in range(self.NumDeer): x = self.random.random() * (self.grid.width) y = self.random.random() * (self.grid.height) a = Deer.Deer(self.getid(), self) self.schedule.add(a) self.grid.place_agent(a, (x, y)) # Add 10 deer with BTV as a case study for i in range(10): a = Deer.Deer(self.getid(), self) a.hasbtv = True self.schedule.add(a) self.grid.place_agent(a, (self.random.random() * self.grid.width, self.random.random() * self.grid.height)) self.traps = [i for i in self.schedule.agents if type(i) == Trap.Trap ] # Fills list of traps (only once) self.deer = [i for i in self.schedule.agents if type(i) == Deer.Deer] # Fills list of deer (only once) self.targets = np.array( combinelists(self.traps, self.deer), dtype=Target.Target ) # Combines all subclasses of the target class into one list self.deerbites = 0 # Global counter of the total number of deer bites # TODO: Implement datacollector that can collect data from different agent types (gonna be a pain in my ass) self.datacollector = DataCollector( model_reporters={ "Day": "day", "MidgePop": "NumMidges", "DeerBites": "deerbites", "DeerwBTV": "DeerwBTV", "NumVectors": "NumVectors", "DPS": "DPS", "MidgeAges": "MidgeAges", "AvgAge": "AvgAge" })