Package ptolemy.domains.fsm.kernel

Examples of ptolemy.domains.fsm.kernel.State


            _debug("Firing " + getFullName(), " at time " + getModelTime());
        }
        FSMActor controller = getController();
        // Read the inputs from the environment.
        controller.readInputs();
        State st = controller.currentState();

        // Chose a preemptive transition, if there is one,
        // and execute its choice actions.
        // The choice actions are the outputActions, not the setActions.
        Transition tr = controller.chooseTransition(st
                .preemptiveTransitionList());
        _enabledTransition = tr;

        // If a preemptive transition was found, prefire and fire
        // the refinements of the transition, and then return.
        if (tr != null) {
            if (_debugging) {
                _debug("Preemptive transition is enabled.");
            }
            Actor[] actors = tr.getRefinement();
            if (actors != null) {
                for (int i = 0; i < actors.length; ++i) {
                    if (_stopRequested) {
                        break;
                    }
                    if (_debugging) {
                        _debug("Prefire and fire the refinement of the preemptive transition: "
                                + actors[i].getFullName());
                    }
                    if (actors[i].prefire()) {
                        actors[i].fire();
                        _actorsFired.add(actors[i]);
                    }
                }
            }
            controller.readOutputsFromRefinement();
            return;
        }

        // There was no preemptive transition, so we proceed
        // to the refinement of the current state.
        Actor[] actors = st.getRefinement();
        if (actors != null) {
            for (int i = 0; i < actors.length; ++i) {
                if (_stopRequested) {
                    break;
                }
                if (_debugging) {
                    _debug("Fire the refinement of the current state: ",
                            actors[i].getFullName());
                }
                actors[i].fire();
                _actorsFired.add(actors[i]);
            }
        }
        // Mark that this state has been visited.
        st.setVisited(true);

        // Read the inputs from the environment.
        controller.readInputs();
        // Read the outputs from the refinement.
        controller.readOutputsFromRefinement();

        // NOTE: we assume the controller, which is an FSM actor, is strict.
        // That is, the controller will only fire when all inputs are ready.
        // NOTE: There seems to be a problem. In particular, if some inputs are
        // unknown before this modal model fires, the transition is not checked.
        // This suggest that we might need another firing if some inputs later
        // become known so that to ensure that no transition is missed.
        // NOTE: this is saved by the _hasIterationConverged() method
        // defined in the FixedPointDirector, where it ensures that no receivers
        // will change their status and until then an iteration is claimed
        // complete.
        Iterator inputPorts = controller.inputPortList().iterator();

        while (inputPorts.hasNext()) {
            IOPort inputPort = (IOPort) inputPorts.next();
            if (!inputPort.isKnown()) {
                return;
            }
        }

        // See whether there is an enabled transition.
        tr = controller.chooseTransition(st.nonpreemptiveTransitionList());
        _enabledTransition = tr;
        if (tr != null) {
            if (_debugging) {
                _debug("Transition: " + tr.getName() + " is enabled.");
            }
View Full Code Here


            return result;
        }
        try {
            // Check whether there is any preemptive transition enabled.
            FSMActor controller = getController();
            State currentState = controller.currentState();
            List preemptiveEnabledTransitions = controller
                    .enabledTransitions(currentState.preemptiveTransitionList());

            if (preemptiveEnabledTransitions.size() != 0) {
                if (_debugging && _verbose) {
                    _debug("Find enabled preemptive transitions.");
                }
            }

            // Check whether there is any non-preemptive transition enabled.
            List nonpreemptiveEnabledTransitions = controller
                    .enabledTransitions(currentState
                            .nonpreemptiveTransitionList());

            if (nonpreemptiveEnabledTransitions.size() != 0) {
                if (_debugging && _verbose) {
                    _debug("Find enabled non-preemptive transitions.");
                }
            }

            // Check whether there is any event detected for preemptive transitions.
            Transition preemptiveTrWithEvent = _checkEvent(currentState
                    .preemptiveTransitionList());

            if (preemptiveTrWithEvent != null) {
                if (_debugging) {
                    _debug("Detected event for transition:  "
                            + preemptiveTrWithEvent.getGuardExpression());
                }
            }

            // Check whether there is any event detected for
            // nonpreemptive transitions.
            Transition nonPreemptiveTrWithEvent = _checkEvent(currentState
                    .nonpreemptiveTransitionList());

            if (nonPreemptiveTrWithEvent != null) {
                if (_debugging) {
                    _debug("Detected event for transition:  "
View Full Code Here

     *  variable being compared and the threshold.
     *  @exception IllegalActionException If thrown by any commit action
     *  or there is no controller.
     */
    public boolean postfire() throws IllegalActionException {
        State currentState = getController().currentState();
        if (_enabledTransition == null) {
            // Only commit the current states of the relationlists
            // of all the transitions during these execution phases.
            Iterator iterator = currentState.nonpreemptiveTransitionList()
                    .listIterator();
            while (iterator.hasNext()) {
                Transition transition = (Transition) iterator.next();
                ParseTreeEvaluatorForGuardExpression parseTreeEvaluator = (ParseTreeEvaluatorForGuardExpression) transition
                        .getParseTreeEvaluator();
                RelationList relationList = parseTreeEvaluator
                        .getRelationList();
                relationList.commitRelationValues();
            }

            iterator = currentState.preemptiveTransitionList().listIterator();
            while (iterator.hasNext()) {
                Transition transition = (Transition) iterator.next();
                ParseTreeEvaluatorForGuardExpression parseTreeEvaluator = (ParseTreeEvaluatorForGuardExpression) transition
                        .getParseTreeEvaluator();
                RelationList relationList = parseTreeEvaluator
                        .getRelationList();
                relationList.commitRelationValues();
            }
        } else {
            // It is important to clear the history information of the
            // relation list since after this breakpoint, no history
            // information is valid.
            Iterator iterator = currentState.nonpreemptiveTransitionList()
                    .listIterator();
            while (iterator.hasNext()) {
                Transition transition = (Transition) iterator.next();
                ParseTreeEvaluatorForGuardExpression parseTreeEvaluator = (ParseTreeEvaluatorForGuardExpression) transition
                        .getParseTreeEvaluator();
                RelationList relationList = parseTreeEvaluator
                        .getRelationList();
                relationList.resetRelationList();
            }

            iterator = currentState.preemptiveTransitionList().listIterator();
            while (iterator.hasNext()) {
                Transition transition = (Transition) iterator.next();
                ParseTreeEvaluatorForGuardExpression parseTreeEvaluator = (ParseTreeEvaluatorForGuardExpression) transition
                        .getParseTreeEvaluator();
                RelationList relationList = parseTreeEvaluator
View Full Code Here

        }

        boolean result = true;
        // if any actor is not ready to fire, stop prefiring the
        // remaining actors, call super.prefire(), and return false;
        State st = getController().currentState();
        Actor[] actors = st.getRefinement();
        if (actors != null) {
            for (int i = 0; i < actors.length; ++i) {
                if (_stopRequested) {
                    break;
                }
View Full Code Here

        System.out.println("Deadlock states:");

        Iterator deadlockStates = automaton.deadlockStates().iterator();

        while (deadlockStates.hasNext()) {
            State state = (State) deadlockStates.next();
            System.out.println("    " + state.getFullName());
        }
    }
View Full Code Here

        CompositeActor container = (CompositeActor) getContainer();
        FSMActor controller = getController();
        controller.setNewIteration(_sendRequest);
        _readInputs();

        State currentState = controller.currentState();

        Actor[] actors = currentState.getRefinement();

        // NOTE: Paranoid coding.
        if ((actors == null) || (actors.length != 1)) {
            throw new IllegalActionException(this,
                    "Current state is required to have exactly one refinement: "
                            + currentState.getName());
        }

        if (!_stopRequested) {
            if (actors[0].prefire()) {
                if (_debugging) {
                    _debug(getFullName(), " fire refinement",
                            ((ptolemy.kernel.util.NamedObj) actors[0])
                                    .getName());
                }

                actors[0].fire();
                _refinementPostfire = actors[0].postfire();
            }
        }

        _readOutputsFromRefinement();

        if (_sendRequest) {
            ChangeRequest request = new ChangeRequest(this,
                    "choose a transition") {
                protected void _execute() throws KernelException,
                        IllegalActionException {
                    FSMActor controller = getController();
                    State currentState = controller.currentState();
                    chooseNextNonTransientState(currentState);
                }
            };

            request.setPersistent(false);
View Full Code Here

        if (_debugging) {
            _debug(getName(), " fire.");
        }

        FSMActor ctrl = getController();
        State currentState = ctrl.currentState();

        ctrl.readInputs();

        Transition transition;

        // NOTE: If an enabled transition is already found,
        // do not try to find another enabled transition.
        // This guarantees that each firing of a modal model produces at most
        // one discrete event.
        // Also, the refinements are not fired to prevent the output from the
        // enabled transitions being overwritten by the outputs from the
        // refinements.
        // This guarantees that only one event is produced at one discrete
        // phase of execution.
        if (_enabledTransition == null) {
            ///////////////////////////////////////////////////////////////////
            // Handle preemptive transitions
            // Only EXECUTE enabled transitions at the generating-event phase
            // and iterating-purely-discrete-actors phase during a
            // discrete-phase execution. In fact, if this director is used
            // inside CT models only, we can further constraint the enabled
            // transitions to be executed only in generating-event phase.
            // However, to support the backwards compatibility such that
            // HSFSMDirector can be also used inside DE models, we also allow the
            // enabled transitions to be executed at the
            // iterating-purely-discrete-actors phase.
            // Check enabled transitions at the end of a continuous phase
            // execution where the accuracy of the current step size is checked.
            if ((getExecutionPhase() == CTExecutionPhase.GENERATING_EVENTS_PHASE)
                    || (getExecutionPhase() == CTExecutionPhase.ITERATING_PURELY_DISCRETE_ACTORS_PHASE)) {
                transition = ctrl.chooseTransition(currentState
                        .preemptiveTransitionList());
                _transitionHasEvent = false;
            } else {
                transition = null;
            }

            // NOTE: The refinements of a transition can not and must not
            // advance time. However, this requirement is not checked here.
            if (transition != null) {
                // record the enabled preemptive transition
                // for the postfire() method.
                _enabledTransition = transition;

                // Disable mutation because we are in the middle of an
                // iteration. The mutation will be enabled again in the
                // postfire() method when the current phase of execution is
                // updating continuous states.
                _mutationEnabled = false;

                Actor[] actors = transition.getRefinement();

                if ((actors != null) && (actors.length > 0)) {
                    for (int i = 0; i < actors.length; ++i) {
                        if (_stopRequested) {
                            break;
                        }

                        if (actors[i].prefire()) {
                            actors[i].fire();
                            actors[i].postfire();
                        }
                    }

                    ctrl.readOutputsFromRefinement();
                }

                // An enabled preemptive transition preempts the
                // firing of the enabled refienements.
                return;
            }

            boolean visited = currentState.isVisited();

            // Fire the refinements of the current state.
            Iterator actors = _enabledRefinements.iterator();

            while (actors.hasNext()) {
                Actor actor = (Actor) actors.next();

                if (_debugging && _verbose) {
                    _debug(getName(), " fire refinement", ((NamedObj) actor)
                            .getName());
                }

                // If this is the first time this state is visited, check
                // whether the director for the refinement is a CT (Embedded)
                // director. If so, establish the initial states for this
                // refinement.
                if (!visited) {
                    Director director = actor.getDirector();

                    if (director instanceof CTEmbeddedDirector) {
                        ((CTEmbeddedDirector) director)
                                .setInitialStatesNotReady();
                    }
                }

                actor.fire();
            }

            // The controller needs to know the most updated outputs from
            // the firing of the enabled refinements.
            ctrl.readOutputsFromRefinement();

            if (!visited) {
                currentState.setVisited(true);
            }

            //////////////////////////////////////////////////////////////////
            // Handle nonpreemptive transitions
            // Only EXECUTE enabled transitions at the generating-event phase
            // and iterating-purely-discrete-actors phase during a
            // discrete-phase execution. In fact, if this director is used
            // inside CT models only, we can further constraint the enabled
            // transitions to be executed only in generating-event phase.
            // However, to support the backwards
            // compatibility such that HSFSMDirector can be also used inside DE
            // models, we also allow the enabled transitions to be executed at
            // the iterating-purely-discrete-actors phase.
            // Check enabled transitions at the end of a continuous
            // phase of execution to verify the accuracy of current step size.
            if ((getExecutionPhase() == CTExecutionPhase.GENERATING_EVENTS_PHASE)
                    || (getExecutionPhase() == CTExecutionPhase.ITERATING_PURELY_DISCRETE_ACTORS_PHASE)) {
                // Note that the output actions associated with the transition
                // are executed.
                transition = ctrl.chooseTransition(currentState
                        .nonpreemptiveTransitionList());
                _transitionHasEvent = false;
            } else {
                transition = null;
            }
View Full Code Here

     */
    public void initialize() throws IllegalActionException {
        super.initialize();

        FSMActor ctrl = getController();
        State currentState = ctrl.currentState();

        _enabledRefinements = new LinkedList();

        Actor[] actors = currentState.getRefinement();

        if (actors != null) {
            for (int i = 0; i < actors.length; ++i) {
                actors[i].initialize();
                _enabledRefinements.add(actors[i]);
View Full Code Here

        // All non-preemptive and preemptive transitions are checked below,
        // because even if a preemptive transition is enabled, the non-preemptive
        // transitions never even get a chance to be evaluated.
        try {
            FSMActor ctrl = getController();
            State currentState = ctrl.currentState();
            // Check if there is any preemptive transition enabled.
            List preemptiveEnabledTransitions = ctrl
                    .enabledTransitions(currentState.preemptiveTransitionList());

            if (preemptiveEnabledTransitions.size() != 0) {
                if (_debugging && _verbose) {
                    _debug("Find enabled preemptive transitions.");
                }
            }

            // Check if there is any non-preemptive transition enabled.
            List nonpreemptiveEnabledTransitions = ctrl
                    .enabledTransitions(currentState
                            .nonpreemptiveTransitionList());

            if (nonpreemptiveEnabledTransitions.size() != 0) {
                if (_debugging && _verbose) {
                    _debug("Find enabled non-preemptive transitions.");
                }
            }

            // Check if there is any event detected for preemptive transitions.
            Transition preemptiveTrWithEvent = _checkEvent(currentState
                    .preemptiveTransitionList());

            if (preemptiveTrWithEvent != null) {
                if (_debugging) {
                    _debug("Detected event for transition:  "
                            + preemptiveTrWithEvent.getGuardExpression());
                }
            }

            // Check if there is any events detected for
            // nonpreemptive transitions.
            Transition nonPreemptiveTrWithEvent = _checkEvent(currentState
                    .nonpreemptiveTransitionList());

            if (nonPreemptiveTrWithEvent != null) {
                if (_debugging) {
                    _debug("Detected event for transition:  "
View Full Code Here

     */
    public boolean postfire() throws IllegalActionException {
        boolean postfireReturns = true;

        FSMActor ctrl = getController();
        State currentState = ctrl.currentState();

        CompositeActor container = (CompositeActor) getContainer();
        Director executiveDirector = container.getExecutiveDirector();
        Iterator refinements = _enabledRefinements.iterator();

        while (refinements.hasNext()) {
            Actor refinement = (Actor) refinements.next();
            postfireReturns = postfireReturns && refinement.postfire();

            // take out event outputs generated in ref.postfire()
            Iterator outports = refinement.outputPortList().iterator();

            while (outports.hasNext()) {
                IOPort p = (IOPort) outports.next();
                transferOutputs(p);
            }
        }

        // If there is one transition enabled, the HSFSMDirector requests
        // to be fired again at the same time to see whether the next state
        // has some outgoing transition enabled.
        Transition tr = _enabledTransition;

        if (tr != null) {
            if (_debugging) {
                _debug("Postfire deals with enabled transition "
                        + tr.getGuardExpression());
            }

            // It is important to clear the history information of the
            // relation list since after this breakpoint, no history
            // information is valid.
            Iterator iterator = currentState.nonpreemptiveTransitionList()
                    .listIterator();

            while (iterator.hasNext()) {
                Transition transition = (Transition) iterator.next();
                ParseTreeEvaluatorForGuardExpression parseTreeEvaluator = (ParseTreeEvaluatorForGuardExpression) transition
                        .getParseTreeEvaluator();
                RelationList relationList = parseTreeEvaluator
                        .getRelationList();
                relationList.resetRelationList();
            }

            iterator = currentState.preemptiveTransitionList().listIterator();

            while (iterator.hasNext()) {
                Transition transition = (Transition) iterator.next();
                ParseTreeEvaluatorForGuardExpression parseTreeEvaluator = (ParseTreeEvaluatorForGuardExpression) transition
                        .getParseTreeEvaluator();
                RelationList relationList = parseTreeEvaluator
                        .getRelationList();
                relationList.resetRelationList();
            }

            // If the top level of the model is modal model, the director
            // is null. We do not request to be fired again since no one in
            // the upper level of hierarchy will do that.
            if (executiveDirector != null) {
                if (_debugging) {
                    _debug(executiveDirector.getFullName()
                            + " requests refiring at " + getModelTime());
                }

                // If there is one transition enabled, the HSFSMDirector requests
                // to be fired again at the same time to see whether the next
                // state has some outgoing transition enabled.
                executiveDirector.fireAt(container, getModelTime());
            }

            // If this iteration will not generate more events, (the
            // current phase of execution is neithter generating-event nor
            // iterating-purely-discrete-actors), or the executive director
            // is not a CT director, reset the _enabledTransition to null.
            // Here we reset the cached enabled transition at the
            // updating-continuous-states phase, indicating the end of a
            // complete iteration of the executive CT director.
            // This guarantees that at most one transition is taken in an
            // iteration of discrete phase of execution.
            // To be more specific, for each (t, n), there is at most
            // one event.
            if ((getExecutionPhase() == CTExecutionPhase.UPDATING_CONTINUOUS_STATES_PHASE)
                    || (executiveDirector == null)) {
                // Only clear the cached enabled transition when no more events
                // will be generated at the current discrete phase of execution.
                _enabledTransition = null;

                // Enable mutation when the current phase of execution is
                // updating continuous states.
                // This is to avoid unnecessary change requests made by
                // the super class FSMDirector.
                _mutationEnabled = true;
            }
        } else {
            if ((getExecutionPhase() == CTExecutionPhase.GENERATING_EVENTS_PHASE)
                    || (getExecutionPhase() == CTExecutionPhase.POSTFIRING_EVENT_GENERATORS_PHASE)) {
                // Only commit the current states of the relationlists
                // of all the transitions during these execution phases.
                Iterator iterator = currentState.nonpreemptiveTransitionList()
                        .listIterator();

                while (iterator.hasNext()) {
                    Transition transition = (Transition) iterator.next();
                    ParseTreeEvaluatorForGuardExpression parseTreeEvaluator = (ParseTreeEvaluatorForGuardExpression) transition
                            .getParseTreeEvaluator();
                    RelationList relationList = parseTreeEvaluator
                            .getRelationList();
                    relationList.commitRelationValues();
                }

                iterator = currentState.preemptiveTransitionList()
                        .listIterator();

                while (iterator.hasNext()) {
                    Transition transition = (Transition) iterator.next();
                    ParseTreeEvaluatorForGuardExpression parseTreeEvaluator = (ParseTreeEvaluatorForGuardExpression) transition
View Full Code Here

TOP

Related Classes of ptolemy.domains.fsm.kernel.State

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.