print(battery.battery_failed) while battery.battery_failed: failed_task = battery.failed_task failed_task.ScaleDown() tasks.calculate_runtime() consumption = battery.tasks_consumption(38, tasks) plot_consumption(battery, tasks) ### Phase 2 # Overall planning strategy to scale down based on maximum slack time slack_times = {} for task in task_list: if task.slack > 0: slack_times[task] = task.slack print(f'Task {task} with slack time {task.slack}') while slack_times: max_slack_task = max(slack_times.items(), key=operator.itemgetter(1))[0] print(f'Task {max_slack_task} with slack time {slack_times[max_slack_task]}') max_slack_task.ScaleDown1() tasks.calculate_runtime() if not tasks.check_scheduable(): print(f'Task {max_slack_task} not scheduable, deleting from task list.') max_slack_task.ScaleUp1() tasks.calculate_runtime() del slack_times[max_slack_task] plot_consumption(battery, tasks)
plot_consumption(battery, tasks) ### Phase 2 # Repeadtedly use the available slack time by scaling down speeds of tasks based on energy efficiency # Try scale down each task and check its effectiveness. while task_list: effectiveness = 0 effective_task = t1 scheduable = 0 for index, task in enumerate(task_list): c0 = battery.tasks_consumption(38, tasks) d0 = task.duration task.ScaleDown1() tasks.calculate_runtime() if tasks.check_scheduable(): scheduable = 1 # Check cost function and new duration c1 = battery.tasks_consumption(38, tasks) d1 = task.duration # Check effectiveness e = -(c1 - c0) / (d1 - d0) if e > effectiveness: effectiveness = e effective_task = task # Scale back task.ScaleUp1() tasks.calculate_runtime()