-
Notifications
You must be signed in to change notification settings - Fork 3
/
env.py
executable file
·64 lines (36 loc) · 1.28 KB
/
env.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
import numpy as np
from variables import*
from util import build_state_space, get_data
class Environment(object):
def __init__(self):
self.state_space = build_state_space
pv_values, demands, hours, days, months = get_data()
self.pv_values = pv_values
self.demands = demands
self.hours = hours
self.days = days
self.months = months
def reset(self):
return initial_state, self.state_space(*initial_state)
@staticmethod
def sample_action():
return np.random.choice([0,1, 2])
def step(self, time_step, prev_state_values, action):
if action == 0:
Ac, Ad = 10, 0
elif action == 1:
Ac, Ad = 0, 10
elif action == 2:
Ac, Ad = 0, 0
Eb_t = prev_state_values[1]
Eb_t1 = Eb_t + Ac - Ad
if Eb_t1 < Ebmin:
Eb_t1 = Ebmin
elif Eb_t1 > Ebmax:
Eb_t1 = Ebmax
demand = self.demands[time_step + 1]
pv_value = self.pv_values[time_step + 1]
new_state_values = (pv_value, Eb_t1, demand)
new_state = self.state_space(*new_state_values)
return new_state_values, new_state
# print(Environment().reset())