-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_agent.py
157 lines (131 loc) · 4.2 KB
/
test_agent.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import sys
"""
Please use python3+ THIS HASN'T BEEN TESTED w/ python <= 2.7
Colab/Notebook : get python version
>>> from platform import python_version
>>> print(python_version())
"""
try:
from platform import python_version
print("Python Version", python_version())
except:
print("Unable to get python version!")
### testing package installation
try:
import numpy as np
print("numpy version", np.__version__)
except ImportError as error:
print(error.__class__.__name__ + ": " + error.msg)
try:
import pandas as pd
print("pandas version", pd.__version__)
except ImportError as error:
print(error.__class__.__name__ + ": " + error.msg)
try:
import json
print("json version", json.__version__)
except ImportError as error:
print(error.__class__.__name__ + ": " + error.msg)
try:
import torch
print("pytorch version", torch.__version__)
except ImportError as error:
print(error.__class__.__name__ + ": " + error.msg)
try:
import copy
import collections
import time
import warnings
import pathlib
except ImportError as error:
print(error.__class__.__name__ + ": " + error.msg)
try:
import cvxpy as cp
print("cvxpy version", cp.__version__)
except ImportError as error:
print(error.__class__.__name__ + ": " + error.msg)
# from cvxpylayers.torch import CvxpyLayer ## COMMENT THIS IF NEEDED
try:
import sklearn
print("sklearn version", sklearn.__version__)
except ImportError as error:
print(error.__class__.__name__ + ": " + error.msg)
try:
import statsmodels
print("statsmodels version", statsmodels.__version__)
except ImportError as error:
print(error.__class__.__name__ + ": " + error.msg)
### testing RBC agent running
class Agent:
def __init__(self, **parameters):
"""Rule based controller. Source: https://github.com/QasimWani/CityLearn/blob/master/agents/rbc.py"""
self.actions_spaces = parameters["action_spaces"]
def add_to_buffer(
self,
state,
action,
reward,
next_state,
done,
coordination_vars,
coordination_vars_next,
):
pass
def select_action(self, states):
hour_day = states[0][0]
multiplier = 0.4
# Daytime: release stored energy 2*0.08 + 0.1*7 + 0.09
a = [
[0.0 for _ in range(len(self.actions_spaces[i].sample()))]
for i in range(len(self.actions_spaces))
]
if hour_day >= 7 and hour_day <= 11:
a = [
[
-0.05 * multiplier
for _ in range(len(self.actions_spaces[i].sample()))
]
for i in range(len(self.actions_spaces))
]
elif hour_day >= 12 and hour_day <= 15:
a = [
[
-0.05 * multiplier
for _ in range(len(self.actions_spaces[i].sample()))
]
for i in range(len(self.actions_spaces))
]
elif hour_day >= 16 and hour_day <= 18:
a = [
[
-0.11 * multiplier
for _ in range(len(self.actions_spaces[i].sample()))
]
for i in range(len(self.actions_spaces))
]
elif hour_day >= 19 and hour_day <= 22:
a = [
[
-0.06 * multiplier
for _ in range(len(self.actions_spaces[i].sample()))
]
for i in range(len(self.actions_spaces))
]
# Early nightime: store DHW and/or cooling energy
if hour_day >= 23 and hour_day <= 24:
a = [
[
0.085 * multiplier
for _ in range(len(self.actions_spaces[i].sample()))
]
for i in range(len(self.actions_spaces))
]
elif hour_day >= 1 and hour_day <= 6:
a = [
[
0.1383 * multiplier
for _ in range(len(self.actions_spaces[i].sample()))
]
for i in range(len(self.actions_spaces))
]
return np.array(a, dtype="object"), None