Пример #1
0
        /// <summary>
        /// Get all states in the given finite automaton from which no accepting state is reachable.
        /// </summary>
        /// <param name="fa">given finite automaton</param>
        /// <returns>all dead states in the finite automaton</returns>
        public static Set <Term> GetDeadStates(FSM fa)
        {
            //build a graph from fa
            Dictionary <Term, int> stateToVertexMap = new Dictionary <Term, int>();

            stateToVertexMap[fa.InitialState] = 0;
            int i = 1;

            foreach (Term state in fa.States.Remove(fa.InitialState))
            {
                stateToVertexMap[state] = i++;
            }

            //create edges that correspond to the transitions
            GraphTraversals.Edge[] edges = new GraphTraversals.Edge[fa.Transitions.Count];
            Triple <Term, CompoundTerm, Term>[] transitions = new Triple <Term, CompoundTerm, Term> [fa.Transitions.Count];
            i = 0;
            foreach (Triple <Term, CompoundTerm, Term> trans in fa.Transitions)
            {
                edges[i] = new GraphTraversals.Edge(stateToVertexMap[trans.First],
                                                    stateToVertexMap[trans.Third], i);
                transitions[i++] = trans;
            }

            GraphTraversals.Graph g =
                new GraphTraversals.Graph(0, edges, new GraphTraversals.Edge[] { },
                                          GraphTraversals.WeakClosureEnum.DoNotClose);

            int[] acceptingVertices = new int[fa.AcceptingStates.Count];
            i = 0;
            foreach (Term accState in fa.AcceptingStates)
            {
                acceptingVertices[i++] = stateToVertexMap[accState];
            }

            GraphTraversals.HSet deadVertices = g.DeadStates(acceptingVertices);

            return(fa.States.Select(delegate(Term state)
                                    { return deadVertices.Contains(stateToVertexMap[state]); }));
        }
Пример #2
0
        /// <summary>
        /// Get all states in the given finite automaton from which no accepting state is reachable.
        /// </summary>
        /// <param name="fa">given finite automaton</param>
        /// <returns>all dead states in the finite automaton</returns>
        public static Set<Term> GetDeadStates(FSM fa)
        {
            //build a graph from fa
            Dictionary<Term, int> stateToVertexMap = new Dictionary<Term, int>();
            stateToVertexMap[fa.InitialState] = 0;
            int i = 1;
            foreach (Term state in fa.States.Remove(fa.InitialState))
                stateToVertexMap[state] = i++;

            //create edges that correspond to the transitions
            GraphTraversals.Edge[] edges = new GraphTraversals.Edge[fa.Transitions.Count];
            Triple<Term, CompoundTerm, Term>[] transitions = new Triple<Term, CompoundTerm, Term>[fa.Transitions.Count];
            i = 0;
            foreach (Triple<Term, CompoundTerm, Term> trans in fa.Transitions)
            {
                edges[i] = new GraphTraversals.Edge(stateToVertexMap[trans.First],
                    stateToVertexMap[trans.Third], i);
                transitions[i++] = trans;
            }

            GraphTraversals.Graph g =
                new GraphTraversals.Graph(0, edges, new GraphTraversals.Edge[] { },
                                          GraphTraversals.WeakClosureEnum.DoNotClose);

            int[] acceptingVertices = new int[fa.AcceptingStates.Count];
            i = 0;
            foreach (Term accState in fa.AcceptingStates)
                acceptingVertices[i++] = stateToVertexMap[accState];

            GraphTraversals.HSet deadVertices = g.DeadStates(acceptingVertices);

            return fa.States.Select(delegate(Term state)
                 { return deadVertices.Contains(stateToVertexMap[state]); });
        }