cpm-rs, a rust crate for Critical Path Method
Tags: cpm, rust, backend, schedule
Published: 2022-04-01 20:10:27

---
title: cpm-rs, a rust crate for Critical Path Method
published: true
description: This article is about my first published rust crate, cpm-rs.
tags: cpm, rust, rustlang, backend, schedule
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qhvd08tyf84x4szysxyr.png
---

# Introduction

The Critical Path Method is a widely used methodology to identify the rigid points of a graph of tasks, where the connections between the tasks are the dependencies. Some things cannot be started without finishing others. There are a lot of real-life examples for this case.

The network of these tasks can be analyzed with different algorithms to get more detailed information about the 'batch', like selecting tasks for high priority. These tasks form a path in the graph alongside their connections. This path is called a 'critical path'. If any of the tasks on this path is being delayed it delays the whole batch, meaning the finishing time for the whole set of tasks will be late.

# cpm-rs

I do not want to bring up the details of the CPM here. There are a lot of very detailed articles and books about the methodology. This article aims to introduce the [cpm-rs](https://crates.io/crates/cpm-rs) Rust crate.
The goal is to have a well tested, reliable library that covers the CPM and still is optimized and scalable.

# Aim

This library should be able to be used in project-management tools and in automated task scheduling for large amount of progressive tasks.

## What do we have

At the moment, the latest published version is v0.1.6 and it is far away from being production-ready. The following features are working:
- File parser for predefined tasks. May be removed later, it is a bit over-engineered and still not so well implemented.
- Critical path calculation.
- Calculation of number of maximum parallel tasks at a time. It means that the Scheduler can calculate the maximal number of parallel tasks in the batch.
- Indexed integer or floating point time units.

### Example

```rust

fn main() {
    let mut scheduler = Scheduler<i32>::new();
    scheduler.add_task(CustomTask::new(
        "Task_A".to_string()
        , 1
        , vec!{}
    ));
    scheduler.add_task(CustomTask::new(
        "Sidetask_B".to_string()
        , 3
        , vec!{"Task_A".to_string()}
    ));
    scheduler.add_task(CustomTask::new(
        "Sidetask_C".to_string()
        , 2
        , vec!{"Task_B".to_string()}
    ));
    scheduler.add_task(CustomTask::new(
        "Finish".to_string()
        , 1
        , vec!{"Sidetask_B".to_string(), "Sidetask_C".to_string()}
    ));
    match scheduler.schedule() {
        Ok(()) => {},
        Err(e) => {eprintln!("Error: {}", e); exit(1);},
    }

}

```

## What we need

The following features are very crucial to have, but not yet implemented:
- Dependency circle check.
- Shiftable tasks.
- Graph visualization.
- Crate features.
- Proper unit tests.
- Stress tests.
- Resource-wise estimation.
- Priority-wise estimation.
- Task grouping.
- Resource type groups.
- Group priority.
- Resource state management.
- Actual time type unit types.
- OPTIMIZATION.
- CI/CD pipeline.

# Call for contribution


![CPM-rs cover](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iarzguk7m3yqpqwsdhgw.png)

If you feel the ambition to participate in this project, you are warmly welcome to contribute!
If you have any questions, please open a pull request on the repository.

[![Crates.io](https://img.shields.io/crates/v/cpm-rs.svg)](https://crates.io/crates/cpm-rs)
[GIT repository](https://github.com/errorport/cpm-rs)
[crates.io page](https://crates.io/crates/cpm-rs)

# References

[The ABCs of the Critical Path Method by F. K. Levy, G. L. Thompson, and J. D. Wiest](https://hbr.org/1963/09/the-abcs-of-the-critical-path-method)