diff --git a/simulation/agents.py b/simulation/agents.py index 3647d26..220d99f 100644 --- a/simulation/agents.py +++ b/simulation/agents.py @@ -619,14 +619,13 @@ def proba_of_becoming_heat_pump_aware_required_to_reach_campaign_target( self, model ) -> float: return ( - model.campaign_target_heat_pump_awareness - model.heat_pump_awareness - ) / (1 - model.heat_pump_awareness) + model.campaign_target_heat_pump_awareness - model.heat_pump_awareness_at_timestep + ) / (1 - model.heat_pump_awareness_at_timestep) def update_heat_pump_awareness(self, model) -> None: - if ( InterventionType.HEAT_PUMP_CAMPAIGN in model.interventions - and model.current_datetime == model.heat_pump_awareness_campaign_date + and model.current_datetime >= model.heat_pump_awareness_campaign_date and model.heat_pump_awareness_at_timestep < model.campaign_target_heat_pump_awareness and not self.is_heat_pump_aware @@ -637,6 +636,8 @@ def update_heat_pump_awareness(self, model) -> None: self.is_heat_pump_aware = true_with_probability( proba_to_become_heat_pump_aware ) + if self.is_heat_pump_aware: + model.num_households_switching_to_heat_pump_aware += 1 def make_decisions(self, model): @@ -714,6 +715,3 @@ def make_decisions(self, model): self.heating_system_costs_subsidies = costs_subsidies self.heating_system_costs_insulation = costs_insulation self.insulation_element_upgrade_costs = chosen_insulation_costs - - if self.is_heat_pump_aware: - model.households_heat_pump_aware_at_current_step += 1 diff --git a/simulation/model.py b/simulation/model.py index 07f6f9a..76f67ae 100644 --- a/simulation/model.py +++ b/simulation/model.py @@ -49,6 +49,7 @@ def __init__( heat_pump_awareness: float, campaign_target_heat_pump_awareness: float, heat_pump_awareness_campaign_date: datetime.datetime, + population_heat_pump_awareness: List[bool], ): self.start_datetime = start_datetime self.step_interval = step_interval @@ -80,7 +81,10 @@ def __init__( self.heat_pump_awareness = heat_pump_awareness self.campaign_target_heat_pump_awareness = campaign_target_heat_pump_awareness self.heat_pump_awareness_campaign_date = heat_pump_awareness_campaign_date - self.households_heat_pump_aware_at_current_step = 0 + + self.population_heat_pump_awareness = population_heat_pump_awareness + self.num_households_heat_pump_aware = sum(population_heat_pump_awareness) + self.num_households_switching_to_heat_pump_aware = 0 super().__init__(UnorderedSpace()) @@ -202,7 +206,7 @@ def boiler_upgrade_scheme_spend_gbp(self) -> int: @property def heat_pump_awareness_at_timestep(self) -> float: - return self.households_heat_pump_aware_at_current_step / self.household_count + return (self.num_households_heat_pump_aware + self.num_households_switching_to_heat_pump_aware) / self.household_count def increment_timestep(self): self.current_datetime += self.step_interval @@ -210,16 +214,15 @@ def increment_timestep(self): self.boiler_upgrade_scheme_spend_gbp ) self.heat_pump_installations_at_current_step = 0 - self.households_heat_pump_aware_at_current_step = 0 def create_household_agents( household_population: pd.DataFrame, - heat_pump_awareness: float, + population_heat_pump_awareness: List[bool], simulation_start_datetime: datetime.datetime, all_agents_heat_pump_suitable: bool, ) -> Iterator[Household]: - for household in household_population.itertuples(): + for i, household in enumerate(household_population.itertuples()): yield Household( id=household.id, location=household.location, @@ -248,7 +251,7 @@ def create_household_agents( is_heat_pump_suitable_archetype=True if all_agents_heat_pump_suitable else household.is_heat_pump_suitable_archetype, - is_heat_pump_aware=random.random() < heat_pump_awareness, + is_heat_pump_aware=population_heat_pump_awareness[i], ) @@ -279,6 +282,8 @@ def create_and_run_simulation( heat_pump_awareness_campaign_date: datetime.datetime, ): + population_heat_pump_awareness = [random.random() < heat_pump_awareness for _ in range(len(household_population))] + model = DomesticHeatingABM( start_datetime=start_datetime, step_interval=step_interval, @@ -299,11 +304,12 @@ def create_and_run_simulation( heat_pump_awareness=heat_pump_awareness, campaign_target_heat_pump_awareness=campaign_target_heat_pump_awareness, heat_pump_awareness_campaign_date=heat_pump_awareness_campaign_date, + population_heat_pump_awareness=population_heat_pump_awareness, ) households = create_household_agents( household_population, - heat_pump_awareness, + population_heat_pump_awareness, model.start_datetime, all_agents_heat_pump_suitable, ) diff --git a/simulation/tests/common.py b/simulation/tests/common.py index c45d921..a27ae6c 100644 --- a/simulation/tests/common.py +++ b/simulation/tests/common.py @@ -60,6 +60,7 @@ def model_factory(**model_attributes): "heat_pump_awareness": 0.5, "campaign_target_heat_pump_awareness": 0.8, "heat_pump_awareness_campaign_date": datetime.datetime(2028, 1, 1), + "population_heat_pump_awareness": [], } return DomesticHeatingABM(**{**default_values, **model_attributes}) diff --git a/simulation/tests/test_agents.py b/simulation/tests/test_agents.py index b42b84f..56cc183 100644 --- a/simulation/tests/test_agents.py +++ b/simulation/tests/test_agents.py @@ -752,8 +752,9 @@ def test_heat_pump_awareness_does_not_increase_when_campaign_target_is_same_as_c step_interval=relativedelta(months=1), interventions=[InterventionType.HEAT_PUMP_CAMPAIGN], heat_pump_awareness_campaign_date=datetime.datetime(2025, 2, 1), - heat_pump_awareness=0.5, - campaign_target_heat_pump_awareness=0.5, + heat_pump_awareness=0.0, + campaign_target_heat_pump_awareness=0.0, + population_heat_pump_awareness=[False], ) agent = household_factory(is_heat_pump_aware=False) model.add_agents([agent]) diff --git a/simulation/tests/test_model.py b/simulation/tests/test_model.py index eb40441..1df77fb 100644 --- a/simulation/tests/test_model.py +++ b/simulation/tests/test_model.py @@ -267,7 +267,7 @@ def test_create_household_agents() -> None: "is_heat_pump_suitable_archetype": [True], } ) - heat_pump_awareness = 0.4 + heat_pump_awareness = [True] simulation_start_datetime = datetime.datetime.now() all_agents_heat_pump_suitable = False household_agents = create_household_agents(