Ejemplo n.º 1
0
 internal ExploredTransitions(ModelProgram modelProgram, int initTransitions, int maxTransitions)
 {
     this.modelProgram = modelProgram;
     this.transitions = Set<Transition>.EmptySet;
     this.groupingTransitions = Set<Transition>.EmptySet;
     Node initNode = new Literal(0);
     this.initialNode = initNode;
     this.nodes = new Set<Node>(initNode);
     this.acceptingNodes = (modelProgram.IsAccepting(modelProgram.InitialState) ?
         new Set<Node>(initNode) :
         Set<Node>.EmptySet);
     //this.errorNodes = (!modelProgram.SatisfiesStateInvariant(modelProgram.InitialState) ?
     //    new Set<Node>(initNode) :
     //    Set<Node>.EmptySet);
     Dictionary<Node, IState> initialStateMap =
         new Dictionary<Node, IState>();
     initialStateMap[initNode] = modelProgram.InitialState;
     this.stateMap = initialStateMap;
     actionsExploredFromNode = new Dictionary<Node, Dictionary<CompoundTerm,Node>>();
     Dictionary<IState, Node> initialNodeMap =
         new Dictionary<IState, Node>();
     initialNodeMap[modelProgram.InitialState] = initNode;
     this.nodeMap = initialNodeMap;
     this.hiddenTransitions = Set<Transition>.EmptySet;
     this.maxTransitions = maxTransitions;
     this.initTransitions = initTransitions;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Explores the model associated with this instance.
        /// The dictionary stateMap (if not null) is used to record the mapping
        /// from generated finite automata states to IStates.
        /// Explore(null) is the same as Explore()
        /// </summary>
        /// <returns>A list of transitions. Each transition is a start state,
        /// an action label and an end state.</returns>
        public FSM Explore(Dictionary <Term, IState> generatedStateMap)
        {
            Set <Symbol> actionSymbols = modelProgram.ActionSymbols();
            IState       initialState  = modelProgram.InitialState;

            Dictionary <IState, int> states   = new Dictionary <IState, int>();
            LinkedList <IState>      frontier = new LinkedList <IState>();

            frontier.AddFirst(initialState);
            int nextStateId = 0;

            Dictionary <Transition, Transition> transitions = new Dictionary <Transition, Transition>();

            while (frontier.Count > 0)
            {
                IState startState = frontier.First.Value;
                frontier.RemoveFirst();
                if (!states.ContainsKey(startState))
                {
                    states.Add(startState, nextStateId++);
                }

                foreach (Symbol actionSymbol in actionSymbols)
                {
                    if (modelProgram.IsPotentiallyEnabled(startState, actionSymbol))
                    {
                        IEnumerable <CompoundTerm> actions = modelProgram.GetActions(startState, actionSymbol);
                        foreach (CompoundTerm action in actions)
                        {
                            TransitionProperties transitionProperties;
                            IState targetState = modelProgram.GetTargetState(startState, action, Set <string> .EmptySet, out transitionProperties);
                            if (IncludeTransition(startState, action, targetState, transitionProperties.Properties))
                            {
                                Transition t = new Transition(startState, action, targetState);
                                transitions.Add(t, t);
                                if (!states.ContainsKey(targetState) && !frontier.Contains(targetState))
                                {
                                    frontier.AddFirst(targetState);
                                }
                            }
                        }
                    }
                }
            }
            Term automatonInitialState = new Literal(states[initialState]);

            Set <Term> automatonStates = Set <Term> .EmptySet;
            Set <Term> acceptingStates = Set <Term> .EmptySet;

            foreach (KeyValuePair <IState, int> kv in states)
            {
                Term automatonState = new Literal(kv.Value);
                automatonStates = automatonStates.Add(automatonState);
                if (modelProgram.IsAccepting(kv.Key))
                {
                    acceptingStates = acceptingStates.Add(automatonState);
                }
                if (generatedStateMap != null)
                {
                    generatedStateMap[automatonState] = kv.Key;
                }
            }

            Set <Triple <Term, CompoundTerm, Term> > automatonTransitions = Set <Triple <Term, CompoundTerm, Term> > .EmptySet;

            foreach (KeyValuePair <Transition, Transition> kv in transitions)
            {
                Transition t = kv.Key;
                automatonTransitions = automatonTransitions.Add(new Triple <Term, CompoundTerm, Term>(new Literal(states[t.startState]),
                                                                                                      t.action,
                                                                                                      new Literal(states[t.targetState])));
            }
            return(new FSM(automatonInitialState, automatonStates, automatonTransitions, acceptingStates));
        }