Skip to content

Instantly share code, notes, and snippets.

@eug
Last active August 23, 2021 22:39
Show Gist options
  • Save eug/086875df1c8fea762ca3453d6c698746 to your computer and use it in GitHub Desktop.
Save eug/086875df1c8fea762ca3453d6c698746 to your computer and use it in GitHub Desktop.
"""
Schedule Work Breakdown Structure Uncertainty with Monte Carlo Simulations
"""
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
def simulate(wbs, n=100000, proba=0.9):
""" Simulate the possible completion time of a WBS project.
Parameters
----------
wbs: dict {str: (int, int, int)}
Work Breakdown Structure
n: int
Number of simulations
proba: float
Probability of interest
"""
values = np.empty((0, n), np.float)
for (mn, lk, mx) in wbs.values():
if mn == mx:
values = np.append(values, [np.zeros(n) + mn], axis=0)
else:
values = np.append(values, [np.random.triangular(left=mn, mode=lk, right=mx, size=n)], axis=0)
sample = values.sum(axis=0)
sns.set_style("whitegrid")
graph = sns.ecdfplot(sample)
graph.axhline(y=proba, xmin=0, xmax=max(sample), color="red", ls="--", lw=1.5, visible=True, label="aaa")
# provide the duration range for each task in the WBS as follows (min, likely, max)
wbs = {
"task1": (3, 5, 7),
"task2": (1, 2, 6),
"task3": (3, 4, 5),
"task4": (2, 4, 8),
"task5": (1, 2, 6),
"task6": (1, 5, 7),
"task7": (1, 2, 7),
"task8": (1, 1, 1),
}
simulate(wbs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment