def get_total_tput(self, rnd_array):
    (source_batch_, index_data) = self.batch_data(rnd_array.astype(int))
    env = LraClusterEnv(num_nodes=self.NUM_NODES)
    observation = env.reset().copy()
    source_batch = source_batch_.copy()
    nodes_per_group = int(params['nodes per group'])
    NUM_CONTAINERS = int(sum(rnd_array))
    '\n        Episode\n        '
    '\n        first layer\n        '
    source_batch_first = source_batch_.copy()
    observation_first_layer = np.zeros([nodes_per_group, env.NUM_APPS], int)
    for inter_episode_index in range(NUM_CONTAINERS):
        appid = index_data[inter_episode_index]
        source_batch_first[appid] -= 1
        observation_first_layer_copy = observation_first_layer.copy()
        observation_first_layer_copy[:, appid] += 1
        observation_first_layer_copy = np.append(observation_first_layer_copy, (observation_first_layer_copy > (9 * 2)), axis=1)
        observation_first_layer_copy = np.append(observation_first_layer_copy, observation_first_layer_copy.sum(axis=1).reshape(nodes_per_group, 1), axis=1)
        observation_first_layer_copy = np.array(observation_first_layer_copy).reshape(1, (- 1))
        observation_first_layer_copy = np.append(observation_first_layer_copy, appid).reshape(1, (- 1))
        observation_first_layer_copy = np.append(observation_first_layer_copy, np.array(source_batch_first)).reshape(1, (- 1))
        (action_1, prob_weights) = self.RL_1.choose_action_determine(observation_first_layer_copy.copy())
        observation_first_layer[(action_1, appid)] += 1
    '\n        second layer\n        '
    observation_second_layer_aggregation = np.empty([0, env.NUM_APPS], int)
    number_cont_second_layer = []
    for second_layer_index in range(nodes_per_group):
        rnd_array = observation_first_layer[second_layer_index].copy()
        (source_batch_second, index_data) = self.batch_data_sub(rnd_array)
        observation_second_layer = np.zeros([nodes_per_group, env.NUM_APPS], int)
        NUM_CONTAINERS_second = sum(source_batch_second)
        number_cont_second_layer.append(NUM_CONTAINERS_second)
        for inter_episode_index in range(NUM_CONTAINERS_second):
            appid = index_data[inter_episode_index]
            source_batch_second[appid] -= 1
            observation_second_layer_copy = observation_second_layer.copy()
            observation_second_layer_copy[:, appid] += 1
            observation_second_layer_copy = np.append(observation_second_layer_copy, (observation_second_layer_copy > (3 * 2)), axis=1)
            observation_second_layer_copy = np.append(observation_second_layer_copy, observation_second_layer_copy.sum(axis=1).reshape(nodes_per_group, 1), axis=1)
            observation_second_layer_copy = np.array(observation_second_layer_copy).reshape(1, (- 1))
            observation_second_layer_copy = np.append(observation_second_layer_copy, appid).reshape(1, (- 1))
            observation_second_layer_copy = np.append(observation_second_layer_copy, np.array(source_batch_second)).reshape(1, (- 1))
            (action_2, prob_weights) = self.RL_2.choose_action_determine(observation_second_layer_copy.copy())
            observation_second_layer[(action_2, appid)] += 1
        observation_second_layer_aggregation = np.append(observation_second_layer_aggregation, observation_second_layer, 0)
    '\n        third layer\n        '
    observation_third_layer_aggregation = np.empty([0, env.NUM_APPS], int)
    number_cont_third_layer = []
    for third_layer_index in range((nodes_per_group * nodes_per_group)):
        rnd_array = observation_second_layer_aggregation[third_layer_index].copy()
        (source_batch_third, index_data) = self.batch_data_sub(rnd_array)
        observation_third_layer = np.zeros([nodes_per_group, env.NUM_APPS], int)
        NUM_CONTAINERS_third = sum(source_batch_third)
        number_cont_third_layer.append(NUM_CONTAINERS_third)
        for inter_episode_index in range(NUM_CONTAINERS_third):
            appid = index_data[inter_episode_index]
            source_batch_third[appid] -= 1
            observation_third_layer_copy = observation_third_layer.copy()
            observation_third_layer_copy[:, appid] += 1
            observation_third_layer_copy = np.append(observation_third_layer_copy, (observation_third_layer_copy > (1 * 2)), axis=1)
            observation_third_layer_copy = np.append(observation_third_layer_copy, observation_third_layer_copy.sum(axis=1).reshape(nodes_per_group, 1), axis=1)
            observation_third_layer_copy = np.array(observation_third_layer_copy).reshape(1, (- 1))
            observation_third_layer_copy = np.append(observation_third_layer_copy, appid).reshape(1, (- 1))
            observation_third_layer_copy = np.append(observation_third_layer_copy, np.array(source_batch_third)).reshape(1, (- 1))
            (action_3, prob_weights) = self.RL_3.choose_action_determine(observation_third_layer_copy.copy())
            observation_third_layer[(action_3, appid)] += 1
        observation_third_layer_aggregation = np.append(observation_third_layer_aggregation, observation_third_layer, 0)
    '\n        After an entire allocation, calculate total throughput, reward\n        '
    env.state = observation_third_layer_aggregation.copy()
    assert (sum(sum(env.state)) == NUM_CONTAINERS)
    assert (env.state.sum(0) == source_batch_).all()
    '\n        After an entire allocation, calculate total throughput, reward\n        '
    return env.state
def get_total_tput(self, rnd_array):
    (source_batch_, index_data) = self.batch_data(rnd_array.astype(int))
    env = LraClusterEnv(num_nodes=self.NUM_NODES)
    observation = env.reset().copy()
    source_batch = source_batch_.copy()
    nodes_per_group = int(params['nodes per group'])
    NUM_CONTAINERS = int(sum(rnd_array))
    '\n        Episode\n        '
    '\n        first layer\n        '
    source_batch_first = source_batch_.copy()
    observation_first_layer = np.zeros([nodes_per_group, env.NUM_APPS], int)
    for inter_episode_index in range(NUM_CONTAINERS):
        appid = index_data[inter_episode_index]
        source_batch_first[appid] -= 1
        observation_first_layer_copy = observation_first_layer.copy()
        observation_first_layer_copy[:, appid] += 1
        observation_first_layer_copy = np.append(observation_first_layer_copy, (observation_first_layer_copy > (9 * 2)), axis=1)
        observation_first_layer_copy = np.append(observation_first_layer_copy, observation_first_layer_copy.sum(axis=1).reshape(nodes_per_group, 1), axis=1)
        observation_first_layer_copy = np.array(observation_first_layer_copy).reshape(1, (- 1))
        observation_first_layer_copy = np.append(observation_first_layer_copy, appid).reshape(1, (- 1))
        observation_first_layer_copy = np.append(observation_first_layer_copy, np.array(source_batch_first)).reshape(1, (- 1))
        (action_1, prob_weights) = self.RL_1.choose_action_determine(observation_first_layer_copy.copy())
        observation_first_layer[(action_1, appid)] += 1
    '\n        second layer\n        '
    observation_second_layer_aggregation = np.empty([0, env.NUM_APPS], int)
    number_cont_second_layer = []
    for second_layer_index in range(nodes_per_group):
        rnd_array = observation_first_layer[second_layer_index].copy()
        (source_batch_second, index_data) = self.batch_data_sub(rnd_array)
        observation_second_layer = np.zeros([nodes_per_group, env.NUM_APPS], int)
        NUM_CONTAINERS_second = sum(source_batch_second)
        number_cont_second_layer.append(NUM_CONTAINERS_second)
        for inter_episode_index in range(NUM_CONTAINERS_second):
            appid = index_data[inter_episode_index]
            source_batch_second[appid] -= 1
            observation_second_layer_copy = observation_second_layer.copy()
            observation_second_layer_copy[:, appid] += 1
            observation_second_layer_copy = np.append(observation_second_layer_copy, (observation_second_layer_copy > (3 * 2)), axis=1)
            observation_second_layer_copy = np.append(observation_second_layer_copy, observation_second_layer_copy.sum(axis=1).reshape(nodes_per_group, 1), axis=1)
            observation_second_layer_copy = np.array(observation_second_layer_copy).reshape(1, (- 1))
            observation_second_layer_copy = np.append(observation_second_layer_copy, appid).reshape(1, (- 1))
            observation_second_layer_copy = np.append(observation_second_layer_copy, np.array(source_batch_second)).reshape(1, (- 1))
            (action_2, prob_weights) = self.RL_2.choose_action_determine(observation_second_layer_copy.copy())
            observation_second_layer[(action_2, appid)] += 1
        observation_second_layer_aggregation = np.append(observation_second_layer_aggregation, observation_second_layer, 0)
    '\n        third layer\n        '
    observation_third_layer_aggregation = np.empty([0, env.NUM_APPS], int)
    number_cont_third_layer = []
    for third_layer_index in range((nodes_per_group * nodes_per_group)):
        rnd_array = observation_second_layer_aggregation[third_layer_index].copy()
        (source_batch_third, index_data) = self.batch_data_sub(rnd_array)
        observation_third_layer = np.zeros([nodes_per_group, env.NUM_APPS], int)
        NUM_CONTAINERS_third = sum(source_batch_third)
        number_cont_third_layer.append(NUM_CONTAINERS_third)
        for inter_episode_index in range(NUM_CONTAINERS_third):
            appid = index_data[inter_episode_index]
            source_batch_third[appid] -= 1
            observation_third_layer_copy = observation_third_layer.copy()
            observation_third_layer_copy[:, appid] += 1
            observation_third_layer_copy = np.append(observation_third_layer_copy, (observation_third_layer_copy > (1 * 2)), axis=1)
            observation_third_layer_copy = np.append(observation_third_layer_copy, observation_third_layer_copy.sum(axis=1).reshape(nodes_per_group, 1), axis=1)
            observation_third_layer_copy = np.array(observation_third_layer_copy).reshape(1, (- 1))
            observation_third_layer_copy = np.append(observation_third_layer_copy, appid).reshape(1, (- 1))
            observation_third_layer_copy = np.append(observation_third_layer_copy, np.array(source_batch_third)).reshape(1, (- 1))
            (action_3, prob_weights) = self.RL_3.choose_action_determine(observation_third_layer_copy.copy())
            observation_third_layer[(action_3, appid)] += 1
        observation_third_layer_aggregation = np.append(observation_third_layer_aggregation, observation_third_layer, 0)
    '\n        After an entire allocation, calculate total throughput, reward\n        '
    env.state = observation_third_layer_aggregation.copy()
    assert (sum(sum(env.state)) == NUM_CONTAINERS)
    assert (env.state.sum(0) == source_batch_).all()
    '\n        After an entire allocation, calculate total throughput, reward\n        '
    return env.state