Exemplo n.º 1
0
def test_global_finite_horizon_optimal_management():
    management = Finite_horizon_optimal_management(resource.index,
                                                   config=config)
    b3 = battery.copy()
    env = Dynamic_environment(b3, resource, management)
    env.set_demand(result_df)
    env.step_over_time()
    env.simulation_result()
Exemplo n.º 2
0
def test_reactive_follow_management():

    management = Reactive_follow_management(demand)
    b2 = battery.copy()
    env = Dynamic_environment(b2, resource, management)
    env.set_demand(result_df)
    env.step_over_time()
    env.simulation_result()
Exemplo n.º 3
0
def test_absolute_follow_managemet():

    management = Absolute_follow_management()
    b1 = battery.copy()
    env = Dynamic_environment(b1, resource, management)
    env.set_demand(result_df)
    env.step_over_time()
    env.simulation_result()
Exemplo n.º 4
0
    def __init__(self, task_name, config=None):
        """
        Initialise simulation environment by task name.

        :param task_name: str name of the task e.g. 'Route-3-2013-01-01-3.pkl'
        """
        with open(task_name, 'rb') as f:
            env_pack = cloudpickle.load(f)
        battery, result_df, resource = env_pack

        battery_copy = battery.copy()
        self.env = Dynamic_environment(battery_copy, resource, None, config=config)
        self.resource = resource
        self.env.set_demand(result_df)
        self.def_space()
Exemplo n.º 5
0
def test_ewm_management():
    management = EWMA_management()
    b4 = battery.copy()
    env = Dynamic_environment(b4, resource, management)
    env.set_demand(result_df)
    env.step_over_time()
    print(env.simulation_result())
    print(env.total_reward)
Exemplo n.º 6
0
class EnergyEnv(gym.Env):
    metadata = {'render.modes': ['human']}

    def __init__(self, task_name, config=None):
        """
        Initialise simulation environment by task name.

        :param task_name: str name of the task e.g. 'Route-3-2013-01-01-3.pkl'
        """
        with open(task_name, 'rb') as f:
            env_pack = cloudpickle.load(f)
        battery, result_df, resource = env_pack

        battery_copy = battery.copy()
        self.env = Dynamic_environment(battery_copy, resource, None, config=config)
        self.resource = resource
        self.env.set_demand(result_df)
        self.def_space()

    def step(self, action):
        """

        Parameters
        ----------
        action :

        Returns
        -------
        ob, reward, episode_over, info : tuple
            ob (object) :
                an environment-specific object representing your observation of
                the environment.
            reward (float) :
                amount of reward achieved by the previous action. The scale
                varies between environments, but the goal is always to increase
                your total reward.
            episode_over (bool) :
                whether it'rlenergy time to reset the environment again. Most (but not
                all) tasks are divided up into well-defined episodes, and done
                being True indicates the episode has terminated. (For example,
                perhaps the pole tipped too far, or you lost your last life.)
            info (dict) :
                 diagnostic information useful for debugging. It can sometimes
                 be useful for learning (for example, it might contain the raw
                 probabilities behind the environment'rlenergy last state change).
                 However, official evaluations of your agent are not allowed to
                 use this for learning.
        """
        ob, reward, done, info = self.env.gym_step(action)
        self.done = done
        if isinstance(reward, np.ndarray):
            reward = reward[0][0]
        return ob, reward, done, info

    def reset(self):
        init_state = self.env.reset()
        # Also return initial state
        return init_state

    def render(self, mode='human', close=False):
        if self.done:
            return self.env.simulation_result()
        else:
            pass

    def def_space(self):
        self.action_space = Box(-1., 1., shape=(1,))
        self.observation_space = Box(-1., 1., shape=(4,))

    def scaler(self):
        return self.env.get_scaler()