Examples of FSMActor


Examples of ptolemy.codegen.c.domains.fsm.kernel.FSMActor

        super.generateModeTransitionCode(code);

        ptolemy.domains.fsm.kernel.FSMActor controller = ((ptolemy.domains.fsm.kernel.FSMDirector) getComponent())
                .getController();
        FSMActor controllerHelper = (FSMActor) _getHelper(controller);

        ptolemy.domains.hdf.kernel.HDFFSMDirector director = (ptolemy.domains.hdf.kernel.HDFFSMDirector) getComponent();
        CompositeActor container = (CompositeActor) director.getContainer();
        ptolemy.codegen.c.actor.TypedCompositeActor containerHelper = (ptolemy.codegen.c.actor.TypedCompositeActor) _getHelper(container);

        code.append(containerHelper.processCode("if ($actorSymbol(fired)) {"
                + _eol));
        // generate code for non-preemptive transition
        code.append(_eol + "/* Nonpreemptive Transition */" + _eol + _eol);
        controllerHelper.generateTransitionCode(code,
                new TransitionRetriever() {
                    public Iterator retrieveTransitions(State state) {
                        return state.nonpreemptiveTransitionList().iterator();
                    }
                });
View Full Code Here

Examples of ptolemy.domains.fsm.kernel.FSMActor

     */
    public void fire() throws IllegalActionException {
        if (_debugging) {
            _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.");
            }
            actors = tr.getRefinement();
            if (actors != null) {
                for (int i = 0; i < actors.length; ++i) {
                    if (_stopRequested) {
                        break;
                    }

                    if (actors[i].prefire()) {
                        if (_debugging) {
                            _debug("Prefire and fire the refinement of the transition: "
                                    + actors[i].getFullName());
                        }
                        actors[i].fire();
                        _actorsFired.add(actors[i]);
                    }
                }
                controller.readOutputsFromRefinement();
            }
        }
    }
View Full Code Here

Examples of ptolemy.domains.fsm.kernel.FSMActor

        if (enclosingDirector == null) {
            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) {
View Full Code Here

Examples of ptolemy.domains.fsm.kernel.FSMActor

     @exception IllegalActionException If there is no controller,
     *   or if the current state has no or more than one refinement.
     */
    public void fire() throws IllegalActionException {
        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

Examples of ptolemy.domains.fsm.kernel.FSMActor

     *  to indicate the modal model can send a change request to the manager.
     *  Set the controller flag to indicate a new iteration begins.
     *  @exception IllegalActionException If the base class throws it.
     */
    public void initialize() throws IllegalActionException {
        FSMActor controller = getController();
        _sendRequest = true;
        controller.setNewIteration(_sendRequest);
        super.initialize();
    }
View Full Code Here

Examples of ptolemy.domains.fsm.kernel.FSMActor

    public void fire() throws IllegalActionException {
        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

Examples of ptolemy.domains.fsm.kernel.FSMActor

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

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

        _enabledRefinements = new LinkedList();

        Actor[] actors = currentState.getRefinement();

View Full Code Here

Examples of ptolemy.domains.fsm.kernel.FSMActor

        // reduce the computation cost.
        // 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) {
View Full Code Here

Examples of ptolemy.domains.fsm.kernel.FSMActor

     *   there is no controller.
     */
    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();

View Full Code Here

Examples of ptolemy.domains.fsm.kernel.FSMActor

     *  or can not find the specified refinements associated with the current
     *  state, or the prefire() method of refinements throw it, or the super
     class throws it.
     */
    public boolean prefire() throws IllegalActionException {
        FSMActor ctrl = getController();
        State currentState = ctrl.currentState();

        if (_debugging) {
            _debug(getName(), " find FSMActor " + ctrl.getName()
                    + " and the current state is " + currentState.getName());
        }

        Actor[] actors = currentState.getRefinement();
        _enabledRefinements = new LinkedList();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.