Exemplo n.º 1
0
def run_for_n_resources(resources):
    """
    Runs experiments for a number of resources.

    Parameters
    ----------
    resources : int
        Number of resources
    """
    print(f'- Running experiment for {resources} resources.')
    # Initializes the cost matrix with zeros
    cost = np.zeros(shape=(resources, max_tasks+1))
    # Fills the cost matrix with costs based on a quadratic function
    base_seed = rng_seed_resources
    for i in range(resources):
        devices.create_quadratic_costs(base_seed, cost, i, max_tasks)
        base_seed += 1

    # Iterates over the number of tasks running all schedulers
    for tasks in range(min_tasks, max_tasks, step_tasks):
        # Prepares the upper and lower limit arrays
        avg_tasks = tasks // resources
        lower_limit = np.full(shape=resources, fill_value=4)
        upper_limit = np.full(shape=resources, fill_value=avg_tasks*2)
        # Finds the resource with the maximum and minimum costs for 'tasks'
        max_index = np.argmax(cost[:, tasks])
        lower_limit[max_index] = avg_tasks // 4
        min_index = np.argmin(cost[:, tasks])
        upper_limit[min_index] = avg_tasks // 2

        # 2. Run Proportional with three task values to base itself
        a = schedulers.extended_proportional(tasks, resources, cost, 1,
                                             lower_limit, upper_limit)
        check_and_store(f'Proportional-(1)', tasks, resources, a, cost,
                        lower_limit, upper_limit)
        a = schedulers.extended_proportional(tasks, resources, cost, avg_tasks,
                                             lower_limit, upper_limit)
        check_and_store(f'Proportional-(tasks/res)', tasks, resources, a, cost,
                        lower_limit, upper_limit)
        a = schedulers.extended_proportional(tasks, resources, cost, tasks,
                                             lower_limit, upper_limit)
        check_and_store(f'Proportional-(tasks)', tasks, resources, a, cost,
                        lower_limit, upper_limit)

        # 3. Run FedAvg
        a = schedulers.extended_fedavg(tasks, resources,
                                       lower_limit, upper_limit)
        check_and_store('FedAvg', tasks, resources, a, cost,
                        lower_limit, upper_limit)

        # 4. Run Fed-LBAP
        a = schedulers.extended_fed_lbap(tasks, resources, cost,
                                         lower_limit, upper_limit)
        check_and_store('Fed-LBAP', tasks, resources, a, cost,
                        lower_limit, upper_limit)

        # 5. Run OLAR
        a = schedulers.olar(tasks, resources, cost, lower_limit, upper_limit)
        check_and_store('OLAR', tasks, resources, a, cost,
                        lower_limit, upper_limit)
def run_for_n_resources(resources):
    """
    Runs experiments for a number of resources.

    Parameters
    ----------
    resources : int
        Number of resources
    """
    print(f'- Running experiment for {resources} resources.')
    # Initializes the cost matrix with zeros
    cost = np.zeros(shape=(resources, max_tasks + 1))
    # Fills the cost matrix with costs based on a mixed function
    base_seed = rng_seed_resources
    for i in range(resources):
        if i % 4 == 0:
            devices.create_recursive_costs(base_seed, cost, i, max_tasks)
        elif i % 4 == 1:
            devices.create_linear_costs(base_seed, cost, i, max_tasks)
        elif i % 4 == 2:
            devices.create_nlogn_costs(base_seed, cost, i, max_tasks)
        else:
            devices.create_quadratic_costs(base_seed, cost, i, max_tasks)

        base_seed += 1
    # Prepares the upper and lower limit arrays
    lower_limit = np.zeros(shape=resources, dtype=int)
    upper_limit = np.full(shape=resources, fill_value=max_tasks + 1, dtype=int)

    # Iterates over the number of tasks running all schedulers
    iteration = 0
    for tasks in range(min_tasks, max_tasks, step_tasks):
        # 1. Run Random with three seeds
        for seed in seeds_for_random:
            a = schedulers.random(tasks, resources, seed + iteration)
            check_and_store(f'Random-(seed:{seed})', tasks, resources, a, cost)
        iteration += 1

        # 2. Run Proportional with three task values to base itself
        a = schedulers.proportional(tasks, resources, cost, 1)
        check_and_store(f'Proportional-(1)', tasks, resources, a, cost)
        a = schedulers.proportional(tasks, resources, cost, tasks // resources)
        check_and_store(f'Proportional-(tasks/res)', tasks, resources, a, cost)
        a = schedulers.proportional(tasks, resources, cost, tasks)
        check_and_store(f'Proportional-(tasks)', tasks, resources, a, cost)

        # 3. Run FedAvg
        a = schedulers.fedavg(tasks, resources)
        check_and_store('FedAvg', tasks, resources, a, cost)

        # 4. Run Fed-LBAP
        a = schedulers.fed_lbap(tasks, resources, cost)
        check_and_store('Fed-LBAP', tasks, resources, a, cost)

        # 5. Run OLAR
        a = schedulers.olar(tasks, resources, cost, lower_limit, upper_limit)
        check_and_store('OLAR', tasks, resources, a, cost)
Exemplo n.º 3
0
    def test_quadratic(self):
        devices.create_quadratic_costs(20, self.matrix, 0, self.size)
        self.assertEqual(self.matrix[0][0], 6.293177209695468)
        self.assertEqual(self.matrix[0][1], 24.396377326152603)
        self.assertEqual(self.matrix[0][2], 60.54713057315448)
        self.assertEqual(self.matrix[0][3], 114.7454369507011)

        devices.create_quadratic_costs(30, self.matrix, 1, self.size)
        self.assertEqual(self.matrix[1][0], 6.797291824615015)
        self.assertEqual(self.matrix[1][1], 18.191459379352082)
        self.assertEqual(self.matrix[1][2], 43.52048923013118)
        self.assertEqual(self.matrix[1][3], 82.78438137695233)