Exemple #1
0
 def initialize_individual_properties(self):
   super().initialize_individual_properties()
   mean = get_parameters().get('risk_tolerance_mean')
   stdev = get_parameters().get('risk_tolerance_stdev')
   self.properties.risk_tolerance = normal_cap(mean, stdev, 0.0, 1.0)
   mean = get_parameters().get('herding_behavior_mean')
   stdev = get_parameters().get('herding_behavior_stdev')
   self.properties.herding_behavior = normal_cap(mean, stdev, 0.0, 1.0)
Exemple #2
0
 def create_restaurant_location(self, index, is_bar):
     if is_bar:
         bar = Restaurant(normal_cap(100, 20, 50, 200), RestaurantType.BAR,
                          flip_coin(0.5), self.model, 'Restaurant',
                          str(index))
         return bar
     else:
         if flip_coin(0.5):
             restaurant_type = RestaurantType.FAST_FOOD
             rtype = "FASTFOOD"
         else:
             restaurant_type = RestaurantType.FANCY
             rtype = "FANCY"
         restaurant = Restaurant(
             normal_cap(
                 get_parameters().params['restaurant_capacity_mean'],
                 get_parameters().params['restaurant_capacity_stdev'], 16,
                 200), restaurant_type, flip_coin(0.5), self.model,
             'Restaurant', str(index))
         return restaurant
Exemple #3
0
 def initialize_individual_properties(self):
     super().initialize_individual_properties()
     self.properties.extroversion = normal_cap(get_parameters().get('extroversion_mean'),
             get_parameters().get('extroversion_stdev'), 0.0, 1.0)
     self.dilemma_history = DilemmaDecisionHistory()
Exemple #4
0
 def initialize_individual_properties(self):
     self.properties.base_health = normal_cap(0.8, 0.2, 0.0, 1.0)
Exemple #5
0
def setup_grid_layout(model, population_size, home_grid_height,
                      home_grid_width, work_height, work_width, school_height,
                      school_width):
    #Makes a grid of homogeneous home districts, overlaid by school and work districts.
    #home_grid_height is the number of home districts high the grid is, and
    #home_grid_width is the nmber of home districts wide the grid is
    #school height and work height are how many home districts high a school
    #district and work are respectively, and the same for their length.
    #each begins in grid 0,0 and cover the orignal home district grid.
    #Persons assigned to the home districts are also assigned to the school
    #and work districts that cover them. The parameters determine the amount
    #of leakage across groups of people.  With parameters (10,10,1,1,1,1) you get 100
    #completely separated districts with no leakage.  With parameters (6,6,2,2,3,3) you
    #get a grid where every one is connected to everyone else, but there is a
    #degree of separation.  For example, a person in home district (0,0) can be infected
    #by a person in (5,5) but it would be bridged by three infections, slowing the
    #virus down.  Larger sizes for work and school districts enable faster spread. Fastest
    #spread occurs with parameters (1,1,1,1,1,1) or equivalently (10,10, 10,10,10,10)
    #or any of the same number
    #Since this is just a way to allocate human interactions, no label is needed and
    #the grid need not be saved, for interactions to occur, although this inforamtion
    #may be useful for visualizations.
    work_building_capacity = 20
    office_capacity = 10
    work_building_occupacy_rate = 0.5
    appartment_building_capacity = 20
    appartment_capacity = 5
    appartment_building_occupacy_rate = 0.5
    school_capacity = 50
    classroom_capacity = 20
    school_occupacy_rate = 0.5

    # Build empty districts
    # https://docs.google.com/document/d/1imCNXOyoyecfD_sVNmKpmbWVB6xqP-FWlHELAyOg1Vs/edit

    home_districts = []
    work_districts = []
    school_districts = []
    school_map = {}
    work_map = {}
    school_grid_height = math.ceil(home_grid_height / school_height)
    school_grid_width = math.ceil(home_grid_width / school_width)
    work_grid_height = math.ceil(home_grid_height / work_height)
    work_grid_width = math.ceil(home_grid_width / work_width)

    for hw in range(home_grid_width):
        for hh in range(home_grid_height):

            home_district = build_district(
                f"Home ({hh},{hw})", model, population_size,
                appartment_building_capacity,
                appartment_capacity, appartment_building_occupacy_rate,
                beta_range(0.021, 0.12))  # normal_ci(0.021, 0.12, 10)

            home_district.debug = model.debug

            home_districts.append(home_district)
            home_number = hw * home_grid_height + hh
            assert home_number == len(home_districts) - 1

            sh = hh // school_height
            sw = hw // school_width
            school_number = sw * school_grid_height + sh
            school_map[home_number] = school_number

            wh = hh // work_height
            ww = hw // work_width
            work_number = ww * work_grid_height + wh
            work_map[home_number] = work_number

    for ww in range(work_grid_width):
        for wh in range(work_grid_height):

            work_district = build_district(
                f"Work ({wh},{ww})", model, population_size,
                work_building_capacity,
                office_capacity, work_building_occupacy_rate,
                beta_range(0.007, 0.06))  # normal_ci(0.007, 0.06, 10)
            # Add Restaurants to work_district

            for i in range(get_parameters().
                           params['restaurant_count_per_work_district']):
                if flip_coin(0.5):
                    restaurant_type = RestaurantType.FAST_FOOD
                    rtype = "FASTFOOD"
                else:
                    restaurant_type = RestaurantType.FANCY
                    rtype = "FANCY"
                restaurant = Restaurant(
                    normal_cap(
                        get_parameters().params['restaurant_capacity_mean'],
                        get_parameters().params['restaurant_capacity_stdev'],
                        16, 200), restaurant_type, flip_coin(0.5), model, '',
                    rtype + '-' + str(i) + f"({wh},{ww})")
                work_district.locations.append(restaurant)
            for i in range(2):
                bar = Restaurant(normal_cap(100, 20, 50,
                                            200), RestaurantType.BAR,
                                 flip_coin(0.5), model, '',
                                 'BAR-' + str(i) + f"({wh},{ww})")
                work_district.locations.append(bar)
            work_district.debug = model.debug
            work_districts.append(work_district)

    for sw in range(school_grid_width):
        for sh in range(school_grid_height):

            school_district = build_district(
                f"School ({sh},{sw})", model, population_size, school_capacity,
                classroom_capacity, school_occupacy_rate,
                beta_range(0.014, 0.08))  # normal_ci(0.014, 0.08, 10)

            school_district.debug = model.debug
            school_districts.append(school_district)

    #print ("work_map")
    #print (work_map)
    #print ("school_map")
    #print (school_map)

    # Build families

    family_factory = FamilyFactory(model)
    family_factory.factory(population_size)
    model.global_count.total_population = family_factory.human_count

    # print(family_factory)

    age_group_sets = {
        Infant: [],
        Toddler: [],
        K12Student: [],
        Adult: [],
        Elder: []
    }

    # Allocate buildings to people
    #print ("home_districts")
    #print (home_districts)
    #print ("work_districts")
    #print (work_districts)
    #print ("school_districts")
    #print (school_districts)

    all_adults = []
    all_students = []
    for family in family_factory.families:
        adults = [human for human in family if isinstance(human, Adult)]
        students = [human for human in family if isinstance(human, K12Student)]
        home_district_num = np.random.randint(0, len(home_districts))
        #print("home_district_num")
        #print(home_district_num)
        home_district = home_districts[home_district_num]
        work_district = work_districts[work_map[home_district_num]]
        school_district = school_districts[school_map[home_district_num]]

        home_district.allocate(family, True, True, True)
        work_district.allocate(adults)
        school_district.allocate(students, True)
        for human in family:
            age_group_sets[type(human)].append(human)
            human.home_district = home_district
            home_district.get_buildings(human)[0].get_unit(
                human).humans.append(human)
        for adult in adults:
            adult.work_district = work_district
            all_adults.append(adult)
        for student in students:
            student.school_district = school_district
            all_students.append(student)

    # Set tribes

    adult_rf = HomophilyRelationshipFactory(model, all_adults)
    student_rf = HomophilyRelationshipFactory(model, all_students)
    # exit()

    count = 0
    for family in family_factory.families:
        for human in family:
            work_district = human.work_district
            school_district = human.school_district
            count += 1
            human.tribe[TribeSelector.AGE_GROUP] = age_group_sets[type(human)]
            human.tribe[TribeSelector.FAMILY] = family
            if isinstance(human, Adult):
                human.unique_id = "Adult" + str(count)
                #print(work_district.get_buildings(human))
                #print(work_district.get_buildings(human))
                #print(workd_district.get_buildings(human)[0].get_unit(human))
                #print(workd_district.get_buildings(human)[0].get_unit(human))
                human.tribe[
                    TribeSelector.COWORKER] = work_district.get_buildings(
                        human)[0].get_unit(human).allocation
                t1 = adult_rf.build_tribe(human,
                                          human.tribe[TribeSelector.COWORKER],
                                          1, office_capacity)
                t2 = adult_rf.build_tribe(human,
                                          human.tribe[TribeSelector.AGE_GROUP],
                                          1, 20)
                human.tribe[TribeSelector.FRIEND] = t1
                for h in t2:
                    if h not in human.tribe[TribeSelector.FRIEND]:
                        human.tribe[TribeSelector.FRIEND].append(h)
            elif isinstance(human, K12Student):
                human.unique_id = "K12Student" + str(count)
                human.tribe[
                    TribeSelector.CLASSMATE] = school_district.get_buildings(
                        human)[0].get_unit(human).allocation
                t1 = student_rf.build_tribe(
                    human, human.tribe[TribeSelector.CLASSMATE], 1,
                    classroom_capacity)
                t2 = student_rf.build_tribe(
                    human, human.tribe[TribeSelector.AGE_GROUP], 1, 20)
                human.tribe[TribeSelector.FRIEND] = t1
                for h in t2:
                    if h not in human.tribe[TribeSelector.FRIEND]:
                        human.tribe[TribeSelector.FRIEND].append(h)
            elif isinstance(human, Elder):
                human.unique_id = "Elder" + str(count)
            elif isinstance(human, Infant):
                human.unique_id = "Infant" + str(count)
            elif isinstance(human, Toddler):
                human.unique_id = "Toddler" + str(count)
Exemple #6
0
def setup_city_layout(model, population_size):
    work_building_capacity = 20
    office_capacity = 10
    work_building_occupacy_rate = 0.5
    appartment_building_capacity = 20
    appartment_capacity = 5
    appartment_building_occupacy_rate = 0.5
    school_capacity = 50
    classroom_capacity = 20
    school_occupacy_rate = 0.5

    # Build empty districts
    # https://docs.google.com/document/d/1imCNXOyoyecfD_sVNmKpmbWVB6xqP-FWlHELAyOg1Vs/edit
    home_district = build_district(
        "Home", model, population_size, appartment_building_capacity,
        appartment_capacity, appartment_building_occupacy_rate,
        beta_range(0.021, 0.12))  # normal_ci(0.021, 0.12, 10)
    work_district = build_district(
        "Work", model, population_size,
        work_building_capacity, office_capacity, work_building_occupacy_rate,
        beta_range(0.007, 0.06))  # normal_ci(0.007, 0.06, 10)
    school_district = build_district(
        "School", model, population_size,
        school_capacity, classroom_capacity, school_occupacy_rate,
        beta_range(0.014, 0.08))  # normal_ci(0.014, 0.08, 10)

    home_district.debug = model.debug
    work_district.debug = model.debug
    school_district.debug = model.debug

    # Add Restaurants to work_district

    for i in range(
            get_parameters().params['restaurant_count_per_work_district']):
        if flip_coin(0.5):
            restaurant_type = RestaurantType.FAST_FOOD
            rtype = "FASTFOOD"
        else:
            restaurant_type = RestaurantType.FANCY
            rtype = "FANCY"
        restaurant = Restaurant(
            normal_cap(get_parameters().params['restaurant_capacity_mean'],
                       get_parameters().params['restaurant_capacity_stdev'],
                       16, 200), restaurant_type, flip_coin(0.5), model, '',
            rtype + '-' + str(i))
        work_district.locations.append(restaurant)
    for i in range(2):
        bar = Restaurant(normal_cap(100, 20, 50, 200), RestaurantType.BAR,
                         flip_coin(0.5), model, '', 'BAR-' + str(i))
        work_district.locations.append(bar)

    # print(home_district)
    # print(work_district)
    # print(school_district)

    # Build families

    family_factory = FamilyFactory(model)
    family_factory.factory(population_size)
    model.global_count.total_population = family_factory.human_count

    # print(family_factory)

    age_group_sets = {
        Infant: [],
        Toddler: [],
        K12Student: [],
        Adult: [],
        Elder: []
    }

    # Allocate buildings to people

    all_adults = []
    all_students = []
    for family in family_factory.families:
        adults = [human for human in family if isinstance(human, Adult)]
        students = [human for human in family if isinstance(human, K12Student)]
        home_district.allocate(family, True, True, True)
        work_district.allocate(adults)
        school_district.allocate(students, True)
        for human in family:
            age_group_sets[type(human)].append(human)
            human.home_district = home_district
            home_district.get_buildings(human)[0].get_unit(
                human).humans.append(human)
        for adult in adults:
            adult.work_district = work_district
            all_adults.append(adult)
        for student in students:
            student.school_district = school_district
            all_students.append(student)

    # Set tribes

    adult_rf = HomophilyRelationshipFactory(model, all_adults)
    student_rf = HomophilyRelationshipFactory(model, all_students)
    # exit()

    count = 0
    for family in family_factory.families:
        for human in family:
            count += 1
            human.tribe[TribeSelector.AGE_GROUP] = age_group_sets[type(human)]
            human.tribe[TribeSelector.FAMILY] = family
            if isinstance(human, Adult):
                human.unique_id = "Adult" + str(count)
                human.tribe[
                    TribeSelector.COWORKER] = work_district.get_buildings(
                        human)[0].get_unit(human).allocation
                t1 = adult_rf.build_tribe(human,
                                          human.tribe[TribeSelector.COWORKER],
                                          1, office_capacity)
                t2 = adult_rf.build_tribe(human,
                                          human.tribe[TribeSelector.AGE_GROUP],
                                          1, 20)
                human.tribe[TribeSelector.FRIEND] = t1
                for h in t2:
                    if h not in human.tribe[TribeSelector.FRIEND]:
                        human.tribe[TribeSelector.FRIEND].append(h)
            elif isinstance(human, K12Student):
                human.unique_id = "K12Student" + str(count)
                human.tribe[
                    TribeSelector.CLASSMATE] = school_district.get_buildings(
                        human)[0].get_unit(human).allocation
                t1 = student_rf.build_tribe(
                    human, human.tribe[TribeSelector.CLASSMATE], 1,
                    classroom_capacity)
                t2 = student_rf.build_tribe(
                    human, human.tribe[TribeSelector.AGE_GROUP], 1, 20)
                human.tribe[TribeSelector.FRIEND] = t1
                for h in t2:
                    if h not in human.tribe[TribeSelector.FRIEND]:
                        human.tribe[TribeSelector.FRIEND].append(h)
            elif isinstance(human, Elder):
                human.unique_id = "Elder" + str(count)
            elif isinstance(human, Infant):
                human.unique_id = "Infant" + str(count)
            elif isinstance(human, Toddler):
                human.unique_id = "Toddler" + str(count)