precedence_net/
lib.rs

1//! # Precedence Network Analysis for Rust                                                                                                                                                                                                                                                                                                                                                                                                 
2//!                                                                                                                                                                                                                                                                                                                                                                                                                                          
3//! ## Precedence Networks                                                                                                                                                                                                                                                                                                                                                                                                                   
4//!                                                                                                                                                                                                                                                                                                                                                                                                                                          
5//! A Precedence Network (or [Precedence diagram method](https://en.wikipedia.org/wiki/Precedence_diagram_method)) is a method of constructing connected                                                                                                                                                                                                                                                                                     
6//! activivies in a directed graph that specify dependencies. By specifyfing the minmimum, expected and maximum duration of each task the network can be analysed to                                                                                                                                                                                                                                                                         
7//! find activities that sit on the critical path and must be completed on time to avoid delaying the entire network.                                                                                                                                                                                                                                                                                                                        
8//!                                                                                                                                                                                                                                                                                                                                                                                                                                          
9//! ## Usage                                                                                                                                                                                                                                                                                                                                                                                                                                 
10//!                                                                                                                                                                                                                                                                                                                                                                                                                                          
11//! Given the following precedence network                                                                                                                                                                                                                                                                                                                                                                                                   
12//!                                                                                                                                                                                                                                                                                                                                                                                                                                          
13//! ```text,ignore                                                                                                                                                                                                                                                                                                                                                                                                                           
14//!                        ┌──────────┐                                                                                                                                                                                                                                                                                                                                                                                                      
15//!      ┌────────────────►│Document:4├─────────────────┐                                                                                                                                                                                                                                                                                                                                                                                    
16//!      │                 └──────────┘                 │                                                                                                                                                                                                                                                                                                                                                                                    
17//!      │                                              ▼                                                                                                                                                                                                                                                                                                                                                                                    
18//! ┌────┴───┐       ┌─────────┐     ┌──────┐      ┌────────┐                                                                                                                                                                                                                                                                                                                                                                                
19//! │Design:5├──────►│Develop:6├────►│Test:4├─────►│Deploy:1│                                                                                                                                                                                                                                                                                                                                                                                
20//! └────────┘       └──────┬──┘     └──────┘      └────────┘                                                                                                                                                                                                                                                                                                                                                                                
21//!                         │                           ▲                                                                                                                                                                                                                                                                                                                                                                                    
22//!                         │         ┌───────┐         │                                                                                                                                                                                                                                                                                                                                                                                    
23//!                         └────────►│Train:3├─────────┘                                                                                                                                                                                                                                                                                                                                                                                    
24//!                                   └───────┘                                                                                                                                                                                                                                                                                                                                                                                              
25//! ```                                                                                                                                                                                                                                                                                                                                                                                                                                      
26//! Using `precedence-net` we can model it with the following code                                                                                                                                                                                                                                                                                                                                                                           
27//!                                                                                                                                                                                                                                                                                                                                                                                                                                          
28//! ```rust                                                                                                                                                                                                                                                                                                                                                                                                                                  
29//! use precedence_net::{Network, Result};                                                                                                                                                                                                                                                                                                                                                                                                   
30//!                                                                                                                                                                                                                                                                                                                                                                                                                                          
31//! fn main() -> Result<()> {                                                                                                                                                                                                                                                                                                                                                                                                                
32//!   let mut network_builder = Network::builder();                                                                                                                                                                                                                                                                                                                                                                                          
33//!                                                                                                                                                                                                                                                                                                                                                                                                                                          
34//!   network_builder.add_activity("Design", 5.0)?;                                                                                                                                                                                                                                                                                                                                                                                          
35//!   network_builder.add_activity("Develop", 6.0)?;                                                                                                                                                                                                                                                                                                                                                                                         
36//!   network_builder.add_activity("Document", 4.0)?;                                                                                                                                                                                                                                                                                                                                                                                        
37//!   network_builder.add_activity("Deploy", 1.0)?;                                                                                                                                                                                                                                                                                                                                                                                          
38//!   network_builder.add_activity("Train", 3.0)?;                                                                                                                                                                                                                                                                                                                                                                                           
39//!   network_builder.add_activity("Test", 4.0)?;                                                                                                                                                                                                                                                                                                                                                                                            
40//!                                                                                                                                                                                                                                                                                                                                                                                                                                          
41//!   network_builder.connect("Design", "Develop")?;                                                                                                                                                                                                                                                                                                                                                                                         
42//!   network_builder.connect("Design", "Document")?;                                                                                                                                                                                                                                                                                                                                                                                        
43//!   network_builder.connect("Develop", "Test")?;                                                                                                                                                                                                                                                                                                                                                                                           
44//!   network_builder.connect("Develop", "Train")?;                                                                                                                                                                                                                                                                                                                                                                                          
45//!   network_builder.connect("Test", "Deploy")?;                                                                                                                                                                                                                                                                                                                                                                                            
46//!   network_builder.connect("Train", "Deploy")?;                                                                                                                                                                                                                                                                                                                                                                                           
47//!   network_builder.connect("Document", "Deploy")?;                                                                                                                                                                                                                                                                                                                                                                                        
48//!                                                                                                                                                                                                                                                                                                                                                                                                                                          
49//!   let network = Network::try_from(network_builder)?;                                                                                                                                                                                                                                                                                                                                                                                     
50//!                                                                                                                                                                                                                                                                                                                                                                                                                                          
51//!   println!("Activity | Earliest Start | Earliest Finish | Latest Start | Latest Finish | Total Float | Free Float | Critical Path");                                                                                                                                                                                                                                                                                                     
52//!   println!("---------------------------------------------------------------------------------------------------------------------");                                                                                                                                                                                                                                                                                                     
53//!   for activity in network.activities()? {                                                                                                                                                                                                                                                                                                                                                                                                
54//!     println!(                                                                                                                                                                                                                                                                                                                                                                                                                            
55//!       "{:^8} | {:>14} | {:>15} | {:>12} | {:>13} | {:>11} | {:>10} | {:^14}",                                                                                                                                                                                                                                                                                                                                                            
56//!       activity,                                                                                                                                                                                                                                                                                                                                                                                                                          
57//!       network.earliest_start(activity)?,                                                                                                                                                                                                                                                                                                                                                                                                 
58//!       network.earliest_finish(activity)?,                                                                                                                                                                                                                                                                                                                                                                                                
59//!       network.latest_start(activity)?,                                                                                                                                                                                                                                                                                                                                                                                                   
60//!       network.latest_finish(activity)?,                                                                                                                                                                                                                                                                                                                                                                                                  
61//!       network.total_float(activity)?,                                                                                                                                                                                                                                                                                                                                                                                                    
62//!       network.free_float(activity)?,                                                                                                                                                                                                                                                                                                                                                                                                     
63//!       network.on_critical_path(activity)?,                                                                                                                                                                                                                                                                                                                                                                                               
64//!     );                                                                                                                                                                                                                                                                                                                                                                                                                                   
65//!   }                                                                                                                                                                                                                                                                                                                                                                                                                                      
66//!   Ok(())                                                                                                                                                                                                                                                                                                                                                                                                                                 
67//! }                                                                                                                                                                                                                                                                                                                                                                                                                                        
68//! ```                                                                                                                                                                                                                                                                                                                                                                                                                                      
69//! will produce the following output                                                                                                                                                                                                                                                                                                                                                                                                        
70//! ```text,ignore                                                                                                                                                                                                                                                                                                                                                                                                                           
71//! Activity | Earliest Start | Earliest Finish | Latest Start | Latest Finish | Total Float | Free Float | Critical Path                                                                                                                                                                                                                                                                                                                    
72//! ---------------------------------------------------------------------------------------------------------------------                                                                                                                                                                                                                                                                                                                    
73//!  Design  |              0 |               5 |            0 |             5 |           0 |          0 |      true                                                                                                                                                                                                                                                                                                                        
74//! Develop  |              5 |              11 |            5 |            11 |           0 |          0 |      true                                                                                                                                                                                                                                                                                                                        
75//! Document |              5 |               9 |           11 |            15 |           6 |          6 |     false                                                                                                                                                                                                                                                                                                                        
76//!   Test   |             11 |              15 |           11 |            15 |           0 |          0 |      true                                                                                                                                                                                                                                                                                                                        
77//!  Train   |             11 |              14 |           12 |            15 |           1 |          1 |     false                                                                                                                                                                                                                                                                                                                        
78//!  Deploy  |             15 |              16 |           15 |            16 |           0 |          0 |      true                                                                                                                                                                                                                                                                                                                        
79//! ```                                                                                                                                                                                                                                                                                                                                                                                                                                      
80//!                                                                                                                                                                                                                                                                                                                                                                                                                                          
81//! ## Performance                                                                                                                                                                                                                                                                                                                                                                                                                           
82//!                                                                                                                                                                                                                                                                                                                                                                                                                                          
83//! Using [Criterion.rs](https://github.com/bheisler/criterion.rs) the following activities were benchmarked for a precedence network of 62 500 activities on an Intel Core i7 with 16GB RAM.                                                                                                                                                                                                                                                
84//!                                                                                                                                                                                                                                                                                                                                                                                                                                          
85//! * Adding activities to the network:      78ms                                                                                                                                                                                                                                                                                                                                                                                            
86//! * Creating Network from Network Builder: 239ms                                                                                                                                                                                                                                                                                                                                                                                           
87//! * Creating NetworkBuilder from Network:  44ms                                                                                                                                                                                                                                                                                                                                                                                            
88//! * Retrieving Critical Path:              1.1ms                                                                                                                                                                                                                                                                                                                                                                                           
89//!                                                                                                                                                                                                                                                                                                                                                                                                                                          
90//! ## To Implement                                                                                                                                                                                                                                                                                                                                                                                                                          
91//!                                                                                                                                                                                                                                                                                                                                                                                                                                          
92//! * Cyclic route checking                                                                                                                                                                                                                                                                                                                                                                                                                  
93//! * Serialize and deserialize                                                                                                                                                                                                                                                                                                                                                                                                              
94//! * Update activities
95
96mod activity;
97mod activity_builder;
98mod duration_type;
99mod error;
100mod network;
101mod network_builder;
102mod result;
103mod start_type;
104mod utilities;
105
106pub use duration_type::DurationType;
107pub use error::Error;
108pub use network::Network;
109pub use network_builder::NetworkBuilder;
110pub use result::Result;
111pub use start_type::StartType;
112use utilities::id;