-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_assigner.py
33 lines (28 loc) · 1.25 KB
/
task_assigner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from typing import List
from tasks import Task, Processor, HighCriticalityTask
from tasks.exceptions import DuplicateTaskAssignmentException, UnassignableTaskSet
def worst_fit_decreasing(cores: List[Processor], tasks: List[Task]):
tasks = sorted(tasks, key=lambda t: (isinstance(t, HighCriticalityTask), t.utilization), reverse=True)
for t in tasks:
cores = sorted(cores, key=lambda c: c.utilization())
for c in cores:
if 1 - c.utilization() >= t.utilization:
try:
c.add_task(t)
break
except DuplicateTaskAssignmentException:
continue
else:
raise UnassignableTaskSet('No core found for task ' + t.name)
def first_fit_decreasing(cores: List[Processor], tasks: List[Task]):
tasks = sorted(tasks, key=lambda t: (isinstance(t, HighCriticalityTask), t.utilization), reverse=True)
for t in tasks:
for c in cores:
if 1 - c.utilization() >= t.utilization:
try:
c.add_task(t)
break
except DuplicateTaskAssignmentException:
continue
else:
raise UnassignableTaskSet('No core found for task ' + t.name)