Created
June 27, 2014 22:59
-
-
Save JoeyEremondi/561af149fc6b4022de53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package DFA; | |
import java.util.*; | |
import java.lang.Math; | |
import automata.FAState; | |
import automata.FiniteAutomaton; | |
public class DFAState { | |
Set<FAState> superState; | |
protected DFAState(Set<FAState> subStates) | |
{ | |
superState = new TreeSet<FAState>(subStates); | |
} | |
private static FAState first(Set<FAState> s){ | |
for (FAState q : s) | |
{ | |
return q; | |
} | |
return null; | |
} | |
public static DFAState delta(DFAState q, String s) | |
{ | |
Set<FAState> accum = new TreeSet<FAState>(); | |
for (FAState subState : q.superState) | |
{ | |
accum.addAll(subState.getNext(s)); | |
} | |
return new DFAState(accum); | |
} | |
public static List<String> deltaSet(DFAState q) | |
{ | |
if (q.superState.isEmpty()) | |
{ | |
return new LinkedList<String>(); | |
} | |
else | |
{ | |
FAState firstState = first(q.superState); | |
Set<String> alphabet = firstState.getowner().getAllTransitionSymbols(); | |
LinkedList<String> accum = new LinkedList<String>(); | |
for (String a : alphabet) | |
{ | |
if (deltaDefined(q,a)) | |
{ | |
accum.add(a); | |
} | |
} | |
return accum; | |
} | |
} | |
public static boolean deltaDefined(DFAState q, String s) | |
{ | |
boolean foundState = false; | |
for (FAState subState : q.superState) | |
{ | |
foundState = foundState || subState.getNext(s).isEmpty(); | |
} | |
return foundState; | |
} | |
public static DFAState initialDFAState(FiniteAutomaton aut) | |
{ | |
Set<FAState> init = new TreeSet<FAState>(); | |
init.add(aut.getInitialState()); | |
return new DFAState(init); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment