Crate perty

Crate perty 

Source
Expand description

§PERTy

A crate for constructing and analysing Program Evaluation and Review Technique (PERT) task graphs. The library provides the ability to run a single PERT analysis or a Monte-Carlo analysis where the solver can perform multiple runs and sampling from the distributions assigned to the tasks..

§Example

This example comes from the wikipedia page so you can check the results with the ones displayed on their page.

A network diagram created using Microsoft Project (MSP). Note the critical path is in red.

More examples can be found in the examples folder in the GitHub repo.

use perty::{Duration, Pert, PostProcess, Task};

fn main() {
    // Create the tasks. We are using the Task struct provided by the library
    // that implements `TryIntoPertTask` and features the minimum data required
    // for the analysis.
    // The crate provides the `TryIntoPertTask` trait that enables
    // users to keep their task data structures which are likely to
    // contain much more metadata relating to the task but not necessary
    // for a PERT analysis.
    let a = Task::new(
        "A".to_string(),
        vec![],
        Duration::Pert {
            optimistic: 2.,
            most_likely: 4.,
            pessimistic: 6.,
        },
    );
    let b = Task::new(
        "B".to_string(),
        vec![],
        Duration::Pert {
            optimistic: 3.,
            most_likely: 5.,
            pessimistic: 9.,
        },
    );
    let c = Task::new(
        "C".to_string(),
        vec!["A".to_string()],
        Duration::Pert {
            optimistic: 4.,
            most_likely: 5.,
            pessimistic: 7.,
        },
    );
    let d = Task::new(
        "D".to_string(),
        vec!["A".to_string()],
        Duration::Pert {
            optimistic: 4.,
            most_likely: 5.,
            pessimistic: 10.,
        },
    );
    let e = Task::new(
        "E".to_string(),
        vec!["B".to_string(), "C".to_string()],
        Duration::Pert {
            optimistic: 4.,
            most_likely: 5.,
            pessimistic: 7.,
        },
    );
    let f = Task::new(
        "F".to_string(),
        vec!["D".to_string()],
        Duration::Pert {
            optimistic: 3.,
            most_likely: 4.,
            pessimistic: 8.,
        },
    );
    let g = Task::new(
        "G".to_string(),
        vec!["E".to_string()],
        Duration::Pert {
            optimistic: 3.,
            most_likely: 5.,
            pessimistic: 8.,
        },
    );

    // Put the tasks into a vec.
    let tasks = vec![a, b, c, d, e, f, g];

    for t in tasks.iter() {
        println!("{}: {:?}", t.id, t.duration);
    }

    // The PERT trait provides a solve_pert function for types that
    // implement the TryIntoPertTask trait.
    let nodes = tasks.solve_pert(1_000).unwrap();

    // Access the results. Which could be added back to your tasks.
    for n in nodes.iter() {
        println!("{}: {:.2} {}", n.id, n.slack(), n.is_critical());
    }

    println!("Total Duration: {:.2}", nodes.project_duration());
}

§CLI

Help is provided by:

perty pert --help

The CLI can accept a file path to a json description of your project and output the results to another file path set by the user.

perty pert <INP> <OUT> [MAX_ITER]

§Support

Please consider supporting the crate by:

  • Downloading and using the crate.
  • Raising issues and improvements on the GitHub repo.
  • Recommending the crate to others.
  • ⭐ the crate on GitHub.
  • Sponsoring the maintainer.

§References

Structs§

PertTask
A struct that contains the data necessary to resolve a PERT task. Use PertTask::new in your impl of TryIntoTask to construct one for your own task struct definition.
Task
A minimal task descriptor that can implement TryIntoPertTask.

Enums§

Duration
An enum detailing the distributions accepted by Task which are then called to generate a single value for the task for a PERT run.
DurationError
PertError
The different types of error that could be returned when solving the PERT problem.

Traits§

MontePostProcess
A trait the provides post processing analyses over multiple PERT runs where one has sampled their tasks distributions many times.
Pert
The trait introduces the solve_pert functionality. The crate has implemented it for any Vec<T> where T implements TryIntoPertTask.
PostProcess
A trait the provides some common post processing analysis following a PERT solution.
TryIntoPertTask
The primary trait that this crate and the functionality it provides is built around. The user of the library should implement this for their data struct which is likely to contain more task-related information than is required for a PERT analysis. It requires the user to implement try_into_pert_task where they can provide their own error type for cases where the task may not be able to be return a PertTask. The user should extract the information they require from their struct and call PertTask::new to construct the PertTask. Have a look at the impl for Task from this library for an example.