Exemplo n.º 1
0
        /// <summary>
        /// Reads matrix and branches (if exists) from specified file.
        /// </summary>
        /// <param name="filePath">File path.</param>
        /// <param name="networkSize">The size of the network (matrix, which represents the network).</param>
        /// <param name="matrixType">The type of given matrix (content of the specified file)</param>
        /// <returns>Matrix and branches (if exists).</returns>
        /// <throws>CoreException, MatrixFormatException.</throws>
        public static MatrixInfoToRead Read(String filePath, int networkSize, AdjacencyMatrixType matrixType)
        {
            MatrixInfoToRead result = new MatrixInfoToRead();

            result.Matrix = MatrixReader(filePath, networkSize, matrixType);
            result.Branches = BranchesReader(filePath.Insert(filePath.Length - 4, "_branches"));

            return result;
        }
        /// <summary>
        /// Reads matrix and branches (if exists) from specified file.
        /// </summary>
        /// <param name="fileName">File name.</param>
        /// <returns>Matrix and branches (if exists).</returns>
        /// <throws>CoreException, MatrixFormatException.</throws>
        public static MatrixInfoToRead Read(String fileName, int size)
        {
            MatrixInfoToRead r = new MatrixInfoToRead();

            if ((File.GetAttributes(fileName) & FileAttributes.Directory) == FileAttributes.Directory)
            {
                throw new CoreException("File should be specified.");
            }
            else
            {
                r.fileName = fileName;
                r.Matrix = ReadMatrix(fileName, size);
                r.Branches = ReadBranches(fileName.Substring(0, fileName.Length - 4) + ".branches");
            }

            return r;
        }
Exemplo n.º 3
0
 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);
     }
 }
 public void StaticGeneration(MatrixInfoToRead matrixInfo)
 {
     container.SetMatrix(matrixInfo.Matrix);
 }
        private void convert_Click(object sender, EventArgs e)
        {
            EnableControls(false);

            int size = int.Parse(sizeTxt.Text.ToString());
            try
            {
                MatrixInfoToRead matrix = FileManager.Read(inputFileNameTxt.Text, size, AdjacencyMatrixType.ClassicalMatrix);

                int newRowIndex = statusTable.Rows.Add();
                statusTable.Rows[newRowIndex].Cells["statusStatusColumn"].Value = "Not Started.";
                statusTable.Rows[newRowIndex].Cells["statusStopColumn"].Value = "Stop";

                Dictionary<int, int[]> subGraphs;

                if (GetSubGraphs(out subGraphs))
                {
                    for (int i = 0; i < subGraphs.Count; ++i)
                    {
                        for (int j = 0; j < subGraphs[i].Count(); ++j)
                        {
                            if (subGraphs[i][j] >= size)
                            {
                                MessageBox.Show("Input subgraphs format is not correct.", "Error");
                                return;
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Input subgraphs format is not correct.", "Error");
                    return;
                }

                int l = inputFileNameTxt.Text.Length;
                int last = inputFileNameTxt.Text.Substring(0, l - 4).LastIndexOf("\\") + 1;

                for (int i = 0; i < subGraphs.Count; ++i)
                {
                    MatrixInfoToRead curMatrix = new MatrixInfoToRead();
                    curMatrix.Matrix = createClassicalMatrix(matrix.Matrix, subGraphs[i]);

                    Guid id = SessionManager.CreateResearch(ResearchType.Basic);
                    SessionManager.AddResearchUpdateHandler(id, CurrentResearch_OnResearchUpdateStatus);
                    SessionManager.AddResearchEnsembleUpdateHandler(id, CurrentResearch_OnResearchEnsembleUpdateStatus);
                    SessionManager.SetResearchModelType(id, ModelType.ER); /* FIXME */
                    SessionManager.SetResearchGenerationType(id, GenerationType.Static);

                    SessionManager.SetResearchStorage(id, StorageType.XMLStorage, ExplorerSettings.StorageDirectory);

                    SessionManager.SetResearchName(id, inputFileNameTxt.Text.Substring(0, l - 4).Substring(last, l - 4 - last) + "_" + i);
                    SessionManager.SetResearchTracingPath(id, ExplorerSettings.TracingDirectory);
                    SessionManager.SetGenerationParameterValue(id, GenerationParameter.AdjacencyMatrix, curMatrix);
                    /* FIXME: Should we set this param value?? */
                    SessionManager.SetGenerationParameterValue(id, GenerationParameter.AdjacencyMatrixFile, curMatrix);
                    SessionManager.SetResearchRealizationCount(id, 1);
                    SessionManager.SetAnalyzeOptions(id, SessionManager.GetAvailableAnalyzeOptions(id));
                    SessionManager.StartResearch(id);
                }

                /* Calculate and save outer connections count. */
                {
                    int outerConnectionCount = 0;
                    for (int i = 0; i < subGraphs.Count; ++i)
                    {
                        for (int j = i + 1; j < subGraphs.Count; ++j)
                        {
                            outerConnectionCount += outerConnectionsCount(matrix.Matrix, subGraphs[i], subGraphs[j]);
                        }
                    }

                    string filePath = ExplorerSettings.StorageDirectory + "\\";
                    filePath  += inputFileNameTxt.Text.Substring(0, l - 4).Substring(last, l - 4 - last) +
                        "_" + subGraphs.Count;
                    if (File.Exists(filePath + ".xml"))
                    {
                        filePath += Guid.NewGuid();
                    }

                    using (XmlWriter writer = XmlWriter.Create(filePath + ".xml"))
                    {
                        writer.WriteStartDocument(true);
                        writer.WriteStartElement("StructuralAnalysis");

                        writer.WriteElementString("OuterConnectionCount", outerConnectionCount.ToString());

                        writer.WriteEndElement();
                    }
                }
            }

            catch (MatrixFormatException)
            {
                MessageBox.Show("Input matrix format is not correct.", "Error");
                inputFileNameTxt.Focus();
                inputFileNameTxt.SelectAll();
                return;
            }

            finally
            {
                EnableControls(true);
            }
        }