FormeleMethode/NdfaToDfaConverter.cs
/// <summary>
/// Renames the states and transitions states.
/// </summary>
Renames the states and transitions states.
Renames the states and transitions states .
public static Automata<string> RenameStates(Automata<string> dfa)
		{
			Dictionary<string, string> dictionay = new Dictionary<string, string>();
			int index = 0;
			foreach (string s in dfa.states)
			{
				if (s != "Fuik")
				{
					dictionay.Add(s, $"q{index}");
					index++;
				}
			}
			SortedSet<string> newStates = new SortedSet<string>();
			foreach (string state in dfa.states)
			{
				if (state != "Fuik")
				{
					newStates.Add(dictionay[state]);
				}
			}
			dfa.states = newStates;
			SortedSet<string> newStartStates = new SortedSet<string>();
			foreach (string startState in dfa.startStates)
			{
				newStartStates.Add(dictionay[startState]);
			}
			dfa.startStates = newStartStates;
			SortedSet<string> newEndStates = new SortedSet<string>();
			foreach (string endState in dfa.endStates)
			{
				newEndStates.Add(dictionay[endState]);
			}
			dfa.endStates = newEndStates;
			HashSet<Transition<string>> newTransitions = new HashSet<Transition<string>>();
			foreach (Transition<string> oldTransition in dfa.transitions)
			{
				newTransitions.Add(new Transition<string>(oldTransition.GetFromState() == "Fuik" ? oldTransition.GetFromState() : dictionay[oldTransition.GetFromState()],
														  oldTransition.GetSymbol(),
														  oldTransition.GetToState() == "Fuik" ? oldTransition.GetToState() : dictionay[oldTransition.GetToState()]));
			}
			dfa.transitions = newTransitions;
			return dfa;
		}
public static Automata < string > RenameStates ( Automata < string > dfa ) { Dictionary < string , string > dictionay = new Dictionary < string , string > ( ) ; int index = 0 ; foreach ( string s in dfa . states ) { if ( s != " " ) { dictionay . Add ( s , $" q { index } " ) ; index ++ ; } } SortedSet < string > newStates = new SortedSet < string > ( ) ; foreach ( string state in dfa . states ) { if ( state != " " ) { newStates . Add ( dictionay [ state ] ) ; } } dfa . states = newStates ; SortedSet < string > newStartStates = new SortedSet < string > ( ) ; foreach ( string startState in dfa . startStates ) { newStartStates . Add ( dictionay [ startState ] ) ; } dfa . startStates = newStartStates ; SortedSet < string > newEndStates = new SortedSet < string > ( ) ; foreach ( string endState in dfa . endStates ) { newEndStates . Add ( dictionay [ endState ] ) ; } dfa . endStates = newEndStates ; HashSet < Transition < string > > newTransitions = new HashSet < Transition < string > > ( ) ; foreach ( Transition < string > oldTransition in dfa . transitions ) { newTransitions . Add ( new Transition < string > ( oldTransition . GetFromState ( ) == " " ? oldTransition . GetFromState ( ) : dictionay [ oldTransition . GetFromState ( ) ] , oldTransition . GetSymbol ( ) , oldTransition . GetToState ( ) == " " ? oldTransition . GetToState ( ) : dictionay [ oldTransition . GetToState ( ) ] ) ) ; } dfa . transitions = newTransitions ; return dfa ; }
Renames the states and transitions states.
Renames the states and transitions states .
// key = old name value = new name // Link shorter name to each state // Rename the states // Rename start states // Rename end states // Rename trans states
dfa
Automata<string>