Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- from scipy import stats
- def monte_carlo_project_simulation(tasks, iterations=10000):
- project_durations = []
- for _ in range(iterations):
- total_duration = 0
- for task, (opt, likely, pess) in tasks.items():
- # Използваме PERT разпределение
- mean = (opt + 4 * likely + pess) / 6
- std = (pess - opt) / 6
- duration = np.random.normal(mean, std)
- total_duration += max(duration, 0)
- project_durations.append(total_duration)
- return np.array(project_durations)
- tasks = {
- 'Иницииране': (8, 10, 15),
- 'Планиране': (12, 15, 20),
- 'Разработка': (25, 30, 40),
- 'Тестване': (15, 20, 30),
- 'Разгръщане': (10, 15, 25)
- }
- # Изпълнение на симулацията
- durations = monte_carlo_project_simulation(tasks)
- # Анализ на резултатите
- confidence_levels = {
- 50: np.percentile(durations, 50),
- 80: np.percentile(durations, 80),
- 90: np.percentile(durations, 90),
- 95: np.percentile(durations, 95)
- }
- # Визуализация
- plt.figure(figsize=(10, 6))
- plt.hist(durations, bins=50, density=True, alpha=0.7)
- plt.axvline(confidence_levels[80], color='r', linestyle='dashed', label='80% confidence')
- plt.axvline(confidence_levels[95], color='g', linestyle='dashed', label='95% confidence')
- plt.title('Разпределение на продължителността на проекта')
- plt.xlabel('Дни')
- plt.ylabel('Вероятност')
- plt.legend()
- plt.grid(True, alpha=0.3)
- plt.show()
- print("\nРезултати от анализа на риска:")
- for conf, duration in confidence_levels.items():
- print(f"{conf}% вероятност проектът да приключи до {duration:.1f} дни")
Advertisement
Add Comment
Please, Sign In to add comment