GeorgePashev_88

Untitled

Nov 27th, 2024
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.85 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from scipy import stats
  4.  
  5. def monte_carlo_project_simulation(tasks, iterations=10000):
  6.  
  7.     project_durations = []
  8.     for _ in range(iterations):
  9.         total_duration = 0
  10.         for task, (opt, likely, pess) in tasks.items():
  11.         # Използваме PERT разпределение
  12.             mean = (opt + 4 * likely + pess) / 6
  13.             std = (pess - opt) / 6
  14.             duration = np.random.normal(mean, std)
  15.             total_duration += max(duration, 0)
  16.  
  17.         project_durations.append(total_duration)
  18.  
  19.     return np.array(project_durations)
  20.  
  21.  
  22. tasks = {
  23. 'Иницииране': (8, 10, 15),
  24. 'Планиране': (12, 15, 20),
  25. 'Разработка': (25, 30, 40),
  26. 'Тестване': (15, 20, 30),
  27. 'Разгръщане': (10, 15, 25)
  28. }
  29.  
  30. # Изпълнение на симулацията
  31. durations = monte_carlo_project_simulation(tasks)
  32.  
  33. # Анализ на резултатите
  34. confidence_levels = {
  35. 50: np.percentile(durations, 50),
  36. 80: np.percentile(durations, 80),
  37. 90: np.percentile(durations, 90),
  38. 95: np.percentile(durations, 95)
  39. }
  40.  
  41. # Визуализация
  42. plt.figure(figsize=(10, 6))
  43. plt.hist(durations, bins=50, density=True, alpha=0.7)
  44. plt.axvline(confidence_levels[80], color='r', linestyle='dashed', label='80% confidence')
  45. plt.axvline(confidence_levels[95], color='g', linestyle='dashed', label='95% confidence')
  46. plt.title('Разпределение на продължителността на проекта')
  47. plt.xlabel('Дни')
  48. plt.ylabel('Вероятност')
  49. plt.legend()
  50. plt.grid(True, alpha=0.3)
  51. plt.show()
  52.  
  53. print("\nРезултати от анализа на риска:")
  54. for conf, duration in confidence_levels.items():
  55.     print(f"{conf}% вероятност проектът да приключи до {duration:.1f} дни")
Advertisement
Add Comment
Please, Sign In to add comment