Compare commits

..

2 Commits

Author SHA1 Message Date
filifa 1fe3e8e7cb get rid of temp variables 2024-05-26 14:33:31 -05:00
filifa c163aa0f23 handle multiple activities with no successor 2024-05-26 13:40:29 -05:00
1 changed files with 12 additions and 13 deletions

View File

@ -70,13 +70,7 @@ func (g *projectNetwork) forwardPass(toposort []*activity) {
// backwardPass computes the late times and slack for each activity using the
// early times
func (g *projectNetwork) backwardPass(toposort []*activity) {
n := len(toposort)
end := toposort[n-1]
end.lateFinish = end.earlyFinish
end.lateStart = end.lateFinish - end.duration
for i := n - 2; i >= 0; i-- {
for i := len(toposort) - 1; i >= 0; i-- {
a := toposort[i]
g.setLateTimes(a)
}
@ -84,25 +78,30 @@ func (g *projectNetwork) backwardPass(toposort []*activity) {
// setEarlyTimes sets the early times for an activity
func (g *projectNetwork) setEarlyTimes(a *activity) {
es := 0.0
predecessors := g.To(a.ID())
for predecessors.Next() {
p := predecessors.Node().(*activity)
es = math.Max(es, p.earlyFinish)
if a.earlyStart < p.earlyFinish {
a.earlyStart = p.earlyFinish
}
}
a.earlyStart = es
a.earlyFinish = a.earlyStart + a.duration
}
// setLateTimes sets the late times for an activity
func (g *projectNetwork) setLateTimes(a *activity) {
lf := math.Inf(1)
a.lateFinish = math.Inf(1)
successors := g.From(a.ID())
for successors.Next() {
s := successors.Node().(*activity)
lf = math.Min(lf, s.lateStart)
if a.lateFinish > s.lateStart {
a.lateFinish = s.lateStart
}
}
if a.lateFinish == math.Inf(1) {
a.lateFinish = a.earlyFinish
}
a.lateFinish = lf
a.lateStart = a.lateFinish - a.duration
a.slack = a.lateFinish - a.earlyFinish
}