private SortedDictionary<double, double> AnalyzeAvgHierarchic(double mu)
        {
            Int16 p = Int16.Parse(this.branchIndexCmb.Text);
            Int16 maxLevel = Int16.Parse(this.maxLevelCmb.Text);
            int realizationCount = (Int32)this.realizationCountNum.Value;

            SortedDictionary<double, double> result = new SortedDictionary<double, double>();
            for (Int16 i = 1; i <= maxLevel; ++i)
            {
                result.Add(i, 0);
            }

            Dictionary<GenerationParam, object> genParameters = new Dictionary<GenerationParam, object>();
            genParameters.Add(GenerationParam.BranchIndex, p);
            genParameters.Add(GenerationParam.Level, maxLevel);
            genParameters.Add(GenerationParam.Mu, mu);

            HierarchicGenerator hGenerator = new HierarchicGenerator();
            HierarchicAnalyzer hAnalyzer;

            for (int r = 0; r < realizationCount; ++r)
            {
                hGenerator.Generation(genParameters);
                hAnalyzer = new HierarchicAnalyzer((HierarchicContainer)hGenerator.Container);

                for (Int16 i = 1; i <= maxLevel; ++i)
                {
                    double maxOrder = hAnalyzer.GetAvgConnSubGraphPerLevel(i);
                    double normMaxOrder = maxOrder / (Math.Pow(p, i));
                    result[i] += normMaxOrder;
                }
            }

            for (Int16 i = 1; i <= maxLevel; ++i)
            {
                result[i] /= realizationCount;
            }

            return result;
        }
        private void InitModel()
        {
            log.Info("Started model initialization.");
            InvokeProgressEvent(GraphProgress.Initializing, 0);
            ModelName = MODEL_NAME;

            // Определение параметров генерации.
            List<GenerationParam> genParams = new List<GenerationParam>();
            genParams.Add(GenerationParam.BranchIndex);
            genParams.Add(GenerationParam.Level);
            genParams.Add(GenerationParam.Mu);
            RequiredGenerationParams = genParams;

            // Определение доступных опций для анализа (вычисляемые характеристики для данной модели (Block-Hierarchic)).
            AvailableOptions = AnalyseOptions.AveragePath |
                AnalyseOptions.MinPathDist |
                AnalyseOptions.Diameter |
                AnalyseOptions.Cycles3 |
                AnalyseOptions.Cycles4 |
                AnalyseOptions.DegreeDistribution |
                AnalyseOptions.ClusteringCoefficient |
                AnalyseOptions.ConnSubGraph |
                AnalyseOptions.Cycles |
                AnalyseOptions.EigenValue |
                AnalyseOptions.DistEigenPath |
                AnalyseOptions.TriangleCountByVertex |
                AnalyseOptions.Cycles5;

            // Определение генератора и анализатора для данной модели (Block-Hierarchic).
            log.Info("Creating generator and analyzer for model.");
            generator = new HierarchicGenerator();
            analyzer = new HierarchicAnalyzer((HierarchicContainer)generator.Container);

            InvokeProgressEvent(GraphProgress.Ready);
            log.Info("Finished model initialization");
        }
        private SortedDictionary<double, SubGraphsInfo> AnalyzeExtendedHierarchic(Int16 currentLevel)
        {
            SortedDictionary<double, SubGraphsInfo> result = new SortedDictionary<double, SubGraphsInfo>();

            Int16 p = Int16.Parse(this.branchIndexCmb.Text);
            Int16 maxLevel = Int16.Parse(this.maxLevelCmb.Text);
            double muLow = Double.Parse(this.muRangeLowExtendedTxt.Text);
            double muHigh = Double.Parse(this.muRangeHighExtendedTxt.Text);
            double muDelta = Double.Parse(this.deltaExtendedTxt.Text);
            int realizationCount = (Int32)this.realizationCountNum.Value;

            HierarchicGenerator hGenerator = new HierarchicGenerator();
            HierarchicAnalyzer hAnalyzer;

            double muTemp = muLow;
            SubGraphsInfo tempInfo = new SubGraphsInfo();
            while (muTemp <= muHigh)
            {
                double avgOrder = 0;
                for (int r = 0; r < realizationCount; ++r)
                {
                    hGenerator.GenerateTreeWithProbability(p, maxLevel, 0, currentLevel,
                        muTemp, new ProbabilityCounter(ProbabilityFunctions.Classical));
                    hAnalyzer = new HierarchicAnalyzer((HierarchicContainer)hGenerator.Container);
                    avgOrder += hAnalyzer.GetConnSubGraph().Last().Key;
                }
                double avgValue = avgOrder / (double)realizationCount;
                tempInfo.avgOrder = avgValue / Math.Pow(p, currentLevel);
                result.Add(muTemp, tempInfo);

                muTemp += muDelta;
            }

            return result;
        }
        private void startGlobal_Click(object sender, EventArgs e)
        {
            Int16 p = Int16.Parse(this.branchIndexCmb.Text);
            Int16 maxLevel = Int16.Parse(this.maxLevelCmb.Text);
            int realizationCount = (Int32)this.realizationCountNum.Value;
            double muLow = Double.Parse(this.muRangeLowExtendedTxt.Text);
            double muHigh = Double.Parse(this.muRangeHighExtendedTxt.Text);
            double muDelta = Double.Parse(this.deltaExtendedTxt.Text);

            ResultResearch result = new ResultResearch();
            result.Name = this.jobName;
            result.ModelType = typeof(HierarchicModel);
            result.Delta = muDelta;
            result.RealizationCount = realizationCount;
            result.Function = this.probabilityFunctionCmb.Text;
            result.GenerationParams[GenerationParam.BranchIndex] = p;
            result.GenerationParams[GenerationParam.Level] = maxLevel;
            result.Size = (int)Math.Pow(p, maxLevel);
            result.Result.Add(maxLevel, new SortedDictionary<double, SubGraphsInfo>());

            Dictionary<GenerationParam, object> genParameters = new Dictionary<GenerationParam, object>();
            genParameters.Add(GenerationParam.BranchIndex, p);
            genParameters.Add(GenerationParam.Level, maxLevel);

            HierarchicGenerator hGenerator = new HierarchicGenerator();
            HierarchicAnalyzer hAnalyzer;

            double muTemp = muLow;

            SortedDictionary<int, int> subGraphInfo = new SortedDictionary<int,int>();
            while (muTemp <= muHigh)
            {
                SubGraphsInfo tempInfo = new SubGraphsInfo();
                for (int r = 0; r < realizationCount; ++r)
                {
                    genParameters[GenerationParam.Mu] = muTemp;
                    hGenerator.Generation(genParameters);
                    hAnalyzer = new HierarchicAnalyzer((HierarchicContainer)hGenerator.Container);
                    subGraphInfo = hAnalyzer.GetConnSubGraph();

                    tempInfo.avgOrder += subGraphInfo.Last().Key;
                    tempInfo.avgOrderCount += subGraphInfo.Last().Value;

                    if (subGraphInfo.Count > 1)
                    {
                        subGraphInfo.Remove(subGraphInfo.Last().Key);
                        tempInfo.secondMax += subGraphInfo.Last().Key;
                        tempInfo.secondMaxCount += subGraphInfo.Last().Value;
                    }

                    if (subGraphInfo.Count > 2)
                    {
                        subGraphInfo.Remove(subGraphInfo.Last().Key);
                        tempInfo.avgOrderRest += subGraphInfo.Average(x => x.Key);
                    }
                }
                tempInfo.avgOrder /= (double)realizationCount;
                tempInfo.avgOrder /= result.Size;
                tempInfo.avgOrderCount /= (double)realizationCount;

                tempInfo.secondMax /= (double)realizationCount;
                tempInfo.secondMax /= result.Size;
                tempInfo.secondMaxCount /= (double)realizationCount;

                tempInfo.avgOrderRest /= (double)realizationCount;
                tempInfo.avgOrderRest /= result.Size;

                result.Result[maxLevel].Add(muTemp, tempInfo);

                muTemp += muDelta;
            }

            XMLResultStorage storage = new XMLResultStorage(Options.StorageDirectory);
            storage.SaveResearch(result);

            MessageBox.Show("Results are saved succesfully!");
        }
        private SortedDictionary<double, SubGraphsInfo> AnalyzeHierarchic(double mu)
        {
            Int16 p = Int16.Parse(this.branchIndexCmb.Text);
            Int16 maxLevel = Int16.Parse(this.maxLevelCmb.Text);
            int realizationCount = (Int32)this.realizationCountNum.Value;

            SortedDictionary<double, SubGraphsInfo> result = new SortedDictionary<double, SubGraphsInfo>();
            for (Int16 i = 1; i <= maxLevel; ++i)
            {
                result.Add(i, new SubGraphsInfo());
            }

            Dictionary<GenerationParam, object> genParameters = new Dictionary<GenerationParam, object>();
            genParameters.Add(GenerationParam.BranchIndex, p);
            genParameters.Add(GenerationParam.Level, maxLevel);
            genParameters.Add(GenerationParam.Mu, mu);

            HierarchicGenerator hGenerator = new HierarchicGenerator();
            HierarchicAnalyzer hAnalyzer;

            for (int r = 0; r < realizationCount; ++r)
            {
                hGenerator.Generation(genParameters);
                hAnalyzer = new HierarchicAnalyzer((HierarchicContainer)hGenerator.Container);

                SortedDictionary<int, int> subGraphInfo;
                for (Int16 i = 1; i <= maxLevel; ++i)
                {
                    subGraphInfo = hAnalyzer.GetConnSubGraphPerLevel(i);

                    result[i].avgOrder += (subGraphInfo.Count != 0) ?
                        subGraphInfo.Last().Key / Math.Pow(p, i) : 1 / Math.Pow(p, i);
                    result[i].avgOrderCount += (subGraphInfo.Count != 0) ?
                        subGraphInfo.Last().Value : 1;

                    if (subGraphInfo.Count > 1)
                    {
                        subGraphInfo.Remove(subGraphInfo.Last().Key);
                        result[i].secondMax += subGraphInfo.Last().Key / Math.Pow(p, i);
                        result[i].secondMaxCount += subGraphInfo.Last().Value;
                    }

                    if (subGraphInfo.Count > 2)
                    {
                        subGraphInfo.Remove(subGraphInfo.Last().Key);
                        result[i].avgOrderRest += subGraphInfo.Average(x => x.Key) / Math.Pow(p, i);
                    }
                }
            }

            for (Int16 i = 1; i <= maxLevel; ++i)
            {
                result[i].avgOrder /= (double)realizationCount;
                result[i].avgOrderCount /= (double)realizationCount;

                result[i].secondMax /= (double)realizationCount;
                result[i].secondMaxCount /= (double)realizationCount;

                result[i].avgOrderRest /= (double)realizationCount;
            }

            return result;
        }