Package ptolemy.actor.util

Examples of ptolemy.actor.util.Time


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

        // Get the current time and period.
        Time currentTime = getDirector().getModelTime();
        double periodValue = ((DoubleToken) period.getToken()).doubleValue();

        if (_debugging) {
            _debug("--- Firing at time " + currentTime + ".");
        }

        // Use the strategy pattern here so that derived classes can
        // override how this is done.
        _updateTentativeValues();

        // Use Time.NEGATIVE_INFINITY to indicate that no refire
        // event should be scheduled because we aren't at a phase boundary.
        _tentativeNextFiringTime = Time.NEGATIVE_INFINITY;

        // By default, the cycle count will not be incremented.
        _tentativeCycleCountIncrement = 0;

        // In case current time has reached or crossed a boundary between
        // periods, update it.  Note that normally it will not
        // have advanced by more than one period
        // (unless, perhaps, the entire domain has been dormant
        // for some time, as might happen for example in a hybrid system).
        // But do not do this if we are before the first iteration.
        if (_tentativeCycleCount > 0) {
            while (_tentativeCycleStartTime.add(periodValue).compareTo(
                    currentTime) < 0) {
                _tentativeCycleStartTime = _tentativeCycleStartTime
                        .add(periodValue);
            }

            Time currentPhaseTime = _tentativeCycleStartTime
                    .add(_offsets[_tentativePhase]);

            // Adjust the phase if time has moved beyond the current phase.
            if (currentTime.compareTo(currentPhaseTime) == 0) {
                // Phase boundary.  Change the current value.
                _tentativeCurrentValue = _getValue(_tentativePhase);

                // Increment to the next phase.
                _tentativePhase++;

                if (_tentativePhase >= _offsets.length) {
                    _tentativePhase = 0;

                    // Schedule the first firing in the next period.
                    _tentativeCycleStartTime = _tentativeCycleStartTime
                            .add(periodValue);

                    // Indicate that the cycle count should increase.
                    _tentativeCycleCountIncrement++;
                }

                if (_offsets[_tentativePhase] >= periodValue) {
                    throw new IllegalActionException(this, "Offset number "
                            + _tentativePhase + " with value "
                            + _offsets[_tentativePhase]
                            + " must be strictly less than the "
                            + "period, which is " + periodValue);
                }

                // Schedule the next firing in this period.
                // NOTE: In the TM domain, this may not occur if we have
                // missed a deadline.  As a consequence, the clock will stop.
                _tentativeNextFiringTime = _tentativeCycleStartTime
                        .add(_offsets[_tentativePhase]);

                if (_debugging) {
                    _debug("next firing is at " + _tentativeNextFiringTime);
                }

                // If we are beyond the number of cycles requested, then
                // change the output value to zero.
                // FIXME: is this a desired behavior? why not simply stop the firing?
                // NOTE: This actor is intended to be used in DE domain. If this actor
                // serves as a source, when the cycle limit is reached, it should stop
                // producing more events and consequently the model stops.
                int cycleLimit = ((IntToken) numberOfCycles.getToken())
                        .intValue();

                if (cycleLimit > 0) {
                    Time stopTime = _tentativeStartTime.add(cycleLimit
                            * periodValue);

                    if (currentTime.compareTo(stopTime) >= 0) {
                        _tentativeCurrentValue = _tentativeCurrentValue.zero();
                    }
View Full Code Here


        if (_debugging) {
            _debug("Initializing " + getFullName() + ".");
        }

        Time timeToStart = getDirector().getModelTime();
        _cycleStartTime = timeToStart;
        _startTime = timeToStart.add(_offsets[0]);
        _currentValue = _getValue(0).zero();
        _phase = 0;
        _tentativeNextFiringTime = _startTime;

        // As in fire(), we use the strategy pattern so that derived classes
View Full Code Here

                start.get(0);

                // Indicate to postfire() that it can call fireAt().
                _tentativeDone = false;

                Time currentTime = getDirector().getModelTime();
                _tentativeCycleStartTime = currentTime;
                _tentativePhase = 0;
                _tentativeCycleCount = 1;
            }
        }
View Full Code Here

     *
     * @exception IllegalActionException If there is an error during
     * the creation of the threads or initialization of the actors.
     */
    public void initialize() throws IllegalActionException {
        _completionTime = new Time(this, PrioritizedTimedQueue.ETERNITY);
        _writeBlockedQueues = new HashMap();
        super.initialize();
    }
View Full Code Here

        DDEReceiver receiver = new DDEReceiver();
        double timeValue;

        try {
            timeValue = ((DoubleToken) stopTime.getToken()).doubleValue();
            receiver._setCompletionTime(new Time(this, timeValue));
            receiver._lastTime = new Time(this);
        } catch (IllegalActionException e) {
            // If the time resolution of the director or the stop
            // time is invalid, it should have been caught before this.
            throw new InternalErrorException(e);
        }
View Full Code Here

        double periodValue = ((DoubleToken) period.getToken()).doubleValue();

        if (periodValue > 0.0) {
            Actor container = (Actor) getContainer();
            Director executiveDirector = container.getExecutiveDirector();
            Time currentTime = getModelTime();

            if (executiveDirector != null) {
                // Not at the top level.
                executiveDirector.fireAt(container, currentTime
                        .add(periodValue));
            } else {
                // At the top level.
                setModelTime(currentTime.add(periodValue));
            }
        }

        return super.postfire();
    }
View Full Code Here

        Nameable container = getContainer();
        if (container instanceof Actor) {
            Director executiveDirector = ((Actor) container)
                    .getExecutiveDirector();
            if (executiveDirector != null) {
                Time outTime = executiveDirector.getModelTime();
                setModelTime(outTime);
                if (_debugging) {
                    _debug("HybridModalDirector: Setting local current time to: "
                            + outTime);
                }
View Full Code Here

        Receiver[][] receivers = output.getRemoteReceivers();

        for (int i = 0; i < receivers.length; i++) {
            for (int j = 0; j < receivers[i].length; j++) {
                DDEReceiver receiver = (DDEReceiver) receivers[i][j];
                receiver.put(new Token(), new Time(getDirector(),
                        PrioritizedTimedQueue.IGNORE));
            }
        }

        receivers = input.getReceivers();
View Full Code Here

            if (stopTimeValue < 0.0) {
                throw new IllegalActionException(this,
                        " stopTime cannot be less than 0.");
            }

            _stopTime = new Time(this, stopTimeValue);
        } else if (attribute == startTime) {
            double startTimeValue = ((DoubleToken) startTime.getToken())
                    .doubleValue();
            _startTime = new Time(this, startTimeValue);
        } else if (attribute == defaultTaskExecutionTime) {
            if (((DoubleToken) defaultTaskExecutionTime.getToken())
                    .doubleValue() < 0.0) {
                throw new IllegalActionException(this,
                        " task execution time cannot be less than 0.");
View Full Code Here

        _nextIterationTime = _stopTime;

        // First look at interrupt events.
        while (!_interruptQueue.isEmpty()) {
            DEEvent interruptEvent = _interruptQueue.get();
            Time timeStamp = interruptEvent.timeStamp();

            if (timeStamp.compareTo(getModelTime()) < 0) {
                // This should never happen.
                throw new IllegalActionException(this,
                        "external input in the past: " + "input time stamp is "
                                + timeStamp + "current time in TM is "
                                + getModelTime());
            } else if (timeStamp == getModelTime()) {
                _interruptQueue.take();

                Actor actor = interruptEvent.actor();

                if (actor != null) {
                    if (actor.prefire()) {
                        actor.fire();

                        if (!actor.postfire()) {
                            _disableActor(actor);
                        }
                    }
                }
            } else {
                // All interrupts are in the future.
                // Get the time for the next interrupt.
                // It will be used for finding the next iteration time.
                _nextIterationTime = timeStamp;
                break;
            }
        }

        // Then we process TM events.
        TMEvent event = null;

        while (!_eventQueue.isEmpty()) {
            event = (TMEvent) _eventQueue.get();

            if (_debugging) {
                _debug("The first event in the queue is ", event.toString());
            }

            // Notice that the first event in the queue
            // either has processing time > 0 or hasn't been started.
            if (!event.hasStarted()) {
                if (_debugging) {
                    _debug(getName(), "put trigger event ", event.toString(),
                            " into " + ((NamedObj) event.actor()).getName()
                                    + " and processing");
                }

                event.receiver()._triggerEvent(event.token());

                // FIXME: What shall we do if there are events to
                // the same actor with the same priority.
                // Check if there are any events with equal priority
                // for this actor. If so, make them available to the
                // actor at the same time.
                Actor actor = event.actor();

                if ((actor == getContainer()) || !actor.prefire()) {
                    // If the actor is the container of this director,
                    // then the event is at the output boundary.
                    // Remove the event and look at the next event.
                    _eventQueue.take();
                    event = null;

                    // Return to the while loop.
                } else {
                    // Determine the processing time.
                    double processingTime = ((DoubleToken) defaultTaskExecutionTime
                            .getToken()).doubleValue();

                    if (actor instanceof TMActor) {
                        processingTime = ((TMActor) actor).getExecutionTime();
                    } else {
                        // Use the executionTime parameter from the port
                        // or the actor.
                        Parameter executionTime = (Parameter) event.receiver()
                                .getContainer().getAttribute("executionTime");

                        // Actor starts to execute
                        if (executionTime == null) {
                            executionTime = (Parameter) ((NamedObj) actor)
                                    .getAttribute("executionTime");
                        }

                        if (executionTime != null) {
                            processingTime = ((DoubleToken) executionTime
                                    .getToken()).doubleValue();
                        }
                    }

                    if (processingTime == 0.0) {
                        if (_debugging) {
                            _debug(getName(), event.toString(),
                                    " has processing time 0, so processed.");
                        }

                        // This event  can be processed immediately.
                        _eventQueue.take();

                        actor.fire();

                        // Actor stops executing, i.e. finishing
                        _displaySchedule(((Nameable) actor).getName(),
                                getModelTime().getDoubleValue(),
                                ScheduleListener.TASK_SLEEPING);
                        _displaySchedule();

                        if (!actor.postfire()) {
                            _disableActor(actor);
                        }
                    } else {
                        // Really start a task with non-zero processing
                        // time.
                        event.setProcessingTime(processingTime);

                        if (_debugging) {
                            _debug("Set processing time ", event.toString());
                        }

                        // Start a new task.
                        // Now the behavior depend on whether the
                        // execution is preemptive.
                        _preemptive = ((BooleanToken) preemptive.getToken())
                                .booleanValue();

                        if (!_preemptive) {
                            event = (TMEvent) _eventQueue.take();
                            event.startProcessing();

                            // Set it priority to 0 so it won't
                            // be preempted.
                            event.setPriority(0);
                            _eventQueue.put(event);
                        } else {
                            event.startProcessing();
                        }

                        if (_debugging) {
                            _debug("Start processing ", event.toString());
                        }

                        _displaySchedule();

                        // Start one real time task a time.
                        break;
                    }
                }
            } else {
                break;
            }
        }

        // The event may be null, when the prefire() of the actor
        // returns false for the last event in the queue.
        // The event may have processing time < 0, in which case
        // it is an event at the output boundary.
        if ((event != null) && (event.processingTime() > 0)) {
            // Check the finish processing time.
            Time finishTime = getModelTime().add(event.processingTime());

            if (_debugging) {
                _debug("finishing time = " + finishTime);
            }

            if (finishTime.compareTo(_nextIterationTime) < 0) {
                _nextIterationTime = finishTime;
            }
        }

        if (_isEmbedded()
View Full Code Here

TOP

Related Classes of ptolemy.actor.util.Time

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.