From c163aa0f2304f52dff32816ea8d7d4db075e7ac2 Mon Sep 17 00:00:00 2001 From: filifa Date: Sun, 26 May 2024 13:40:29 -0500 Subject: [PATCH] handle multiple activities with no successor --- projectnetwork.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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