/
LookParam.py
40 lines (33 loc) · 1.89 KB
/
LookParam.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
# Copyright (c) 2019-2020, RTE (https://www.rte-france.com)
# See AUTHORS.txt
# This Source Code Form is subject to the terms of the Mozilla Public License, version 2.0.
# If a copy of the Mozilla Public License, version 2.0 was not distributed with this file,
# you can obtain one at http://mozilla.org/MPL/2.0/.
# SPDX-License-Identifier: MPL-2.0
# This file is part of Grid2Op, Grid2Op a testbed platform to model sequential decision making in power systems.
import numpy as np
from grid2op.Exceptions import IllegalAction
from grid2op.Rules.BaseRules import BaseRules
class LookParam(BaseRules):
"""
This subclass only check that the number of powerlines reconnected / disconnected by the agent.
This class doesn't require any environment information. The "env" argument is only used to look for the
game rules implemented in :class:`grid2op.Parameters`.
See :func:`BaseRules.__call__` for a definition of the parameters of this function.
"""
def __call__(self, action, env):
"""
See :func:`BaseRules.__call__` for a definition of the parameters of this function.
"""
# at first iteration, env.current_obs is None...
powerline_status = env.get_current_line_status()
aff_lines, aff_subs = action.get_topological_impact(powerline_status)
if np.sum(aff_lines) > env.parameters.MAX_LINE_STATUS_CHANGED:
ids = np.where(aff_lines)[0]
return False, IllegalAction("More than {} line status affected by the action: {}"
"".format(env.parameters.MAX_LINE_STATUS_CHANGED, ids))
if np.sum(aff_subs) > env.parameters.MAX_SUB_CHANGED:
ids = np.where(aff_subs)[0]
return False, IllegalAction("More than {} substation affected by the action: {}"
"".format(env.parameters.MAX_SUB_CHANGED, ids))
return True, None