<jupyter_start><jupyter_text>Test Model<jupyter_code># Global Variables:
job_list = ["Thornton","Rotunda","UVA Health","Nau Hall","Minor Hall","Mcintire"]
house_list = ["McCormick","Alderman","Dungle-Jungle","Gooch-Dillard"]
leisure_list = ["Clem","Clark","Corner","Mad Bowl"]

locations = {'Thornton': [9,7], 'Rotunda': [5,14], 'UVA Health': [12,16], 'Nau Hall': [11,13], 'Minor Hall': [8,12], 'Mcintire': [10,14]}
leisure = {'Clem':[5,11],'Clark':[8,10],'Corner': [6,15],'Mad Bowl':[3,14]}
houses = {'McCormick':[6,6],"Alderman":[8,3],"Dungle-Jungle":[10,1], "Gooch-Dillard":[15,1]}

for k in locations.keys():
    locations[k] = tuple([i*6 for i in locations[k]])

for k in leisure.keys():
    leisure[k] = tuple([i*6 for i in leisure[k]])
    
for k in houses.keys():
    houses[k] = tuple([i*6 for i in houses[k]]) 

density_threshold = 178/2500;
mask_advantage = 0.1
all_infected = 0 
time = 0;
prob_infection = 1 - 0.8
prob_recovery = 0.68
# Model with quarantine implementation.
import numpy as np
import pandas as pd

from mesa import Agent, Model
from mesa.time import RandomActivation
from mesa.space import MultiGrid
from mesa.datacollection import DataCollector
from scipy.spatial import distance
import matplotlib.pyplot as plt

class Individual(Agent):
  #age,health,job
    def __init__(self,unique_id,model,infected,house,mask,responsible): # incubation period? 
        super().__init__(unique_id,model)

        # list of jobs students can have and the probability they are that student
        self.infected = infected
        self.job = np.random.choice(job_list)
        self.home = house
        self.leisure = np.random.choice(leisure_list)
        if self.infected == 1:
            self.time_infected = 0
        else:
            self.time_infected = -1
        #instantiate private variables like age, pre-existing conditions...
        self.mask = mask
        self.responsible = responsible
  
    def step(self):
        if (self.model.time % 96) == 72:
            self.leisure = np.random.choice(leisure_list)

        if self.infected == 0:
            if (self.model.time % 96) < 40 and self.pos != houses[self.home]:
                self.move()
            if (self.model.time % 96) >= 40 and (self.model.time%96) < 56:
#                 print("im here")
                if self.pos != locations[self.job]:
#                     print(" gonna move")
                    self.move()
            if (self.model.time % 96) >= 56 and (self.model.time%96) < 72:
                if self.pos != houses[self.home]:
                    self.move()
            if (self.model.time % 96) >= 72:
                if self.pos != leisure[self.leisure]:
                    self.move()       
        else:
            if self.model.quarantine == True:
                if self.pos != (20,20):
                    self.move()
            else:
                if self.pos != houses[self.home]:
                    self.move()
                    
        if self.infected == 1:
            self.time_infected = self.time_infected + 1;
            if self.time_infected > 48 and self.time_infected < 480:
                self.infect()
            self.recover()
    
    def move(self):
        neighbors = self.model.grid.get_neighborhood(self.pos, moore = True, radius = 5, include_center = False)
        #not sure what we wanna do w/ the grid size. Grounds is 1.8 miles^2 = ~50 mil ft^2. if each patch is 100x100 ft, we have 5000 patches
        grid_size = 5000 #100 ft x 100 ft patch (is that too big?)
        densities = []
        dictionary = {}
        
        if self.infected == 0:
            if (self.model.time % 96) < 40:
                destination = houses[self.home]
            if (self.model.time % 96) >= 40 and (self.model.time%96) < 56:
                destination = locations[self.job]
            if (self.model.time % 96) >= 56 and (self.model.time%96) < 72:
                destination = houses[self.home]
            if (self.model.time % 96) >= 72:
                destination = leisure[self.leisure]
        else:
            if self.model.quarantine == True:
                p = np.random.random()
                if p < 0.8:
                    destination = (20,20)
                else:
                    destination = houses[self.home]
            else:
                destination = houses[self.home]
            
        distances = [distance.euclidean(i,destination) for i in neighbors]  
        densities = [len(self.model.grid.get_cell_list_contents([n])) / grid_size for n in neighbors]
        viable_patches = [i < density_threshold for i in densities]
        min_index = 0
        
        if self.infected == 0:
            if sum(viable_patches) > 0:
                for i in range(len(distances)):
                    if viable_patches[i] ==  True and distances[i] < distances[min_index]:
                        min_index = i;
            else:
                if responsible == 1:
                    min_index = np.argmin(densities)
                else:
                    min_index = np.argmin(distances)
        else:
            min_index = np.argmin(distances)
        new_position = neighbors[min_index]
        self.model.grid.move_agent(self, new_position)
        
    def infect(self):
        num_mask = 0;
        num_infected = 0;
        if self.infected == 1:
            people = self.model.grid.get_cell_list_contents([self.pos])
            density = len(people) / 5000
            for i in people:
                p = np.random.random()
                if i.infected == 0:
                    if (self.model.time % 96) < 40 and p < 0.05:
                        i.infected = 1
                        i.time_infected = 0
                    if (self.model.time % 96) >= 40 and (self.model.time%96) < 56 and p < 0.1:
                        i.infected = 1
                        i.time_infected = 0
                    if (self.model.time % 96) >= 56 and (self.model.time%96) < 72 and p < 0.05:
                        i.infected = 1
                        i.time_infected = 0
                    if (self.model.time % 96) >= 72 and p < 0.5:
                        i.infected = 1
                        i.time_infected = 0

    def recover(self):
        p = np.random.random()
        if self.infected == 1:
            if (self.time_infected) > 96:
                if p < prob_recovery:
                    self.infected = 0;
                    self.time_infected = -1
        

class CovidModel(Model):
    def __init__(self,N,width,height,initial_infected,p_mask, p_responsible,quarantine):
        super().__init__()
        self.num_agents = N
        self.grid = MultiGrid(width,height,True)
        self.schedule = RandomActivation(self)
        self.time = 0
        self.quarantine = quarantine
        
        for i in range(N):
            p = np.random.random()
            mask_i = 0;
            responsible_i = 0;
            infected_i = 0;
            
            if p < p_mask:
                mask_i = 1;
            if p < p_responsible:
                responsible_i = 1;
            if i < initial_infected:
                infected_i = 1
            
            house_i = np.random.choice(house_list)
            
            a = Individual(i,self,infected_i, house_i, mask_i,responsible_i)
            self.schedule.add(a)
            
            loc = houses[house_i]
            self.grid.place_agent(a,(loc))
            
        self.datacollector = DataCollector(
          model_reporters = {"Number_Infected": calc_num_infected},
          agent_reporters = {"Infection_Status": "infected"}
        )
#         print("finished")
   
    def step(self):
        self.schedule.step()
        self.time = self.time + 1
        self.datacollector.collect(self)
        

def calc_num_infected(model):
    return sum(a.infected for a in model.schedule.agents)<jupyter_output><empty_output><jupyter_text>Testing imported class.<jupyter_code>from mesaModelAssistant import ModelExplorerMP as mp
batchrunner  = mp.ModelExplorerMP(model_cls=CovidModel,num_cores=2,variable_parameters = {
                                                        "p_mask": [0.1, 0.3, 0.5],
                                                        "p_responsible": [0.6, 0.8, 1]
                                                    },
                                                   fixed_parameters = {
                                                        "N":100,
                                                        "width":100,
                                                        "height":100,
                                                        "initial_infected":5,
                                                        "quarantine":True
                                                    },
                                                   iterations = 2,
                                                   max_steps = 100)
batchrunner.generate_run_matrix()
batchrunner.schedule_run_all_param_combinations()<jupyter_output>Run ['p_mask', 'p_responsible'] = [0.1, 0.6]; Iteration 0 started.
Run ['p_mask', 'p_responsible'] = [0.1, 0.6]; Iteration 1 started.
Run [0.1, 0.6]; Iteration 0 finished.
Run [0.1, 0.6]; Iteration 1 finished.
Run ['p_mask', 'p_responsible'] = [0.1, 0.8]; Iteration 0 started.
Run ['p_mask', 'p_responsible'] = [0.1, 0.8]; Iteration 1 started.
Run [0.1, 0.8]; Iteration 1 finished.
Run [0.1, 0.8]; Iteration 0 finished.
Run ['p_mask', 'p_responsible'] = [0.1, 1]; Iteration 0 started.
Run ['p_mask', 'p_responsible'] = [0.1, 1]; Iteration 1 started.
Run [0.1, 1]; Iteration 1 finished.
Run [0.1, 1]; Iteration 0 finished.
Run ['p_mask', 'p_responsible'] = [0.3, 0.6]; Iteration 0 started.
Run ['p_mask', 'p_responsible'] = [0.3, 0.6]; Iteration 1 started.
Run [0.3, 0.6]; Iteration 0 finished.
Run [0.3, 0.6]; Iteration 1 finished.
Run ['p_mask', 'p_responsible'] = [0.3, 0.8]; Iteration 0 started.
Run ['p_mask', 'p_responsible'] = [0.3, 0.8]; Iteration 1 started.
Run [0.3, 0.8]; Iteration 1 finish[...]
{'fraction_non_alphanumeric': 0.1191730444289832, 'fraction_numerical': 0.03448961335851307, 'mean_word_length': 1.6053858104609011, 'pattern_counts': {'":': 12, '<': 29, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '256014', 'license': 'MIT', 'n_tokens_mistral': 3315, 'n_tokens_neox': 2913, 'n_words': 734, 'path': '.ipynb_checkpoints/test_mesaModelAssistant-checkpoint.ipynb', 'repo_name': 'nikita-sivakumar/mesa-model-assistant', 'size': '10061'}