get rid of temp variables

This commit is contained in:
filifa 2024-05-26 14:33:31 -05:00
parent c163aa0f23
commit 1fe3e8e7cb
1 changed files with 9 additions and 8 deletions

View File

@ -78,29 +78,30 @@ 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)
es = math.Max(es, p.earlyFinish) if a.earlyStart < 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) {
lf := math.Inf(1) a.lateFinish = 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)
lf = math.Min(lf, s.lateStart) if a.lateFinish > s.lateStart {
a.lateFinish = s.lateStart
}
} }
if lf == math.Inf(1) { if a.lateFinish == math.Inf(1) {
lf = a.earlyFinish 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
} }