Class OrderedMerge

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

    public class OrderedMerge
    extends TypedAtomicActor
    This actor merges two monotonically nondecreasing streams of tokens into one monotonically nondecreasing stream. On each firing, it reads data from one of the inputs. On the first firing, it simply records that token. On the second firing, it reads data from the other input and outputs the smaller of the recorded token and the one it just read. If they are equal, then it outputs the recorded token. It then records the larger token. On each subsequent firing, it reads a token from the input port that did not provide the recorded token, and produces at the output the smaller of the recorded token and the one just read. Each time it produces an output token, it also produces true on the selectedA output if the output token came from inputA, and false if it came from inputB.

    If both input sequences are nondecreasing, then the output sequence will be nondecreasing. Note that if the inputs are not nondecreasing, then the output is rather complex. The key is that in each firing, it produces the smaller of the recorded token and the token it is currently reading.

    Since:
    Ptolemy II 2.0.1
    Version:
    $Id$
    Author:
    Edward A. Lee
    Pt.AcceptedRating:
    Red (eal)
    Pt.ProposedRating:
    Red (eal)
    • Field Detail

      • eliminateDuplicates

        public Parameter eliminateDuplicates
        If true, eliminate duplicate tokens in the output stream. This is a boolean that defaults to false.
      • inputA

        public TypedIOPort inputA
        The first input port, which accepts any scalar token.
      • inputA_tokenConsumptionRate

        public Parameter inputA_tokenConsumptionRate
        The token consumption rate for inputA.
      • inputB

        public TypedIOPort inputB
        The second input port, which accepts any scalar token with the same type as the first input port.
      • inputB_tokenConsumptionRate

        public Parameter inputB_tokenConsumptionRate
        The token consumption rate for inputB.
      • output

        public TypedIOPort output
        The output port, which has the same type as the input ports.
      • selectedA

        public TypedIOPort selectedA
        Output port indicating whether the output token came from inputA.
    • Method Detail

      • fire

        public void fire()
                  throws IllegalActionException
        Read one token from the port that did not provide the recorded token (or inputA, on the first firing), and output the smaller of the recorded token or the newly read token. If there is no token on the port to be read, then do nothing and return. If an output token is produced, then also produce true on the selectedA output if the output token came from inputA, and false if it came from inputB.
        Specified by:
        fire in interface Executable
        Overrides:
        fire in class AtomicActor<TypedIOPort>
        Throws:
        IllegalActionException - If there is no director.
      • _getNextPort

        protected TypedIOPort _getNextPort()
        Return the port that this actor will read from on the next invocation of the fire() method. This will be null before the first invocation of initialize().
        Returns:
        The next input port.
      • _defaultTypeConstraints

        protected java.util.Set<Inequality> _defaultTypeConstraints()
        The output must be greater than or equal to each of both inputs. Since inputA is set to be the same as inputB, the output is simply set to be greater than or equal to inputA.
        Overrides:
        _defaultTypeConstraints in class TypedAtomicActor
        Returns:
        A set of type constraints