protected override void ValidateResearchParameters() { if (!ResearchParameterValues.ContainsKey(ResearchParameter.InputPath) || ResearchParameterValues[ResearchParameter.InputPath] == null || ((MatrixPath)ResearchParameterValues[ResearchParameter.InputPath]).Path == "") { CustomLogger.Write("Research - " + ResearchName + ". Invalid research parameters."); throw new InvalidResearchParameters(); } MatrixPath mp = ((MatrixPath)ResearchParameterValues[ResearchParameter.InputPath]); if ((File.GetAttributes(mp.Path) & FileAttributes.Directory) != FileAttributes.Directory) { CustomLogger.Write("Research - " + ResearchName + ". Invalid research parameters." + " Directory should be specified."); throw new InvalidResearchParameters(); } if (Directory.GetFiles(mp.Path, "*.txt").Count() != 1) { CustomLogger.Write("Research - " + ResearchName + ". Invalid research parameters." + " Directory should contain only 1 .txt file."); throw new InvalidResearchParameters(); } base.ValidateResearchParameters(); }
private Object GetValueFromControl(Control c) { Debug.Assert(!(c is Label)); if (c is TextBox) { return((c as TextBox).Text); } else if (c is CheckBox) { return((c as CheckBox).Checked); } else if (c is ComboBox) { return((c as ComboBox).Text); } else if (c is FileInput) { FileInput fi = c as FileInput; MatrixPath mp = new MatrixPath(); mp.Path = fi.MatrixPath; mp.Size = fi.MatrixSize; return(mp); } else { Debug.Assert(false); return(null); } }
public override void StartResearch() { ValidateResearchParameters(); StatusInfo = new ResearchStatusInfo(ResearchStatus.Running, 0); Logger.Write("Research ID - " + ResearchID.ToString() + ". Research - " + ResearchName + ". STARTED COLLECTION RESEARCH."); MatrixPath mp = ((MatrixPath)ResearchParameterValues[ResearchParameter.InputPath]); List <MatrixPath> matrixes = new List <MatrixPath>(); Debug.Assert((File.GetAttributes(mp.Path) & FileAttributes.Directory) == FileAttributes.Directory); foreach (string fn in Directory.GetFiles(mp.Path, "*.txt")) { MatrixPath m = new MatrixPath(); m.Path = fn; m.Size = mp.Size; matrixes.Add(m); } ResearchType rt = ResearchType.Basic; // subresearch type is not supported and is always Basic subResearches = new List <AbstractResearch>(); foreach (MatrixPath m in matrixes) { AbstractResearch r = AbstractResearch.CreateResearchByType(rt); r.ResearchName = ResearchName + "_" + Path.GetFileNameWithoutExtension(m.Path); r.GenerationType = GenerationType.Static; r.ModelType = ModelType; Debug.Assert(r.GenerationParameterValues.ContainsKey(GenerationParameter.AdjacencyMatrix)); r.GenerationParameterValues[GenerationParameter.AdjacencyMatrix] = m; r.AnalyzeOption = AnalyzeOption; string storageString = Storage.StorageString; // depracate sql storage /*if (Storage.GetStorageType() != StorageType.SQLStorage) * {*/ storageString += ResearchName; if (!Directory.Exists(storageString)) { Directory.CreateDirectory(storageString); } //} r.Storage = AbstractResultStorage.CreateStorage(Storage.GetStorageType(), storageString); r.OnUpdateResearchStatus += method; subResearches.Add(r); } if (subResearches.Count() != 0) { ++currentResearchIndex; subResearches[currentResearchIndex].StartResearch(); } }
public override int GetProcessStepsCount() { Debug.Assert(realizationCount == 1); if (processStepCount == -1) { MatrixPath mp = ((MatrixPath)ResearchParameterValues[ResearchParameter.InputPath]); processStepCount = Directory.GetFiles(mp.Path, "*.txt").Count(); } return(processStepCount); }
/// <summary> /// Generates random network from generation parameters. /// </summary> public bool Generate(bool visualMode = false) { try { CustomLogger.Write("Research - " + ResearchName + ". GENERATION STARTED for network - " + NetworkID.ToString()); if (GenerationType == GenerationType.Static) { Debug.Assert(GenerationParameterValues.ContainsKey(GenerationParameter.AdjacencyMatrix)); MatrixPath fp = (MatrixPath)GenerationParameterValues[GenerationParameter.AdjacencyMatrix]; Debug.Assert(fp.Path != null && fp.Path != ""); NetworkInfoToRead ni = FileManager.Read(fp.Path, fp.Size); networkGenerator.StaticGeneration(ni); CustomLogger.Write("Research - " + ResearchName + ". Static GENERATION FINISHED for network - " + NetworkID.ToString()); } else { Debug.Assert(!GenerationParameterValues.ContainsKey(GenerationParameter.AdjacencyMatrix)); networkGenerator.RandomGeneration(GenerationParameterValues, visualMode); if (ResearchType == ResearchType.Activation) { Debug.Assert(ResearchParameterValues.ContainsKey(ResearchParameter.InitialActivationProbability)); Double IP = Double.Parse(ResearchParameterValues[ResearchParameter.InitialActivationProbability].ToString(), CultureInfo.InvariantCulture); (networkGenerator.Container as AbstractNetworkContainer).RandomActivating(IP); } if (visualMode) { Debug.Assert(networkGenerator.GenerationSteps != null); GenerationSteps = networkGenerator.GenerationSteps; Branches = networkGenerator.Container.GetBranches(); } CustomLogger.Write("Research - " + ResearchName + ". Random GENERATION FINISHED for network - " + NetworkID.ToString()); } UpdateStatus(NetworkStatus.StepCompleted); } catch (CoreException ex) { UpdateStatus(NetworkStatus.Failed); CustomLogger.Write("Research - " + ResearchName + "GENERATION FAILED for network - " + NetworkID.ToString() + ". Exception message: " + ex.Message); return(false); } return(true); }
public void VerifyWithSpecialCase() { var matrix = new[] { new[] { 1, 1, 0, 1 }, new[] { 1, 1, 1, 1 } }; var result = new MatrixPath().GetNumberOfPaths(matrix); Assert.AreEqual(2, result); }
private void LoadGenerationParameters(ResearchResult r) { while (reader.Read()) { if (reader.Name == "GenerationParameter") { reader.MoveToAttribute("name"); string g = reader.ReadContentAsString(); GenerationParameter gp; if (g == "FileName") { gp = GenerationParameter.AdjacencyMatrix; } else { gp = (GenerationParameter)Enum.Parse(typeof(GenerationParameter), g); } reader.MoveToAttribute("value"); GenerationParameterInfo gpInfo = (GenerationParameterInfo)(gp.GetType().GetField(gp.ToString()).GetCustomAttributes(typeof(GenerationParameterInfo), false)[0]); if (gpInfo.Type.Equals(typeof(UInt32))) { r.GenerationParameterValues.Add(gp, UInt32.Parse(reader.Value)); } else if (gpInfo.Type.Equals(typeof(Double))) { r.GenerationParameterValues.Add(gp, Double.Parse(reader.Value, CultureInfo.InvariantCulture)); } else if (gpInfo.Type.Equals(typeof(Boolean))) { r.GenerationParameterValues.Add(gp, Boolean.Parse(reader.Value)); } else if (gpInfo.Type.Equals(typeof(MatrixPath))) { MatrixPath mp = new MatrixPath(); mp.Path = reader.Value; r.GenerationParameterValues.Add(gp, mp); } else { Debug.Assert(false); //throw new InvalidGenerationParameters(); } } if (reader.Name == "Ensembles") { break; } } }
private void AddFileInputToParametersPanel(string text, FileInputType t, Object value, int x, int y) { FileInput fi = new FileInput(); fi.Name = text; fi.Type = t; fi.Location = new Point(x, y * 30 + 5); if (value != null) { MatrixPath mp = (MatrixPath)value; fi.MatrixPath = mp.Path; fi.MatrixSize = mp.Size; } parametersPanel.Controls.Add(fi); }
private void AddFileInputToParametersPanel(String text, FileInputType t, Object value, Int32 x, Int32 y) { FileInput fi = new FileInput { Name = text, Type = t, Location = new Point(x, y * 30 + 5) }; if (value != null) { MatrixPath mp = (MatrixPath)value; fi.MatrixPath = mp.Path; fi.MatrixSize = mp.Size; } parametersPanel.Controls.Add(fi); }
private void LoadResearchParameters(ResearchResult r) { while (reader.Read()) { if (reader.Name == "ResearchParameter") { reader.MoveToAttribute("name"); ResearchParameter rp = (ResearchParameter)Enum.Parse(typeof(ResearchParameter), reader.ReadContentAsString()); reader.MoveToAttribute("value"); ResearchParameterInfo rpInfo = (ResearchParameterInfo)(rp.GetType().GetField(rp.ToString()).GetCustomAttributes(typeof(ResearchParameterInfo), false)[0]); if (rpInfo.Type.Equals(typeof(UInt32))) { r.ResearchParameterValues.Add(rp, UInt32.Parse(reader.Value)); } else if (rpInfo.Type.Equals(typeof(Double))) { r.ResearchParameterValues.Add(rp, Double.Parse(reader.Value, CultureInfo.InvariantCulture)); } else if (rpInfo.Type.Equals(typeof(Boolean))) { r.ResearchParameterValues.Add(rp, Boolean.Parse(reader.Value)); } else if (rpInfo.Type.Equals(typeof(ResearchType))) { r.ResearchParameterValues.Add(rp, reader.Value); } else if (rpInfo.Type.Equals(typeof(MatrixPath))) { MatrixPath mp = new MatrixPath(); mp.Path = reader.Value; r.ResearchParameterValues.Add(rp, mp); } else { Debug.Assert(false); //throw new InvalidResearchParameters(); } } else if (reader.Name == "GenerationParameterValues") { break; } } }
protected override void ValidateResearchParameters() { if (!ResearchParameterValues.ContainsKey(ResearchParameter.InputPath) || ResearchParameterValues[ResearchParameter.InputPath] == null || ((MatrixPath)ResearchParameterValues[ResearchParameter.InputPath]).Path == "") { Logger.Write("Research - " + ResearchName + ". Invalid research parameters."); throw new InvalidResearchParameters(); } MatrixPath mp = ((MatrixPath)ResearchParameterValues[ResearchParameter.InputPath]); if ((File.GetAttributes(mp.Path) & FileAttributes.Directory) != FileAttributes.Directory) { Logger.Write("Research - " + ResearchName + ". Invalid research parameters." + " Directory should be specified."); throw new InvalidResearchParameters(); } Logger.Write("Research - " + ResearchName + ". Validated research parameters."); }
public override Task StartResearch() { ValidateResearchParameters(); StatusInfo = new ResearchStatusInfo(ResearchStatus.Running, 0); CustomLogger.Write("Research ID - " + ResearchID.ToString() + ". Research - " + ResearchName + ". STARTED STRUCTURAL RESEARCH."); MatrixPath mp = ((MatrixPath)ResearchParameterValues[ResearchParameter.InputPath]); List <MatrixPath> matrixes = new List <MatrixPath>(); Debug.Assert((File.GetAttributes(mp.Path) & FileAttributes.Directory) == FileAttributes.Directory); Debug.Assert(Directory.GetFiles(mp.Path, "*.txt").Count() == 1); MatrixPath m = new MatrixPath(); m.Path = Directory.GetFiles(mp.Path, "*.txt")[0]; m.Size = mp.Size; matrixes.Add(m); NetworkInfoToRead mr = FileManager.Read(m.Path, m.Size); // TODO FIX Debug.Assert(mr is MatrixInfoToRead); string storageString = Storage.StorageString; // depraceting sql storage /*if (Storage.GetStorageType() != StorageType.SQLStorage) * {*/ storageString += ResearchName; if (!Directory.Exists(storageString)) { Directory.CreateDirectory(storageString); } //} foreach (string fn in Directory.GetFiles(mp.Path, "*.sm")) { int[] s; FileManager.ReadSubnetworkMatrix(fn, out s); MatrixInfoToWrite tmp = new MatrixInfoToWrite(); // TODO FIX //tmp.Matrix = CreateMatrixForSubgraph((mr as MatrixInfoToRead).Matrix, s); // Create temporary .txt files for each matrix string tmpFileName = storageString + "\\" + Path.GetFileNameWithoutExtension(fn); FileManager.Write(RandNetSettings.TracingDirectory, tmp, tmpFileName); MatrixPath sm = new MatrixPath(); sm.Path = tmpFileName + ".txt"; matrixes.Add(sm); } ResearchType rt = ResearchType.Basic; // subresearch type is not supported and is always Basic subResearches = new List <AbstractResearch>(); foreach (MatrixPath p in matrixes) { AbstractResearch r = AbstractResearch.CreateResearchByType(rt); r.ResearchName = ResearchName + "_" + Path.GetFileNameWithoutExtension(p.Path); r.GenerationType = GenerationType.Static; r.ModelType = ModelType; Debug.Assert(r.GenerationParameterValues.ContainsKey(GenerationParameter.AdjacencyMatrix)); r.GenerationParameterValues[GenerationParameter.AdjacencyMatrix] = p; r.AnalyzeOption = AnalyzeOption; r.Storage = AbstractResultStorage.CreateStorage(Storage.GetStorageType(), storageString); r.OnUpdateResearchStatus += method; subResearches.Add(r); } if (subResearches.Count() != 0) { ++currentResearchIndex; return(subResearches[currentResearchIndex].StartResearch()); } return(Task.Run(() => {})); }
private void RunTest(uint matrixIndex, uint erIndex, uint hIndex, uint nhIndex) { Debug.Assert(matrixIndex < matrixFiles.Count()); MatrixPath m = new MatrixPath(); m.Path = matrixesPath + "\\" + matrixFiles[matrixIndex]; Dictionary <GenerationParameter, Object> gp = new Dictionary <GenerationParameter, Object>(); gp.Add(GenerationParameter.AdjacencyMatrix, m); AnalyzeOption opts = SessionManager.GetAvailableAnalyzeOptions(ResearchType.Basic, ModelType); opts &= ~AnalyzeOption.EigenValues; opts &= ~AnalyzeOption.EigenDistanceDistribution; //opts &= ~AnalyzeOption.CycleDistribution; AbstractNetwork n = AbstractNetwork.CreateNetworkByType(ModelType, "", ResearchType.Basic, GenerationType.Static, TracingType.Matrix, new Dictionary <ResearchParameter, Object>(), gp, opts); n.Generate(); n.Analyze(); RealizationResult rn = n.NetworkResult; ResearchResult er = null; if (erIndex < erFiles.Count()) { er = erStorage.Load(erPath + "\\" + erFiles[erIndex]); } Debug.Assert(hIndex < regularHierarchicFiles.Count()); ResearchResult hr = regularHierarchicStorage.Load(regularHierarchicPath + "\\" + regularHierarchicFiles[hIndex]); Debug.Assert(nhIndex < nonRegularHierarchicFiles.Count()); ResearchResult nhr = nonRegularHierarchicStorage.Load(nonRegularHierarchicPath + "\\" + nonRegularHierarchicFiles[nhIndex]); string s; foreach (AnalyzeOption o in rn.Result.Keys) { if (er != null) { s = Check(o, rn, er) ? "Passed" : "Failed"; optionsTable.Rows.Add(o.ToString(), er.ResearchName, s); optionsTable.FirstDisplayedScrollingRowIndex = optionsTable.RowCount - 1; Application.DoEvents(); } s = Check(o, rn, hr) ? "Passed" : "Failed"; optionsTable.Rows.Add(o.ToString(), hr.ResearchName, s); optionsTable.FirstDisplayedScrollingRowIndex = optionsTable.RowCount - 1; Application.DoEvents(); s = Check(o, rn, nhr) ? "Passed" : "Failed"; optionsTable.Rows.Add(o.ToString(), nhr.ResearchName, s); optionsTable.FirstDisplayedScrollingRowIndex = optionsTable.RowCount - 1; Application.DoEvents(); } }
private void LoadGeneralInfo(String folderName, ResearchResult r) { using (StreamReader rd = new StreamReader(folderName + "\\general.txt")) { rd.ReadLine(); r.ResearchID = new Guid(rd.ReadLine().Substring(13)); r.ResearchName = rd.ReadLine().Substring(15); r.ResearchType = (ResearchType)Enum.Parse(typeof(ResearchType), rd.ReadLine().Substring(15)); r.ModelType = (ModelType)Enum.Parse(typeof(ModelType), rd.ReadLine().Substring(12)); r.RealizationCount = Int32.Parse(rd.ReadLine().Substring(19)); r.Date = DateTime.Parse(rd.ReadLine().Substring(7)); r.Size = Int32.Parse(rd.ReadLine().Substring(7)); r.Edges = Double.Parse(rd.ReadLine().Substring(8), CultureInfo.InvariantCulture); rd.ReadLine(); String str = null; while ((str = rd.ReadLine()) != "Generation Parameters") { String[] split = str.Split(' '); ResearchParameter rp = (ResearchParameter)Enum.Parse(typeof(ResearchParameter), split[0]); ResearchParameterInfo rpInfo = (ResearchParameterInfo)(rp.GetType().GetField(rp.ToString()).GetCustomAttributes(typeof(ResearchParameterInfo), false)[0]); if (rpInfo.Type.Equals(typeof(Int32))) { r.ResearchParameterValues.Add(rp, Int32.Parse(split[1])); } else if (rpInfo.Type.Equals(typeof(Double))) { r.ResearchParameterValues.Add(rp, Double.Parse(split[1], CultureInfo.InvariantCulture)); } else if (rpInfo.Type.Equals(typeof(Boolean))) { r.ResearchParameterValues.Add(rp, Boolean.Parse(split[1])); } else if (rpInfo.Type.Equals(typeof(ResearchType))) { r.ResearchParameterValues.Add(rp, split[1]); } else if (rpInfo.Type.Equals(typeof(MatrixPath))) { MatrixPath mp = new MatrixPath(); mp.Path = split[1]; r.ResearchParameterValues.Add(rp, mp); } else { Debug.Assert(false); } } while ((str = rd.ReadLine()) != null) { String[] split = str.Split(' '); GenerationParameter gp; if (split[0] == "FileName") { gp = GenerationParameter.AdjacencyMatrix; } else { gp = (GenerationParameter)Enum.Parse(typeof(GenerationParameter), split[0]); } GenerationParameterInfo gpInfo = (GenerationParameterInfo)(gp.GetType().GetField(gp.ToString()).GetCustomAttributes(typeof(GenerationParameterInfo), false)[0]); if (gpInfo.Type.Equals(typeof(Int32))) { r.GenerationParameterValues.Add(gp, Int32.Parse(split[1])); } else if (gpInfo.Type.Equals(typeof(Double))) { r.GenerationParameterValues.Add(gp, Double.Parse(split[1], CultureInfo.InvariantCulture)); } else if (gpInfo.Type.Equals(typeof(Boolean))) { r.GenerationParameterValues.Add(gp, Boolean.Parse(split[1])); } else if (gpInfo.Type.Equals(typeof(MatrixPath))) { MatrixPath mp = new MatrixPath(); mp.Path = split[1]; r.GenerationParameterValues.Add(gp, mp); } else { Debug.Assert(false); } } } }