Class Average

  • All Implemented Interfaces:
    java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class Average
    extends Transformer

    Output the average of the inputs after the last time a true token is received at the reset port. One output is produced each time the actor is fired. The inputs and outputs can be any token type that supports addition and division by an integer. The output type is constrained to be the same as the input type. Note that if the input is an integer, then the output is an integer, which may not be what you want. You may need to set the input and output ports to double to force the result to be a double.

    Note that the type system will fail to catch some errors. Static type checking may result in a resolved type that does not support addition and division. In this case, a run-time error will occur.

    Since:
    Ptolemy II 0.3
    Version:
    $Id$
    Author:
    Edward A. Lee, Jie Liu
    Pt.AcceptedRating:
    Green (bilung)
    Pt.ProposedRating:
    Green (eal)
    • Field Detail

      • reset

        public TypedIOPort reset
        The reset port of type BooleanToken. If this input port receives a True token, then the averaging process will be reset.
    • Method Detail

      • fire

        public void fire()
                  throws IllegalActionException
        Consume at most one token from the input and compute the average of the input tokens so far. Send the result to the output. If there is no input token available, no output will be produced. If there is a true-valued token on the reset input, then the average is reset, and the output will be equal to the input token (if there is one). If the fire method is invoked multiple times in one iteration, then only the input read on the last invocation in the iteration will affect future averages. Inputs that are read earlier in the iteration are forgotten.
        Specified by:
        fire in interface Executable
        Overrides:
        fire in class AtomicActor<TypedIOPort>
        Throws:
        IllegalActionException - If addition or division by an integer are not supported by the supplied tokens.