---
title: criticalpath - R Package Implementation of Critical Path Method
output: 
  rmarkdown::html_vignette:
    toc: TRUE
    number_sections: true
    toc_depth: 3
author:
  Rubens Jose Rosa, Marcos dos Santos, Thiago Marques
date: 2022-01-10
vignette: >
  %\VignetteIndexEntry{criticalpath Package Introduction}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```


```{r setup}
library(criticalpath)
```


`criticalpath` package is an R implementation of the
Critical Path Method (CPM). CPM is a method used to estimate
the minimum project duration and  determine the amount of scheduling flexibility
on the logical network paths within the schedule model. The flexibility is in
terms of early start, early finish, late start, late finish, total float and
free float. Beside, it permits to quantify the complexity of network diagram
through the analysis of topological indicators. Finally, it permits to change
the activities duration to perform what-if scenario analysis.

With this package, you can calculate the following CPM parameters:

- Schedule duration;
- Early start and finish date of each activity;
- Late start and finish date of each activity;
- Critical activities;
- Critical path;
- Total float and free float;
- Gantt Matrix;
- What-if scenario analysis;
- Topological indicators.


The aim of this package is to apply critical path method, for project managers
and researchers to make experiments with CPM parameters.

# How to create a schedule

To create a schedule, you need to add activities and their relations in it.
Optionally, you may define a title and a reference. You have the following
alternatives to create a schedule:

1. Create a schedule with activities and relations.
1. Create a schedule, add activities and relations to it.
1. Create a schedule and add activities at the same time that 
add relations to it.
1. Create a schedule and add activities to it.

Lets see example from each one.


## Create a schedule with activities and relations

Make a schedule with activities and relations between activities. 
For this, you have the following steps:

1. create an empty schedule:
   - `sch_new()`
1. define the title of the schedule:
   - `sch_title()`
1. define the reference of the schedule:
   - `sch_reference()`
1. add activities to the schedule:
   - `sch_add_activities()`
1. add relations to the schedule:
   - `sch_add_relations()`
1. plan the schedule
   - `sch_plan()`

**Attention:** The `sch_plan()` function is crucial:
it responsible to apply the Critical Path Method (CPM).

Example:


```{r}
sch <- sch_new() %>% 
  sch_title("Project 1: Cost Information System") %>% 
  sch_reference("VANHOUCKE, Mario.
    Integrated project management and control:
    first comes the theory, then the practice.
    Gent: Springer, 2014, p. 6") %>% 
  sch_add_activities(
    id        = 1:17,
    name      = paste("a", as.character(1:17), sep=""),
    duration  = c(1L,2L,2L,4L,3L,3L,3L,2L,1L,1L,2L,1L,1L,1L,1L,2L,1L)
  ) %>% 
  sch_add_relations(
  from = c(1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L,  3L,  4L,  5L,  6L,
           7L,  8L,  9L, 10L, 11L, 11L, 12L, 12L, 13L, 13L, 14L, 14L, 15L, 15L),
  to   = c(2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 11L, 11L,
           12L, 13L, 14L, 15L, 16L, 17L, 16L, 17L, 16L, 17L, 16L, 17L, 16L, 17L)
  ) %>% 
  sch_plan()

sch_duration(sch)
sch_activities(sch)
sch_relations(sch)
```



## Create a schedule, add activities and relations to it

Create a schedule and add each activity to it, one by one.
Also, add each relation to it, one by one, too.
Steps:

1. create an empty schedule:
   - `sch_new()`
1. define the title of the schedule:
   - `sch_title()`
1. define the reference of the schedule:
   - `sch_reference()`
1. add each activity to the schedule:
   - `sch_add_activity()`
1. add each relation to the schedule:
   - `sch_add_relation()`
1. plan the schedule
   - `sch_plan()`

**Attention:** The `sch_plan()` function is crucial:
it responsible to apply the Critical Path Method (CPM).

Example:

```{r}
sch <- sch_new() %>% 
  sch_title("Project 3: Old Carriage House Renovation") %>% 
  sch_reference(
  "VANHOUCKE, Mario. Integrated project management and control:
  first comes the theory, then the practice. Gent: Springer, 2014, p. 11") %>% 
  sch_add_activity( 1L, "a1" , 2L) %>% 
  sch_add_activity( 2L, "a2" , 2L) %>% 
  sch_add_activity( 3L, "a3" , 4L) %>% 
  sch_add_activity( 4L, "a4" , 3L) %>% 
  sch_add_activity( 5L, "a5" , 4L) %>% 
  sch_add_activity( 6L, "a6" , 1L) %>% 
  sch_add_activity( 7L, "a7" , 1L) %>% 
  sch_add_activity( 8L, "a8" , 1L) %>% 
  sch_add_activity( 9L, "a9" , 1L) %>% 
  sch_add_activity(10L, "a10", 1L) %>% 
  sch_add_activity(11L, "a11", 3L) %>% 
  sch_add_activity(12L, "a12", 2L) %>% 
  sch_add_activity(13L, "a13", 1L) %>% 
  sch_add_activity(14L, "a14", 1L) %>% 
  sch_add_activity(15L, "a15", 2L) %>% 
  sch_add_activity(16L, "a16", 1L) %>% 
  sch_add_activity(17L, "a17", 1L) %>% 
  sch_add_relation( 1L,  2L) %>% 
  sch_add_relation( 2L,  3L) %>% 
  sch_add_relation( 3L,  4L) %>% 
  sch_add_relation( 4L,  5L) %>% 
  sch_add_relation( 5L,  6L) %>% 
  sch_add_relation( 6L,  7L) %>% 
  sch_add_relation( 6L,  8L) %>% 
  sch_add_relation( 6L,  9L) %>% 
  sch_add_relation( 7L, 10L) %>% 
  sch_add_relation( 8L, 10L) %>% 
  sch_add_relation( 9L, 10L) %>% 
  sch_add_relation(10L, 11L) %>% 
  sch_add_relation(10L, 13L) %>% 
  sch_add_relation(11L, 12L) %>% 
  sch_add_relation(12L, 15L) %>% 
  sch_add_relation(13L, 14L) %>% 
  sch_add_relation(14L, 15L) %>% 
  sch_add_relation(15L, 16L) %>% 
  sch_add_relation(16L, 17L) %>% 
  sch_plan()

sch_duration(sch)
sch_activities(sch)
sch_relations(sch)
```

## Create a schedule and add activities at the same time that add relations to it

Add an activity to a schedule in the same time that adds relations.
The steps are:

1. create an empty schedule:
   - `sch_new()`
1. define the title of the schedule:
   - `sch_title()`
1. define the reference of the schedule:
   - `sch_reference()`
1. add each activity to the schedule 
and, in the same time, the activity's relation:
   - `sch_add_activity()`
1. plan the schedule
   - `sch_plan()`

**Attention:** The `sch_plan()` function is crucial:
it responsible to apply the Critical Path Method (CPM).

Example:

```{r}
# Create a schedule
sch <- sch_new() %>% 
  sch_title("Fictitious Project Example") %>% 
  sch_reference("VANHOUCKE, Mario. Measuring time:
  improving project performance using earned value management.
  Gent: Springer, 2009, p. 18") %>% 
  sch_add_activity( 1L, "a1" , 0L,  2L,3L,4L) %>% 
  sch_add_activity( 2L, "a2" , 4L,  5L) %>% 
  sch_add_activity( 3L, "a3" , 9L, 10L) %>% 
  sch_add_activity( 4L, "a4" , 1L,  6L) %>% 
  sch_add_activity( 5L, "a5" , 4L,  9L) %>% 
  sch_add_activity( 6L, "a6" , 5L,  7L) %>% 
  sch_add_activity( 7L, "a7" , 1L,  8L,11L) %>% 
  sch_add_activity( 8L, "a8" , 7L, 12L) %>% 
  sch_add_activity( 9L, "a9" , 8L, 12L) %>% 
  sch_add_activity(10L, "a10", 3L, 12L) %>% 
  sch_add_activity(11L, "a11", 3L, 12L) %>% 
  sch_add_activity(12L, "a12", 0L) %>% 
  sch_plan()

sch_duration(sch)
sch_activities(sch)
sch_relations(sch)
```



## Create a schedule and add activities to it

Creates a schedule only with activities. 
The steps are:

1. create an empty schedule:
   - `sch_new()`
1. define the title of the schedule:
   - `sch_title()`
1. define the reference of the schedule:
   - `sch_reference()`
1. add each activity to the schedule :
   - `sch_add_activity()`
1. plan the schedule
   - `sch_plan()`

**Attention:** The `sch_plan()` function is crucial:
it responsible to apply the Critical Path Method (CPM).

Example:

```{r}
# Activities added one by one
sch <- sch_new() %>% 
  sch_add_activity(1L, "Task 1", 5L) %>% 
  sch_add_activity(2L, "Task 2", 6L) %>% 
  sch_add_activity(3L, "Task 3", 8L) %>% 
  sch_add_activity(4L, "Task 4", 6L) %>% 
  sch_add_activity(5L, "Task 5", 9L) %>% 
  sch_add_activity(6L, "Task 6", 3L) %>% 
  sch_add_activity(7L, "Task 7", 4L) %>% 
  sch_plan()
sch_duration(sch)
sch_activities(sch)
```


## Observations

- You must always to call `sch_plan()` function.
- You may have a schedule without relation.
In this case, by CPM definition, all activities are parallel.




# How to get schedule information

After schedule creation, it is possible access several type of information,
such as Title, Reference and Schedule Duration.

## Title

A project title for identification. It depends on
user of the class. Its use are:

   - `sch %>% sch_title("A title")` : sets a title for a project.
   - `sch_title(sch)` : gets the title of the project.

## Reference

A reference from project origin, for example, a book, a paper, a corporation,
or nothing.

   - `sch %>% sch_reference("A reference")` : sets a reference for a project.
   - `sch_reference(sch)` : gets the reference of the project.

## Duration

An integer value that indicate the project duration calculated by CPM, that is
made by `sch_plan(sch)` function. You can only read the schedule duration.

   - `sch_duration(sch)` : gets the duration of the project.

## Example

```{r}
# Create a schedule
sch <- sch_new() %>% 
  sch_title("Fictitious Project Example") %>% 
  sch_reference("VANHOUCKE, Mario. Measuring time:
    improving project performance using earned value management.
    Gent: Springer, 2009, p. 18") %>% 
# Add activities and relations to it.
  sch_add_activity(  1L, "a1" , 0L,  2L,3L,4L) %>% 
  sch_add_activity(  2L, "a2" , 4L,  5L) %>% 
  sch_add_activity(  3L, "a3" , 9L,  10L) %>% 
  sch_add_activity(  4L, "a4" , 1L,  6L) %>% 
  sch_add_activity(  5L, "a5" , 4L,  9L) %>% 
  sch_add_activity(  6L, "a6" , 5L,  7L) %>% 
  sch_add_activity(  7L, "a7" , 1L,  8L,11L) %>% 
  sch_add_activity(  8L, "a8" , 7L, 12L) %>% 
  sch_add_activity(  9L, "a9" , 8L, 12L) %>% 
  sch_add_activity( 10L, "a10", 3L, 12L) %>% 
  sch_add_activity( 11L, "a11", 3L, 12L) %>% 
  sch_add_activity( 12L, "a12", 0L) %>% 
  sch_plan()
sch_title(sch)
sch_reference(sch) %>% cat()
sch_duration(sch)
```



# How to get activities properties

There several methods about activities that you can use to get
information about them. After you add activities to a schedule, you may
want to know how much activities has in a schedule or when each activity
is planned to start or to finish.
In this section, we will explain how you can find these information.

## Has Any Activity

A logical value that indicate if the schedule
has any activity. A TRUE value means that the schedule has some
activity; a FALSE, means that the schedule is empty.

   - `sch_has_any_activity(sch)`

## Number of Activities

Number of activities in a schedule as an integer value.

   - `sch_nr_activities(sch)`

## Get Activity

Gets an activity by id. It returns a tibble  with one line about activity.
The structure of a data is described in next topic.

   - `sch_get_activity(sch, id)`

## Activities

Return a tibble with all activities of a schedule.
This is the main information calculated by CPM.
The tibble is formed by following columns:

   - **id:** Activity id.
   - **name:** The name of activity.
   - **duration:** A number that represents the activity's duration.
   - **milestone:** A milestone is an activity with zero duration.
   This property indicates if a activity is a milestone or not:
   `TRUE` indicates it is a milestone; `FALSE` indicates it is not.
   - **critical:** A critical activity is one with total float minor or equal
   to zero. This property indicates if a activity is critical:
   `TRUE` indicates it is critical;
   `FALSE` indicates it is not critical.
   - **early_start:** Early Start: is the earliest start period an activity can begin
   after its predecessors without violating precedence relation.
   - **early_finish:** Early Finish: is the early start plus activity duration.
   - **late_start:** Late Start: is the late finish minus activity duration.
   - **late_finish:** Late Finish: is the latest finish an activity can finish
   before their successors without violating precedence relation.
   - **total_float:** It is the amount of period an activity can be
   delayed without violating the project duration. Its formula is:
   `late_start - early_star` or `late_finish - late_start`.
   - **free_float:** It is the amount of period an activity can be
   delayed without violating the start time of the successors activities.
   - **progr_level:** Progressive level is the rank of activities counted
   from begin. The level of the activities that don't have predecessor is one;
   the level of the other activities, is one plus the maximal level of
   their predecessor.
   - **regr_level:** Regressive level is the rank of activities counted
   from the end. The level of the activities that don't have successor is the
   maximal progressive level; the level of the other activities,
   is one minus the minimal level of their successor.
   - **topo_float:** It is the difference between progressive level
    and regressive level.

   - Usage: `sch_activities(sch)`

```{r}
# Create a schedule
sch <- sch_new() %>% 
  sch_title("Fictitious Project Example") %>% 
  sch_reference("VANHOUCKE, Mario. Measuring time:
    improving project performance using earned value management.
    Gent: Springer, 2009, p. 18") 

sch_has_any_activity(sch)  # FALSE
sch_nr_activities(sch)     # 0

# Add activities and relations to it.
sch %<>% 
  sch_add_activity(  1L, "a1" , 0L,  2L,3L,4L) %>% 
  sch_add_activity(  2L, "a2" , 4L,  5L) %>% 
  sch_add_activity(  3L, "a3" , 9L,  10L) %>% 
  sch_add_activity(  4L, "a4" , 1L,  6L) %>% 
  sch_add_activity(  5L, "a5" , 4L,  9L) %>% 
  sch_add_activity(  6L, "a6" , 5L,  7L) %>% 
  sch_add_activity(  7L, "a7" , 1L,  8L,11L) %>% 
  sch_add_activity(  8L, "a8" , 7L, 12L) %>% 
  sch_add_activity(  9L, "a9" , 8L, 12L) %>% 
  sch_add_activity( 10L, "a10", 3L, 12L) %>% 
  sch_add_activity( 11L, "a11", 3L, 12L) %>% 
  sch_add_activity( 12L, "a12", 0L) %>% 
  sch_plan()

sch_has_any_activity(sch)  # TRUE
sch_nr_activities(sch)     # 12

sch_get_activity(sch, 10L)
sch_activities(sch)
```


## Gantt Matrix

Create a matrix that represents a Gantt chart,
a matrix where "1" indicate that an activity is planned to be
in execution.

In this matrix, the rows represent activities,
whereas the columns represents the activity execution period.
So, the number of columns is equal to project duration.

- `sch_gantt_matrix(sch)` Return the Gantt matrix.

- `sch_xy_gantt_matrix(sch, gantt=NULL)`
Transform a Gantt matrix in x, y coordinates and the weight one.
Each point greater than zero in a Gantt matrix becomes a x, y coordinate.

```{r}
sch <- sch_new() %>% 
  sch_title("A project") %>%
  sch_reference("From criticalpath") %>% 
  sch_add_activities(
    id        = c( 1L,   2L,   3L,   4L ),
    name      = c("A", "B", "C", "D"),
    duration  = c( 2L,   3L,   1L,   2L )
  ) %>% 
  sch_add_relations(
    from = c(1L, 2L, 4L, 4L),
    to   = c(3L, 3L, 1L, 2L)
  ) %>% 
  sch_plan()

gantt <- sch_gantt_matrix(sch)

gantt

# What is the effort by time period?
colSums(gantt) # 1 1 2 2 1 1

# What is the duration by activities?
rowSums(gantt) # 2 3 1 2

# what is the S curve
cumsum(colSums(gantt))
plot(cumsum(colSums(gantt)), type="l", lwd=3)
xyw <- sch_xy_gantt_matrix(sch)
xyw
plot(xyw[, 1:2])
```


# How to change activities duration

Change activities duration and calculates critical path.
This way is faster than creating a new schedule with new duration.
The order of duration is the insertion order of activities.

- `sch %<>% sch_change_durations(new_durations)`

```{r}
sch <- sch_new() %>% 
  sch_title("Project 2: Patient Transport System") %>% 
  sch_reference(
  "VANHOUCKE, Mario. Integrated project management and control:
  first comes the theory, then the practice. Gent: Springer, 2014, p. 9") %>% 
  sch_add_activities(
    id        = 1:17,
    name      = paste("a", as.character(1:17), sep=""),
    duration  = c(1L,1L,3L,2L, 2L,2L,2L,1L, 4L,5L,3L,3L, 4L,5L,1L,5L,2L)
  ) %>% 
  sch_add_relations(
    from = c(1L, 2L, 3L, 3L, 4L, 5L, 6L, 7L, 8L,  8L,  8L,
      8L,  8L,  9L, 10L, 11L, 12L, 13L, 13L, 14L, 14L, 15L, 15L),
    to   = c(2L, 3L, 4L, 6L, 5L, 8L, 7L, 8L, 9L, 10L, 11L,
     12L, 13L, 14L, 14L, 14L, 14L, 14L, 15L, 16L, 17L, 16L, 17L)
  ) %>% 
  sch_plan()

#Project duration
sch_duration(sch) # 25

#Activities duration
sch_activities(sch)$duration

new_durations <- c(1L,2L,5L, 4L,3L, 2L,1L, 5L, 3L,5L,5L,3L,4L, 2L,1L, 2L,4L)
sch %<>% 
  sch_change_activities_duration(new_durations)

#Project duration
sch_duration(sch) # 31
#Activities duration
sch_activities(sch)$duration

```

Now, we will create the same schedule, but with activities insertion in random
order. The relation between activities will be the same.

Then, will change the activities duration with the same data as above.
The new schedule duration will be the same.

```{r}
n <- sch %>% sch_nr_activities()
set.seed(45678)
i <- sample(n)

another_schedule <- sch_new() %>% 
  sch_add_activities(
    id        = sch_activities(sch)$id[i],
    name      = sch_activities(sch)$name[i],
    duration  = sch_activities(sch)$duration[i]
  ) %>%
  sch_add_relations(
    from = c(1L, 2L, 3L, 3L, 4L, 5L, 6L, 7L, 8L,  8L,  8L,
             8L,  8L,  9L, 10L, 11L, 12L, 13L, 13L, 14L, 14L, 15L, 15L),
    to   = c(2L, 3L, 4L, 6L, 5L, 8L, 7L, 8L, 9L, 10L, 11L,
             12L, 13L, 14L, 14L, 14L, 14L, 14L, 15L, 16L, 17L, 16L, 17L)
  ) %>%
  sch_plan()


another_schedule %<>% sch_change_activities_duration(new_durations[i])
# Second schedule.
sch_duration(another_schedule)

# First schedule.
sch_duration(sch)
```


# How to get relations properties

## Relation Properties

There are several methods about relations that you can use to get
information about them. After you add activities and relations
to a schedule, you may want to know how much relations has in a
schedule or which relations belong to critical path.
In this section, we will explain how you can find these information.

- **Has Any Relation:**
A logical value that indicates if the schedule
has any relation. A TRUE value means that the schedule has some
relation; a FALSE, means that the schedule does not have any relation.
   - `sch_has_any_relation(sch)`

- **Number of Relations:**
Number of relations in a schedule as an integer value.
   - `sch_nr_relations(sch)`

- **Relations:**
Return a tibble with all relations of a schedule
in topological order. This is the main information calculated by CPM.
The tibble is formed by following structure:
   - **from:** Predecessor activity id from a relation.
   - **to:** Successor activity id from a relation.
   - **type:** The type of relation between activities.
   Its value may be: FS, FF, SS, SF.
   - **lag:** The time period between activity predecessor and
   activity successor activity
   - **critical:** A critical relation formed by two activity critical:
   predecessor and successor.
   `TRUE` indicates it is critical;
   `FALSE` indicates it is not critical.
   - **ord:** Indicates de order that the relation was added in the schedule.
   - **i_from:** It the index of predecessor activity in the
   activities data frame.
   - **i_to:** It the index of successor activity in the
   activities data frame.

   - Usage: `sch_relations(sch)`

```{r}
# Create a schedule
sch <- sch_new() %>% 
  sch_title("Fictitious Project Example") %>% 
  sch_reference("VANHOUCKE, Mario. Measuring time:
  improving project performance using earned value management.
  Gent: Springer, 2009, p. 18")

sch_has_any_relation(sch)  # FALSE
sch_nr_relations(sch)      # 0

sch %<>% 
  sch_add_activity( 1L, "a1" , 0L,  2L,3L,4L) %>% 
  sch_add_activity( 2L, "a2" , 4L,  5L) %>% 
  sch_add_activity( 3L, "a3" , 9L, 10L) %>% 
  sch_add_activity( 4L, "a4" , 1L,  6L) %>% 
  sch_add_activity( 5L, "a5" , 4L,  9L) %>% 
  sch_add_activity( 6L, "a6" , 5L,  7L) %>% 
  sch_add_activity( 7L, "a7" , 1L,  8L,11L) %>% 
  sch_add_activity( 8L, "a8" , 7L, 12L) %>% 
  sch_add_activity( 9L, "a9" , 8L, 12L) %>% 
  sch_add_activity(10L, "a10", 3L, 12L) %>% 
  sch_add_activity(11L, "a11", 3L, 12L) %>% 
  sch_add_activity(12L, "a12", 0L) %>% 
  sch_plan()


sch_has_any_relation(sch)  # TRUE
sch_nr_relations(sch)      # 14

sch_relations(sch)
```


## Successors and Predecessors

A schedule is structured by activities and each activity has
zero, one or more successors and predecessors. Besides, a relation
may be redundant. In `criticalpath` package there are several methods
to deal these properties.

- **All Successors:**
List all successors from an activity: direct and indirect successors.
   - `sch_all_successors(sch, id)`
   
- **Successors:**
List direct successors from an activity.
   - `sch_successors(sch, id)`

- **All Predecessors:**
List all predecessors from an activity: direct or indirect predecessors.
   - `sch_all_predecessors(sch, id)`

- **Predecessors:**
List directe predecessors from an activity.
   - `sch_all_predecessors(sch, id)`

- **Is Redundant:**
Verify if a relation between two activities is redundant.
A relation A->C is redundant if there are A->C, A->B, B->C relations.
It returns a logical `TRUE` if an arc is redundant;
`FALSE` if it is not.
   - `sch_is_redundant(sch, id_from, id_to)`

```{r}
# Create a schedule
sch <- sch_new() %>% 
  sch_title("Fictitious Project Example") %>% 
  sch_reference("VANHOUCKE, Mario. Measuring time:
    improving project performance using earned value management.
    Gent: Springer, 2009, p. 18") %>% 
  sch_add_activity( 2L, "a2" , 4L,  5L, 12L) %>% 
  sch_add_activity( 3L, "a3" , 9L, 10L) %>% 
  sch_add_activity( 4L, "a4" , 1L,  6L) %>% 
  sch_add_activity( 5L, "a5" , 4L,  9L) %>% 
  sch_add_activity( 6L, "a6" , 5L,  7L) %>% 
  sch_add_activity( 7L, "a7" , 1L,  8L,11L) %>% 
  sch_add_activity( 8L, "a8" , 7L, 12L) %>% 
  sch_add_activity( 9L, "a9" , 8L, 12L) %>% 
  sch_add_activity(10L, "a10", 3L, 12L) %>% 
  sch_add_activity(11L, "a11", 3L, 12L) %>% 
  sch_add_activity(12L, "a12", 0L) %>% 
  sch_plan()

sch_all_successors(sch, 2) # 5, 9, 12
sch_all_successors(sch, 7) # 8, 11, 12
sch_all_successors(sch, 10) # 12

sch_successors(sch, 2) # 5, 12
sch_successors(sch, 7) # 8, 11
sch_successors(sch, 10) # 12

sch_all_predecessors(sch, 2) # nothing
sch_all_predecessors(sch, 7) # 6, 4
sch_all_predecessors(sch, 10) # 3

sch_predecessors(sch, 2) # nothing
sch_predecessors(sch, 7) # 6
sch_predecessors(sch, 10) # 3

sch_is_redundant(sch, 2, 5)  #FALSE
sch_is_redundant(sch, 2, 12) #TRUE

```

# How to get topological properties: Topological Indicators

Shows information about network structure. It may be of four type:

**SP Serial or Parallel:**
It shows the closeness of a network to a serial or parallel graph.
As the network becomes serial, the SP increase, until one;
As the network becomes parallel, the SP decrease until zero.
   - `sch_topoi_sp()`

**AD Activity Distribution:**
Measures the distribution of the activities over the levels.
If AD is approximately equal zero, each level has same numbers of activities.
Otherwise, if AD is equal one, the quantity of each level is not
uniformly distributed.
   - `sch_topoi_ad()`

**LA Length of Arcs:**
Measures the presence of long arcs based on the difference between
the progressive level of the end activity and the start node
of each relation.
If LA is approximately equal zero, the progressive level between
activities are as far as possible.
Otherwise, if LA is equal one, the relation distance are one.
   - `sch_topoi_la()`

**TF Topological Float Indicator:**
Measures the topological float of each activity.
If TF = 0, there is no float between activities.
If TF = 1, there is float between activities
and they may be shift without affecting other activities.
   - `sch_topoi_tf()`

```{r}
# Create a schedule
sch <- sch_new() %>% 
  sch_title("Fictitious Project Example") %>%
  sch_reference("VANHOUCKE, Mario. Measuring time:
    improving project performance using earned value management.
    Gent: Springer, 2009, p. 18") %>% 
  # Add activities and relations to it.
  sch_add_activity( 1L, "a1" , 0L,  2L,3L,4L) %>% 
  sch_add_activity( 2L, "a2" , 4L,  5L) %>% 
  sch_add_activity( 3L, "a3" , 9L, 10L) %>% 
  sch_add_activity( 4L, "a4" , 1L,  6L) %>% 
  sch_add_activity( 5L, "a5" , 4L,  9L) %>% 
  sch_add_activity( 6L, "a6" , 5L,  7L) %>% 
  sch_add_activity( 7L, "a7" , 1L,  8L,11L) %>% 
  sch_add_activity( 8L, "a8" , 7L, 12L) %>% 
  sch_add_activity( 9L, "a9" , 8L, 12L) %>% 
  sch_add_activity(10L, "a10", 3L, 12L) %>% 
  sch_add_activity(11L, "a11", 3L, 12L) %>% 
  sch_add_activity(12L, "a12", 0L) %>% 
  sch_plan()

sch_topoi_sp(sch)
sch_topoi_ad(sch)
sch_topoi_la(sch)
sch_topoi_tf(sch)
```

# References

Csardi, G. & Nepusz, T. (2005).
The Igraph Software Package for Complex Network Research.
**InterJournal**. Complex Systems. 1695.

Project Management Institute (2017)
**A Guide to the Project Management Body of Knowledge (PMBOK Guide)**.
Sixth Edition.

Project Management Institute (2017)
**PMI Lexicon of Project Management Terms:** Version 3.2.

Vanhoucke, M. (2009) **Measuring Time**:
Improving Project Performance Using Earned Value Management.
Springer-Verlag US.

Vanhoucke, M. (2013) **Project Management with Dynamic Scheduling**:
Baseline Scheduling, Risk Analysis and Project Control.
Springer-Verlag Berlin Heidelberg.

Vanhoucke, M. (2014) **Integrated Project Management and Control**:
First Comes the Theory, then the Practice.
Springer International Publishing Switzerland.
