-
Notifications
You must be signed in to change notification settings - Fork 0
/
environment.py
70 lines (51 loc) · 1.74 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
"""Abstract environment base class for RL-Glue-py.
"""
from __future__ import print_function
from abc import ABCMeta, abstractmethod
class BaseEnvironment:
"""Implements the environment for an RLGlue environment
Note:
env_init, env_start, env_step, env_cleanup, and env_message are required
methods.
"""
__metaclass__ = ABCMeta
def __init__(self):
reward = None
observation = None
termination = None
self.reward_obs_term = (reward, observation, termination)
@abstractmethod
def env_init(self, env_info={}):
"""Setup for the environment called when the experiment first starts.
Note:
Initialize a tuple with the reward, first state observation, boolean
indicating if it's terminal.
"""
@abstractmethod
def env_start(self):
"""The first method called when the experiment starts, called before the
agent starts.
Returns:
The first state observation from the environment.
"""
@abstractmethod
def env_step(self, action):
"""A step taken by the environment.
Args:
action: The action taken by the agent
Returns:
(float, state, Boolean): a tuple of the reward, state observation,
and boolean indicating if it's terminal.
"""
@abstractmethod
def env_cleanup(self):
"""Cleanup done after the environment ends"""
@abstractmethod
def env_message(self, message):
"""A message asking the environment for information
Args:
message: the message passed to the environment
Returns:
the response (or answer) to the message
"""