コード例 #1
0
        // Загрузка исследования по данному идентификатору исследования.
        public override ResultResearch LoadResearch(Guid researchID)
        {
            log.Info("Loading research with ID " + researchID.ToString() + ".");

            log.Info("Loading common info of research.");

            ResultResearch resultResearch = new ResultResearch();
            resultResearch.ResearchID = researchID;

            XmlDocument xml = new XmlDocument();

            xml.Load(this.directory + researchID.ToString() + ".xml");
            resultResearch.Name = xml.SelectSingleNode("/research/name").InnerText;
            resultResearch.Delta = Double.Parse(xml.SelectSingleNode("/research/delta").InnerText);
            resultResearch.RealizationCount = Int32.Parse(xml.SelectSingleNode("/research/realizationcount").InnerText);
            resultResearch.Function = xml.SelectSingleNode("/research/function").InnerText;
            resultResearch.ModelType = GetModelType(int.Parse(xml.SelectSingleNode("/research/graphmodel").Attributes["id"].Value));
            resultResearch.Size = Int32.Parse(xml.SelectSingleNode("/research/size").InnerText);

            log.Info("Loading generation parameters values of research.");
            foreach (XmlNode paramNode in xml.SelectNodes("/research/generationparams/generationparam"))
            {
                GenerationParam param = (GenerationParam)Enum.ToObject(typeof(GenerationParam), int.Parse(paramNode.Attributes["id"].Value));

                GenerationParamInfo paramInfo = (GenerationParamInfo)(param.GetType().GetField(param.ToString()).GetCustomAttributes(typeof(GenerationParamInfo), false)[0]);
                if (paramInfo.Type.Equals(typeof(Double)))
                {
                    resultResearch.GenerationParams.Add(param, Convert.ToDouble(paramNode.Attributes["value"].Value, CultureInfo.InvariantCulture));
                }
                else if (paramInfo.Type.Equals(typeof(Int16)))
                {
                    resultResearch.GenerationParams.Add(param, Convert.ToInt16(paramNode.Attributes["value"].Value));
                }
                else if (paramInfo.Type.Equals(typeof(Int32)))
                {
                    resultResearch.GenerationParams.Add(param, Convert.ToInt32(paramNode.Attributes["value"].Value));
                }
                else if (paramInfo.Type.Equals(typeof(bool)))
                {
                    resultResearch.GenerationParams.Add(param, Convert.ToBoolean(paramNode.Attributes["value"].Value));
                }
                else if (paramInfo.Type.Equals(typeof(String)))
                {
                    resultResearch.GenerationParams.Add(param, Convert.ToString(paramNode.Attributes["value"].Value));
                }
            }

            log.Info("Loading research results.");

            int count = xml.SelectSingleNode("/research/results").ChildNodes.Count;
            for (int i = 1; i <= count; ++i)
            {
                SortedDictionary<double, SubGraphsInfo> r = new SortedDictionary<double, SubGraphsInfo>();
                foreach (XmlNode paramNode in xml.SelectNodes("/research/results/level" + i.ToString()))
                {
                    foreach (XmlNode item in paramNode.SelectNodes("avgorder"))
                    {
                        SubGraphsInfo tempInfo = new SubGraphsInfo();
                        tempInfo.avgOrder = Double.Parse(item.Attributes["order"].Value);
                        tempInfo.avgOrderCount = Double.Parse(item.Attributes["count"].Value);

                        // read <secondmax> value;
                        tempInfo.secondMax = Double.Parse(item.ChildNodes[0].Attributes["value"].InnerText);
                        tempInfo.secondMaxCount = Double.Parse(item.ChildNodes[0].Attributes["count"].Value);

                        // read <avgorderrest> value
                        tempInfo.avgOrderRest = Double.Parse(item.ChildNodes[1].InnerText);

                        r.Add(Double.Parse(item.Attributes["q"].Value), tempInfo);
                    }
                }

                resultResearch.Result.Add(i, r);
            }

            return resultResearch;
        }
コード例 #2
0
        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;
        }
コード例 #3
0
        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!");
        }
コード例 #4
0
        private void startHierarchic_Click(object sender, EventArgs e)
        {
            ResultResearch result = new ResultResearch();
            result.Name = this.jobName;
            result.ModelType = typeof(HierarchicModel);
            result.Delta = Double.Parse(this.deltaExtendedTxt.Text);
            result.RealizationCount = (Int32)this.realizationCountNum.Value;
            result.Function = this.probabilityFunctionCmb.Text;
            result.GenerationParams[GenerationParam.BranchIndex] = Int16.Parse(this.branchIndexCmb.Text);
            result.GenerationParams[GenerationParam.Level] = Int16.Parse(this.maxLevelCmb.Text);
            result.Size = (int)Math.Pow(Int16.Parse(this.branchIndexCmb.Text), Int16.Parse(this.maxLevelCmb.Text));

            Int16 maxLevel = Int16.Parse(this.maxLevelCmb.Text);
            for (Int16 g = 1; g <= maxLevel; ++g)
            {
                result.Result.Add(g, new SortedDictionary<double, SubGraphsInfo>());
            }

            double muLow = Double.Parse(this.muRangeLowExtendedTxt.Text);
            double muHigh = Double.Parse(this.muRangeHighExtendedTxt.Text);
            double muDelta = Double.Parse(this.deltaExtendedTxt.Text);

            double muTemp = muLow;
            SubGraphsInfo tempInfo = new SubGraphsInfo();
            while (muTemp < muHigh)
            {
                SortedDictionary<double, SubGraphsInfo> r = AnalyzeHierarchic(muTemp);
                foreach (double gamma in r.Keys)
                {
                    result.Result[gamma].Add(muTemp, r[gamma]);
                }

                muTemp += muDelta;
            }

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

            MessageBox.Show("Results are saved succesfully!");
        }
コード例 #5
0
        /*private void startExtended_Click(object sender, EventArgs e)
        {
            ResultResearch result = new ResultResearch();
            result.Name = this.jobName;
            result.ModelType = typeof(HierarchicModel);
            result.Delta = Double.Parse(this.deltaExtendedTxt.Text);
            result.RealizationCount = (Int32)this.realizationCountNum.Value;
            result.Function = this.probabilityFunctionCmb.Text;
            result.GenerationParams[GenerationParam.BranchIndex] = Int16.Parse(this.branchIndexCmb.Text);
            result.GenerationParams[GenerationParam.Level] = Int16.Parse(this.maxLevelCmb.Text);
            result.Size = (int)Math.Pow(Int16.Parse(this.branchIndexCmb.Text), Int16.Parse(this.maxLevelCmb.Text));

            Int16 maxLevel = Int16.Parse(this.maxLevelCmb.Text);
            for (Int16 g = 1; g <= maxLevel; ++g)
            {
                result.Result.Add(g, AnalyzeExtendedHierarchic(g));
            }

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

            MessageBox.Show("Results are saved succesfully!");
        }*/
        private void startER_Click(object sender, EventArgs e)
        {
            ResultResearch result = new ResultResearch();
            result.Name = this.jobName;
            result.ModelType = typeof(ERModel);

            // TODO remove hardcoded data
            result.Delta = 0.00001;
            result.RealizationCount = 100;
            result.GenerationParams[GenerationParam.Vertices] = 65536;
            SortedDictionary<double, SubGraphsInfo> pInfo =
                new SortedDictionary<double, SubGraphsInfo>();

            this.folderBrowserDialog1.ShowDialog();
            string dirName = this.folderBrowserDialog1.SelectedPath;

            DirectoryInfo parentDir = new DirectoryInfo(dirName);
            foreach (FileInfo f in parentDir.GetFiles())
            {
                double p = Double.Parse(f.Name.Remove(f.Name.Length - 4));
                SubGraphsInfo value = new SubGraphsInfo();

                SortedDictionary<int, double> r = new SortedDictionary<int, double>();
                using (StreamReader streamReader = new StreamReader(f.FullName, System.Text.Encoding.Default))
                {
                    string contents;

                    while ((contents = streamReader.ReadLine()) != null)
                    {
                        string first = "", second = "";
                        int j = 0;
                        while (contents[j] != ' ')
                        {
                            first += contents[j];
                            ++j;
                        }

                        second = contents.Substring(j);

                        r.Add(int.Parse(first), double.Parse(second));
                    }
                }

                value.avgOrder = r.First().Value;
                value.avgOrderCount = r.First().Key;

                if (r.Count > 1)
                {
                    r.Remove(r.First().Key);
                    value.secondMax = r.First().Value;
                    value.secondMaxCount = r.First().Key;
                }

                if (r.Count > 2)
                {
                    r.Remove(r.First().Key);
                    value.avgOrderRest = r.Average(x => x.Value);
                }

                pInfo.Add(p, value);
            }

            result.Result.Add(1, pInfo);

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

            MessageBox.Show("Results are saved succesfully!");
        }