예제 #1
0
    def __init__(self, action_space, observation_space):
        """Initialize a new agent."""
        BaseAgent.__init__(self, action_space=action_space)

        #from amorot
        #super().__init__(action_space)
        #self.name = name
        #self.grid = gridName  # IEEE14,IEEE118_R2 (WCCI or Neurips Track Robustness), IEEE118
        #logging.info("the grid you indicated to the Expert System is:" + gridName)
        self.curr_iter = 0
        self.sub_2nodes = set()
        self.lines_disconnected = set()
        self.action_space = action_space
        self.observation_space = observation_space
        self.threshold_powerFlow_safe = 0.95
        self.maxOverloadsAtATime = 3  # We should not run it more than
        self.config = {
            "totalnumberofsimulatedtopos": 25,
            "numberofsimulatedtopospernode": 5,
            "maxUnusedLines": 2,
            "ratioToReconsiderFlowDirection": 0.75,
            "ratioToKeepLoop": 0.25,
            "ThersholdMinPowerOfLoop": 0.1,
            "ThresholdReportOfLine": 0.2
        }
        self.reward_type = "MinMargin_reward"  # "MinMargin_reward"#we use the L2RPN reward to score the topologies, not the interal alphadeesp score

        self.action_space = action_space
    def __init__(self, action_space):
        """Initialize a new agent."""
        BaseAgent.__init__(self, action_space=action_space)
        self.state_size = 943 + 177
        self.action_size = 987 + 21
        self.hidden1, self.hidden2, self.hidden3 = 1000, 1000, 1000

        self.actor = self.build_model()

        self.load_model('pypow_wcci_a3c_backup')
        print("Loaded saved NN model parameters \n")
        #self.backup_agent2 = Backup_agent2(action_space)

        tf.get_default_graph()

        #self.sess = tf.InteractiveSession()
        #K.set_session(self.sess)

        #self.sess = tf.InteractiveSession()
        # TF 1.x - sess = tf.InteractiveSession(); TF 2.X sess=tf.compat.v1.InteractiveSession()
        #K.set_session(self.sess) # tensorflow 1.X
        #tf.compat.v1.keras.backend.set_session(self.sess) # tensorflow 2.X
        #tf.compat.v1.disable_eager_execution() # compatibility issues due to tf 2.0
        #self.sess.run(tf.global_variables_initializer())  # tensorflow 1.X
        self.tested_action = None
예제 #3
0
 def __init__(self, action_space,net_dict,effective_topo,sub_info):
     """Initialize a new agent."""
     BaseAgent.__init__(self, action_space=action_space)
     self.policy_net = Network()
     self.policy_net.load_state_dict(net_dict)
     self.policy_net.eval()
     self.effective_topo = effective_topo
     self.sub_info = sub_info
예제 #4
0
    def __init__(self, action_space, observation_space):
        """Initialize a new agent."""
        BaseAgent.__init__(self, action_space=action_space)

        #super().__init__(action_space)
        #self.name = name
        #self.grid = gridName  # IEEE14,IEEE118_R2 (WCCI or Neurips Track Robustness), IEEE118
        #logging.info("the grid you indicated to the Expert System is:" + gridName)
        self.curr_iter = 0
        self.sub_2nodes = set()
        self.lines_disconnected = set()
        self.action_space = action_space
        self.observation_space = observation_space
        self.threshold_powerFlow_safe = 0.95
        self.maxOverloadsAtATime = 3  # We should not run it more than
        self.config = {
            "totalnumberofsimulatedtopos": 25,
            "numberofsimulatedtopospernode": 5,
            "maxUnusedLines": 2,
            "ratioToReconsiderFlowDirection": 0.75,
            "ratioToKeepLoop": 0.25,
            "ThersholdMinPowerOfLoop": 0.1,
            "ThresholdReportOfLine": 0.2
        }
        self.reward_type = "MinMargin_reward"  # "MinMargin_reward"#we use the L2RPN reward to score the topologies, not the interal alphadeesp score

        self.nline = 186
        self.ngen = 22
        self.controllablegen = {0, 2, 3, 4, 10, 13, 16, 19, 20, 21}
        self.redispatchable = np.bool([
            True, False, True, True, True, False, False, False, False, False,
            True, False, False, True, False, False, True, False, False, True,
            True, True
        ])
        self.timestep = 0
        self.target_dispatch = np.zeros(self.ngen)
        self.base_power = [
            48, 28.2, 0, 150, 50, 0, 0, 0, 0, 0, 47.6, 0, 0, 70, 0, 0, 98.9, 0,
            0, 300, 51, 180
        ]
        self.lines_attacked = [0, 9, 13, 14, 18, 23, 27, 39, 45, 56]
        self.lines_cut = set()
        self.thermal_limits = [
            60.9, 231.9, 272.6, 212.8, 749.2, 332.4, 348., 414.4, 310.1, 371.4,
            401.2, 124.3, 298.5, 86.4, 213.9, 160.8, 112.2, 291.4, 489., 489.,
            124.6, 196.7, 191.9, 238.4, 174.2, 105.6, 143.7, 293.4, 288.9,
            107.7, 415.5, 148.2, 124.2, 154.4, 85.9, 106.5, 142., 124., 130.2,
            86.2, 278.1, 182., 592.1, 173.1, 249.8, 441., 344.2, 722.8, 494.6,
            494.6, 196.7, 151.8, 263.4, 364.1, 327.
        ]
        self.operationsequence = np.zeros(self.nline)
        self.recoversequence = np.zeros(self.nline)

        self.action_space = action_space
        #self.observation_space = observation_space
        self.threshold_powerFlow_safe = 0.95
예제 #5
0
    def __init__(
            self,
            actor,  # the agent that will take some actions
            proxy,  # the proxy to train / evaluate
            logdir=None,  # tensorboard logs
            update_tensorboard=256,  # tensorboard is updated every XXX training iterations
            save_freq=int(1024) *
        int(64),  # model is saved every save_freq training iterations
            ext=".h5",  # extension of the file in which you want to save the proxy
            nb_obs_init=256,  # number of observations that are sent to the proxy to be initialized
    ):
        BaseAgent.__init__(self, actor.action_space)
        self.actor = actor

        # to fill the training / test dataset
        self.global_iter = 0
        self.train_iter = 0
        self.__is_init = False  # is this model initiliazed
        self.is_training = True
        self._nb_obs_init = nb_obs_init

        # proxy part
        self._proxy = proxy

        # tensorboard (should be initialized after the proxy)
        if logdir is not None:
            logpath = os.path.join(logdir, self.get_name())
            self._tf_writer = tf.summary.create_file_writer(
                logpath, name=self.get_name())
        else:
            self._tf_writer = None
        self.update_tensorboard = update_tensorboard
        self.save_freq = int(save_freq)

        # save / load
        if re.match(r"^\.", ext) is None:
            # add a point at the beginning of the extension
            self.ext = f".{ext}"
        else:
            self.ext = ext
        self.save_path = None
    def __init__(self, action_space):
        """Initialize a new agent."""
        BaseAgent.__init__(self, action_space=action_space)
        self.action_space = action_space
        self.device = torch.device(
            "cuda:" + str(0) if torch.cuda.is_available() else "cpu")
        self.obs_size = 1040
        self.act_size = 386
        self.start_epoch = 1

        self.distr_params = {"num_bins": 51, "v_min": -1.0, "v_max": 1.0}
        self.prioritized_params = {"a": 0.6, "b": 0.6, "eps": 1e-5}

        self.distr_params["v_range"] = torch.linspace(
            self.distr_params["v_min"], self.distr_params["v_max"],
            self.distr_params["num_bins"]).to(self.device)
        self.model = DuelingDistributionalNetwork(self.obs_size, self.act_size,
                                                  self.distr_params,
                                                  True).to(self.device)
        self.optimizer = optim.Adam(self.model.parameters(), lr=0.0001)
        self.load_weights()
예제 #7
0
    def __init__(self, action_space, observation_space):
        """Initialize a new agent."""
        BaseAgent.__init__(self, action_space=action_space)

        #from amarot
        self.sub_2nodes = set()
        self.lines_disconnected = set()
        self.action_space = action_space
        self.observation_space = observation_space
        self.threshold_powerFlow_safe = 0.95
        self.maxOverloadsAtATime = 3  # We should not run it more than
        self.config = {
            "totalnumberofsimulatedtopos": 25,
            "numberofsimulatedtopospernode": 5,
            "maxUnusedLines": 2,
            "ratioToReconsiderFlowDirection": 0.75,
            "ratioToKeepLoop": 0.25,
            "ThersholdMinPowerOfLoop": 0.1,
            "ThresholdReportOfLine": 0.2
        }
        self.reward_type = "MinMargin_reward"  # "MinMargin_reward"#we use the L2RPN reward to score the topologies, not the interal alphadeesp score

        self.action_space = action_space
 def __init__(self, action_space, this_directory_path='./'):
     """Initialize a new agent."""
     BaseAgent.__init__(self, action_space=action_space)
     self.actions62 = np.load(
         os.path.join(this_directory_path, 'actions62.npy'))
     self.actions146 = np.load(
         os.path.join(this_directory_path, 'actions146.npy'))
     self.actions = np.concatenate((self.actions62, self.actions146),
                                   axis=0)
     self.actions1255 = np.load(
         os.path.join(this_directory_path, 'actions1255.npy'))
     chosen = list(range(2, 7)) + list(range(7, 73)) + list(range(
         73, 184)) + list(range(184, 656))
     chosen += list(range(656, 715)) + list(range(715, 774)) + list(
         range(774, 833)) + list(range(833, 1010))
     chosen += list(range(1010, 1069)) + list(range(1069, 1105)) + list(
         range(1105, 1164)) + list(range(1164, 1223))
     self.chosen = chosen
     self.ppo = tf.keras.models.load_model(
         os.path.join(this_directory_path, './ppo-ckpt'))
     self.last_step = datetime.datetime.now()
     self.recovery_stack = []
     self.overflow_steps = 0
예제 #9
0
    def __init__(self,
                 action_space,
                 env,
                 n_gens_to_Redispatch=2,
                 redispatching_increment=1):
        """
        Initialize agent
        :param action_space: the Grid2Op action space
        :param n_gens_to_Redispatch: the maximum number of dispatchable generators to play with
        :param redispatching_increment: the redispatching MW value to play with (both Plus or Minus)
        """
        BaseAgent.__init__(self, action_space)
        self.desired_actions = []

        # we create a dictionnary of redispatching actions we want to play with
        GensToRedipsatch = [
            i for i in range(len(env.gen_redispatchable))
            if env.gen_redispatchable[i]
        ]
        if len(GensToRedipsatch) > n_gens_to_Redispatch:
            GensToRedipsatch = GensToRedipsatch[0:n_gens_to_Redispatch]

        # action dic will have 2 actions par generator (increase or decrease by the increment) + do nothing
        self.desired_actions.append(self.action_space({}))  # do_nothing action

        for i in GensToRedipsatch:

            # redispatching decreasing the production by the increment
            act1 = self.action_space(
                {"redispatch": [(i, -redispatching_increment)]})
            self.desired_actions.append(act1)

            # redispatching increasing the production by the increment
            act2 = self.action_space(
                {"redispatch": [(i, +redispatching_increment)]})
            self.desired_actions.append(act2)
예제 #10
0
 def __init__(self, action_space):
     BaseAgent.__init__(self, action_space)
예제 #11
0
 def __init__(self, action_space):
     """Initialize a new agent."""
     BaseAgent.__init__(self, action_space=action_space)
예제 #12
0
 def __init__(self, action_space, this_directory_path):
     BaseAgent.__init__(self, action_space=action_space)
     self.time_step = 0
     self.lasttime = datetime.datetime.now()
     self.actions = np.load(
         os.path.join(this_directory_path, 'actions1_109.npy'))  #
     self.actions2 = np.load(
         os.path.join(this_directory_path, 'actions2_124.npy'))
     self.substation_g1 = np.zeros(len(self.actions), dtype=np.int16)
     self.substation_g2 = np.zeros(len(self.actions2), dtype=np.int16)
     self.actionstack = []
     self.sub_item1 = []
     self.sub_item2 = []
     for idx, a in enumerate(self.actions):
         action = self.action_space(
             {'change_bus': self.actions[idx][719:1252]})
         action._change_bus_vect = action._change_bus_vect.astype(bool)
         ta = action.as_dict()
         self.substation_g1[idx] = int(
             ta['change_bus_vect']['modif_subs_id'][0])
         self.sub_item1.append(ta['change_bus_vect'][str(
             self.substation_g1[idx])].items())
     for idx, a in enumerate(self.actions2):
         action = self.action_space(
             {'change_bus': self.actions2[idx][719:1252]})
         action._change_bus_vect = action._change_bus_vect.astype(bool)
         ta = action.as_dict()
         self.substation_g2[idx] = int(
             ta['change_bus_vect']['modif_subs_id'][0])
         self.sub_item2.append(ta['change_bus_vect'][str(
             self.substation_g2[idx])].items())
     self.dict = {
         0: [0, 1, 2, 4, 6, 10, 11, 13, 15, 116],
         1: [0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 13, 15, 116],
         2: [0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 116],
         3: [67, 68, 69, 70, 71, 72, 73, 74, 76, 46, 48, 117, 22, 23],
         4: [68, 69, 70, 71, 72, 73, 74, 21, 22, 23, 24, 31],
         5: [68, 69, 70, 71, 72, 73, 74, 22, 23],
         6: [68, 69, 70, 71, 72, 73, 74, 23],
         7: [67, 68, 69, 70, 71, 72, 73, 74, 76, 46, 48, 117, 22, 23],
         8: [
             67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 46, 79, 48, 81,
             117, 22, 23
         ],
         9: [
             23, 41, 44, 45, 46, 47, 48, 49, 50, 53, 64, 65, 67, 68, 69, 70,
             73, 74, 75, 76, 77, 79, 80, 81, 115, 117
         ],
         10: [67, 68, 69, 70, 73, 74, 75, 76, 77, 46, 79, 48, 81, 117, 23],
         11: [
             46, 48, 67, 68, 69, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 95,
             96, 97, 98, 117
         ],
         12: [
             23, 41, 44, 45, 46, 47, 48, 49, 50, 53, 64, 65, 67, 68, 69, 70,
             73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 95, 96, 97, 98, 115,
             117
         ],
         13: [0, 1, 2, 3, 4, 5, 6, 10, 11, 12, 13, 14, 15, 16, 116],
         14: [
             23, 46, 48, 67, 68, 69, 70, 73, 74, 75, 76, 77, 78, 79, 80, 81,
             82, 95, 96, 97, 98, 117
         ],
         15: [
             46, 48, 67, 68, 69, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 95,
             96, 97, 98, 117
         ],
         16: [96, 97, 98, 68, 74, 75, 76, 77, 78, 79, 80, 81, 95],
         17: [
             46, 48, 67, 68, 69, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 93,
             94, 95, 96, 97, 98, 99, 117
         ],
         18: [
             46, 48, 67, 68, 69, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 93,
             94, 95, 96, 97, 98, 99, 117
         ],
         19: [
             96, 97, 98, 67, 68, 99, 74, 75, 76, 77, 78, 79, 80, 81, 93, 94,
             95
         ],
         20: [
             46, 48, 67, 68, 69, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
             84, 93, 94, 95, 96, 97, 98, 117
         ],
         21: [
             96, 68, 74, 75, 76, 77, 79, 81, 82, 83, 84, 85, 87, 88, 93, 94,
             95
         ],
         22: [76, 81, 82, 83, 84, 85, 87, 88, 95],
         23: [76, 81, 82, 83, 84, 85, 86, 87, 88, 89, 91, 95],
         24: [0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 116],
         25: [81, 82, 83, 84, 85, 86, 87, 88, 89, 91],
         26: [81, 82, 83, 84, 85, 86, 87, 88, 89, 91],
         27: [81, 82, 83, 84, 85, 86, 87, 88, 89, 91],
         28: [99, 101, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93],
         29: [99, 101, 82, 83, 84, 85, 87, 88, 89, 90, 91, 92, 93],
         30: [99, 101, 82, 83, 84, 85, 87, 88, 89, 90, 91, 92, 93],
         31: [99, 101, 82, 83, 84, 85, 87, 88, 89, 90, 91, 92, 93],
         32: [99, 101, 84, 87, 88, 89, 90, 91, 92, 93],
         33: [
             82, 83, 84, 85, 87, 88, 89, 90, 91, 92, 93, 94, 95, 97, 98, 99,
             100, 101, 102, 103, 105
         ],
         34: [
             82, 83, 84, 85, 87, 88, 89, 90, 91, 92, 93, 94, 95, 97, 98, 99,
             100, 101, 102, 103, 105
         ],
         35: [0, 1, 2, 3, 4, 5, 6, 10, 11, 12, 13, 14, 15, 16, 116],
         36: [
             97, 98, 99, 100, 101, 102, 103, 105, 84, 87, 88, 89, 90, 91,
             92, 93, 94, 95
         ],
         37: [
             97, 98, 99, 100, 101, 102, 103, 105, 84, 87, 88, 89, 90, 91,
             92, 93, 94, 95
         ],
         38: [
             79, 81, 84, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
             100, 101, 102, 103, 105
         ],
         39: [
             96, 97, 98, 99, 100, 101, 102, 103, 105, 79, 81, 88, 90, 91,
             92, 93, 94, 95
         ],
         40: [
             96, 97, 98, 99, 100, 101, 102, 103, 105, 79, 81, 88, 90, 91,
             92, 93, 94, 95
         ],
         41: [
             67, 68, 74, 75, 76, 77, 78, 79, 80, 81, 82, 91, 92, 93, 94, 95,
             96, 97, 98, 99
         ],
         42: [
             68, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 91, 92, 93, 94,
             95, 96, 97, 98, 99
         ],
         43: [
             76, 78, 79, 80, 81, 82, 88, 90, 91, 92, 93, 94, 95, 96, 97, 98,
             99, 100, 101, 102, 103, 105
         ],
         44: [
             96, 97, 98, 67, 68, 99, 74, 75, 76, 77, 78, 79, 80, 81, 93, 94,
             95
         ],
         45: [
             67, 68, 74, 75, 76, 77, 78, 79, 80, 81, 91, 93, 94, 95, 96, 97,
             98, 99, 100, 102, 103, 105
         ],
         46: [32, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 18, 116],
         47: [
             67, 68, 74, 75, 76, 77, 78, 79, 80, 81, 91, 93, 94, 95, 96, 97,
             98, 99, 100, 102, 103, 105
         ],
         48: [
             79, 84, 87, 88, 89, 90, 91, 92, 93, 94, 95, 97, 98, 99, 100,
             101, 102, 103, 104, 105, 106, 109
         ],
         49: [
             79, 81, 88, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
             102, 103, 104, 105, 106, 109
         ],
         50: [96, 97, 98, 99, 76, 78, 79, 80, 81, 82, 91, 92, 93, 94, 95],
         51: [96, 97, 98, 99, 76, 78, 79, 80, 81, 82, 91, 92, 93, 94, 95],
         52: [
             76, 78, 79, 80, 88, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
             100, 101, 102, 103, 104, 105, 106, 109
         ],
         53: [
             76, 78, 79, 80, 88, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
             100, 101, 102, 103, 104, 105, 106, 109
         ],
         54: [
             79, 88, 90, 91, 92, 93, 94, 95, 97, 98, 99, 100, 101, 102, 103,
             104, 105, 106, 109
         ],
         55: [
             97, 98, 99, 100, 101, 102, 103, 105, 84, 87, 88, 89, 90, 91,
             92, 93, 94, 95
         ],
         56: [97, 98, 99, 100, 101, 102, 103, 105, 88, 90, 91, 92, 93],
         57: [0, 1, 2, 3, 4, 5, 6, 32, 10, 11, 12, 13, 14, 15, 16, 18, 116],
         58: [
             79, 88, 90, 91, 92, 93, 94, 95, 97, 98, 99, 100, 101, 102, 103,
             104, 105, 106, 107, 108, 109, 110, 111
         ],
         59: [
             79, 88, 90, 91, 92, 93, 94, 95, 97, 98, 99, 100, 101, 102, 103,
             104, 105, 106, 107, 109
         ],
         60: [
             97, 98, 99, 100, 102, 103, 104, 105, 106, 107, 108, 109, 110,
             111, 91, 93
         ],
         61: [
             97, 98, 99, 100, 102, 103, 104, 105, 106, 107, 108, 109, 110,
             111, 91, 93
         ],
         62: [
             79, 88, 90, 91, 92, 93, 94, 95, 97, 98, 99, 100, 101, 102, 103,
             104, 105, 106, 107, 109
         ],
         63:
         [97, 98, 99, 100, 102, 103, 104, 105, 106, 107, 108, 109, 91, 93],
         64:
         [97, 98, 99, 100, 102, 103, 104, 105, 106, 107, 108, 109, 91, 93],
         65: [99, 102, 103, 104, 105, 106, 107, 108, 109],
         66: [99, 102, 103, 104, 105, 106, 107, 108, 109],
         67: [97, 98, 99, 100, 102, 103, 104, 105, 106, 107, 91, 93],
         68: [
             32, 33, 3, 4, 36, 10, 11, 12, 13, 14, 15, 16, 17, 18, 112, 19,
             29, 30
         ],
         69: [102, 103, 104, 105, 106, 107, 108, 109, 110, 111],
         70: [
             97, 98, 99, 100, 102, 103, 104, 105, 106, 107, 108, 109, 110,
             111, 91, 93
         ],
         71: [99, 102, 103, 104, 107, 108, 109, 110, 111],
         72: [99, 102, 103, 104, 107, 108, 109, 110, 111],
         73: [99, 102, 103, 104, 107, 108, 109, 110, 111],
         74: [
             7, 11, 12, 13, 14, 15, 16, 17, 18, 22, 25, 26, 28, 29, 30, 31,
             32, 37, 112, 113
         ],
         75: [
             14, 15, 112, 16, 113, 17, 114, 21, 22, 23, 24, 26, 27, 28, 29,
             30, 31
         ],
         76: [112, 113, 114, 16, 21, 22, 23, 24, 26, 27, 28, 30, 31],
         77: [112, 113, 114, 22, 24, 25, 26, 27, 28, 30, 31],
         78: [112, 113, 114, 22, 24, 26, 27, 30, 31],
         79: [
             1, 2, 6, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 29, 30, 32,
             33, 36, 112, 116
         ],
         80: [0, 1, 2, 3, 4, 5, 6, 10, 11, 12, 13, 14, 15, 16, 116],
         81: [67, 68, 69, 70, 73, 74, 75, 76, 77, 46, 79, 48, 81, 117, 23],
         82: [68, 69, 73, 74, 75, 76, 77, 79, 81, 117],
         83: [
             0, 1, 2, 3, 4, 5, 6, 10, 11, 12, 13, 14, 15, 16, 17, 29, 30,
             112, 116
         ],
         84: [
             7, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 25, 28, 29, 30, 31,
             32, 33, 36, 37, 112
         ],
         85: [0, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 29],
         86: [
             1, 2, 6, 7, 10, 11, 12, 13, 14, 15, 16, 17, 18, 25, 28, 29, 30,
             31, 32, 37, 112, 116
         ],
         87: [
             7, 11, 12, 13, 14, 15, 16, 17, 18, 19, 25, 28, 29, 30, 31, 32,
             33, 37, 112
         ],
         88: [
             32, 33, 35, 36, 42, 12, 13, 14, 15, 16, 17, 18, 19, 112, 20,
             29, 30
         ],
         89: [32, 33, 35, 36, 42, 12, 13, 14, 16, 17, 18, 19, 20, 21],
         90: [
             10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 29, 30, 32, 33, 35,
             36, 42, 112
         ],
         91: [33, 14, 17, 18, 19, 20, 21, 22],
         92: [18, 19, 20, 21, 22, 23, 24, 31],
         93: [69, 71, 112, 113, 19, 20, 21, 22, 23, 24, 25, 26, 30, 31],
         94: [
             68, 69, 70, 71, 73, 74, 112, 113, 20, 21, 22, 23, 24, 25, 26,
             30, 31
         ],
         95: [
             69, 71, 112, 113, 114, 20, 21, 22, 23, 24, 25, 26, 27, 29, 30,
             31
         ],
         96: [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 15, 116, 29],
         97: [112, 113, 114, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31],
         98: [112, 113, 114, 22, 24, 25, 26, 27, 28, 30, 31],
         99: [16, 114, 24, 26, 27, 28, 30, 31],
         100: [
             2, 3, 4, 5, 7, 8, 9, 10, 14, 15, 16, 17, 24, 25, 29, 30, 36,
             37, 64, 112
         ],
         101:
         [64, 4, 37, 36, 7, 8, 14, 15, 16, 17, 112, 22, 24, 25, 26, 29, 30],
         102: [
             7, 11, 12, 13, 14, 15, 16, 17, 18, 22, 25, 26, 27, 28, 29, 30,
             31, 32, 37, 112, 113
         ],
         103: [14, 15, 16, 17, 112, 113, 22, 26, 27, 28, 29, 30, 31],
         104: [
             69, 71, 112, 113, 114, 16, 20, 21, 22, 23, 24, 25, 26, 27, 28,
             30, 31
         ],
         105: [
             14, 15, 16, 112, 113, 17, 114, 21, 22, 23, 24, 26, 27, 28, 29,
             30, 31
         ],
         106: [112, 113, 114, 16, 21, 22, 23, 24, 25, 26, 27, 28, 30, 31],
         107: [0, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 29],
         108: [
             10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 29, 30, 32, 33, 34, 36,
             37, 38, 39, 112
         ],
         109: [
             32, 33, 34, 35, 36, 37, 38, 39, 42, 43, 12, 13, 14, 16, 17, 18,
             19, 20
         ],
         110: [32, 33, 34, 35, 36, 37, 38, 39, 42, 18],
         111: [32, 33, 34, 35, 36, 37, 38, 39, 64, 40, 42, 41, 14, 18, 29],
         112: [
             32, 33, 34, 35, 36, 37, 38, 39, 64, 40, 42, 41, 12, 13, 14, 16,
             18, 29
         ],
         113: [32, 33, 34, 35, 36, 37, 38, 39, 42, 43, 14, 17, 18, 19],
         114: [
             32, 33, 34, 35, 36, 37, 38, 39, 64, 40, 42, 41, 43, 14, 17, 18,
             19, 29
         ],
         115: [32, 33, 34, 35, 36, 37, 38, 39, 64, 40, 42, 41, 14, 18, 29],
         116:
         [32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 64, 14, 48, 18, 29],
         117: [
             4, 7, 8, 14, 15, 16, 17, 24, 25, 29, 30, 32, 33, 34, 36, 37,
             38, 39, 63, 64, 65, 67, 112
         ],
         118: [1, 2, 3, 4, 5, 6, 7, 10, 11, 13, 15, 116],
         119: [32, 33, 34, 36, 37, 38, 39, 40, 41, 48],
         120: [32, 33, 34, 36, 37, 38, 39, 40, 41, 48],
         121: [
             32, 33, 34, 65, 36, 37, 38, 39, 40, 41, 68, 44, 46, 47, 48, 49,
             50, 53
         ],
         122: [65, 36, 68, 38, 39, 40, 41, 44, 46, 47, 48, 49, 50, 53],
         123: [33, 35, 36, 42, 43, 44, 45, 48, 18],
         124: [32, 33, 34, 35, 36, 37, 38, 39, 42, 43, 44, 14, 17, 18, 19],
         125: [33, 65, 68, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 53],
         126: [65, 68, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 53],
         127:
         [65, 67, 68, 69, 41, 74, 43, 44, 45, 46, 47, 48, 49, 50, 76, 53],
         128: [65, 68, 41, 43, 44, 45, 46, 47, 48, 49, 50, 53],
         129: [2, 3, 4, 5, 37, 7, 8, 9, 10, 16, 25, 29],
         130: [
             39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
             56, 57, 58, 61, 64, 65, 66, 67, 68, 69, 74, 76
         ],
         131: [
             36, 38, 39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
             54, 55, 56, 57, 58, 61, 64, 65, 66, 67, 68, 69, 74, 76
         ],
         132: [
             36, 38, 39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
             54, 55, 56, 57, 58, 61, 64, 65, 66, 67, 68, 69, 74, 76
         ],
         133: [
             39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
             55, 56, 57, 58, 61, 64, 65, 66, 67, 68, 69, 74, 76
         ],
         134: [
             39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
             56, 57, 58, 61, 64, 65, 66, 67, 68, 69, 74, 76
         ],
         135: [
             39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
             56, 57, 58, 61, 64, 65, 66, 67, 68, 69, 74, 76
         ],
         136: [
             39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
             56, 57, 58, 61, 64, 65, 66, 67, 68, 69, 74, 76
         ],
         137: [65, 68, 41, 44, 46, 47, 48, 49, 50, 51, 52, 53, 55, 57],
         138: [48, 50, 51, 52, 53, 54, 55, 57, 58],
         139: [
             41, 44, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
             60, 62, 65, 68
         ],
         140: [4, 7, 8, 9, 29],
         141: [
             39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
             56, 57, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 74, 76
         ],
         142: [
             39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
             56, 57, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 74, 76
         ],
         143: [
             41, 44, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
             60, 62, 65, 68
         ],
         144: [
             41, 44, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
             60, 62, 65, 68
         ],
         145: [48, 49, 50, 52, 53, 54, 55, 56, 57, 58, 59, 60, 62],
         146: [48, 49, 50, 52, 53, 54, 55, 56, 57, 58, 59, 60, 62],
         147: [65, 68, 41, 44, 46, 47, 48, 49, 50, 53, 54, 55, 56, 57, 58],
         148: [48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 62],
         149: [
             65, 68, 41, 44, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
             58
         ],
         150: [
             41, 44, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
             60, 61, 62, 63, 65, 68
         ],
         151: [1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 116],
         152: [48, 49, 50, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63],
         153: [48, 49, 50, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63],
         154: [48, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63],
         155: [65, 66, 48, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63],
         156:
         [64, 65, 66, 48, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63],
         157: [64, 65, 66, 53, 54, 55, 58, 59, 60, 61, 62, 63],
         158: [64, 65, 66, 48, 53, 54, 55, 58, 59, 60, 61, 62, 63],
         159: [64, 65, 66, 48, 53, 54, 55, 58, 59, 60, 61, 62, 63],
         160: [64, 65, 67, 37, 53, 54, 55, 58, 59, 60, 61, 62, 63],
         161: [
             7, 16, 25, 29, 32, 33, 34, 36, 37, 38, 39, 48, 60, 61, 62, 63,
             64, 65, 66, 67, 68, 80, 115
         ],
         162: [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 116, 29],
         163: [
             64, 65, 66, 67, 36, 37, 68, 48, 80, 61, 115, 58, 59, 60, 29,
             62, 63
         ],
         164: [
             37, 39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
             55, 56, 57, 58, 59, 60, 61, 63, 64, 65, 66, 67, 68, 69, 74, 76
         ],
         165: [
             37, 39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
             55, 56, 57, 58, 59, 60, 61, 63, 64, 65, 66, 67, 68, 69, 74, 76
         ],
         166: [
             37, 41, 44, 46, 47, 48, 49, 50, 53, 58, 59, 60, 61, 63, 64, 65,
             66, 67, 68
         ],
         167: [64, 65, 66, 48, 58, 59, 60, 61, 63],
         168: [
             64, 65, 66, 67, 68, 37, 41, 44, 46, 47, 48, 49, 50, 53, 59, 60,
             61, 63
         ],
         169: [
             23, 41, 44, 45, 46, 47, 48, 49, 50, 53, 64, 65, 67, 68, 69, 70,
             73, 74, 75, 76, 77, 79, 80, 81, 115, 117
         ],
         170: [
             23, 39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
             55, 56, 57, 58, 61, 64, 65, 66, 67, 68, 69, 70, 73, 74, 75, 76,
             77, 79, 80, 81, 115, 117
         ],
         171: [
             22, 23, 41, 44, 45, 46, 47, 48, 49, 50, 53, 64, 65, 67, 68, 69,
             70, 71, 72, 73, 74, 75, 76, 77, 79, 80, 81, 115, 117
         ],
         172: [
             67, 68, 69, 70, 71, 72, 73, 74, 76, 46, 48, 21, 22, 23, 24,
             117, 31
         ],
         173: [0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 37, 16, 25, 29],
         174: [37, 7, 16, 114, 21, 22, 23, 24, 25, 26, 27, 29, 31],
         175: [
             64, 67, 68, 74, 75, 76, 77, 78, 79, 80, 81, 93, 94, 95, 96, 97,
             98, 99, 115
         ],
         176: [82, 83, 84, 85, 86, 87, 88],
         177: [64, 65, 67, 68, 37, 69, 74, 76, 46, 79, 80, 48, 115, 63],
         178: [
             4, 7, 8, 11, 12, 13, 14, 15, 16, 17, 18, 24, 25, 28, 29, 30,
             31, 32, 36, 37, 64, 112
         ],
         179: [
             7, 14, 16, 18, 25, 29, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
             42, 63, 64, 65, 67
         ],
         180: [64, 48, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63],
         181: [64, 65, 66, 67, 37, 53, 54, 55, 58, 59, 60, 61, 62, 63],
         182: [
             29, 36, 37, 41, 44, 46, 47, 48, 49, 50, 53, 59, 60, 61, 62, 63,
             64, 65, 66, 67, 68, 80, 115
         ],
         183: [
             29, 36, 37, 46, 48, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 74,
             76, 79, 80, 115
         ],
         184: [
             23, 37, 41, 44, 45, 46, 47, 48, 49, 50, 53, 63, 64, 65, 67, 68,
             69, 70, 73, 74, 75, 76, 77, 79, 80, 81, 115, 117
         ],
         185: [
             37, 46, 48, 63, 64, 65, 67, 68, 69, 74, 76, 78, 79, 80, 95, 96,
             97, 98, 115
         ]
     }
     self.lines = [
         2, 3, 4, 7, 8, 9, 10, 11, 12, 13, 14, 19, 20, 21, 22, 23, 24, 25,
         27, 28, 29, 30, 31, 32, 33, 34, 35, 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, 66, 68, 69, 70, 71, 74, 79, 83, 84, 85, 86, 87, 88, 89,
         90, 91, 92, 93, 94, 95, 96, 97, 101, 102, 104, 105, 106, 108, 112,
         115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 126, 127, 128,
         130, 131, 132, 133, 135, 136, 137, 138, 139, 141, 142, 143, 144,
         145, 146, 147, 148, 149, 150, 151, 153, 154, 155, 156, 158, 159,
         160, 161, 162, 163, 164, 166, 167, 168, 169, 170, 171, 172, 174,
         178, 179, 180, 181, 182, 183, 184
     ]
예제 #13
0
 def __init__(self, *args, **kwargs):
     BaseAgent.__init__(self, *args, **kwargs)
 def __init__(self, action_space, action_space_directory):
     BaseAgent.__init__(self, action_space=action_space)
     self.actions62 = np.load(os.path.join(action_space_directory, 'actions62.npy'))
     self.actions146 = np.load(os.path.join(action_space_directory, 'actions146.npy'))
예제 #15
0
    def __init__(self, action_space):
        BaseAgent.__init__(self, action_space=action_space)
        self.simulate_times = 0

        unitary_action_model = UnitaryActionModel()
        algorithm = ES(unitary_action_model)
        self.unitary_es_agent = UnitaryESAgent(algorithm)

        combined_actions_model_1 = CombinedActionsModel()
        combined_actions_model_2 = CombinedActionsModel()
        ensemble_algorithm = EnsembleES(combined_actions_model_1,
                                        combined_actions_model_2)
        self.combine_es_agent = CombineESAgent(ensemble_algorithm)

        self.unitary_es_agent.restore('./saved_files',
                                      'unitary_action_model.ckpt')
        self.combine_es_agent.restore('./saved_files',
                                      'combined_actions_model.ckpt')

        unitary_actions_vec = np.load(
            "./saved_files/v6_top500_unitary_actions.npz")["actions"]
        self.unitary_actions = []
        for i in range(unitary_actions_vec.shape[0]):
            action = action_space.from_vect(unitary_actions_vec[i])
            self.unitary_actions.append(action)

        redispatch_actions_vec = np.load(
            "./saved_files/redispatch_actions.npz")["actions"]
        self.redispatch_actions = []
        for i in range(redispatch_actions_vec.shape[0]):
            action = action_space.from_vect(redispatch_actions_vec[i])
            self.redispatch_actions.append(action)

        with open("./saved_files/action_to_sub_id.pickle", "rb") as f:
            self.action_to_sub_id = pickle.load(f)

        self.after_line56_or_line45_disconnect_actions = []
        self.three_sub_action_to_sub_ids = {}

        actions_vec = np.load(
            "./saved_files/v10_merge_three_sub_actions.npz")["actions"]
        for i in range(actions_vec.shape[0]):
            action = action_space.from_vect(actions_vec[i])
            self.after_line56_or_line45_disconnect_actions.append(action)

        with open("saved_files/three_sub_action_to_sub_ids.pickle", "rb") as f:
            self.three_sub_action_to_sub_ids = pickle.load(f)

        self.used_combine_actions = False
        self.redispatch_cnt = 0
        self.max_redispatch_cnt = 3
        self.serial_actions = []

        self.do_nothing_action = action_space({})
        self.action_space = action_space

        offset = 59
        self.action_to_sub_topo = {}
        for sub_id, sub_elem_num in enumerate(action_space.sub_info):
            self.action_to_sub_topo[sub_id] = (offset, offset + sub_elem_num)
            offset += sub_elem_num

        self.observation = None

        self.redispatch_months = set([3])