Class SmallWorldRouter
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.InstantiableNamedObj
-
- ptolemy.kernel.Entity<T>
-
- ptolemy.kernel.ComponentEntity<T>
-
- ptolemy.actor.AtomicActor<TypedIOPort>
-
- ptolemy.actor.TypedAtomicActor
-
- ptolemy.domains.wireless.demo.SmallWorld.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)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.LinkedList
_connectedNodes
A list of entities that can receive message from this actor.protected Variable
_distance
A variable that is set to the distance between the transmitter and the receiver before the lossProbability expression is evaluated.protected java.util.Random
_random
A random number generator.Parameter
delay
The time required for relaying a message.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.WirelessIOPort
input
The input port for messages to route.StringParameter
inputChannelName
Name of the input channel.Parameter
lossProbability
The probability that a connection between two node will fail to happen.WirelessIOPort
output
The output port that send a message to connected nodes.StringParameter
outputChannelName
Name of the output channel.Parameter
seed
The seed that controls the random number generation.Parameter
sureRange
The for sure connected range between two nodes.WirelessIOPort
test
This port is for analysis uses.StringParameter
testChannelName
Name of the test channel.-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
-
-
Constructor Summary
Constructors Constructor Description SmallWorldRouter(CompositeEntity container, java.lang.String name)
Construct a channel with the given name and container.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected double
_distanceBetween(Locatable location1, Locatable location2)
Return the distance between two location.void
declareDelayDependency()
Override the base class to declare that the output does not depend on the input in a firing.void
fire()
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.void
initialize()
Initialize the random number generator with the seed, if it has been given.protected java.util.List
nodesInRange(WirelessIOPort sourcePort)
Return the list of nodes that can receive from the specified port.-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup
-
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
-
Methods inherited from class ptolemy.kernel.Entity
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
-
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeChanged, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
-
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable, wrapup
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
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
-
declareDelayDependency
public void declareDelayDependency() throws IllegalActionException
Override the base class to declare that the output does not depend on the input in a firing.- Overrides:
declareDelayDependency
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If the causality interface cannot be computed.- See Also:
AtomicActor.getCausalityInterface()
,AtomicActor._declareDelayDependency(IOPort, IOPort, double)
-
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 interfaceExecutable
- Overrides:
fire
in classAtomicActor<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 interfaceInitializable
- Overrides:
initialize
in classAtomicActor<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.
-
-