-
Notifications
You must be signed in to change notification settings - Fork 43
/
baseline1.py
64 lines (44 loc) · 1.5 KB
/
baseline1.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
# Author: Taha Nakabi
from DQN import Environment
PRICES_ACTIONS=[0,0,0,0,1,2,3,4,4,3,2,1,2,1,2,0,0,0,0,0,0,0,0,0]
import numpy as np
REWARDS = {}
for i in range(11):
REWARDS[i]=[]
class Agentb1:
def __init__(self, stateCnt, actionCnt):
self.stateCnt = stateCnt
self.actionCnt = actionCnt
def act(self, s,deter):
return [0,PRICES_ACTIONS[int(s[-1]*24)],1,1]
def observe(self, sample):
pass
def replay(self):
pass
class Environmentb1(Environment):
def __init__(self, render = False):
super().__init__(render)
def run(self, agent, day=None):
s = self.env.reset(day=day)
R = 0
while True:
if self.render: self.env.render(name='baseline1')
a = agent.act(s,deter=self.render)
s_, r, done, info = self.env.step(a)
if done: # terminal state
s_ = None
s = s_
R += r
if done:
if self.render: self.env.render(name='baseline1')
break
REWARDS[self.env.day].append(R)
print("Total reward:", R)
if __name__=="__main__":
env_test=Environmentb1(render=True)
stateCnt = env_test.env.observation_space.shape[0]
actionCnt = env_test.env.action_space.n
agent = Agentb1(stateCnt, actionCnt)
# for day in range(11):
env_test.run(agent,day=3)
# print(np.average([REWARDS[i] for i in range(11)]))