Skip to content

Commit

Permalink
Remove strict date requirement for campaign
Browse files Browse the repository at this point in the history
  • Loading branch information
charlotte-avery committed Nov 21, 2024
1 parent fa4b6f2 commit bc959fd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
12 changes: 5 additions & 7 deletions simulation/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):

Expand Down Expand Up @@ -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
20 changes: 13 additions & 7 deletions simulation/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -202,24 +206,23 @@ 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
self.boiler_upgrade_scheme_cumulative_spend_gbp += (
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,
Expand Down Expand Up @@ -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],
)


Expand Down Expand Up @@ -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,
Expand All @@ -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,
)
Expand Down
1 change: 1 addition & 0 deletions simulation/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
5 changes: 3 additions & 2 deletions simulation/tests/test_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion simulation/tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit bc959fd

Please sign in to comment.