/// <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; } }
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; }