Risk Analysis Tool
Contents
[
Hide
Show
]Performing Risk Analysis
Aspose.Tasks for C++ API supports performing risk analysis on Microsoft Project (MPP/XML) files. This is based on the Monte Carlo simulation that supports different probability distributions and correlations. The Aspose.Tasks.RiskAnalysis.RiskAnalyzer class can be used to perform the risk analysis that is based on a project schedule (task durations and their start/finish dates). So, a project Finish date can be the output of such analysis. The following code example illustrates this functionality step-by-step.
Preparing Analysis Settings
1System::SharedPtr<RiskAnalysisSettings> settings = System::MakeObject<RiskAnalysisSettings>();
2
3// Set number of iterations for Monte Carlo simulation (the default value is 100).
4settings->set_IterationsCount(200);
Identifying the Input of Analysis
1System::SharedPtr<Project> project = System::MakeObject<Project>(dataDir + u"Software Development Plan-1.mpp");
2System::SharedPtr<Task> task = project->get_RootTask()->get_Children()->GetById(17);
3
4// Initialize a risk pattern
5System::SharedPtr<RiskPattern> pattern = System::MakeObject<RiskPattern>(task);
6
7// Select a distribution type for the random number generator to generate possible values from (only two types currently supported, namely normal and uniform)
8// For more details see here: https://en.wikipedia.org/wiki/Normal_distribution)
9pattern->set_Distribution(Aspose::Tasks::RiskAnalysis::ProbabilityDistributionType::Normal);
10
11// Set the percentage of the most likely task duration which can happen in the best possible project scenario
12// The default value is 75, which means that if the estimated specified task duration is 4 days then the optimistic duration will be 3 days
13pattern->set_Optimistic(70);
14
15// Set the percentage of the most likely task duration which can happen in the worst possible project scenario
16// The defaut value is 125, which means that if the estimated specified task duration is 4 days then the pessimistic duration will be 5 days.
17pattern->set_Pessimistic(130);
18
19// Set a confidence level that correspond to the percentage of the time the actual values will be within optimistic and pessimistic estimates.
20// You can think of it as a value of standard deviation: the more uncertain about your estimates you are, the more the value of standard deviation used in random number generator is
21pattern->set_ConfidenceLevel(Aspose::Tasks::RiskAnalysis::ConfidenceLevel::CL75);
22
23settings->get_Patterns()->Add(pattern);
1// Analyze the project risks
2System::SharedPtr<RiskAnalyzer> analyzer = System::MakeObject<RiskAnalyzer>(settings);
3System::SharedPtr<RiskAnalysisResult> analysisResult = analyzer->Analyze(project);
Use the Results of the Analysis
1// Select the desired output (here we get early finish of the root task)
2System::SharedPtr<RiskItemStatistics> rootEarlyFinish = analysisResult->GetRiskItems(Aspose::Tasks::RiskAnalysis::RiskItemType::EarlyFinish)->Get(project->get_RootTask());
3
4System::Console::WriteLine(u"Expected value: {0}", System::ObjectExt::Box<System::DateTime>(rootEarlyFinish->get_ExpectedValue()));
5System::Console::WriteLine(u"StandardDeviation: {0}", System::ObjectExt::Box<Duration>(rootEarlyFinish->get_StandardDeviation()));
6System::Console::WriteLine(u"10% Percentile: {0}", System::ObjectExt::Box<System::DateTime>(rootEarlyFinish->GetPercentile(10)));
7System::Console::WriteLine(u"50% Percentile: {0}", System::ObjectExt::Box<System::DateTime>(rootEarlyFinish->GetPercentile(50)));
8System::Console::WriteLine(u"90% Percentile: {0}", System::ObjectExt::Box<System::DateTime>(rootEarlyFinish->GetPercentile(90)));
9System::Console::WriteLine(u"Minimum: {0}", System::ObjectExt::Box<System::DateTime>(rootEarlyFinish->get_Minimum()));
10System::Console::WriteLine(u"Maximum: {0}", System::ObjectExt::Box<System::DateTime>(rootEarlyFinish->get_Maximum()));
11
12// Save PDF report which is rendered for Project Root Task Finish date
13analysisResult->SaveReport(dataDir + u"AnalysisReport_out.pdf");