/// <summary> /// Obtenir l'automate qui defini l'union des deux languages definis par A et B /// </summary> /// <returns>Un automate de type PGfa</returns> public static PGfa Union(Automata A, Automata B) { PGfa a = A.toPGfa(); PGfa b = B.toPGfa(); PGfa aUb = new PGfa(arrayListUnion(a.X, b.X), a.S + b.S + 1); aUb.S0 = 0; foreach (int Fi in a.F) aUb.AddFinalState(Fi + 1); foreach (int Fi in b.F) aUb.AddFinalState(Fi + a.S + 1); for (int i = 0; i < a.S; i++) foreach (char car in a.X) foreach (int j in a.getInstruction(i, car)) aUb.AddInstruction(i + 1, car, j + 1); for (int i = 0; i < b.S; i++) foreach (char car in b.X) foreach (int j in b.getInstruction(i, car)) aUb.AddInstruction(i + a.S + 1, car, j + b.S + 1); aUb.AddInstruction(aUb.S0, EPSILON, new ArrayList { a.S0 + 1, b.S0 + a.S + 1 }); return aUb; }
/// <summary> /// Obtenir l'automate qui defini la concatenation de deux laguages definis par A et B /// </summary> /// <returns>Un automate de type PGfa</returns> public static PGfa Concatenation(Automata A, Automata B) { PGfa a = A.toPGfa(); PGfa b = B.toPGfa(); ArrayList f = new ArrayList(); foreach (int Fi in b.F) f.Add(Fi + a.S); PGfa aCb = new PGfa(arrayListUnion(a.X, b.X), a.S + b.S, a.S0, f, (ArrayList[,])a.getInstructionTable()); for (int i = 0; i < b.S; i++) foreach (char car in b.X) foreach (int j in b.getInstruction(i, car)) aCb.AddInstruction(i + a.S, car, j + b.S); foreach (int Fi in a.F) aCb.AddInstruction(Fi, EPSILON, b.S0 + a.S); return aCb; }