Path

public class Path

Author

Tebin Raouf

This class generates paths and task attributes from a Graph object

  • A holder for all paths

    Declaration

    Swift

    private var _allPaths: [[TaskNode]]
  • A holder for all tasks in a path

    Declaration

    Swift

    private var _paths: [TaskNode]
  • A graph representing all tasks

    Declaration

    Swift

    private var graph: Graph
  • All generated paths. Task attributes (such as ES, EF, LS, LF, Slack, isOnCriticalPath) are not calculated

    Declaration

    Swift

    public var paths: [[TaskNode]] { get }
  • Labeled Paths - Critical and None Paths

    Declaration

    Swift

    public var labeledPaths: [PathType : Dictionary<Int, [[TaskNode]]>]
  • All critical paths. Task attributes are calculated

    Declaration

    Swift

    public var criticalPaths: [Int : [[TaskNode]]]
  • Number of paths in a graph

    Declaration

    Swift

    public var count: Int { get }
  • Initialize the Path with a graph

    Declaration

    Swift

    public init(_ graph: Graph)

    Parameters

    graph

    the graph from which pathes are generated

  • Generate all paths and calculate all attributes

    Declaration

    Swift

    public func generate()

    Return Value

    Void

  • Generate paths from a graph. _allPaths is updated

    Declaration

    Swift

    private func initialPathsGenerator()

    Return Value

    Void

  • Remove a task in a collection of paths of tasks

    Declaration

    Swift

    private func remove(task: TaskNode, allPaths: [[TaskNode]]) -> [[TaskNode]]

    Parameters

    task

    The task to be removed

    allPaths

    the collection from which the task is removed

    Return Value

    the new collection without the task which is an array of paths of tasks.

  • Search the graph by using Depth-First Search Algorithm to find all paths

    This method adds each path to _allPaths array

    Declaration

    Swift

    private func getPaths(_ graph: Graph, source: TaskNode)

    Parameters

    graph

    the graph to be searched for paths

    source

    the starting point (TaskNode) of the search

    Return Value

    void

  • Calculate Early Start (ES), Early Finish (EF), Late Start (LS), Late Finish (LF), and Slack for tasks on critical paths

    Declaration

    Swift

    private func calculateCPAttributes()

    Return Value

    Void

  • This function isolates all the paths into PathType. Paths are either Critical or None

    Declaration

    Swift

    private func isolatePaths()

    Return Value

    A key-value pair. Key is of type PathType. Value is a key-value pair. Key is the total duration of the path. Value is an array of paths.

  • This function calculates the total duration of each path

    Declaration

    Swift

    private func getPathsWithDuration() -> Dictionary<Int, [[TaskNode]]>

    Return Value

    A key-value pair. The key is the total duration and the value is any number of paths.

  • Calculate Early Start (ES), Early Finish (EF), Late Start (LS), Late Finish (LF), and Slack for tasks on none critical paths

    Declaration

    Swift

    private func calculateNoneCPAttributes()

    Return Value

    Void

  • A utility function to loop through all none critical paths. labeledPaths property is updated.

    Declaration

    Swift

    private func calculateEarlyStartFinish(_ callback: (TaskNode) -> ())

    Parameters

    callback

    a callback function to handle how tasks’ ES and EF are calculated. It differs for tasks with one predecessor and tasks with more than one predecessor

    Return Value

    Void

  • A utility function to loop though all none critical paths in reverse order. labeledPaths property is updated.

    Declaration

    Swift

    private func calculateLateStartFinish(_ callback: (TaskNode) -> ())

    Parameters

    callback

    a callback function to handle how tasks’ LS and LF are calculated. It differs for tasks with no successors and tasks with successors.

    Return Value

    void