-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
executable file
·62 lines (52 loc) · 2.07 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Run this again after editing submodules so Colab uses the updated versions
from citylearn import CityLearn
from pathlib import Path
from TD3 import Agent
import numpy as np
import torch
# Load environment
climate_zone = 5
params = {
"data_path": Path("data/Climate_Zone_" + str(climate_zone)),
"building_attributes": "building_attributes.json",
"weather_file": "weather_data.csv",
"solar_profile": "solar_generation_1kW.csv",
"carbon_intensity": "carbon_intensity.csv",
"building_ids": ["Building_" + str(i) for i in [1, 2, 3, 4, 5, 6, 7, 8, 9]],
"buildings_states_actions": "buildings_state_action_space.json",
"simulation_period": (0, 8760 * 4 - 1),
"cost_function": [
"ramping",
"1-load_factor",
"average_daily_peak",
"peak_demand",
"net_electricity_consumption",
"carbon_emissions",
],
"central_agent": False,
"save_memory": False,
}
# Contain the lower and upper bounds of the states and actions, to be provided to the agent to normalize the variables between 0 and 1.
env = CityLearn(**params)
observations_spaces, actions_spaces = env.get_state_action_spaces()
# Provides information on Building type, Climate Zone, Annual DHW demand, Annual Cooling Demand, Annual Electricity Demand, Solar Capacity, and correllations among buildings
building_info = env.get_building_information()
params_agent = {
"building_ids": ["Building_" + str(i) for i in [1, 2, 3, 4, 5, 6, 7, 8, 9]],
"buildings_states_actions": "buildings_state_action_space.json",
"building_info": building_info,
"observation_spaces": observations_spaces,
"action_spaces": actions_spaces,
}
# Instantiating the control agent(s)
agents = Agent(**params_agent)
state = env.reset()
done = False
while not done:
action, _ = agents.select_action(state)
next_state, reward, done, _ = env.step(action)
agents.add_to_buffer(state, action, reward, next_state, done)
state = next_state
print(f"\r {env.time_step}", end="")
cost = env.cost()
print(cost)