diff --git a/projectnetwork.go b/projectnetwork.go index e15e58d..13559ea 100644 --- a/projectnetwork.go +++ b/projectnetwork.go @@ -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) } @@ -102,6 +96,10 @@ func (g *projectNetwork) setLateTimes(a *activity) { s := successors.Node().(*activity) lf = math.Min(lf, s.lateStart) } + + if lf == math.Inf(1) { + lf = a.earlyFinish + } a.lateFinish = lf a.lateStart = a.lateFinish - a.duration a.slack = a.lateFinish - a.earlyFinish