Risk Analysis Tool
Contents
[
Hide
Show
]Performing Risk Analysis
Aspose.Tasks for Java API supports for performing risk analysis on a Project data file. This is based on the Monte Carlo simulation that supports different probability distributions and correlations. The 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 example illustrates this functionality step-by-step.
1. Preparing Analysis Settings
1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
2RiskAnalysisSettings settings = new RiskAnalysisSettings();
3// set a number of iterations for Monte Carlo simulation (the default value is 100).
4settings.setIterationsCount(200);
2. Identifying the Input of Analysis
1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
2Project project = new Project("NewProductDev.mpp"); // attached test project
3
4// Initialize a risk pattern
5Task task = project.getRootTask().getChildren().getById(14);
6
7RiskPattern pattern = new RiskPattern(task);
8// Select a distribution type for the random number generator to generate possible values from (only two types currently supported, namely normal and uniform)
9// note that the normal distributions are often used in the natural and social sciences to represent real-valued random variables whose distributions are not known,
10// thus this distribution is set to default (for more details see here: https://en.wikipedia.org/wiki/Normal_distribution)
11pattern.setDistribution (ProbabilityDistributionType.Normal);
12// Set the percentage of the most likely task duration which can happen in the best possible project scenario
13// (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)
14pattern.setOptimistic(70);
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.setPessimistic(130);
18// Set a confidence level that correspond to the percentage of the time the actual values will be within optimistic and pessimistic estimates.
19// 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
20pattern.setConfidenceLevel(ConfidenceLevel.CL75);
21
22// you can add as many risk patterns as needed to model expected project risks
23settings.getPatterns().add(pattern);
3. Analyze the Risks
1RiskAnalyzer analyzer = new RiskAnalyzer(settings);
2RiskAnalysisResult analysisResult = analyzer.analyze(project);
4. Use the Results of the Analysis
1// For complete examples and data files, please go to https://github.com/aspose-tasks/Aspose.Tasks-for-Java
2//Select the desired output (here we get early finish of the root task)
3RiskItemStatistics rootEarlyFinish = analysisResult.getRiskItems(RiskItemType.EarlyFinish).get(project.getRootTask());
4
5System.out.println("Expected value: "+ rootEarlyFinish.getExpectedValue());
6System.out.println("StandardDeviation: " + rootEarlyFinish.getStandardDeviation());
7System.out.println("10% Percentile: " +rootEarlyFinish.getPercentile(10));
8System.out.println("50% Percentile: " + rootEarlyFinish.getPercentile(50));
9System.out.println("90% Percentile: " + rootEarlyFinish.getPercentile(90));
10System.out.println("Minimum: " + rootEarlyFinish.getMinimum());
11System.out.println("Maximum: " + rootEarlyFinish.getMaximum());
12
13// Also pdf report can be saved (it is rendered for Project Root Task Finish date):
14analysisResult.saveReport("AnalysisReport.pdf");