-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActivity.py
More file actions
77 lines (69 loc) · 2.5 KB
/
Activity.py
File metadata and controls
77 lines (69 loc) · 2.5 KB
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
class ActivityEdge:
def __init__(self, Duration, name, Prereq):
"""
Initializes the activity edges with
duration, and list of prerequisite activities.
"""
self.name = name
self.duration = Duration
self.prereq = Prereq
self.freefloat = 0
def findFreeFloat(self, path):
"""
Calculates the free float of the activity
based on the early start time and late start time of
node path.
FF(activity) = LT(endNode) - ET(startNode) - Dur(activity)
"""
startNode, endNode = path
self.freefloat = endNode.lateStart - startNode.earlyStart -\
self.duration
return self.freefloat
class ProjectNode:
def __init__(self, inputPaths):
"""
Initializes the project nodes with input activities and nodes
and early start time.
"""
self.inputPaths = inputPaths
self.earlyStart = 0
self.lateStart = 0
def findEarlyStart(self):
"""
Find early start time for all project nodes
"""
# if no prereq, early start time is 0
if self.inputPaths is None:
self.earlyStart = 0
# if one prereq, add duration of prereq + previous node's early start
elif len(self.inputPaths) == 1:
prereq, prenode = self.inputPaths[0]
# print(prereq.duration, prenode.earlyStart)
self.earlyStart = prereq.duration + prenode.earlyStart
# if more than one prereq, find the maximum
else:
max_time = 0
for prereq, prenode in self.inputPaths:
tmp_et = prenode.earlyStart + prereq.duration
if tmp_et > max_time:
max_time = tmp_et
self.earlyStart = max_time
return self.earlyStart
def findLateStart(self, maxDuration, outputPaths):
"""
Find late start time for all project nodes
"""
# if last project node as output path, equal to early start time
if outputPaths is None:
self.lateStart = self.earlyStart
elif len(outputPaths) == 1:
act, node = outputPaths[0]
self.lateStart = node.lateStart - act.duration
else:
min_time = maxDuration
for act, node in outputPaths:
tmp_lt = node.lateStart - act.duration
if tmp_lt < min_time:
min_time = tmp_lt
self.lateStart = min_time
return self.lateStart