-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproject.py
169 lines (132 loc) · 4.05 KB
/
project.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
from dataclasses import dataclass
from typing import List
@dataclass
class Role:
name: str
level: int
@dataclass
class Person:
name: str
roles: List[Role]
class Project:
name: str
duration: int
score: int
best_before: int
roles: List[Role]
class Progress:
people: List[Person]
project: Project
start: int
class History:
project: str
people: List[str]
@dataclass
class Solver:
step: int
people: List[Person]
projects: List[Project]
progress: List[Progress]
solvable: bool
score: int
day: int
history: List[History]
def __init__(self, people: List[Person], projects: List[Project]):
pass
def copy(self):
Solver(
step=self.step,
projects=self.projects,
people=[
Person(
name=person.name,
roles=[
Role(name=role.name, level=role.level)
for role in person.roles
]
)
for person in self.people
],
progress=self.progress,
solvable=self.solvable,
score=self.score,
day=self.day,
prev=self
)
def run(self) -> True:
number = 0
best = None
for project in self.get_projects():
for people in self.get_solvers(project):
result = self.solve(project, people)
if result.solvable and (best is None or result.score > best.score):
best = result
if best is None:
return self.next_day().run()
return best
def solve(self, project: Project, people: List[Person]):
solver = self.copy()
solver.projects.remove(project)
solver.progress.append(Progress(project=project, people=people, day=self.day))
solver.history.append(History(project=project.name, people=[person.name for person in people]))
return solver.run()
def next_day(self) -> Solver:
""" Probalbly obsolete """
solving = self.copy()
solving.step += 1
solving.day += 1
remove = [
progress for progress in solving.progress
if progress.project.duration + progress.start >= solving.day
]
# Todo: calcaulation is not acurate
for progress in remove:
solving.score += progress.project.score
# todo skill people
solving.progress = [progress for progress in solving.progress if progress not in remove]
return solving
def next(self,) -> Solver:
""" will pick up project and pepople """
# project: Project, people: List[Person]
solving = self.copy()
solving.step += 1 #etc.
return solving
def get_projects(self) -> Generator[Project]:
"""
Return projects what is possible to work on
"""
def get_solvers(self, project: Project) -> Generator[List[Person]]:
"""
Get sovlers what can work on project
"""
p = get_free_people()
sol = []
def assign(k, ppl_free:List[Person], ppl_in:List[Person]):
nonlocal sol
nonlocal project
if( k==len(project.roles) ):
sol.append(ppl_in)
return
role = project.roles[k]
mentor = False
for x in ppl_in:
for r in x.roles:
if r.name==role.name and r.level>role.level:
mentor=True
for x in ppl_free:
r:Role=None
for y in x.roles:
if r.name==role.name:
r=y
if r==None:
continue
if r.level>=role.level or r.level==role.leve-1 and mentor:
assign(k+1, [y for y in ppl_free if y!=x], ppl_in+[x])
assign(0, p, [])
return sol
def get_free_people(self):
pass
"""
A -> B -> C -> D -> E
E.D.C.B.A
"""