Compare commits

..

No commits in common. "1fe3e8e7cb521abe29ae15cb2671151447297bbd" and "82befabe646ef1f43b82c26fd4ac18c4d03a77cc" have entirely different histories.

1 changed files with 13 additions and 12 deletions

View File

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