/*
         * private void NFAtoDFA1(Automaton automatonGraph)
         * {
         *
         *  DefinitionAutomaton DFAdef = new DefinitionAutomaton();
         *
         *  string[] newInputSymbols = NewStates(automatonGraph.definition);
         *  string[,] DFAInputSimbol = new string[newInputSymbols.Length, automatonGraph.InputCharacters.Count];
         *
         *
         *  for (int i = 1; i < newInputSymbols.Length; i++)
         *  {
         *      for (int ii = 0; ii < automatonGraph.InputCharacters.Count; ii++)
         *      {
         *          string[] str;
         *          str = newInputSymbols[i].Split(',');
         *
         *          for (int j = 0; j < str.Length; j++)
         *          {
         *              DFAInputSimbol[i, ii] += " " + Union(automatonGraph.findByName(str[j]).ConversionTable, automatonGraph.InputCharacters[ii]);
         *              //automatonGraph.findByName(str[j]).ConversionTable
         *          }
         *          DFAInputSimbol[i, ii] = DFAInputSimbol[i, ii].Trim();
         *          DFAInputSimbol[i, ii] = DFAInputSimbol[i, ii].Replace(" ", ",");
         *          DFAInputSimbol[i, ii] = String.Join(",", RemoveDuplicates(DFAInputSimbol[i, ii].Split(',')));
         *      }
         *  }
         *
         *
         *  DFAdef.Q = newInputSymbols;
         *  DFAdef.Q0 = automatonGraph.definition.Q0;
         * // DFAdef.Sigma = automatonGraph.InputCharacters;
         *  Automaton DFA = new Automaton(automatonGraph.InputCharacters);
         *  // DFAdef.F = ;
         *
         *
         *  for (int i = 1; i < newInputSymbols.Length; i++)
         *  {
         *      if (ItIsFinyly(DFAdef.Q[i].Split(','), automatonGraph.definition.F) && (DFAdef.Q[i] == DFAdef.Q0))
         *      {
         *          DFA.addState(new DFAGraphNode<string>(DFAdef.Q[i], true, true));
         *      }
         *      else if (ItIsFinyly(DFAdef.Q[i].Split(','), automatonGraph.definition.F))
         *      {
         *          DFA.addState(new DFAGraphNode<string>(DFAdef.Q[i], false, true));
         *      }
         *      else if (DFAdef.Q[i] == DFAdef.Q0)
         *      {
         *          DFA.addState(new DFAGraphNode<string>(DFAdef.Q[i], true, false));
         *      }
         *      else
         *      {
         *          DFA.addState(new DFAGraphNode<string>(DFAdef.Q[i], false, false));
         *      }
         *  }
         *
         *  DFA.findHead();
         *
         *  for (int i = 1; i < DFAdef.Q.Length; i++)
         *  {
         *      List<StateTransitionTable> _conversionTable = new List<StateTransitionTable>();
         *
         *
         *      for (int j = 0; j < DFAdef.Sigma.Length; j++)
         *      {
         *
         *          for (int ii = 0; ii < DFAdef.Q.Length; ii++)
         *          {
         *              if (DFAInputSimbol[i, j] == DFAdef.Q[ii])
         *              {
         *                  _conversionTable.Add(new StateTransitionTable(DFA.findByName(DFAdef.Q[ii]), DFAdef.Sigma[j], true));
         *              }
         *          }
         *
         *      }
         *
         *      DFA.findByName(DFAdef.Q[i]).ConversionTable = _conversionTable;
         *
         *  }
         *
         *
         *
         *  for (int i = DFA.Size - 1; i > 0; i--)
         *  {
         *      if (DFA.Reachability(DFA.head, DFA.GetNodeByIndex(i)) == false)
         *      {
         *          DFA.Remove(DFA.GetNodeByIndex(i));
         *      }
         *  }
         *
         *
         *
         *  for (int i = DFA.Size - 1; i > 0; i--)
         *  {
         *      if (DFA.AttainabilityOfTheTop(DFA.GetNodeByIndex(i)) == false)
         *      {
         *          DFA.Remove(DFA.GetNodeByIndex(i));
         *      }
         *  }
         *
         *  automatonGraph = DFA;
         *  OutputToCanvas();
         * }
         *
         *
         */



        private bool ItIsFinyly(string[] str1, string[] str2)
        {
            if (StaticAnyWhere.occurrence(str1, str2) == true)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        private void buildingDeltaBtn_Click(object sender, RoutedEventArgs e)
        {
            bool state = true;


            if (state != false)
            {
                if (enterQTb.Text.Length >= 1)
                {
                    def.Q = StaticAnyWhere.prepareStringArr(enterQTb.Text);
                }
                else
                {
                    state = false;
                    ErrorWindow errorWindow = new ErrorWindow("Ошибка ввода!", "Должно быть хоть одно начальное состояние ");
                    errorWindow.ShowDialog();
                }
            }

            if (state != false)
            {
                if ((enterEpsTb.Text.Length >= 1) || (enterDeltaRadioBtn.IsChecked == true))
                {
                    def.Sigma = StaticAnyWhere.prepareStringArr(enterEpsTb.Text);
                }
                else
                {
                    state = false;
                    ErrorWindow errorWindow = new ErrorWindow("Ошибка ввода!", "Должно быть хоть одно множество входных символов ");
                    errorWindow.ShowDialog();
                }
            }

            if (state != false)
            {
                if (StaticAnyWhere.prepareStringArr(enterqTb.Text).Length == 1)
                {
                    if (StaticAnyWhere.occurrence(def.Q, StaticAnyWhere.prepareStringArr(enterqTb.Text)))
                    {
                        def.Q0 = StaticAnyWhere.prepareString(enterqTb.Text);
                    }
                    else
                    {
                        state = false;
                        ErrorWindow errorWindow = new ErrorWindow("Ошибка ввода!", "Начальное состояние (q0) должно быть одним из конечного множества состояний (Q)");
                        errorWindow.ShowDialog();
                    }
                }
                else
                {
                    state = false;
                    ErrorWindow errorWindow = new ErrorWindow("Ошибка ввода!", "Начальное состояние может быть только одно");
                    errorWindow.ShowDialog();
                }
            }

            if (state != false)
            {
                if (StaticAnyWhere.occurrence(def.Q, StaticAnyWhere.prepareStringArr(enterFTb.Text)))
                {
                    def.F = StaticAnyWhere.prepareStringArr(enterFTb.Text);
                }
                else
                {
                    state = false;
                    ErrorWindow errorWindow = new ErrorWindow("Ошибка ввода!", "Множество заключительных состояний (F) должно быть подмножеством конечного множества состояний (Q)");
                    errorWindow.ShowDialog();
                }
            }

            if (state != false)
            {
                if (enterDeltaRadioBtn.IsChecked == true)
                {
                    def.Type  = 2;
                    def.Sigma = StaticAnyWhere.prepareStringArr("ε " + enterEpsTb.Text);
                }
                else
                {
                    def.Type = 3;
                }
            }



            if (state == true)
            {
                StaticAnyWhere.Def = def;
                this.NavigationService.Navigate(new Uri("Pages/SettingTheTransitionFunction.xaml", UriKind.Relative));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Создания матрицы для ввода таблицы переходов
        /// </summary>
        private void prepar()
        {
            transToDFABtn.Visibility = Visibility.Collapsed;
            viewToDFABtn.Visibility  = Visibility.Collapsed;
            def = StaticAnyWhere.Def;



            CanvasTB.Width  = 60 * (def.Sigma.Length + 1);
            CanvasTB.Height = 35 * (def.Q.Length + 1);

            for (int i = 0, countTestQ = 0; i < def.Q.Length + 1; i++)
            {
                for (int j = 0; j < def.Sigma.Length + 1; j++)
                {
                    TextBox Tb = new TextBox();
                    Tb.Width    = 50;
                    Tb.Height   = 25;
                    Tb.FontSize = 16;
                    // Tb.Name = Tb + Convert.ToString(i) + Convert.ToString(j);
                    Tb.Margin = new Thickness(j * (Tb.Width + 10), i * (Tb.Height + 20), 0, 0);

                    if (i == 0)
                    {
                        if (j == 0)
                        {
                            Tb.Text = "delta";
                        }
                        else
                        {
                            Tb.Text = def.Sigma[j - 1];
                        }

                        Tb.IsEnabled = false;
                    }
                    else if ((i > 0) & (j == 0))
                    {
                        Tb.Text = "";

                        Tb.Text      = def.Q[i - 1];
                        Tb.IsEnabled = false;

                        if (def.Q[i - 1] == def.Q0)
                        {
                            Tb.Text = "->" + Tb.Text;
                        }

                        if (StaticAnyWhere.occurrence(def.F, new string[] { def.Q[i - 1] }))
                        {
                            Tb.Text = "*" + Tb.Text;
                        }
                    }
                    else
                    {
                        if (def.ItIsTest == true)
                        {
                            Tb.Text = def.Tabel[countTestQ];
                            countTestQ++;
                        }
                        else
                        {
                            Tb.Text = "";
                        }

                        Tb.Background = Brushes.LightYellow;
                        C.Add(Tb);
                    }

                    this.CanvasTB.Children.Add(Tb);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Добавление таблицы переходов
        /// </summary>
        /// <param name="arrayTransition"></param>
        /// <returns></returns>
        private bool AddTransitionFunction(ref string[, ][] arrayTransition)
        {
            bool flagType2 = false, erorFlag = false;

            if (def.Type == 2)
            {
                for (int i = 0, counter = 0; i < def.Q.Length; i++)
                {
                    for (int j = 0; j < def.Sigma.Length; j++, counter++)
                    {
                        if ((StaticAnyWhere.occurrence(def.Q, StaticAnyWhere.prepareStringArr(C[counter].Text))) || (C[counter].Text == "Null" || (C[counter].Text == "null") || (C[counter].Text == " ") || (C[counter].Text == "")))
                        {
                            arrayTransition[i, j] = StaticAnyWhere.prepareStringArr(C[counter].Text);
                            C[counter].Background = Brushes.LightGreen;
                        }
                        else
                        {
                            erorFlag = true;
                            C[counter].Background = Brushes.LightPink;
                        }
                    }
                }
            }
            else
            {
                for (int i = 0, counter = 0; i < def.Q.Length; i++)
                {
                    for (int j = 0; j < def.Sigma.Length; j++, counter++)
                    {
                        if ((StaticAnyWhere.occurrence(def.Q, StaticAnyWhere.prepareStringArr(C[counter].Text))) || (C[counter].Text == "Null" || (C[counter].Text == "null" || (C[counter].Text == ""))))
                        {
                            arrayTransition[i, j] = StaticAnyWhere.prepareStringArr(C[counter].Text);
                            C[counter].Background = Brushes.LightGreen;

                            if (arrayTransition[i, j].Length > 1)
                            {
                                flagType2 = true;
                            }
                        }
                        else
                        {
                            erorFlag = true;
                            C[counter].Background = Brushes.LightPink;
                        }
                    }
                }

                if (flagType2 == true && def.Type != 2)
                {
                    def.Type = 1;
                }
                else
                {
                    def.Type = 0;
                }
            }



            if (erorFlag)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Создание автомата
        /// </summary>
        /// <param name="arrayTransition"></param>
        private void CreateAutomatonGraph(string[, ][] arrayTransition)
        {
            List <DFAGraphNode <string> > Q = new List <DFAGraphNode <string> >();
            bool flagAttainability;

            automatonGraph = new Automaton(new List <string>(def.Sigma));
            Automaton automatonGraphTemp = new Automaton(automatonGraph);

            //    automatonGraph.
            //  = new Automaton(def);

            for (int i = 0; i < def.Q.Length; i++)
            {
                if ((StaticAnyWhere.occurrence(def.F, new string[] { def.Q[i] })) && (def.Q[i] == def.Q0))
                {
                    automatonGraphTemp.addState(new DFAGraphNode <string>(def.Q[i], true, true));
                }
                else if (StaticAnyWhere.occurrence(def.F, new string[] { def.Q[i] }))
                {
                    automatonGraphTemp.addState(new DFAGraphNode <string>(def.Q[i], false, true));
                }
                else if (def.Q[i] == def.Q0)
                {
                    automatonGraphTemp.addState(new DFAGraphNode <string>(def.Q[i], true, false));
                }
                else
                {
                    automatonGraphTemp.addState(new DFAGraphNode <string>(def.Q[i], false, false));
                }
            }

            automatonGraphTemp.findHead();


            for (int i = 0; i < def.Q.Length; i++)
            {
                List <StateTransitionTable> _conversionTable = new List <StateTransitionTable>();


                for (int j = 0; j < def.Sigma.Length; j++)
                {
                    for (int k = 0; k < arrayTransition[i, j].Length; k++)
                    {
                        for (int ii = 0; ii < def.Q.Length; ii++)
                        {
                            if (arrayTransition[i, j][k] == def.Q[ii])
                            {
                                _conversionTable.Add(new StateTransitionTable(automatonGraphTemp.findByName(def.Q[ii]), def.Sigma[j], true));
                            }
                        }
                    }
                }

                automatonGraphTemp.findByName(def.Q[i]).ConversionTable = _conversionTable;
            }

            flagAttainability = automatonGraphTemp.AttainabilityOfTheTop();

            if (flagAttainability)
            {
                automatonGraph = automatonGraphTemp;
                if (def.Type == 0)
                {
                    viewToDFABtn.Visibility = Visibility.Visible;
                }
                else if (def.Type == 1)
                {
                    viewToDFABtn.Visibility  = Visibility.Visible;
                    transToDFABtn.Visibility = Visibility.Visible;
                }
                else if (def.Type == 2)
                {
                    viewToDFABtn.Visibility  = Visibility.Visible;
                    transToDFABtn.Visibility = Visibility.Visible;
                }
            }
            else
            {
                ErrorWindow errorWindow = new ErrorWindow("Ошибка ввода", "Заключительное состояние не достижимо Возможно вы ошиблись при заполнении таблицы перехода, попробуйте изменить значения. Убедитесь, что конечное состояние достижимо.");
                errorWindow.ShowDialog();
                // StaticAnyWhere.Error = "Заключительное состояние автомата не достижимо";
                //  StaticAnyWhere.Rootclass.GoTo("Pages/Error.xaml");
            }
        }