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)
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, avg_tasks, lower_limit, upper_limit) check_and_store(f'Ext-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'Ext-Proportional-(tasks)', tasks, resources, a, cost, lower_limit, upper_limit) a = schedulers.proportional(tasks, resources, cost, avg_tasks) check_and_store(f'Proportional-(tasks/res)', tasks, resources, a, cost, lower_limit, upper_limit) a = schedulers.proportional(tasks, resources, cost, tasks) check_and_store(f'Proportional-(tasks)', tasks, resources, a, cost, lower_limit, upper_limit)
def test_proportional(self): assignment = schedulers.proportional(self.tasks, self.resources, self.cost, 1) self.assertEqual(assignment[0], 2) self.assertEqual(assignment[1], 2) self.assertEqual(assignment[2], 0) assignment = schedulers.proportional(self.tasks, self.resources, self.cost, 2) self.assertEqual(assignment[0], 2) self.assertEqual(assignment[1], 1) self.assertEqual(assignment[2], 1) assignment = schedulers.proportional(self.tasks, self.resources, self.cost, 4) self.assertEqual(assignment[0], 1) self.assertEqual(assignment[1], 2) self.assertEqual(assignment[2], 1)