forked from 4nnta/Team-JKJ-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJobAssignment.py
68 lines (46 loc) · 1.73 KB
/
JobAssignment.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from Employee import Employee
from Task import Task
from PriorityQueue import PriorityQueue
class JobAssignment(object):
# return # of matching entries between 2 lists
def compareList(self, list1: [], list2: []):
appeared = {}
for entry in list1:
appeared[entry] = 1
numMatched = 0
for entry in list2:
if entry in appeared:
numMatched = numMatched + 1
return numMatched
def evaluation(self, matchDept: int, matchSkill: int, capacity: int)->float:
return 1 * matchDept + 1 * matchSkill + 1 * capacity
# weight1 * matchDept + weight2 * matchSkill + weight3 * capacity
# assignment list for a single task
def singleTaskAssignment(self, task: Task, employeeList: [], maxCapacity = 1000):
availableEmployee = employeeList
PQ = PriorityQueue([])
it = 0
for employee in availableEmployee:
matchDept = self.compareList(employee.department, task.department)
matchSkill = self.compareList(employee.skillSet, task.skillSet)
if employee.capacity >= maxCapacity or matchDept == 0 or matchSkill == 0:
continue
evaluation = self.evaluation(matchDept, matchSkill, maxCapacity - employee.capacity)
PQ.add((-evaluation, it, employee))
it = it + 1
assignedEmployee = []
for i in range(min(len(availableEmployee), task.assignedNeeded)):
employee = PQ.pop()
assignedEmployee.append(employee)
return assignedEmployee
def getAssignment(self, taskList: [], employeeList: []):
queue = PriorityQueue([])
for task in taskList:
queue.add((-task.priority, task))
assignmentList = []
while (queue.size() > 0):
task = queue.pop()
assignment = self.singleTaskAssignment(task[1], employeeList)
for employee in assignment:
assignmentList.append((task, employee))
return assignmentList