forked from farismismar/Deep-Q-Learning-SON-Perf-Improvement
-
Notifications
You must be signed in to change notification settings - Fork 0
/
environment.py
54 lines (38 loc) · 1.35 KB
/
environment.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jun 5 17:26:31 2017
@author: farismismar
"""
import math
from gym import spaces, logger
from gym.utils import seeding
import numpy as np
# An attempt to follow
# https://github.com/openai/gym/blob/master/gym/envs/classic_control/cartpole.py
class SON_environment:
def __init__(self, seed):
self.num_states = 3
self.num_actions = 6
self.action_space = spaces.Discrete(self.num_actions) # action size is here
self.observation_space = spaces.Discrete(self.num_states) # action size is here
self.seed(seed=seed)
self.step_count = 0 # which step
self.state = 0
def seed(self, seed=None):
self.np_random, seed = seeding.np_random(seed)
return [seed]
def reset(self):
self.state = 0
self.step_count = 0
return np.array(self.state)
def close(self):
self.reset()
def step(self, action):
# Check if action is integer
# if isinstance(action, np.ndarray):
# action = action[0]
# Update the state based on the action
# This is handled by Matlab's function.
self.step_count += 1
return self.state, None, None, None