示例#1
0
    def setUp(self):
        self.backend = PandaPowerBackend(
            detailed_infos_for_cascading_failures=True)
        self.path_matpower = PATH_DATA_TEST
        self.case_file = "test_case14.json"
        self.backend.load_grid(self.path_matpower, self.case_file)
        self.tolvect = 1e-2
        self.tol_one = 1e-5
        self.game_rules = GameRules()
        self.action_env = HelperAction(
            gridobj=self.backend, legal_action=self.game_rules.legal_action)

        self.lines_flows_init = np.array([
            638.28966637, 305.05042301, 17658.9674809, 26534.04334098,
            10869.23856329, 4686.71726729, 15612.65903298, 300.07915572,
            229.8060832, 169.97292682, 100.40192958, 265.47505664,
            21193.86923911, 21216.44452327, 49701.1565287, 124.79684388,
            67.59759985, 192.19424706, 666.76961936, 1113.52773632
        ])
        # _parameters for the environment
        self.env_params = Parameters()

        # used for init an env too
        self.chronics_handler = ChronicsHandler()
        self.id_first_line_disco = 8  # due to hard overflow
        self.id_2nd_line_disco = 11  # due to soft overflow
示例#2
0
 def setUp(self):
     self.backend = PandaPowerBackend()
     self.path_matpower = PATH_DATA_TEST
     self.case_file = "test_case14.json"
     self.backend.load_grid(self.path_matpower, self.case_file)
     self.tolvect = 1e-2
     self.tol_one = 1e-5
     self.game_rules = GameRules()
     self.action_env = HelperAction(name_prod=self.backend.name_prods,
                                    name_load=self.backend.name_loads,
                                    name_line=self.backend.name_lines,
                               subs_info=self.backend.subs_elements,
                               load_to_subid=self.backend.load_to_subid,
                               gen_to_subid=self.backend.gen_to_subid,
                               lines_or_to_subid=self.backend.lines_or_to_subid,
                               lines_ex_to_subid=self.backend.lines_ex_to_subid, #####
                               load_to_sub_pos=self.backend.load_to_sub_pos,
                               gen_to_sub_pos=self.backend.gen_to_sub_pos,
                               lines_or_to_sub_pos=self.backend.lines_or_to_sub_pos,
                               lines_ex_to_sub_pos=self.backend.lines_ex_to_sub_pos, #####
                               load_pos_topo_vect=self.backend.load_pos_topo_vect,
                               gen_pos_topo_vect=self.backend.gen_pos_topo_vect,
                               lines_or_pos_topo_vect=self.backend.lines_or_pos_topo_vect,
                               lines_ex_pos_topo_vect=self.backend.lines_ex_pos_topo_vect,
                                    game_rules=self.game_rules)
示例#3
0
 def setUp(self):
     self.backend = PandaPowerBackend()
     self.path_matpower = PATH_DATA_TEST
     self.case_file = "test_case14.json"
     self.backend.load_grid(self.path_matpower, self.case_file)
     self.tolvect = 1e-2
     self.tol_one = 1e-5
     self.game_rules = GameRules()
     self.action_env = HelperAction(
         gridobj=self.backend, legal_action=self.game_rules.legal_action)
示例#4
0
 def setUp(self):
     """
     The case file is a representation of the case14 as found in the ieee14 powergrid.
     :return:
     """
     # from ADNBackend import ADNBackend
     # self.backend = ADNBackend()
     # self.path_matpower = "/home/donnotben/Documents/RL4Grid/RL4Grid/data"
     # self.case_file = "ieee14_ADN.xml"
     # self.backend.load_grid(self.path_matpower, self.case_file)
     self.tolvect = 1e-2
     self.tol_one = 1e-5
     self.game_rules = GameRules()
     # pdb.set_trace()
     self.helper_action = HelperAction(
         name_prod=["gen_{}".format(i) for i in range(5)],
         name_load=["load_{}".format(i) for i in range(11)],
         name_line=["line_{}".format(i) for i in range(20)],
         subs_info=np.array([3, 6, 4, 6, 5, 6, 3, 2, 5, 3, 3, 3, 4, 3],
                            dtype=np.int),
         load_to_subid=np.array([1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13]),
         gen_to_subid=np.array([0, 1, 2, 5, 7]),
         lines_or_to_subid=np.array(
             [0, 0, 1, 1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 6, 8, 8, 9, 11,
              12]),
         lines_ex_to_subid=np.array([
             1, 4, 2, 3, 4, 3, 4, 6, 8, 5, 10, 11, 12, 7, 8, 9, 13, 10, 12,
             13
         ]),  #####
         load_to_sub_pos=np.array([4, 2, 5, 4, 4, 4, 1, 1, 1, 2, 1]),
         gen_to_sub_pos=np.array([2, 5, 3, 5, 1]),
         lines_or_to_sub_pos=np.array(
             [0, 1, 1, 2, 3, 1, 2, 3, 4, 3, 1, 2, 3, 1, 2, 2, 3, 0, 0, 1]),
         lines_ex_to_sub_pos=np.array(
             [0, 0, 0, 0, 1, 1, 2, 0, 0, 0, 2, 2, 3, 0, 1, 2, 2, 0, 0,
              0]),  #####
         load_pos_topo_vect=np.array(
             [7, 11, 18, 23, 28, 39, 41, 44, 47, 51, 54]),
         gen_pos_topo_vect=np.array([2, 8, 12, 29, 34]),
         lines_or_pos_topo_vect=np.array([
             0, 1, 4, 5, 6, 10, 15, 16, 17, 22, 25, 26, 27, 31, 32, 37, 38,
             40, 46, 50
         ]),
         lines_ex_pos_topo_vect=np.array([
             3, 19, 9, 13, 20, 14, 21, 30, 35, 24, 45, 48, 52, 33, 36, 42,
             55, 43, 49, 53
         ]),
         game_rules=self.game_rules)
示例#5
0
    def __init__(self, gridobj, controler_backend):
        """

        Parameters
        ----------
        gridobj: :class:`grid2op.Space.Space`
            Structure of the powergrid

        envbackend: :class:`grid2op.Backend.Backend`
            An instanciated backend to perform some computation on a powergrid, before taking some actions.

        """
        legal_act = AllwaysLegal()
        self.action_space = HelperAction(gridobj=gridobj,
                                         actionClass=VoltageOnlyAction,
                                         legal_action=legal_act)
        self.backend = controler_backend.copy()
示例#6
0
    def init_backend(self, init_grid_path, chronics_handler, backend,
                     names_chronics_to_backend, actionClass, observationClass,
                     rewardClass, legalActClass):

        if not isinstance(rewardClass, type):
            raise Grid2OpException(
                "Parameter \"rewardClass\" used to build the Environment should be a type (a class) "
                "and not an object (an instance of a class). "
                "It is currently \"{}\"".format(type(rewardClass)))
        if not issubclass(rewardClass, Reward):
            raise Grid2OpException(
                "Parameter \"rewardClass\" used to build the Environment should derived form the grid2op.Reward class, "
                "type provided is \"{}\"".format(type(rewardClass)))
        self.rewardClass = rewardClass
        self.actionClass = actionClass
        self.observationClass = observationClass

        # backend
        self.init_grid_path = os.path.abspath(init_grid_path)

        if not isinstance(backend, Backend):
            raise Grid2OpException(
                "Parameter \"backend\" used to build the Environment should derived form the grid2op.Backend class, "
                "type provided is \"{}\"".format(type(backend)))
        self.backend = backend
        self.backend.load_grid(
            self.init_grid_path)  # the real powergrid of the environment

        self.backend.load_redispacthing_data(
            os.path.split(self.init_grid_path)[0])
        self.backend.assert_grid_correct()
        self.init_grid(backend)
        self._has_been_initialized()
        if self._thermal_limit_a is None:
            self._thermal_limit_a = self.backend.thermal_limit_a
        else:
            self.backend.set_thermal_limit(self._thermal_limit_a)

        *_, tmp = self.backend.generators_info()

        # rules of the game
        if not isinstance(legalActClass, type):
            raise Grid2OpException(
                "Parameter \"legalActClass\" used to build the Environment should be a type "
                "(a class) and not an object (an instance of a class). "
                "It is currently \"{}\"".format(type(legalActClass)))
        if not issubclass(legalActClass, LegalAction):
            raise Grid2OpException(
                "Parameter \"legalActClass\" used to build the Environment should derived form the "
                "grid2op.LegalAction class, type provided is \"{}\"".format(
                    type(legalActClass)))
        self.game_rules = GameRules(legalActClass=legalActClass)
        self.legalActClass = legalActClass

        # action helper
        if not isinstance(actionClass, type):
            raise Grid2OpException(
                "Parameter \"actionClass\" used to build the Environment should be a type (a class) "
                "and not an object (an instance of a class). "
                "It is currently \"{}\"".format(type(legalActClass)))
        if not issubclass(actionClass, Action):
            raise Grid2OpException(
                "Parameter \"actionClass\" used to build the Environment should derived form the "
                "grid2op.Action class, type provided is \"{}\"".format(
                    type(actionClass)))

        if not isinstance(observationClass, type):
            raise Grid2OpException(
                "Parameter \"actionClass\" used to build the Environment should be a type (a class) "
                "and not an object (an instance of a class). "
                "It is currently \"{}\"".format(type(legalActClass)))
        if not issubclass(observationClass, Observation):
            raise Grid2OpException(
                "Parameter \"observationClass\" used to build the Environment should derived form the "
                "grid2op.Observation class, type provided is \"{}\"".format(
                    type(observationClass)))

        # action affecting the grid that will be made by the agent
        self.helper_action_player = HelperAction(
            gridobj=self.backend,
            actionClass=actionClass,
            legal_action=self.game_rules.legal_action)

        # action that affect the grid made by the environment.
        self.helper_action_env = HelperAction(
            gridobj=self.backend,
            actionClass=Action,
            legal_action=self.game_rules.legal_action)

        self.helper_observation = ObservationHelper(
            gridobj=self.backend,
            observationClass=observationClass,
            rewardClass=rewardClass,
            env=self)

        # handles input data
        if not isinstance(chronics_handler, ChronicsHandler):
            raise Grid2OpException(
                "Parameter \"chronics_handler\" used to build the Environment should derived form the "
                "grid2op.ChronicsHandler class, type provided is \"{}\"".
                format(type(chronics_handler)))
        self.chronics_handler = chronics_handler
        self.chronics_handler.initialize(
            self.name_load,
            self.name_gen,
            self.name_line,
            self.name_sub,
            names_chronics_to_backend=names_chronics_to_backend)
        self.names_chronics_to_backend = names_chronics_to_backend

        # test to make sure the backend is consistent with the chronics generator
        self.chronics_handler.check_validity(self.backend)

        # reward function
        self.reward_helper = RewardHelper(rewardClass=rewardClass)
        self.reward_helper.initialize(self)

        # controler for voltage
        if not issubclass(self.voltagecontrolerClass, ControlVoltageFromFile):
            raise Grid2OpException(
                "Parameter \"voltagecontrolClass\" should derive from \"ControlVoltageFromFile\"."
            )

        self.voltage_controler = self.voltagecontrolerClass(
            gridobj=self.backend, controler_backend=self.backend)

        # performs one step to load the environment properly (first action need to be taken at first time step after
        # first injections given)
        self._reset_maintenance()
        do_nothing = self.helper_action_env({})
        *_, fail_to_start, _ = self.step(do_nothing)
        if fail_to_start:
            raise Grid2OpException(
                "Impossible to initialize the powergrid, the powerflow diverge at iteration 0."
            )

        # test the backend returns object of the proper size
        self.backend.assert_grid_correct_after_powerflow()

        # for gym compatibility
        self.action_space = self.helper_action_player  # this should be an action !!!
        self.observation_space = self.helper_observation  # this return an observation.
        self.reward_range = self.reward_helper.range()
        self.viewer = None

        self.metadata = {'render.modes': ["human", "rgb_array"]}
        self.spec = None

        self.current_reward = self.reward_range[0]
        self.done = False
        self._reset_vectors_and_timings()
示例#7
0
    def __init__(self,
                 init_grid_path: str,
                 chronics_handler,
                 backend,
                 parameters,
                 names_chronics_to_backend=None,
                 actionClass=TopologyAction,
                 observationClass=CompleteObservation,
                 rewardClass=FlatReward,
                 legalActClass=AllwaysLegal):
        """
        Initialize the environment. See the descirption of :class:`grid2op.Environment.Environment` for more information.

        Parameters
        ----------
        init_grid_path: ``str``
            Used to initailize :attr:`Environment.init_grid_path`

        chronics_handler
        backend
        parameters
        names_chronics_to_backend
        actionClass
        observationClass
        rewardClass
        legalActClass
        """
        # TODO documentation!!

        # some timers
        self._time_apply_act = 0
        self._time_powerflow = 0
        self._time_extract_obs = 0

        # define logger
        self.logger = None

        # and calendar data
        self.time_stamp = None
        self.nb_time_step = 0

        # specific to power system
        if not isinstance(parameters, Parameters):
            raise Grid2OpException(
                "Parameter \"parameters\" used to build the Environment should derived form the "
                "grid2op.Parameters class, type provided is \"{}\"".format(
                    type(parameters)))
        self.parameters = parameters

        if not isinstance(rewardClass, type):
            raise Grid2OpException(
                "Parameter \"rewardClass\" used to build the Environment should be a type (a class) "
                "and not an object (an instance of a class). "
                "It is currently \"{}\"".format(type(rewardClass)))
        if not issubclass(rewardClass, Reward):
            raise Grid2OpException(
                "Parameter \"rewardClass\" used to build the Environment should derived form the grid2op.Reward class, "
                "type provided is \"{}\"".format(type(rewardClass)))
        self.rewardClass = rewardClass

        # backend
        self.init_grid_path = os.path.abspath(init_grid_path)

        if not isinstance(backend, Backend):
            raise Grid2OpException(
                "Parameter \"backend\" used to build the Environment should derived form the grid2op.Backend class, "
                "type provided is \"{}\"".format(type(backend)))
        self.backend = backend
        self.backend.load_grid(
            self.init_grid_path)  # the real powergrid of the environment
        self.backend.assert_grid_correct()
        *_, tmp = self.backend.generators_info()

        # rules of the game
        if not isinstance(legalActClass, type):
            raise Grid2OpException(
                "Parameter \"legalActClass\" used to build the Environment should be a type "
                "(a class) and not an object (an instance of a class). "
                "It is currently \"{}\"".format(type(legalActClass)))
        if not issubclass(legalActClass, LegalAction):
            raise Grid2OpException(
                "Parameter \"legalActClass\" used to build the Environment should derived form the "
                "grid2op.LegalAction class, type provided is \"{}\"".format(
                    type(legalActClass)))
        self.game_rules = GameRules(legalActClass=legalActClass)

        # action helper
        if not isinstance(actionClass, type):
            raise Grid2OpException(
                "Parameter \"actionClass\" used to build the Environment should be a type (a class) "
                "and not an object (an instance of a class). "
                "It is currently \"{}\"".format(type(legalActClass)))
        if not issubclass(actionClass, Action):
            raise Grid2OpException(
                "Parameter \"actionClass\" used to build the Environment should derived form the "
                "grid2op.Action class, type provided is \"{}\"".format(
                    type(actionClass)))

        if not isinstance(observationClass, type):
            raise Grid2OpException(
                "Parameter \"actionClass\" used to build the Environment should be a type (a class) "
                "and not an object (an instance of a class). "
                "It is currently \"{}\"".format(type(legalActClass)))
        if not issubclass(observationClass, Observation):
            raise Grid2OpException(
                "Parameter \"observationClass\" used to build the Environment should derived form the "
                "grid2op.Observation class, type provided is \"{}\"".format(
                    type(observationClass)))

        # action affecting the _grid that will be made by the agent
        self.helper_action_player = HelperAction(gridobj=self.backend,
                                                 actionClass=actionClass,
                                                 game_rules=self.game_rules)

        # action that affect the _grid made by the environment.
        self.helper_action_env = HelperAction(gridobj=self.backend,
                                              actionClass=Action,
                                              game_rules=self.game_rules)

        self.helper_observation = ObservationHelper(
            gridobj=self.backend,
            observationClass=observationClass,
            rewardClass=rewardClass,
            env=self)
        # observation
        self.current_obs = None

        # type of power flow to play
        # if True, then it will not disconnect lines above their thermal limits
        self.no_overflow_disconnection = self.parameters.NO_OVERFLOW_DISCONNECTION
        self.timestep_overflow = np.zeros(shape=(self.backend.n_line, ),
                                          dtype=np.int)
        self.nb_timestep_overflow_allowed = np.full(
            shape=(self.backend.n_line, ),
            fill_value=self.parameters.NB_TIMESTEP_POWERFLOW_ALLOWED)
        # store actions "cooldown"
        self.times_before_line_status_actionable = np.zeros(
            shape=(self.backend.n_line, ), dtype=np.int)
        self.max_timestep_line_status_deactivated = self.parameters.NB_TIMESTEP_LINE_STATUS_REMODIF

        self.times_before_topology_actionable = np.zeros(
            shape=(self.backend.n_sub, ), dtype=np.int)
        self.max_timestep_topology_deactivated = self.parameters.NB_TIMESTEP_TOPOLOGY_REMODIF

        # for maintenance operation
        self.time_next_maintenance = np.zeros(shape=(self.backend.n_line, ),
                                              dtype=np.int) - 1
        self.duration_next_maintenance = np.zeros(
            shape=(self.backend.n_line, ), dtype=np.int)

        # hazard (not used outside of this class, information is given in `time_remaining_before_line_reconnection`
        self._hazard_duration = np.zeros(shape=(self.backend.n_line, ),
                                         dtype=np.int)

        # hard overflow part
        self.hard_overflow_threshold = self.parameters.HARD_OVERFLOW_THRESHOLD
        self.time_remaining_before_line_reconnection = np.full(
            shape=(self.backend.n_line, ), fill_value=0, dtype=np.int)
        self.env_dc = self.parameters.ENV_DC

        # handles input data
        if not isinstance(chronics_handler, ChronicsHandler):
            raise Grid2OpException(
                "Parameter \"chronics_handler\" used to build the Environment should derived form the "
                "grid2op.ChronicsHandler class, type provided is \"{}\"".
                format(type(chronics_handler)))
        self.chronics_handler = chronics_handler
        self.chronics_handler.initialize(
            self.backend.name_load,
            self.backend.name_gen,
            self.backend.name_line,
            self.backend.name_sub,
            names_chronics_to_backend=names_chronics_to_backend)
        self.names_chronics_to_backend = names_chronics_to_backend

        # test to make sure the backend is consistent with the chronics generator
        self.chronics_handler.check_validity(self.backend)

        # store environment modifications
        self._injection = None
        self._maintenance = None
        self._hazards = None
        self.env_modification = None

        # reward
        self.reward_helper = RewardHelper(rewardClass=rewardClass)
        self.reward_helper.initialize(self)

        # performs one step to load the environment properly (first action need to be taken at first time step after
        # first injections given)
        self._reset_maintenance()
        do_nothing = self.helper_action_env({})
        *_, fail_to_start, _ = self.step(do_nothing)
        if fail_to_start:
            raise Grid2OpException(
                "Impossible to initialize the powergrid, the powerflow diverge at iteration 0."
            )

        # test the backend returns object of the proper size
        self.backend.assert_grid_correct_after_powerflow()

        # for gym compatibility
        self.action_space = self.helper_action_player  # this should be an action !!!
        self.observation_space = self.helper_observation  # this return an observation.
        self.reward_range = self.reward_helper.range()
        self.viewer = None

        self.metadata = {'render.modes': []}
        self.spec = None

        self._reset_vectors_and_timings()
示例#8
0
    def setUp(self):
        """
        The case file is a representation of the case14 as found in the ieee14 powergrid.
        :return:
        """
        self.tolvect = 1e-2
        self.tol_one = 1e-5
        self.game_rules = GameRules()
        self.gridobj = GridObjects()
        self.gridobj.init_grid_vect(
            name_prod=["gen_{}".format(i) for i in range(5)],
            name_load=["load_{}".format(i) for i in range(11)],
            name_line=["line_{}".format(i) for i in range(20)],
            name_sub=["sub_{}".format(i) for i in range(14)],
            sub_info=np.array([3, 6, 4, 6, 5, 6, 3, 2, 5, 3, 3, 3, 4, 3],
                              dtype=np.int),
            load_to_subid=np.array([1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13]),
            gen_to_subid=np.array([0, 1, 2, 5, 7]),
            line_or_to_subid=np.array(
                [0, 0, 1, 1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 6, 8, 8, 9, 11,
                 12]),
            line_ex_to_subid=np.array([
                1, 4, 2, 3, 4, 3, 4, 6, 8, 5, 10, 11, 12, 7, 8, 9, 13, 10, 12,
                13
            ]),  #####
            load_to_sub_pos=np.array([4, 2, 5, 4, 4, 4, 1, 1, 1, 2, 1]),
            gen_to_sub_pos=np.array([2, 5, 3, 5, 1]),
            line_or_to_sub_pos=np.array(
                [0, 1, 1, 2, 3, 1, 2, 3, 4, 3, 1, 2, 3, 1, 2, 2, 3, 0, 0, 1]),
            line_ex_to_sub_pos=np.array(
                [0, 0, 0, 0, 1, 1, 2, 0, 0, 0, 2, 2, 3, 0, 1, 2, 2, 0, 0,
                 0]),  #####
            load_pos_topo_vect=np.array(
                [7, 11, 18, 23, 28, 39, 41, 44, 47, 51, 54]),
            gen_pos_topo_vect=np.array([2, 8, 12, 29, 34]),
            line_or_pos_topo_vect=np.array([
                0, 1, 4, 5, 6, 10, 15, 16, 17, 22, 25, 26, 27, 31, 32, 37, 38,
                40, 46, 50
            ]),
            line_ex_pos_topo_vect=np.array([
                3, 19, 9, 13, 20, 14, 21, 30, 35, 24, 45, 48, 52, 33, 36, 42,
                55, 43, 49, 53
            ]))
        # pdb.set_trace()
        self.helper_action = HelperAction(
            self.gridobj, legal_action=self.game_rules.legal_action)

        self.helper_action_env = HelperAction(
            self.gridobj,
            legal_action=self.game_rules.legal_action,
            actionClass=Action)

        self.res = {
            'name_gen': ['gen_0', 'gen_1', 'gen_2', 'gen_3', 'gen_4'],
            'name_load': [
                'load_0', 'load_1', 'load_2', 'load_3', 'load_4', 'load_5',
                'load_6', 'load_7', 'load_8', 'load_9', 'load_10'
            ],
            'name_line': [
                'line_0', 'line_1', 'line_2', 'line_3', 'line_4', 'line_5',
                'line_6', 'line_7', 'line_8', 'line_9', 'line_10', 'line_11',
                'line_12', 'line_13', 'line_14', 'line_15', 'line_16',
                'line_17', 'line_18', 'line_19'
            ],
            'name_sub': [
                'sub_0', 'sub_1', 'sub_2', 'sub_3', 'sub_4', 'sub_5', 'sub_6',
                'sub_7', 'sub_8', 'sub_9', 'sub_10', 'sub_11', 'sub_12',
                'sub_13'
            ],
            'sub_info': [3, 6, 4, 6, 5, 6, 3, 2, 5, 3, 3, 3, 4, 3],
            'load_to_subid': [1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13],
            'gen_to_subid': [0, 1, 2, 5, 7],
            'line_or_to_subid':
            [0, 0, 1, 1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 6, 8, 8, 9, 11, 12],
            'line_ex_to_subid': [
                1, 4, 2, 3, 4, 3, 4, 6, 8, 5, 10, 11, 12, 7, 8, 9, 13, 10, 12,
                13
            ],
            'load_to_sub_pos': [4, 2, 5, 4, 4, 4, 1, 1, 1, 2, 1],
            'gen_to_sub_pos': [2, 5, 3, 5, 1],
            'line_or_to_sub_pos':
            [0, 1, 1, 2, 3, 1, 2, 3, 4, 3, 1, 2, 3, 1, 2, 2, 3, 0, 0, 1],
            'line_ex_to_sub_pos':
            [0, 0, 0, 0, 1, 1, 2, 0, 0, 0, 2, 2, 3, 0, 1, 2, 2, 0, 0, 0],
            'load_pos_topo_vect': [7, 11, 18, 23, 28, 39, 41, 44, 47, 51, 54],
            'gen_pos_topo_vect': [2, 8, 12, 29, 34],
            'line_or_pos_topo_vect': [
                0, 1, 4, 5, 6, 10, 15, 16, 17, 22, 25, 26, 27, 31, 32, 37, 38,
                40, 46, 50
            ],
            'line_ex_pos_topo_vect': [
                3, 19, 9, 13, 20, 14, 21, 30, 35, 24, 45, 48, 52, 33, 36, 42,
                55, 43, 49, 53
            ],
            'gen_type':
            None,
            'gen_pmin':
            None,
            'gen_pmax':
            None,
            'gen_redispatchable':
            None,
            'gen_max_ramp_up':
            None,
            'gen_max_ramp_down':
            None,
            'gen_min_uptime':
            None,
            'gen_min_downtime':
            None,
            'gen_cost_per_MW':
            None,
            'gen_startup_cost':
            None,
            'gen_shutdown_cost':
            None,
            'subtype':
            'Action.Action'
        }

        self.size_act = 229
示例#9
0
    def setUp(self):
        """
        The case file is a representation of the case14 as found in the ieee14 powergrid.
        :return:
        """
        # from ADNBackend import ADNBackend
        # self.backend = ADNBackend()
        # self.path_matpower = "/home/donnotben/Documents/RL4Grid/RL4Grid/data"
        # self.case_file = "ieee14_ADN.xml"
        # self.backend.load_grid(self.path_matpower, self.case_file)
        self.tolvect = 1e-2
        self.tol_one = 1e-5
        self.game_rules = GameRules()
        self.gridobj = GridObjects()
        self.gridobj.init_grid_vect(name_prod=["gen_{}".format(i) for i in range(5)],
                                          name_load=["load_{}".format(i) for i in range(11)],
                                          name_line=["line_{}".format(i) for i in range(20)],
                                          name_sub=["sub_{}".format(i) for i in range(14)],
                                          sub_info=np.array([3, 6, 4, 6, 5, 6, 3, 2, 5, 3, 3, 3, 4, 3], dtype=np.int),
                                          load_to_subid=np.array([1,  2,  3,  4,  5,  8,  9, 10, 11, 12, 13]),
                                          gen_to_subid=np.array([0, 1, 2, 5, 7]),
                                          line_or_to_subid=np.array([ 0,  0,  1,  1,  1,  2,  3,  3,  3,  4,  5,  5,
                                                                       5,  6,  6,  8,  8, 9, 11, 12]),
                                          line_ex_to_subid=np.array([ 1,  4,  2,  3,  4,  3,  4,  6,  8,  5, 10, 11,
                                                                       12,  7,  8,  9, 13, 10, 12, 13]),  #####
                                          load_to_sub_pos=np.array([4, 2, 5, 4, 4, 4, 1, 1, 1, 2, 1]),
                                          gen_to_sub_pos=np.array([2, 5, 3, 5, 1]),
                                          line_or_to_sub_pos=np.array([0, 1, 1, 2, 3, 1, 2, 3, 4, 3, 1, 2, 3, 1, 2, 2,
                                                                        3, 0, 0, 1]),
                                          line_ex_to_sub_pos=np.array([0, 0, 0, 0, 1, 1, 2, 0, 0, 0, 2, 2, 3, 0, 1, 2, 2, 0, 0, 0]),  #####
                                          load_pos_topo_vect=np.array([ 7, 11, 18, 23, 28, 39, 41, 44, 47, 51, 54]),
                                          gen_pos_topo_vect=np.array([ 2,  8, 12, 29, 34]),
                                          line_or_pos_topo_vect=np.array([ 0,  1,  4,  5,  6, 10, 15, 16, 17, 22, 25, 26, 27, 31, 32, 37, 38, 40, 46, 50]),
                                          line_ex_pos_topo_vect=np.array([ 3, 19,  9, 13, 20, 14, 21, 30, 35, 24, 45, 48, 52, 33, 36, 42, 55, 43, 49, 53]))
        # pdb.set_trace()
        self.helper_action = HelperAction(self.gridobj,
                                          game_rules=self.game_rules)


        self.helper_action_env = HelperAction(self.gridobj,
                                              game_rules=self.game_rules,
                                              actionClass=Action)

        self.res = {'name_gen': ['gen_0', 'gen_1', 'gen_2', 'gen_3', 'gen_4'],
               'name_load': ['load_0', 'load_1', 'load_2', 'load_3', 'load_4', 'load_5', 'load_6',
                             'load_7', 'load_8', 'load_9', 'load_10'],
               'name_line': ['line_0', 'line_1', 'line_2', 'line_3', 'line_4', 'line_5', 'line_6', 'line_7',
                             'line_8', 'line_9', 'line_10', 'line_11', 'line_12', 'line_13', 'line_14', 'line_15',
                             'line_16', 'line_17', 'line_18', 'line_19'],
                'name_sub': ["sub_0", "sub_1", "sub_2", "sub_3", "sub_4", "sub_5", "sub_6", "sub_7", "sub_8", "sub_9",
                             "sub_10", "sub_11", "sub_12", "sub_13"],
               'sub_info': [3, 6, 4, 6, 5, 6, 3, 2, 5, 3, 3, 3, 4, 3],
               'load_to_subid': [1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13],
               'gen_to_subid': [0, 1, 2, 5, 7],
               'line_or_to_subid': [0, 0, 1, 1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 6, 8, 8, 9, 11, 12],
               'line_ex_to_subid': [1, 4, 2, 3, 4, 3, 4, 6, 8, 5, 10, 11, 12, 7, 8, 9, 13, 10, 12, 13],
               'load_to_sub_pos': [4, 2, 5, 4, 4, 4, 1, 1, 1, 2, 1], 'gen_to_sub_pos': [2, 5, 3, 5, 1],
               'line_or_to_sub_pos': [0, 1, 1, 2, 3, 1, 2, 3, 4, 3, 1, 2, 3, 1, 2, 2, 3, 0, 0, 1],
               'line_ex_to_sub_pos': [0, 0, 0, 0, 1, 1, 2, 0, 0, 0, 2, 2, 3, 0, 1, 2, 2, 0, 0, 0],
               'load_pos_topo_vect': [7, 11, 18, 23, 28, 39, 41, 44, 47, 51, 54],
               'gen_pos_topo_vect': [2, 8, 12, 29, 34],
               'line_or_pos_topo_vect': [0, 1, 4, 5, 6, 10, 15, 16, 17, 22, 25, 26, 27, 31, 32, 37, 38, 40, 46, 50],
               'line_ex_pos_topo_vect': [3, 19, 9, 13, 20, 14, 21, 30, 35, 24, 45, 48, 52, 33, 36, 42, 55, 43, 49, 53],
               'subtype': 'Action.Action'}
示例#10
0
 def _action_env_setup(self):
     return HelperAction(self.gridobj, legal_action=self.game_rules.legal_action, actionClass=PowerLineSet)
示例#11
0
 def _action_env_setup(self):
     return HelperAction(self.gridobj, legal_action=self.game_rules.legal_action, actionClass=TopoAndRedispAction)