public SSA <SYMBOL> ForwardStateLanguage(int state) { if (!States.Contains(state)) { throw SSAException.StateNotInStates(); } return(new SSA <SYMBOL>(state, FinalStates, Moves, Alphabet, null, StateNames)); }
public SSA <SYMBOL> BackwardStateLanguage(int state) { if (!States.Contains(state)) { throw SSAException.StateNotInStates(); } return(new SSA <SYMBOL>(InitialState, new int[] { state }, Moves, Alphabet, null, StateNames)); }
/* label automaton states by predicate states whose forward/backward languages intersect */ private Dictionary <int, Set <int> > MakeLabels(SSA <SYMBOL> m) { var labels = new Dictionary <int, Set <int> >(m.States.Count()); foreach (int state in m.States) { labels[state] = new Set <int>(); } var stack = new Stack <Tuple <int, int> >(); foreach (SSA <SYMBOL> pred in predicateAutomata) { if (m.Algebra.Alphabet != pred.Algebra.Alphabet) { throw SSAException.IncompatibleAlphabets(); } } Func <int, IEnumerable <Move <Predicate <SYMBOL> > > > getMoves = forward ? (Func <int, IEnumerable <Move <Predicate <SYMBOL> > > >)m.GetMovesTo : m.GetMovesFrom; foreach (SSA <SYMBOL> pred in predicateAutomata) { if (forward) { foreach (int mState in m.FinalStates) { foreach (int pState in pred.FinalStates) { stack.Push(new Tuple <int, int>(mState, pState)); } } } else { stack.Push(new Tuple <int, int>(m.InitialState, pred.InitialState)); } while (stack.Count > 0) { var pair = stack.Pop(); int mState = pair.Item1; int pState = pair.Item2; labels[mState].Add(pair.Item2); foreach (var mMove in getMoves(mState)) { int state = forward ? mMove.SourceState : mMove.TargetState; foreach (var pMove in (forward ? pred.GetMovesTo(pState) : pred.GetMovesFrom(pState))) { if (!m.Algebra.IsSatisfiable(mMove.Label & pMove.Label)) { continue; } int stateLabel = forward ? pMove.SourceState : pMove.TargetState; if (!labels[state].Contains(stateLabel)) { stack.Push(new Tuple <int, int>(state, stateLabel)); } } } } } return(labels); }