-
Notifications
You must be signed in to change notification settings - Fork 0
/
solver.py
137 lines (125 loc) · 6.76 KB
/
solver.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from dataparser import Data, Role
import random
import numpy as np
from tqdm import tqdm
def solve(data: Data):
# TODO: Implement Greedy Solver
return
def get_compatible_contributor(data: Data, role: Role, current_people, current_skills):
possible_candidates = []
if current_skills[role.skill_index] >= role.level:
possible_candidates = []
for con in data.contributors:
if con.skills[role.skill_index] == role.level - 1 and con.name not in current_people:
possible_candidates.append(con)
for con in data.contributors:
if con.skills[role.skill_index] >= role.level and con.name not in current_people:
possible_candidates.append(con)
if len(possible_candidates) > 0:
canditate_scores = [con.get_score() for con in possible_candidates]
sorted_scores_index = np.argsort(canditate_scores)
con = possible_candidates[sorted_scores_index[0]]
if (current_skills[role.skill_index] >= role.level and con.skills[role.skill_index] == role.level - 1) or (con.skills[role.skill_index] == role.level):
con.temp_skill_increase = role.skill_index
return con
return None
def get_compatible_contributor_old(data: Data, role: Role, current_people, current_skills):
if current_skills[role.skill_index] >= role.level:
possible_candidates = []
for con in data.contributors:
if con.skills[role.skill_index] == role.level - 1 and con.name not in current_people:
possible_candidates.append(con)
if len(possible_candidates) > 0:
canditate_scores = [con.get_score() for con in possible_candidates]
sorted_scores_index = np.argsort(canditate_scores)
possible_candidates[sorted_scores_index[0]].temp_skill_increase = role.skill_index
return possible_candidates[sorted_scores_index[0]]
possible_candidates = []
possible_level_candidates = []
for con in data.contributors:
if con.skills[role.skill_index] == role.level and con.name not in current_people:
possible_level_candidates.append(con)
if con.skills[role.skill_index] >= role.level and con.name not in current_people:
possible_candidates.append(con)
if len(possible_level_candidates) > 0:
canditate_scores = [con.get_score() for con in possible_level_candidates]
sorted_scores_index = np.argsort(canditate_scores)
possible_level_candidates[sorted_scores_index[0]].temp_skill_increase = role.skill_index
return possible_level_candidates[sorted_scores_index[0]]
if len(possible_candidates) > 0:
canditate_scores = [con.get_score() for con in possible_candidates]
sorted_scores_index = np.argsort(canditate_scores)
return possible_candidates[sorted_scores_index[0]]
return None
def solve_peter(data: Data):
project_scores = [project.get_score() for project in data.projects]
sorted_scores_index = np.argsort(project_scores)[::-1]
solution = []
second_try = []
score = 0
for project_index in tqdm(sorted_scores_index):
all_good = True
current_people = []
current_skills = np.zeros(len(data.all_skills))
for role in data.projects[project_index].roles:
role.assigned = get_compatible_contributor(data, role, current_people, current_skills)
if role.assigned is None:
all_good = False
else:
current_skills = np.maximum(current_skills, role.assigned.skills)
current_people.append(role.assigned.name)
if all_good:
start_time = max([role.assigned.work_time for role in data.projects[project_index].roles])
if start_time + data.projects[project_index].D < data.projects[project_index].B + data.projects[project_index].S:
for con in [role.assigned for role in data.projects[project_index].roles]:
con.work_time = start_time + data.projects[project_index].D
if con.temp_skill_increase is not None:
con.skills[con.temp_skill_increase] += 1
solution.append(data.projects[project_index])
if start_time + data.projects[project_index].D < data.projects[project_index].B:
score += data.projects[project_index].S
else:
score += data.projects[project_index].S - (start_time + data.projects[project_index].D - data.projects[project_index].B)
else:
second_try.append(project_index)
for con in [role.assigned for role in data.projects[project_index].roles]:
if con is not None:
con.temp_skill_increase = None
while True:
original_second_try = list(second_try)
second_try = []
for project_index in tqdm(original_second_try):
all_good = True
current_people = []
current_skills = np.zeros(len(data.all_skills))
for role in data.projects[project_index].roles:
role.assigned = get_compatible_contributor(data, role, current_people, current_skills)
if role.assigned is None:
all_good = False
else:
current_skills = np.maximum(current_skills, role.assigned.skills)
current_people.append(role.assigned.name)
if all_good:
start_time = max([role.assigned.work_time for role in data.projects[project_index].roles])
if start_time + data.projects[project_index].D < data.projects[project_index].B + data.projects[
project_index].S:
for con in [role.assigned for role in data.projects[project_index].roles]:
con.work_time = start_time + data.projects[project_index].D
if con.temp_skill_increase is not None:
con.skills[con.temp_skill_increase] += 1
con.temp_skill_increase = None
solution.append(data.projects[project_index])
if start_time + data.projects[project_index].D < data.projects[project_index].B:
score += data.projects[project_index].S
else:
score += data.projects[project_index].S - (
start_time + data.projects[project_index].D - data.projects[project_index].B)
else:
for con in [role.assigned for role in data.projects[project_index].roles]:
if con is not None:
con.temp_skill_increase = None
second_try.append(project_index)
if len(original_second_try) == len(second_try):
break
print("Score:", score)
return solution