Exemple #1
0
 public void RunCommand(string strCommand)
 {
     if (strCommand == "MMP")
     {
         OpenFileDialog dialog = new OpenFileDialog();
         dialog.Filter = "pnt files (*.pnt)|*.pnt| All files (*.*)|*.*";
         DialogResult result = dialog.ShowDialog();
         if (result == DialogResult.OK)
         {
             Marking      M0  = PetriNetOperator.GetInitialMarkingFromPntFile(dialog.FileName);
             Reachability gra = new Reachability(M0);
             MMPCaculate  mmp = new MMPCaculate(gra);
             mmp.ExportStateFile();
             RootApp.UI.UI.ShowDebugText("Success export state file.");
             mmp.ExportMMPILPFile(true);
             RootApp.UI.UI.ShowDebugText("Success export MMP ILP files.");
         }
     }
     else if (strCommand == "NMMP")
     {
         OpenFileDialog dialog = new OpenFileDialog();
         dialog.Filter = "pnt files (*.pnt)|*.pnt| All files (*.*)|*.*";
         DialogResult result = dialog.ShowDialog();
         if (result == DialogResult.OK)
         {
             Marking      M0   = PetriNetOperator.GetInitialMarkingFromPntFile(dialog.FileName);
             Reachability gra  = new Reachability(M0);
             NMMPCaculate nmmp = new NMMPCaculate(gra);
             nmmp.ExportStateFile();
             RootApp.UI.UI.ShowDebugText("Success export state file.");
             nmmp.ExportNMMPILPFile();
             RootApp.UI.UI.ShowDebugText("Success export NMMP ILP files.");
             nmmp.ExportXls();
             RootApp.UI.UI.ShowDebugText("Success export excel file.");
         }
     }
 }
 private void btExportGra_Click(object sender, EventArgs e)
 {
     PetriNetOperator.ExportReachabilityFileFromPlaceDiationary(this.m_PlaceTable);
     setNotice("Export reability graph file success.");
 }
        private void CbExportMatrix_SelectedIndexChanged(object sender, EventArgs e)
        {
            string item = cbExportMatrix.SelectedItem as string;

            if (item == "Export Matrix")
            {
                return;
            }
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter = "matrix files (*.matrix)|*.matrix| All files (*.*)|*.*";
            DialogResult result = saveFileDialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                cbExportMatrix.SelectedIndex = cbExportMatrix.Items.Count - 1;
                return;
            }

            FileInfo fileInfo = new FileInfo(saveFileDialog.FileName);

            if (!Directory.Exists(fileInfo.DirectoryName))
            {
                return;
            }
            if (File.Exists(fileInfo.FullName))
            {
                File.Delete(fileInfo.FullName);
            }
            FileStream   fs = new FileStream(fileInfo.FullName, FileMode.Create);
            StreamWriter sw = new StreamWriter(fs);

            MathematicalTool.Matrix data = new Matrix();
            switch (item)
            {
            case "Pre Incidence Matrix":
                data = PetriNetOperator.GetPreIncidenceMatrixFromPlaceDictionary(this.m_PlaceTable);
                break;

            case "Post Incidence Matrix":
                data = PetriNetOperator.GetPostIncidenceMatrixFromPlaceDictionary(this.m_PlaceTable);
                break;

            case "Inceidence Matrix":
                data = PetriNetOperator.GetIncidenceMatrixFromPlaceDictionary(this.m_PlaceTable);
                break;
            }


            string          T = "T = {";
            SortedSet <int> transitionNames = PetriNetOperator.GetTransitionNamesFromPlaceDictionary(this.m_PlaceTable);

            foreach (int name in transitionNames)
            {
                T += "t" + name.ToString() + " , ";
            }

            string P = "P = {";
            string initialMarking = "M0 = [";

            foreach (KeyValuePair <int, Place> subitem in this.m_PlaceTable)
            {
                P += "p" + subitem.Key.ToString() + " , ";
                initialMarking += subitem.Value.InitialTokenNum.ToString() + " ";
            }
            T  = T.Remove(T.Length - 2, 2);
            T += "}";
            P  = P.Remove(P.Length - 2, 2);
            P += "}";
            initialMarking  = initialMarking.Remove(initialMarking.Length - 1, 1);
            initialMarking += "]";
            sw.WriteLine(P);
            sw.WriteLine(T);
            sw.WriteLine(initialMarking);
            sw.WriteLine("N = " + data.ToString());
            sw.Close();
            fs.Close();

            cbExportMatrix.SelectedIndex = cbExportMatrix.Items.Count - 1;
            setNotice("Export matrix success.");
        }
        private void btImportPnt_Click(object sender, EventArgs e)
        {
            setNotice("The short Cut \"Import\" is Alt+I.");
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "pnt files (*.pnt)|*.pnt| All files (*.*)|*.*";
            DialogResult result = dialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            this.m_PlaceTable.Clear();
            this.m_PlaceTable = PetriNetOperator.GetDataFromPntFile(dialog.FileName);
            if (this.m_PlaceTable == null)
            {
                return;
            }
            for (int i = this.dgvTable.Rows.Count - 1; i >= 0; i--)
            {
                this.dgvTable.Rows.Remove(this.dgvTable.Rows[i]);
            }
            foreach (Place p in this.m_PlaceTable.Values.ToList())
            {
                List <KeyValuePair <int, int> > preList  = p.PreTransitions.ToList();
                List <KeyValuePair <int, int> > postList = p.PostTransitions.ToList();

                int minCount = preList.Count < postList.Count ? preList.Count : postList.Count;
                for (int i = 0; i < minCount; i++)
                {
                    dgvTable.Rows.Add();
                    List <int> valuesList = new List <int> {
                        p.PlaceName, p.InitialTokenNum,
                        preList[i].Key, preList[i].Value, postList[i].Key, postList[i].Value
                    };
                    setDgvTableRowValue(dgvTable.RowCount - 1, valuesList);
                }
                if (minCount == preList.Count)
                {
                    for (int i = minCount; i < postList.Count; i++)
                    {
                        dgvTable.Rows.Add();
                        List <int> valuesList = new List <int> {
                            p.PlaceName, p.InitialTokenNum,
                            0, 0, postList[i].Key, postList[i].Value
                        };
                        setDgvTableRowValue(dgvTable.RowCount - 1, valuesList);
                    }
                }
                else
                {
                    for (int i = minCount; i < preList.Count; i++)
                    {
                        dgvTable.Rows.Add();
                        List <int> valuesList = new List <int> {
                            p.PlaceName, p.InitialTokenNum,
                            preList[i].Key, preList[i].Value, 0, 0
                        };
                        setDgvTableRowValue(dgvTable.RowCount - 1, valuesList);
                    }
                }
            }
        }