Esempio n. 1
0
        public static void Run()
        {
            // ExStart:PrepareAnalysisSettings
            RiskAnalysisSettings settings = new RiskAnalysisSettings();

            // Set number of iterations for Monte Carlo simulation (the default value is 100).
            settings.IterationsCount = 200;
            // ExEnd:PrepareAnalysisSettings

            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

            // ExStart:IdentifyAnalysisInput
            Project project = new Project(dataDir + "Software Development Plan-1.mpp");
            Task    task    = project.RootTask.Children.GetById(17);

            // Initialize a risk pattern
            RiskPattern pattern = new RiskPattern(task);

            // Select a distribution type for the random number generator to generate possible values from (only two types currently supported, namely normal and uniform)
            // For more details see here: https://en.wikipedia.org/wiki/Normal_distribution)
            pattern.Distribution = ProbabilityDistributionType.Normal;

            // Set the percentage of the most likely task duration which can happen in the best possible project scenario
            // 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
            pattern.Optimistic = 70;

            // Set the percentage of the most likely task duration which can happen in the worst possible project scenario
            // 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.
            pattern.Pessimistic = 130;

            // Set a confidence level that correspond to the percentage of the time the actual values will be within optimistic and pessimistic estimates.
            // 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
            pattern.ConfidenceLevel = ConfidenceLevel.CL75;

            settings.Patterns.Add(pattern);
            // ExEnd:IdentifyAnalysisInput

            // ExStart:AnalyzeRisks
            // Analyze the project risks
            RiskAnalyzer       analyzer       = new RiskAnalyzer(settings);
            RiskAnalysisResult analysisResult = analyzer.Analyze(project);
            // ExEnd:AnalyzeRisks

            // ExStart:UseAnalysisResult
            // Select the desired output (here we get early finish of the root task)
            RiskItemStatistics rootEarlyFinish = analysisResult.GetRiskItems(RiskItemType.EarlyFinish).Get(project.RootTask);

            Console.WriteLine("Expected value: {0}", rootEarlyFinish.ExpectedValue);
            Console.WriteLine("StandardDeviation: {0}", rootEarlyFinish.StandardDeviation);
            Console.WriteLine("10% Percentile: {0}", rootEarlyFinish.GetPercentile(10));
            Console.WriteLine("50% Percentile: {0}", rootEarlyFinish.GetPercentile(50));
            Console.WriteLine("90% Percentile: {0}", rootEarlyFinish.GetPercentile(90));
            Console.WriteLine("Minimum: {0}", rootEarlyFinish.Minimum);
            Console.WriteLine("Maximum: {0}", rootEarlyFinish.Maximum);

            // Save PDF report which is rendered for Project Root Task Finish date
            analysisResult.SaveReport(dataDir + "AnalysisReport_out.pdf");
            // ExEnd:UseAnalysisResult
        }
        public static void Run()
        {
            // ExStart:PrepareAnalysisSettings
            RiskAnalysisSettings settings = new RiskAnalysisSettings();

            // Set number of iterations for Monte Carlo simulation (the default value is 100).
            settings.IterationsCount = 200;
            // ExEnd:PrepareAnalysisSettings

            string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);

            // ExStart:IdentifyAnalysisInput
            Project project = new Project(dataDir + "Software Development Plan-1.mpp");
            Task task = project.RootTask.Children.GetById(17);

            // Initialize a risk pattern
            RiskPattern pattern = new RiskPattern(task);

            // Select a distribution type for the random number generator to generate possible values from (only two types currently supported, namely normal and uniform)            
            // For more details see here: https://en.wikipedia.org/wiki/Normal_distribution)
            pattern.Distribution = ProbabilityDistributionType.Normal;

            // Set the percentage of the most likely task duration which can happen in the best possible project scenario 
            // 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
            pattern.Optimistic = 70;

            // Set the percentage of the most likely task duration which can happen in the worst possible project scenario 
            // 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.
            pattern.Pessimistic = 130;

            // Set a confidence level that correspond to the percentage of the time the actual values will be within optimistic and pessimistic estimates. 
            // 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
            pattern.ConfidenceLevel = ConfidenceLevel.CL75;
            
            settings.Patterns.Add(pattern);
            // ExEnd:IdentifyAnalysisInput

            // ExStart:AnalyzeRisks
            // Analyze the project risks
            RiskAnalyzer analyzer = new RiskAnalyzer(settings);
            RiskAnalysisResult analysisResult = analyzer.Analyze(project);
            // ExEnd:AnalyzeRisks

            // ExStart:UseAnalysisResult
            // Select the desired output (here we get early finish of the root task)
            RiskItemStatistics rootEarlyFinish = analysisResult.GetRiskItems(RiskItemType.EarlyFinish).Get(project.RootTask);

            Console.WriteLine("Expected value: {0}", rootEarlyFinish.ExpectedValue);
            Console.WriteLine("StandardDeviation: {0}", rootEarlyFinish.StandardDeviation);
            Console.WriteLine("10% Percentile: {0}", rootEarlyFinish.GetPercentile(10));
            Console.WriteLine("50% Percentile: {0}", rootEarlyFinish.GetPercentile(50));
            Console.WriteLine("90% Percentile: {0}", rootEarlyFinish.GetPercentile(90));
            Console.WriteLine("Minimum: {0}", rootEarlyFinish.Minimum);
            Console.WriteLine("Maximum: {0}", rootEarlyFinish.Maximum);

            // Save PDF report which is rendered for Project Root Task Finish date
            analysisResult.SaveReport(dataDir + "AnalysisReport_out.pdf");
            // ExEnd:UseAnalysisResult
        }
Esempio n. 3
0
        public void UseRiskPattern()
        {
            // ExStart:UseRiskPattern
            // ExFor: RiskPattern
            // ExFor: RiskPattern.#ctor(Task)
            // ExFor: RiskPattern.Distribution
            // ExFor: RiskPattern.Optimistic
            // ExFor: RiskPattern.Pessimistic
            // ExFor: RiskPattern.ConfidenceLevel
            // ExFor: RiskPattern.Task
            // ExSummary: Shows how to define risk simulation settings.
            var settings = new RiskAnalysisSettings();

            settings.IterationsCount = 200;

            var project = new Project(DataDir + "Software Development Plan-1.mpp");
            var task    = project.RootTask.Children.GetById(17);

            // Initialize a risk pattern
            var pattern = new RiskPattern(task);

            // Select a distribution type for the random number generator to generate possible values from (only two types currently supported, namely normal and uniform)
            // For more details see here: https://en.wikipedia.org/wiki/Normal_distribution)
            pattern.Distribution = ProbabilityDistributionType.Normal;

            // Set the percentage of the most likely task duration which can happen in the best possible project scenario
            // 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
            pattern.Optimistic = 70;

            // Set the percentage of the most likely task duration which can happen in the worst possible project scenario
            // The default value is 125, which means that if the estimated specified task duration is 4 days then the pessimistic duration will be 5 days.
            pattern.Pessimistic = 130;

            // Set a confidence level that correspond to the percentage of the time the actual values will be within optimistic and pessimistic estimates.
            // 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
            pattern.ConfidenceLevel = ConfidenceLevel.CL75;

            settings.Patterns.Add(pattern);

            var analyzer       = new RiskAnalyzer(settings);
            var analysisResult = analyzer.Analyze(project);
            var earlyFinish    = analysisResult.GetRiskItems(RiskItemType.EarlyFinish).Get(project.RootTask);

            Console.WriteLine("Expected value: {0}", earlyFinish.ExpectedValue);
            Console.WriteLine("StandardDeviation: {0}", earlyFinish.StandardDeviation);
            Console.WriteLine("10% Percentile: {0}", earlyFinish.GetPercentile(10));
            Console.WriteLine("50% Percentile: {0}", earlyFinish.GetPercentile(50));
            Console.WriteLine("90% Percentile: {0}", earlyFinish.GetPercentile(90));
            Console.WriteLine("Minimum: {0}", earlyFinish.Minimum);
            Console.WriteLine("Maximum: {0}", earlyFinish.Maximum);

            analysisResult.SaveReport(OutDir + "AnalysisReport_out.pdf");

            // ExEnd:UseRiskPattern
        }
        public void WorkWithRiskAnalysisResult()
        {
            // ExStart
            // ExFor: RiskAnalysis.RiskAnalysisResult
            // ExFor: RiskAnalysis.RiskAnalysisResult.GetRiskItems(RiskItemType)
            // ExFor: RiskAnalysis.RiskAnalysisResult.SaveReport(Stream)
            // ExFor: RiskAnalysis.RiskAnalysisResult.SaveReport(String)
            // ExFor: RiskItemType
            // ExSummary: Shows how to calculate statistic of risks and save it into as PDF report.
            var settings = new RiskAnalysisSettings
            {
                IterationsCount = 200
            };

            var project = new Project(DataDir + "Software Development Plan-1.mpp");
            var task    = project.RootTask.Children.GetById(17);

            // Initialize a risk pattern
            var pattern = new RiskPattern(task)
            {
                // Select a distribution type for the random number generator to generate possible values from (only two types currently supported, namely normal and uniform)
                // For more details see here: https://en.wikipedia.org/wiki/Normal_distribution)
                Distribution = ProbabilityDistributionType.Normal,

                // Set the percentage of the most likely task duration which can happen in the best possible project scenario
                // 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
                Optimistic = 70,

                // Set the percentage of the most likely task duration which can happen in the worst possible project scenario
                // The default value is 125, which means that if the estimated specified task duration is 4 days then the pessimistic duration will be 5 days.
                Pessimistic = 130,

                // Set a confidence level that correspond to the percentage of the time the actual values will be within optimistic and pessimistic estimates.
                // 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
                ConfidenceLevel = ConfidenceLevel.CL75
            };

            settings.Patterns.Add(pattern);

            // Analyze the project risks
            var analyzer       = new RiskAnalyzer(settings);
            var analysisResult = analyzer.Analyze(project);

            // save analysis as a report into a file by file path
            analysisResult.SaveReport(OutDir + "AnalysisResult_out.pdf");

            // or save analysis into a stream
            using (var stream = new FileStream(OutDir + "AnalysisResult_out1.pdf", FileMode.Create))
            {
                analysisResult.SaveReport(stream);
            }

            // ExEnd
        }
        public void WorkWithRiskItemStatisticsCollection()
        {
            // ExStart
            // ExFor: RiskAnalysis.RiskItemStatisticsCollection
            // ExFor: RiskAnalysis.RiskItemStatisticsCollection.Get(Task)
            // ExFor: RiskAnalysis.RiskItemStatisticsCollection.GetEnumerator
            // ExSummary: Shows how to work with collection of risk statistics.
            var settings = new RiskAnalysisSettings
            {
                IterationsCount = 200
            };

            var project = new Project(DataDir + "Software Development Plan-1.mpp");
            var task    = project.RootTask.Children.GetById(17);

            // Initialize a risk pattern
            var pattern = new RiskPattern(task)
            {
                // Select a distribution type for the random number generator to generate possible values from (only two types currently supported, namely normal and uniform)
                // For more details see here: https://en.wikipedia.org/wiki/Normal_distribution)
                Distribution = ProbabilityDistributionType.Normal,

                // Set the percentage of the most likely task duration which can happen in the best possible project scenario
                // 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
                Optimistic = 70,

                // Set the percentage of the most likely task duration which can happen in the worst possible project scenario
                // The default value is 125, which means that if the estimated specified task duration is 4 days then the pessimistic duration will be 5 days.
                Pessimistic = 130,

                // Set a confidence level that correspond to the percentage of the time the actual values will be within optimistic and pessimistic estimates.
                // 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
                ConfidenceLevel = ConfidenceLevel.CL75
            };

            settings.Patterns.Add(pattern);

            var analyzer       = new RiskAnalyzer(settings);
            var analysisResult = analyzer.Analyze(project);

            // iterate over all statistic items
            var statistics = analysisResult.GetRiskItems(RiskItemType.EarlyFinish);

            foreach (var statistic in statistics)
            {
                Console.WriteLine("Short statistic: " + statistic);
                Console.WriteLine();
                Console.WriteLine("Statistic details: ");
                Console.WriteLine("Item Type: {0}", statistic.ItemType);
                Console.WriteLine("Expected value: {0}", statistic.ExpectedValue);
                Console.WriteLine("StandardDeviation: {0}", statistic.StandardDeviation);
                Console.WriteLine("10% Percentile: {0}", statistic.GetPercentile(10));
                Console.WriteLine("50% Percentile: {0}", statistic.GetPercentile(50));
                Console.WriteLine("90% Percentile: {0}", statistic.GetPercentile(90));
                Console.WriteLine("Minimum: {0}", statistic.Minimum);
                Console.WriteLine("Maximum: {0}", statistic.Maximum);
            }

            // or get a specific stats
            var itemStatistics = analysisResult.GetRiskItems(RiskItemType.EarlyFinish).Get(project.RootTask);

            Console.WriteLine("Print the specific statistic: ");
            Console.WriteLine("Expected value: {0}", itemStatistics.ExpectedValue);
            Console.WriteLine("StandardDeviation: {0}", itemStatistics.StandardDeviation);
            Console.WriteLine("10% Percentile: {0}", itemStatistics.GetPercentile(10));
            Console.WriteLine("50% Percentile: {0}", itemStatistics.GetPercentile(50));
            Console.WriteLine("90% Percentile: {0}", itemStatistics.GetPercentile(90));
            Console.WriteLine("Minimum: {0}", itemStatistics.Minimum);
            Console.WriteLine("Maximum: {0}", itemStatistics.Maximum);

            // ExEnd
        }
Esempio n. 6
0
        public void WorkWithRiskPatternCollection()
        {
            // ExStart
            // ExFor: RiskPatternCollection
            // ExFor: RiskPatternCollection.Add(RiskPattern)
            // ExFor: RiskPatternCollection.Clear
            // ExFor: RiskPatternCollection.Contains(RiskPattern)
            // ExFor: RiskPatternCollection.CopyTo(RiskPattern[],Int32)
            // ExFor: RiskPatternCollection.Count
            // ExFor: RiskPatternCollection.GetEnumerator
            // ExFor: RiskPatternCollection.IsReadOnly
            // ExFor: RiskPatternCollection.Item(Task)
            // ExFor: RiskPatternCollection.Remove(RiskPattern)
            // ExSummary: Shows how to work with risk pattern collections.
            var settings = new RiskAnalysisSettings
            {
                // Set number of iterations for Monte Carlo simulation (the default value is 100).
                IterationsCount = 200
            };

            var project = new Project(DataDir + "Software Development Plan-1.mpp");
            var task1   = project.RootTask.Children.GetById(17);
            var task2   = project.RootTask.Children.GetById(18);

            // as far as RiskPatternCollection is not a read-only
            Console.WriteLine("Is pattern collection read-only?: " + settings.Patterns.IsReadOnly);

            // one can add new patterns
            var pattern1 = new RiskPattern(task1)
            {
                Distribution    = ProbabilityDistributionType.Normal,
                Optimistic      = 60,
                Pessimistic     = 140,
                ConfidenceLevel = ConfidenceLevel.CL75
            };
            var pattern2 = new RiskPattern(task2)
            {
                Distribution    = ProbabilityDistributionType.Normal,
                Optimistic      = 70,
                Pessimistic     = 130,
                ConfidenceLevel = ConfidenceLevel.CL75
            };

            settings.Patterns.Add(pattern1);
            settings.Patterns.Add(pattern2);

            // iterate over added patterns
            Console.WriteLine("Patterns count: " + settings.Patterns.Count);
            foreach (var pattern in settings.Patterns)
            {
                Console.WriteLine("Task: " + pattern.Task);
                Console.WriteLine("Distribution: " + pattern.Distribution);
                Console.WriteLine("Optimistic: " + pattern.Optimistic);
                Console.WriteLine("Pessimistic: " + pattern.Pessimistic);
                Console.WriteLine("Confidence Level: " + pattern.ConfidenceLevel);
                Console.WriteLine();
            }

            // edit the pattern in the collection by using index access
            settings.Patterns[task1].Optimistic  = 70;
            settings.Patterns[task1].Pessimistic = 140;

            // check patterns after edits
            Console.WriteLine("Print edited patterns: ");
            foreach (var pattern in settings.Patterns)
            {
                Console.WriteLine("Task: " + pattern.Task);
                Console.WriteLine("Distribution: " + pattern.Distribution);
                Console.WriteLine("Optimistic: " + pattern.Optimistic);
                Console.WriteLine("Pessimistic: " + pattern.Pessimistic);
                Console.WriteLine("Confidence Level: " + pattern.ConfidenceLevel);
                Console.WriteLine();
            }

            // we can remove the pattern
            Console.WriteLine("Removing the first pattern...");
            settings.Patterns.Remove(pattern1);

            // check that pattern not in the collection
            Console.WriteLine("Is collection contains the first pattern?: " + settings.Patterns.Contains(pattern1));

            Assert.IsFalse(settings.Patterns.Contains(pattern1)); // ExSkip

            // one can clear the collection in two ways

            // copy patterns into the array and delete them one by one
            var patterns = new RiskPattern[settings.Patterns.Count];

            settings.Patterns.CopyTo(patterns, 0);
            foreach (var pattern in patterns)
            {
                settings.Patterns.Remove(pattern);
            }

            // or one can clear a pattern collection completely
            settings.Patterns.Clear();

            // ExEnd
        }