mirror of
https://github.com/fazo96/pbs.git
synced 2025-01-29 14:54:18 +01:00
fixed critical path calculation. chained delays still bugged
This commit is contained in:
parent
d551a9c6db
commit
b893e65e1e
@ -1,10 +1,17 @@
|
|||||||
class Pert
|
class Pert
|
||||||
constructor: (@list, @verbose) ->
|
constructor: (@list, @verbose) ->
|
||||||
|
@verbose = true
|
||||||
@days = []
|
@days = []
|
||||||
@criticalPaths = []
|
@criticalPaths = []
|
||||||
|
|
||||||
log: (x...) -> if @verbose then console.log chalk.bold("Pert:"), x...
|
log: (x...) ->
|
||||||
err: (x...) -> console.log chalk.bold (chalk.red "Pert:"), x...
|
if chalk?
|
||||||
|
console.log chalk.bold "[ Pert ]", x...
|
||||||
|
else console.log "[ Pert ]", x...
|
||||||
|
err: (x...) ->
|
||||||
|
if chalk?
|
||||||
|
console.log chalk.bold chalk.red("[ !Pert! ]"), x...
|
||||||
|
else console.log "[ !Pert! ]", x...
|
||||||
|
|
||||||
# Returns the highest number in an array of numbers
|
# Returns the highest number in an array of numbers
|
||||||
maxa: (l) -> return Math.max.apply null, l
|
maxa: (l) -> return Math.max.apply null, l
|
||||||
@ -50,19 +57,15 @@ class Pert
|
|||||||
|
|
||||||
calculateDelays: (item) =>
|
calculateDelays: (item) =>
|
||||||
if !item.dependant? or item.dependant.length is 0 then return no
|
if !item.dependant? or item.dependant.length is 0 then return no
|
||||||
lowestFDelay = 0; fDelay = no; cDelay = no; lowestCDelay = 0
|
lowestFDelay = 0; fDelay = no
|
||||||
for j,i of item.dependant
|
for j,i of item.dependant
|
||||||
x = @toActivity i
|
x = @toActivity i
|
||||||
if x.permittedDelay > 0
|
if x.permittedDelay > 0 and (x.permittedDelay < lowestFDelay or fDelay is no)
|
||||||
if x.permittedDelay < lowestFDelay or fDelay is no
|
lowestFDelay = x.permittedDelay
|
||||||
lowestFDelay = x.permittedDelay
|
fDelay = yes
|
||||||
fDelay = yes
|
|
||||||
if x.chainedDelay > 0
|
|
||||||
if x.chainedDelay < lowestCDelay or cDelay is no
|
|
||||||
lowestCDelay = x.chainedDelay
|
|
||||||
cDelay = yes
|
|
||||||
olDelay = item.chainedDelay
|
olDelay = item.chainedDelay
|
||||||
item.chainedDelay = lowestFDelay + lowestCDelay
|
item.chainedDelay = lowestFDelay or 0
|
||||||
|
@log "chained delay of", item.id, "is", item.chainedDelay
|
||||||
return item.chainedDelay isnt olDelay
|
return item.chainedDelay isnt olDelay
|
||||||
|
|
||||||
calculateCriticalPaths: (path) ->
|
calculateCriticalPaths: (path) ->
|
||||||
@ -72,12 +75,14 @@ class Pert
|
|||||||
if last.dependant? and last.dependant.length > 0
|
if last.dependant? and last.dependant.length > 0
|
||||||
last.dependant.forEach (x) =>
|
last.dependant.forEach (x) =>
|
||||||
ii = @toActivity x
|
ii = @toActivity x
|
||||||
unless ((ii.permittedDelay or 0) + (ii.chainedDelay or 0)) > 0
|
delay = ii.permittedDelay or 0
|
||||||
p = path; p.push x
|
if delay is 0
|
||||||
@calculateCriticalPaths p
|
@calculateCriticalPaths path.concat x
|
||||||
|
else
|
||||||
|
@log "dead end at", lastID, "-->", x, "because delay is", delay
|
||||||
else
|
else
|
||||||
@log "calculated path", path
|
|
||||||
path.forEach (x) => @toActivity(x).critical = yes
|
path.forEach (x) => @toActivity(x).critical = yes
|
||||||
|
@log "calculated path", path
|
||||||
@criticalPaths.push path
|
@criticalPaths.push path
|
||||||
|
|
||||||
# Find out which activity has the highest id
|
# Find out which activity has the highest id
|
||||||
|
Loading…
Reference in New Issue
Block a user