public IAutomat KleeneStern() { var neaET = new NFAeTransform { { 0, null, this.StartState + 1 } // accepted front state }; // add transforms, +1 foreach (var item in this.Transforms) { uint[] qnext = new uint[item.Value.Length]; for (int i = 0; i < item.Value.Length; i++) { qnext[i] = item.Value[i] + 1; } neaET.Add(item.Key.q + 1, item.Key.c, qnext); } var acceptedStates = new uint[this.AcceptedStates.Length + 1]; acceptedStates[0] = 0; // add e-transform from org accepted to front state for (uint i = 0; i < this.AcceptedStates.Length; i++) { acceptedStates[i + 1] = this.AcceptedStates[i] + 1; // a little redundant, because all accepted states must go back to first neaET.Add(this.AcceptedStates[i] + 1, null, 0); } return(new NFAe($"NFAe_KleeneStern({Name})", this.StatesCount + 1, this.Alphabet, neaET, 0, acceptedStates)); }
public override IAutomat HomomorphismChar(Dictionary <char, char> translate) { var neat = new NFAeTransform(); char[] Alp = this.Alphabet.Clone() as char[]; foreach (var dt in this.Transforms) { if (translate.ContainsKey(dt.Key.c.Value)) { neat.Add(dt.Key.q, translate[dt.Key.c.Value], dt.Value); } else { neat.Add(dt.Key.q, dt.Key.c.Value, dt.Value); } } for (int i = 0; i < this.Alphabet.Length; i++) { if (translate.ContainsKey(this.Alphabet[i])) { Alp[i] = translate[this.Alphabet[i]]; } } return(new NFA($"NFA_HomomorphismChar({Name})", StatesCount, Alp, neat, StartState, AcceptedStates)); }
IAcceptWord JoinConcatUnion(IAcceptWord automat, JoinConcatUnionKind unionConcatJoinKind) { if (!(automat is FABase fa2)) { throw new System.NotSupportedException(); } uint offsetA1 = 0; // first state of A2 uint offsetA2 = this.StatesCount; // first state of A2 if (unionConcatJoinKind == JoinConcatUnionKind.Union) { offsetA1 = 1; offsetA2++; } char[] inputAlphabet = this.Alphabet.Union(fa2.Alphabet).ToArray(); var neaeT = new NFAeTransform(); uint startState; // Union: add new start state, with e to both starts if (unionConcatJoinKind == JoinConcatUnionKind.Union) { startState = 0; neaeT.Add(0, null, this.StartState + offsetA1); neaeT.AddM(0, null, fa2.StartState + offsetA2); } else { startState = this.StartState; } // add each A1 transform + offset of A1 foreach (var item in this.Transforms) { foreach (var val in item.Value) { neaeT.AddM(item.Key.q + offsetA1, item.Key.c, val + offsetA1); } } // add each A1 transform, + offset of A2 foreach (var item in fa2.Transforms) { foreach (var val in item.Value) { neaeT.AddM(item.Key.q + offsetA2, item.Key.c, val + offsetA2); } } uint[] accStates; if (unionConcatJoinKind == JoinConcatUnionKind.Concat) { // Concat: has only accepted states from A2 accStates = new uint[fa2.AcceptedStates.Length]; } else { // Join, Union has A1, A2 accpted states accStates = new uint[this.AcceptedStates.Length + fa2.AcceptedStates.Length]; } int i = 0; // store where D1 acc ends // iterate A1 acc for (; i < this.AcceptedStates.Length; i++) { if (unionConcatJoinKind == JoinConcatUnionKind.Concat) { // Concat: lead accepted states from A1 to A2 start neaeT.AddM(this.AcceptedStates[i] + offsetA1, null, fa2.StartState + offsetA2); } else { // Join, Union: states from A1 are normal accepted accStates[i] = this.AcceptedStates[i] + offsetA1; } } if (unionConcatJoinKind == JoinConcatUnionKind.Concat) { i = 0; } // iterate A2 acs and + offsetA2 for (int j = 0; j < fa2.AcceptedStates.Length; j++) { accStates[i + j] = (fa2.AcceptedStates[j] + offsetA2); } return(new NFAe($"NEAe{unionConcatJoinKind.ToString()}({Name}+{fa2.Name})", this.StatesCount + fa2.StatesCount + offsetA1, inputAlphabet, neaeT, startState, accStates)); }