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

mod activity;
mod activity_builder;
mod duration_type;
mod error;
mod network;
mod network_builder;
mod result;
mod start_type;
mod utilities;

pub use duration_type::DurationType;
pub use error::Error;
pub use network::Network;
pub use network_builder::NetworkBuilder;
pub use result::Result;
pub use start_type::StartType;
use utilities::id;