/// <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 virtual void StaticGeneration(NetworkInfoToRead info) { if (info is MatrixInfoToRead) { MatrixInfoToRead mi = info as MatrixInfoToRead; Container.SetMatrix(mi.Matrix); } else { Debug.Assert(info is NeighbourshipInfoToRead); NeighbourshipInfoToRead ni = info as NeighbourshipInfoToRead; Container.SetNeighbourship(ni.Neighbours, ni.Size); } if (info.ActiveStates != null) { Container.SetActiveStatuses(info.ActiveStates); } }
private void Convert(string fileName) { string sourceBranchesFilePath = fileName.Substring(0, fileName.Length - 4) + ".branches"; string sourceActiveStatesFilePath = fileName.Substring(0, fileName.Length - 4) + ".actives"; NetworkInfoToRead network = FileManager.Read(fileName, 0); Debug.Assert(network is MatrixInfoToRead); ArrayList m = (network as MatrixInfoToRead).Matrix; fileName = Path.GetFileName(fileName); int l = fileName.Length; string outFileName = outputPathTxt.Text + "\\" + fileName.Substring(0, l - 4) + "_out.txt"; string outBranchesFileName = outputPathTxt.Text + "\\" + fileName.Substring(0, l - 4) + "_out.branches"; string outActiveStatesFileName = outputPathTxt.Text + "\\" + fileName.Substring(0, l - 4) + "_out.actives"; using (StreamWriter file = new StreamWriter(outFileName)) { ArrayList row = new ArrayList(); for (int i = 0; i < m.Count - 1; ++i) { row = (ArrayList)m[i]; for (int j = i; j < m.Count; ++j) { if ((bool)row[j] == true) { file.WriteLine(i.ToString() + " " + j.ToString()); } } } } if (network.Branches != null) { File.Copy(sourceBranchesFilePath, outBranchesFileName); } if (network.ActiveStates != null) { File.Copy(sourceActiveStatesFilePath, outActiveStatesFileName); } }
public override void StaticGeneration(NetworkInfoToRead info) { Debug.Assert(info.Branches != null); container.SetBranches(info.Branches); base.StaticGeneration(info); }
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(() => {})); }