Class SmallWorldRouter

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

    public class SmallWorldRouter
    extends TypedAtomicActor
    This actor implements a routing algorithm to route a message to the destination via a short path based only on local information. It assumes that it knows which nodes are in range and the location of that node. It also assumes that the location of the destination is known. Based on this information, it finds the node that is closest to the destination from its connected node set.

    We assume that the actor are connected to nodes inside a particular range, specified by the sureRange parameter, for sure. Outside this range, it may connected to a node with probability propotional to the r-th inverse power of the distance between them. Whether it is connected to a particular node is independent of whether it is connected to any other node.

    For convenience, a variable named "distance" is available and equal to the distance between this actor and other actors. The loss probability can be given as an expression that depends on this distance.

    The distance between the transmitter and receiver is determined by the protected method _distanceBetween(), which is also used to set the value of the distance variable that can be used in the expression for loss probability.

    Since:
    Ptolemy II 4.0
    Version:
    $Id$
    Author:
    Yang Zhao
    Pt.AcceptedRating:
    Red (pjb2e)
    Pt.ProposedRating:
    Yellow (eal)
    • Field Detail

      • input

        public WirelessIOPort input
        The input port for messages to route. It requires the received token to be a record token has type: {data=double, destination=String, routeTo=String, hops=int}.
      • inputChannelName

        public StringParameter inputChannelName
        Name of the input channel. This is a string that defaults to "InputChannel".
      • output

        public WirelessIOPort output
        The output port that send a message to connected nodes. This has type: {data=double, destination=String, routeTo=String, hops=int}.
      • test

        public WirelessIOPort test
        This port is for analysis uses. When the destination node receives the message, it outputs an int token to indicate how many hops from the source.
      • outputChannelName

        public StringParameter outputChannelName
        Name of the output channel. This is a string that defaults to "OutputChannel".
      • testChannelName

        public StringParameter testChannelName
        Name of the test channel. This is a string that defaults to "testChannel".
      • lossProbability

        public Parameter lossProbability
        The probability that a connection between two node will fail to happen. This is a double that defaults to 0.0, which means that no loss occurs. FIXME: get a better name for it.
      • sureRange

        public Parameter sureRange
        The for sure connected range between two nodes. This is a double that defaults to 100.0. The icon for this sensor node includes a circle with this as its radius.
      • delay

        public Parameter delay
        The time required for relaying a message. This is a double that defaults to 1.0.
      • seed

        public Parameter seed
        The seed that controls the random number generation. A seed of zero is interpreted to mean that no seed is specified, which means that each execution of the model could result in distinct data. For the value 0, the seed is set to System.currentTimeMillis() + hashCode(), which means that with extremely high probability, two distinct actors will have distinct seeds. However, current time may not have enough resolution to ensure that two subsequent executions of the same model have distinct seeds. This parameter contains a LongToken, initially with value 0.
      • doublePath

        public Parameter doublePath
        If true, then this actor will also route the message to the node that is the second closest to the destination among all its connected nodes. FIXME: This is still under experiment. The issue I try to address is that some links may fail and long links may fail with higher probability. If so, routing a message to two paths may improve the hit probability. However, this will also cost more energy and also lower the capacity of the network. There is a tradeoff. A simple idea is to use a threshold to control the exponentially increased branches. For example, with a threshold equals 2, it only route to two pathes for the first hop.
      • _distance

        protected Variable _distance
        A variable that is set to the distance between the transmitter and the receiver before the lossProbability expression is evaluated.
      • _random

        protected java.util.Random _random
        A random number generator.
      • _connectedNodes

        protected java.util.LinkedList _connectedNodes
        A list of entities that can receive message from this actor.
    • Constructor Detail

      • SmallWorldRouter

        public SmallWorldRouter​(CompositeEntity container,
                                java.lang.String name)
                         throws IllegalActionException,
                                NameDuplicationException
        Construct a channel with the given name and container. The container argument must not be null, or a NullPointerException will be thrown. If the name argument is null, then the name is set to the empty string.
        Parameters:
        container - The container.
        name - The name of the channel.
        Throws:
        IllegalActionException - If the container is incompatible.
        NameDuplicationException - If the name coincides with a relation already in the container.
    • Method Detail

      • fire

        public void fire()
                  throws IllegalActionException
        Check whether it is the destination of the massage, if so, change the color of the icon to red and schedule another firing after 1.0 time unit to change it back to white. If not, check whether it is on the short path (hops ==0 means it detected a signal and would initiate a message). If yes, change its icon to green, calculate the distance between a node connected to it and the destination node, choose the one closest the the destination to be the next node on the short path, and schedule another firing after some delay time to output the message and change its icon back to white.
        Specified by:
        fire in interface Executable
        Overrides:
        fire in class AtomicActor<TypedIOPort>
        Throws:
        IllegalActionException - Not thrown in this base class.
      • initialize

        public void initialize()
                        throws IllegalActionException
        Initialize the random number generator with the seed, if it has been given. A seed of zero is interpreted to mean that no seed is specified. In such cases, a seed based on the current time and this instance of a RandomSource is used to be fairly sure that two identical sequences will not be returned. Decide all the nodes that are connected to it.
        Specified by:
        initialize in interface Initializable
        Overrides:
        initialize in class AtomicActor<TypedIOPort>
        Throws:
        IllegalActionException - If the parent class throws it.
      • _distanceBetween

        protected double _distanceBetween​(Locatable location1,
                                          Locatable location2)
                                   throws IllegalActionException
        Return the distance between two location. This is a convenience method provided to make it easier to calculate the distance between two locations.
        Parameters:
        location1 - The first location.
        location2 - The second location.
        Returns:
        The distance between the two locations.
        Throws:
        IllegalActionException - If the distance cannot be determined.
      • nodesInRange

        protected java.util.List nodesInRange​(WirelessIOPort sourcePort)
                                       throws IllegalActionException
        Return the list of nodes that can receive from the specified port.
        Parameters:
        sourcePort - The sending port.
        Returns:
        A list of instances of Entity.
        Throws:
        IllegalActionException - If a location of a port cannot be evaluated.