private void ValidateInstructions_Click(object sender, EventArgs e)
        {
            this.myDfa = myNfa.toDfa();
            myCompDfa = myNfa.Complete();
            myRdDfa = this.myDfa.Reduce();
            ShowButtons.Enabled = true;
            Test.Enabled = true;
            ValidateInstructions.Enabled = false;
            for (int s = 0; s < myNfa.S; s++)
                foreach (char car in myNfa.X)
                    myNfa.I[s, myNfa.toIndex(car)].Sort();

            NfaInfo.Controls[0].Text = myNfa.toString() + "\n\nInstructions:\n" + myNfa.ItoStringTriplet();
            Dfa myDfa = myNfa.toDfa();
            DfaInfo.Controls[0].Text = myDfa.ToString() + "\n\n" + myNfa.StCorTabToString() + "\n\nInstructions:\n" + myDfa.ItoStringTriplet();
            Dfa myTempDfa = myDfa.Reduce();
            ReducedInfo.Controls[0].Text = myTempDfa.ToString() + "\n\n" + myNfa.StCorTabToString() + "\n\n" + myTempDfa.Rd_StoString() + "\nInstructions:\n" + myTempDfa.ItoStringTriplet();
            myTempDfa = myDfa.Complete();
            CompleteInfo.Controls[0].Text = myTempDfa.ToString() + "\n\n" + myNfa.StCorTabToString() + "\n\nInstructions:\n" + myTempDfa.ItoStringTriplet();
        }
Exemple #2
0
        public void AjouterDfa(Auto UserAuto)
        {
            if (UserAuto.Automate == null) return;
            Selected = UserAuto;

            Automates_list.Add(UserAuto);

            // l'automate Dfa
            Dfa UserDfa_ = new Dfa();
            UserDfa_ = ((Dfa)UserAuto.Automate).toDfa();
            UserDfa_.Name = ((Dfa)UserAuto.Automate).Name + "[Dfa]";

            Auto UserAuto_Dfa_ = new Auto(UserDfa_);
            UserAuto_Dfa_.type = Automata.TYPE.Dfa;
            Automates_list.Add(UserAuto_Dfa_);

            // l'automate Nfa
            Nfa UserNfa_ = new Nfa();
            UserNfa_ = ((Dfa)UserAuto.Automate).toNfa();
            UserNfa_.Name = ((Dfa)UserAuto.Automate).Name + "[Nfa]";

            Auto UserAuto_Nfa_ = new Auto(UserNfa_);
            UserAuto_Nfa_.type = Automata.TYPE.Nfa;
            Automates_list.Add(UserAuto_Nfa_);

            // l'automate PGfa
            PGfa UserPGfa = new PGfa();
            UserPGfa = ((Dfa)UserAuto.Automate).toPGfa();
            UserPGfa.Name = ((Dfa)UserAuto.Automate).Name + "[PGfa]";

            Auto UserAuto_PGfa = new Auto(UserPGfa);
            UserAuto_PGfa.type = Automata.TYPE.PGfa;
            Automates_list.Add(UserAuto_PGfa);

            // l'automate Gfa
            Gfa UserGfa = new Gfa();
            UserGfa = ((Dfa)UserAuto.Automate).toGfa();
            UserGfa.Name = ((Dfa)UserAuto.Automate).Name + "[Gfa]";

            Auto UserAuto_Gfa = new Auto(UserGfa);
            UserAuto_Gfa.type = Automata.TYPE.Gfa;
            Automates_list.Add(UserAuto_Gfa);

            // l'automate reduit
            Dfa UserDfa_reduit = new Dfa();
            UserDfa_reduit = ((Dfa)UserAuto.Automate).toReduced();
            UserDfa_reduit.Name = ((Dfa)UserAuto.Automate).Name + "[Reduit]";

            Auto UserAuto_DfaReduit = new Auto(UserDfa_reduit);
            UserAuto_DfaReduit.type = Automata.TYPE.Dfa;
            Automates_list.Add(UserAuto_DfaReduit);

            // l'automate complet
            Dfa UserDfa_complet = new Dfa();
            UserDfa_complet = ((Dfa)UserAuto.Automate).toComplete();
            UserDfa_complet.Name = ((Dfa)UserAuto.Automate).Name + "[Complet]";

            Auto UserAuto_DfaComplet = new Auto(UserDfa_complet);
            UserAuto_DfaComplet.type = Automata.TYPE.Dfa;
            Automates_list.Add(UserAuto_DfaComplet);

            TreeNode node_automate = new TreeNode(UserAuto.ToString());
            TreeNode node_automate_Dfa = new TreeNode(UserAuto_Dfa_.ToString());
            TreeNode node_automate_Nfa = new TreeNode(UserAuto_Nfa_.ToString());
            TreeNode node_automate_PGfa = new TreeNode(UserAuto_PGfa.ToString());
            TreeNode node_automate_Gfa = new TreeNode(UserAuto_Gfa.ToString());
            TreeNode node_automate_DfaReduit = new TreeNode(UserAuto_DfaReduit.ToString());
            TreeNode node_automate_DfaComplet = new TreeNode(UserAuto_DfaComplet.ToString());

            node_automate.ContextMenuStrip = RightMenu;
            node_automate_Dfa.ContextMenuStrip = RightMenu;
            node_automate_Nfa.ContextMenuStrip = RightMenu;
            node_automate_PGfa.ContextMenuStrip = RightMenu;
            node_automate_Gfa.ContextMenuStrip = RightMenu;
            node_automate_DfaReduit.ContextMenuStrip = RightMenu;
            node_automate_DfaComplet.ContextMenuStrip = RightMenu;

            node_automate.ToolTipText = Enum.GetName(typeof(Automata.TYPE), UserAuto.type);
            node_automate_Dfa.ToolTipText = Enum.GetName(typeof(Automata.TYPE), UserAuto_Dfa_.type);
            node_automate_Nfa.ToolTipText = Enum.GetName(typeof(Automata.TYPE), UserAuto_Nfa_.type);
            node_automate_PGfa.ToolTipText = Enum.GetName(typeof(Automata.TYPE), UserAuto_PGfa.type);
            node_automate_Gfa.ToolTipText = Enum.GetName(typeof(Automata.TYPE), UserAuto_Gfa.type);
            node_automate_DfaReduit.ToolTipText = Enum.GetName(typeof(Automata.TYPE), UserAuto_DfaReduit.type);
            node_automate_DfaComplet.ToolTipText = Enum.GetName(typeof(Automata.TYPE), UserAuto_DfaComplet.type);

            node_automate.Nodes.Add(node_automate_Dfa);
            node_automate.Nodes.Add(node_automate_Nfa);
            node_automate.Nodes.Add(node_automate_PGfa);
            node_automate.Nodes.Add(node_automate_Gfa);
            node_automate.Nodes.Add(node_automate_DfaReduit);
            node_automate.Nodes.Add(node_automate_DfaComplet);
            Automates_tree.Nodes.Add(node_automate);

            //node_automate.Nodes.Add(node_automate);
            node_automate.Expand();

            ((Dfa)UserAuto.Automate).Draw(Drawpanel, true);
            ((Dfa)UserAuto.Automate).Afficher_grid(transition_Grid);
            Type_label.Text = "L'automate : " + ((Automata)Selected.Automate).Name + "  de type : " + Selected.type.ToString();
            Drawpanel.Refresh();
        }
Exemple #3
0
        private void complementMI_Click(object sender, EventArgs e)
        {
            if (Selected.Automate != null)
            {
                Dfa UserDfa = new Dfa();

                UserDfa = ((Automata)Selected.Automate).getComplementary();
                UserDfa.Name = "Automate" + Automates_list.Count;
                Auto UserAuto = new Auto(UserDfa);
                UserAuto.type = Automata.TYPE.Dfa;
                AjouterDfa(UserAuto);
            }
        }
Exemple #4
0
 /// <summary>
 /// Convertir l'automate courant vers un automate reduit equivalant
 /// </summary>
 /// <returns>Automate de type Dfa reduit</returns>
 public override Dfa toReduced()
 {
     Dfa reduit = new Dfa(Dfa_CV.X, Dfa_CV.S, Dfa_CV.S0, Dfa_CV.F, Dfa_CV.getInstructionTable());
     return (isConverted) ? reduit : this.toDfa().toReduced();
 }
Exemple #5
0
 /// <summary>
 /// Obtenir l'automate du language complement
 /// </summary>
 /// <returns>Un automate de type Dfa</returns>
 public Dfa getComplementary()
 {
     Dfa temp = this.toComplete();
     ArrayList f = new ArrayList();
     for (int Fi = 0; Fi < temp.S; Fi++)
         if (!temp.F.Contains(Fi))
             f.Add(Fi);
     Dfa dfa = new Dfa(temp.X, temp.S, temp.S0, f, temp.getInstructionTable());
     return dfa;
 }
Exemple #6
0
        /// <summary>
        /// Convertir l'automate Nfa courant vers un automate Dfa equivalant.
        /// </summary>
        /// <returns>Un automate de type Dfa</returns>
        public override Dfa toDfa()
        {
            if (isConverted)
            {
                return Dfa_CV;
            }
            else
            {
                Dfa_CV = new Dfa();//le nouveau automate Dfa à construire

                Dfa_CV.X = this.X;
                ArrayList temp = new ArrayList();
                temp.Add(this.S0);
                StCorTab = new ArrayList();
                StCorTab.Add(temp);                        //on rajoute l'état initial et l'insère dans StCorTab
                Dfa_CV.S = 1;
                if (this.F.Contains(this.S0))                   //si l'état initial est egalement final on l'insère dans la liste des états finaux
                    Dfa_CV.F.Add(this.S0);
                ArrayList instructions = new ArrayList();
                //on parcours les élement de la table StCorTab (cette table est mis à jour à l'interieur)
                for (int etat = 0; etat < Dfa_CV.S; etat++)
                {
                    if (((ArrayList)StCorTab[etat]).Count == 1)
                    {
                        if (this.F.Contains(((ArrayList)StCorTab[etat])[0]))
                            Dfa_CV.F.Add(etat);
                    }
                    foreach (char car in X)
                    {                   //pour chaque lettre de X
                        int c = toIndex(car);
                        temp = new ArrayList();
                        foreach (int Si in ((ArrayList)StCorTab[etat]))       //puisque on a plusieurs etats de départ (dans les instruction)
                            if (Si < this.S)
                                if (I[Si, c].Count != 0)
                                    temp = arrayListUnion(temp, I[Si, c]);   //on fait l'union des ensembles d'arrivé de chaque etat de départ
                        if (temp.Count != 0)
                        {                  //si l'ensemble d'arrivée n'est pas vide (l'instruction existe)
                            temp.Sort();
                            int index = contains(StCorTab, temp);
                            if (index == -1)                    //si cet ensemble d'etats n'est pas encore renommé(s'il n'existe pas dans StCorTab)
                            {
                                instructions.Add(new Instruction(etat, car, Dfa_CV.S));       //on recopie l'instrucion (avec les nouveau nom)
                                StCorTab.Add(temp);           //on le renomme (on l'insère dans StCorTab
                                //on vérifie si cet état et final, si c'est le cas on l'insère dans la liste des états finaux
                                if (temp.Count == 1)            //cas d'un état simple
                                {
                                    if (this.F.Contains(temp))
                                        Dfa_CV.F.Add(Dfa_CV.S);
                                }
                                else                            //cas d'un ensemble d'état
                                {
                                    if (Intersect(temp, this.F))
                                        Dfa_CV.F.Add(Dfa_CV.S);
                                }
                                Dfa_CV.S++;                     //on ajoute un état à S
                            }
                            else
                                instructions.Add(new Instruction(etat, car, index));    //si l'état est déjà renommé on recopie l'instrucion directement
                        }
                    }
                }
                Dfa_CV.InitI();
                foreach (Instruction instruction in instructions)
                    Dfa_CV.AddInstruction(instruction);
                Dfa_CV.F.Sort();
                isConverted = true;
                return Dfa_CV;
            }
        }
Exemple #7
0
 /// <summary>
 /// Convertir l'automate courant vers un automate complet equivalant
 /// </summary>
 /// <returns>l'automate Dfa complet equivalant</returns>
 public override Dfa toComplete()
 {
     Dfa Complet = new Dfa(Dfa_CV.X, Dfa_CV.S, Dfa_CV.S0, Dfa_CV.F, Dfa_CV.getInstructionTable());
     return (isConverted) ? Complet : this.toDfa().toComplete();
 }
Exemple #8
0
 public override Dfa toReduced()
 {
     if (this.isReduced())
     {
         Dfa temp = new Dfa(this.X, this.S, this.S0, this.F, this.getInstructionTable());
         return temp;
     }
     Dfa Reduit = new Dfa();
     Reduit.X = this.X;
     coAccessible.Sort();
     if (coAccessible.Count != 0)
     {
         Reduit.S = coAccessible.Count;
         Reduit.InitI();
         Reduit.S0 = this.S0;
         for (int i = 0; i < coAccessible.Count; i++)
         {
             Reduit.RdStateCorTab.Add(coAccessible[i]);
             if (this.F.Contains(coAccessible[i]))
                 Reduit.F.Add(i);
         }
         for (int i = 0; i < Reduit.RdStateCorTab.Count; i++)
             foreach (char car in X)
             {                                       //on recopie les instruction consernant les etats de la table de correspondance
                 int c = toIndex(car);
                 int k = (int)Reduit.RdStateCorTab[i];
                 Reduit.I[i, c] = (Reduit.RdStateCorTab.Contains(this.I[k, c])) ? (int)Reduit.RdStateCorTab.IndexOf(this.I[k, c]) : -1;
             }
     }
     return Reduit;
 }
Exemple #9
0
 public override Dfa toDfa()
 {
     Dfa temp = new Dfa(this.X, this.S, this.S0, this.F, this.getInstructionTable());
     return temp;
 }
Exemple #10
0
 public override Dfa toComplete()
 {
     if (this.isComplete())
         return this;
     Dfa Complet = new Dfa(this.X, this.S + 1, this.S0, this.F, this.I);
     for (int i = 0; i < this.S; i++)
         foreach (char car in this.X)
             if (this.getInstruction(i, car) == -1)
                 Complet.AddInstruction(i, car, this.S);
     foreach (char car in this.X)
         Complet.AddInstruction(this.S, car, this.S);
     return Complet;
 }