org.jscience.architecture.traffic.infrastructure
Class Node

java.lang.Object
  extended by org.jscience.architecture.traffic.infrastructure.Node
All Implemented Interfaces:
Selectable, SelectionStarter, InstantiationAssistant, TwoStageLoader, XMLSerializable
Direct Known Subclasses:
Junction, SpecialNode

public abstract class Node
extends java.lang.Object
implements Selectable, XMLSerializable, TwoStageLoader, InstantiationAssistant

Basic node


Nested Class Summary
 class Node.NodeStatistics
          Basic node statistics.
 
Field Summary
static int C_DOWN
          DOCUMENT ME!
static int C_LEFT
          DOCUMENT ME!
static int C_RIGHT
          DOCUMENT ME!
static int C_UP
          DOCUMENT ME!
protected  java.awt.Point coord
          The coordinates of this node in pixels
static int D_AHEAD
          DOCUMENT ME!
static int D_BACK
          DOCUMENT ME!
static int D_LEFT
          DOCUMENT ME!
static int D_RIGHT
          DOCUMENT ME!
static int EDGE
          Constant for Node type EdgeNode.
protected  Drivelane[] inboundLanes
          Caches for inbound and outbound lanes
static int JUNCTION
          Constant for Node type Junction (normal Node with traffic lights).
static int NET_TUNNEL
          Constant for Node type NetTunnel.
protected  int nodeId
          The Id of this node
static int NON_TL
          Constant for Node type NoTLJunction (Node without traffic lights).
protected  Drivelane[] outboundLanes
          Caches for inbound and outbound lanes
protected  java.lang.String parentName
          DOCUMENT ME!
protected  SPData spdata
          Shortest path data
static int STAT_NUM_DATA
          The number of roadusers delay tables are maintained of.
protected  Node.NodeStatistics[] statistics
          All statistics of this Node.
 
Constructor Summary
protected Node()
          Creates a new Node object.
protected Node(java.awt.Point c)
          Creates a new Node object.
 
Method Summary
abstract  void addRoad(Road r, int pos)
          Adds a road at a connection-position.
 void addShortestPath(Drivelane lane, int nodeId, int ruType, int length)
          Adds shortest path for an exitnode
 boolean areAllTailsFree()
          Returns whether or not all the Tails of all the outbound lanes of this Node are free or not
protected abstract  int calcDelay(Roaduser ru, int cycle, int distance)
          Calculates the delay that has to be logged for this Node.
 boolean canCreateInstance(java.lang.Class request)
          DOCUMENT ME!
 java.lang.Object createInstance(java.lang.Class request)
          DOCUMENT ME!
abstract  Drivelane[] getAllLanes()
          Returns an array of all lanes on this node
abstract  Road[] getAllRoads()
          Returns all roads connected to this node.
abstract  Road[] getAlphaRoads()
          Returns the alpha roads connected to this node
 java.awt.Rectangle getBounds()
          Returns the bounding box of this Selectable
 java.awt.Point getCenterPoint()
          DOCUMENT ME!
 java.util.Enumeration getChildren()
          DOCUMENT ME!
 java.awt.Shape getComplexBounds()
          DOCUMENT ME!
 java.awt.Point getCoord()
          Returns the view coordinates of this node
abstract  int getDesiredSignType()
          Returns the desired type of signs to add to inbound lanes on this node.
static int getDirection(int src, int dest)
          Calculates the direction from one road to another.
 int getDistance(java.awt.Point p)
          DOCUMENT ME!
 int getId()
          Returns the Id of this node
abstract  Drivelane[] getInboundLanes()
          Returns an array of all inbound lanes on this node
abstract  Drivelane[] getLanesLeadingFrom(Drivelane lane, int ruType)
          Returns an array of all outbound lanes supporting roadusers of given type that can be reached from the given inbound lane.
abstract  Drivelane[] getLanesLeadingTo(Drivelane lane, int ruType)
          Returns an array of all inbound lanes supporting roadusers of given type that lead to the given outbound lane.
abstract  java.lang.String getName()
          Returns the name of this node.
abstract  int getNumAllLanes()
          Returns the total number of lanes on this node
abstract  int getNumAlphaRoads()
          Returns the number of alpha roads of this node
abstract  int getNumInboundLanes()
          Returns the number of inbound lanes on this node
abstract  int getNumOutboundLanes()
          Returns the number of outbound lanes on this node
abstract  int getNumRealSigns()
          Returns the number of signs with a type !
abstract  int getNumRoads()
          Returns the number of roads connected to this node
abstract  int getNumSigns()
          Returns the total number of signs on this node
 int getNumSkip(int direction, int laneNumber)
          Calculates the number of positions a roaduser can skip in the tail of its destination lane
abstract  Drivelane[] getOutboundLanes()
          Returns an array of all outbound lanes on this node
 java.awt.Point getSelectionPoint()
          DOCUMENT ME!
 java.awt.Point[] getSelectionPoints()
          DOCUMENT ME!
 int[] getShortestPathDestinations(int ruType)
          Returns all the exitnode ids this Node has shortestpath data to
 Drivelane[] getShortestPaths(int nodeID, int ruType)
          Returns shortest paths for exitnode and Roaduser type
 Node.NodeStatistics[] getStatistics()
          Returns the statistics for all types of roadusers.
 Node.NodeStatistics getStatistics(int ruType)
          Returns the statistics for the given roaduser type.
abstract  int getType()
          Returns the type of this node
abstract  int getWidth()
          Returns the width of this node in number of lanes
 boolean hasChildren()
          DOCUMENT ME!
 void initStats()
          Initializes the statistics for this node.
abstract  boolean isAlphaRoad(Road r)
          Checks if the given road is an alpha road of this node.
abstract  boolean isConnected(Road r)
          Checks if the given road is connected to this node.
abstract  int isConnectedAt(Road r)
          Finds the connection-position of a given road.
abstract  boolean isConnectionPosFree(int pos)
          Checks if a road is connected at the given connection-position
 boolean isSelectable()
          DOCUMENT ME!
 void load(XMLElement myElement, XMLLoader loader)
          Load this XMLSerializable
 void loadSecondStage(java.util.Dictionary dictionaries)
          DOCUMENT ME!
abstract  void paint(java.awt.Graphics g)
          DOCUMENT ME!
abstract  void paint(java.awt.Graphics g, int offx, int offy, float zf)
          DOCUMENT ME!
 void processStats(Roaduser ru, int cycle, Sign sign)
          Processes the statistics of a Roaduser crossing/arriving at this node.
abstract  void remAllRoads()
          Removes all roads from this node.
 void remPaths(int nodeId, int ruType, int length)
          Removes all lanes on the path towards nodeId with length larger than length
abstract  void remRoad(int pos)
          Removes the road at the given position from this node.
abstract  void remRoad(Road r)
          Removes a road from this node.
 void reset()
          Resets the data of this node.
 void resetStats()
          Resets the statistics for this node.
 void saveChilds(XMLSaver saver)
          DOCUMENT ME!
 XMLElement saveSelf()
          DOCUMENT ME!
abstract  void setAlphaRoad(int pos)
          Sets a road to be an alpha road
 void setCoord(java.awt.Point p)
          Sets the view coordinates of this node
 void setId(int id)
          Sets the Id of this node
 void setParentName(java.lang.String parentName)
          DOCUMENT ME!
 void setShortestPath(Drivelane lane, int nodeId, int ruType, int length)
          Sets the shortest path for an exitnode
abstract  void setSigns(Sign[] s)
          Sets the list of signs on this node
protected  void updateLanes()
          Update inboundLanes,outboundLanes and outboundQueues
 void zapShortestPaths()
          Removes all SPData, creating a new instance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jscience.architecture.traffic.xml.XMLSerializable
getXMLName
 

Field Detail

STAT_NUM_DATA

public static int STAT_NUM_DATA
The number of roadusers delay tables are maintained of.


EDGE

public static final int EDGE
Constant for Node type EdgeNode.

See Also:
Constant Field Values

JUNCTION

public static final int JUNCTION
Constant for Node type Junction (normal Node with traffic lights).

See Also:
Constant Field Values

NON_TL

public static final int NON_TL
Constant for Node type NoTLJunction (Node without traffic lights).

See Also:
Constant Field Values

NET_TUNNEL

public static final int NET_TUNNEL
Constant for Node type NetTunnel.

See Also:
Constant Field Values

C_UP

public static final int C_UP
DOCUMENT ME!

See Also:
Constant Field Values

C_RIGHT

public static final int C_RIGHT
DOCUMENT ME!

See Also:
Constant Field Values

C_DOWN

public static final int C_DOWN
DOCUMENT ME!

See Also:
Constant Field Values

C_LEFT

public static final int C_LEFT
DOCUMENT ME!

See Also:
Constant Field Values

D_BACK

public static final int D_BACK
DOCUMENT ME!

See Also:
Constant Field Values

D_RIGHT

public static final int D_RIGHT
DOCUMENT ME!

See Also:
Constant Field Values

D_AHEAD

public static final int D_AHEAD
DOCUMENT ME!

See Also:
Constant Field Values

D_LEFT

public static final int D_LEFT
DOCUMENT ME!

See Also:
Constant Field Values

nodeId

protected int nodeId
The Id of this node


spdata

protected SPData spdata
Shortest path data


coord

protected java.awt.Point coord
The coordinates of this node in pixels


statistics

protected Node.NodeStatistics[] statistics
All statistics of this Node.


inboundLanes

protected Drivelane[] inboundLanes
Caches for inbound and outbound lanes


outboundLanes

protected Drivelane[] outboundLanes
Caches for inbound and outbound lanes


parentName

protected java.lang.String parentName
DOCUMENT ME!

Constructor Detail

Node

protected Node(java.awt.Point c)
Creates a new Node object.

Parameters:
c - DOCUMENT ME!

Node

protected Node()
Creates a new Node object.

Method Detail

getId

public int getId()
Returns the Id of this node

Returns:
DOCUMENT ME!

setId

public void setId(int id)
Sets the Id of this node

Parameters:
id - DOCUMENT ME!

getCoord

public java.awt.Point getCoord()
Returns the view coordinates of this node

Returns:
DOCUMENT ME!

setCoord

public void setCoord(java.awt.Point p)
Sets the view coordinates of this node

Parameters:
p - DOCUMENT ME!

getStatistics

public Node.NodeStatistics[] getStatistics()
Returns the statistics for all types of roadusers.

Returns:
DOCUMENT ME!

getStatistics

public Node.NodeStatistics getStatistics(int ruType)
Returns the statistics for the given roaduser type.

Parameters:
ruType - The roaduser type to return statistics of. (0 if all roadusers)
Returns:
DOCUMENT ME!

getDirection

public static int getDirection(int src,
                               int dest)
Calculates the direction from one road to another.

Parameters:
src - The position of the source road (expressed in a C_ constant, see above)
dest - The position of the destination road (expressed in a C_ constant, see above)
Returns:
The Direction from src to dest (expressed in D_ constants, see above in Object variables of Node)

getNumSkip

public int getNumSkip(int direction,
                      int laneNumber)
               throws InfraException
Calculates the number of positions a roaduser can skip in the tail of its destination lane

Parameters:
direction - The direction in which the roaduser is going
laneNumber - The position in the road of the lane from which the roaduser is coming. (0=rightmost lane)
Returns:
DOCUMENT ME!
Throws:
InfraException - DOCUMENT ME!

initStats

public void initStats()
Initializes the statistics for this node.


resetStats

public void resetStats()
Resets the statistics for this node.


processStats

public void processStats(Roaduser ru,
                         int cycle,
                         Sign sign)
Processes the statistics of a Roaduser crossing/arriving at this node.

Parameters:
ru - The Roaduser to process.
cycle - The current cycle.
sign - The Sign the Roaduser is currently passing by.

calcDelay

protected abstract int calcDelay(Roaduser ru,
                                 int cycle,
                                 int distance)
Calculates the delay that has to be logged for this Node.

Parameters:
ru - DOCUMENT ME!
cycle - DOCUMENT ME!
distance - DOCUMENT ME!
Returns:
DOCUMENT ME!

load

public void load(XMLElement myElement,
                 XMLLoader loader)
          throws XMLTreeException,
                 java.io.IOException,
                 XMLInvalidInputException
Description copied from interface: XMLSerializable
Load this XMLSerializable

Specified by:
load in interface XMLSerializable
Parameters:
myElement - The XMLElement which represents this object in the XML tree. It can contain attributes which hold information about the object.
loader - The XMLLoader which this XMLSerializable can use to load child objects.
Throws:
XMLTreeException - The parser can throw this exception if it is called by the XMLSerializable. The XMLSerializable should NOT throw this exception by itself and preferrably not catch it too.
java.io.IOException - Thrown in case of an read error in the XML file.
XMLInvalidInputException - The XMLSerializable can throw this exception if it cannot load itself or one of its child objects for whatever reason.

saveSelf

public XMLElement saveSelf()
                    throws XMLCannotSaveException
DOCUMENT ME!

Specified by:
saveSelf in interface XMLSerializable
Returns:
DOCUMENT ME!
Throws:
XMLCannotSaveException - DOCUMENT ME!

saveChilds

public void saveChilds(XMLSaver saver)
                throws XMLTreeException,
                       java.io.IOException,
                       XMLCannotSaveException
DOCUMENT ME!

Specified by:
saveChilds in interface XMLSerializable
Parameters:
saver - DOCUMENT ME!
Throws:
XMLTreeException - DOCUMENT ME!
java.io.IOException - DOCUMENT ME!
XMLCannotSaveException - DOCUMENT ME!

loadSecondStage

public void loadSecondStage(java.util.Dictionary dictionaries)
                     throws XMLInvalidInputException,
                            XMLTreeException
DOCUMENT ME!

Specified by:
loadSecondStage in interface TwoStageLoader
Parameters:
dictionaries - DOCUMENT ME!
Throws:
XMLInvalidInputException - DOCUMENT ME!
XMLTreeException - DOCUMENT ME!

setParentName

public void setParentName(java.lang.String parentName)
DOCUMENT ME!

Specified by:
setParentName in interface XMLSerializable
Parameters:
parentName - DOCUMENT ME!

canCreateInstance

public boolean canCreateInstance(java.lang.Class request)
DOCUMENT ME!

Specified by:
canCreateInstance in interface InstantiationAssistant
Parameters:
request - DOCUMENT ME!
Returns:
DOCUMENT ME!

createInstance

public java.lang.Object createInstance(java.lang.Class request)
                                throws java.lang.ClassNotFoundException,
                                       java.lang.InstantiationException,
                                       java.lang.IllegalAccessException
DOCUMENT ME!

Specified by:
createInstance in interface InstantiationAssistant
Parameters:
request - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.ClassNotFoundException - DOCUMENT ME!
java.lang.InstantiationException - DOCUMENT ME!
java.lang.IllegalAccessException - DOCUMENT ME!

getBounds

public java.awt.Rectangle getBounds()
Description copied from interface: Selectable
Returns the bounding box of this Selectable

Specified by:
getBounds in interface Selectable
Returns:
DOCUMENT ME!

getComplexBounds

public java.awt.Shape getComplexBounds()
DOCUMENT ME!

Specified by:
getComplexBounds in interface Selectable
Returns:
DOCUMENT ME!

getSelectionPoint

public java.awt.Point getSelectionPoint()
DOCUMENT ME!

Specified by:
getSelectionPoint in interface Selectable
Returns:
DOCUMENT ME!

getSelectionPoints

public java.awt.Point[] getSelectionPoints()
DOCUMENT ME!

Specified by:
getSelectionPoints in interface Selectable
Returns:
DOCUMENT ME!

getCenterPoint

public java.awt.Point getCenterPoint()
DOCUMENT ME!

Specified by:
getCenterPoint in interface Selectable
Returns:
DOCUMENT ME!

getDistance

public int getDistance(java.awt.Point p)
DOCUMENT ME!

Specified by:
getDistance in interface Selectable
Parameters:
p - DOCUMENT ME!
Returns:
DOCUMENT ME!

hasChildren

public boolean hasChildren()
DOCUMENT ME!

Specified by:
hasChildren in interface SelectionStarter
Returns:
DOCUMENT ME!

isSelectable

public boolean isSelectable()
DOCUMENT ME!

Specified by:
isSelectable in interface Selectable
Returns:
DOCUMENT ME!

getChildren

public java.util.Enumeration getChildren()
DOCUMENT ME!

Specified by:
getChildren in interface SelectionStarter
Returns:
DOCUMENT ME!

paint

public abstract void paint(java.awt.Graphics g)
                    throws TrafficException
DOCUMENT ME!

Parameters:
g - DOCUMENT ME!
Throws:
TrafficException - DOCUMENT ME!

paint

public abstract void paint(java.awt.Graphics g,
                           int offx,
                           int offy,
                           float zf)
                    throws TrafficException
DOCUMENT ME!

Parameters:
g - DOCUMENT ME!
offx - DOCUMENT ME!
offy - DOCUMENT ME!
zf - DOCUMENT ME!
Throws:
TrafficException - DOCUMENT ME!

getType

public abstract int getType()
Returns the type of this node

Returns:
DOCUMENT ME!

getName

public abstract java.lang.String getName()
Returns the name of this node. The name of a node is unique in an infrastructure.

Returns:
DOCUMENT ME!

getAllRoads

public abstract Road[] getAllRoads()
Returns all roads connected to this node. This may contain null pointers

Returns:
DOCUMENT ME!

getAlphaRoads

public abstract Road[] getAlphaRoads()
Returns the alpha roads connected to this node

Returns:
DOCUMENT ME!

getWidth

public abstract int getWidth()
Returns the width of this node in number of lanes

Returns:
DOCUMENT ME!

reset

public void reset()
Resets the data of this node. This also resets all AlphaRoads.

See Also:
Road.reset()

addRoad

public abstract void addRoad(Road r,
                             int pos)
                      throws InfraException
Adds a road at a connection-position.

Parameters:
r - The road to add
pos - The connection-position to connect this road at
Throws:
InfraException - if a road is already connected at the given position

setAlphaRoad

public abstract void setAlphaRoad(int pos)
                           throws InfraException
Sets a road to be an alpha road

Parameters:
pos - The connection-position the road is connected at
Throws:
InfraException - if no road is connected at the given position

remRoad

public abstract void remRoad(int pos)
                      throws InfraException
Removes the road at the given position from this node.

Parameters:
pos - The connection-position of the road to remove
Throws:
InfraException - if no road is connected at the given position

remRoad

public abstract void remRoad(Road r)
                      throws InfraException
Removes a road from this node.

Parameters:
r - The road to remove
Throws:
InfraException - if r is null

remAllRoads

public abstract void remAllRoads()
                          throws InfraException
Removes all roads from this node.

Throws:
InfraException - DOCUMENT ME!

setSigns

public abstract void setSigns(Sign[] s)
                       throws InfraException
Sets the list of signs on this node

Parameters:
s - The new signs
Throws:
InfraException - DOCUMENT ME!

getDesiredSignType

public abstract int getDesiredSignType()
                                throws InfraException
Returns the desired type of signs to add to inbound lanes on this node.

Returns:
DOCUMENT ME!
Throws:
InfraException - DOCUMENT ME!

isAlphaRoad

public abstract boolean isAlphaRoad(Road r)
                             throws InfraException
Checks if the given road is an alpha road of this node.

Parameters:
r - The road to check
Returns:
true if the given road is an alpha road
Throws:
InfraException - if r is null

isConnected

public abstract boolean isConnected(Road r)
                             throws InfraException
Checks if the given road is connected to this node.

Parameters:
r - The road to check
Returns:
true if the given road is conencted to this node
Throws:
InfraException - if r is null

isConnectedAt

public abstract int isConnectedAt(Road r)
                           throws InfraException
Finds the connection-position of a given road.

Parameters:
r - The road to find the connection-position of
Returns:
the connection-position of the given road
Throws:
InfraException - if r is null

isConnectionPosFree

public abstract boolean isConnectionPosFree(int pos)
                                     throws InfraException
Checks if a road is connected at the given connection-position

Parameters:
pos - The position to check
Returns:
true if no road is connected at the given position
Throws:
InfraException - if the given position is not a valid connection-position

getNumRoads

public abstract int getNumRoads()
Returns the number of roads connected to this node

Returns:
DOCUMENT ME!

getNumAlphaRoads

public abstract int getNumAlphaRoads()
Returns the number of alpha roads of this node

Returns:
DOCUMENT ME!

getNumInboundLanes

public abstract int getNumInboundLanes()
                                throws InfraException
Returns the number of inbound lanes on this node

Returns:
DOCUMENT ME!
Throws:
InfraException - DOCUMENT ME!

getNumOutboundLanes

public abstract int getNumOutboundLanes()
                                 throws InfraException
Returns the number of outbound lanes on this node

Returns:
DOCUMENT ME!
Throws:
InfraException - DOCUMENT ME!

getNumAllLanes

public abstract int getNumAllLanes()
Returns the total number of lanes on this node

Returns:
DOCUMENT ME!

getNumSigns

public abstract int getNumSigns()
Returns the total number of signs on this node

Returns:
DOCUMENT ME!

getNumRealSigns

public abstract int getNumRealSigns()
Returns the number of signs with a type != Sign.NO_SIGN

Returns:
DOCUMENT ME!

getLanesLeadingTo

public abstract Drivelane[] getLanesLeadingTo(Drivelane lane,
                                              int ruType)
                                       throws InfraException
Returns an array of all inbound lanes supporting roadusers of given type that lead to the given outbound lane.

Parameters:
lane - Outbound lane the lanes lead to
ruType - The type of roaduser the inbound lanes should support
Returns:
An array of inbound lanes
Throws:
InfraException - if the given lane is not an outbound lane on this node

getLanesLeadingFrom

public abstract Drivelane[] getLanesLeadingFrom(Drivelane lane,
                                                int ruType)
                                         throws InfraException
Returns an array of all outbound lanes supporting roadusers of given type that can be reached from the given inbound lane.

Parameters:
lane - Inbound lane
ruType - The type of roaduser the outbound lanes should support
Returns:
An array of outbound lanes
Throws:
InfraException - if the given lane is not an inbound lane on this node

getOutboundLanes

public abstract Drivelane[] getOutboundLanes()
                                      throws InfraException
Returns an array of all outbound lanes on this node

Returns:
DOCUMENT ME!
Throws:
InfraException - DOCUMENT ME!

getInboundLanes

public abstract Drivelane[] getInboundLanes()
                                     throws InfraException
Returns an array of all inbound lanes on this node

Returns:
DOCUMENT ME!
Throws:
InfraException - DOCUMENT ME!

getAllLanes

public abstract Drivelane[] getAllLanes()
                                 throws InfraException
Returns an array of all lanes on this node

Returns:
DOCUMENT ME!
Throws:
InfraException - DOCUMENT ME!

updateLanes

protected void updateLanes()
                    throws InfraException
Update inboundLanes,outboundLanes and outboundQueues

Throws:
InfraException - DOCUMENT ME!

areAllTailsFree

public boolean areAllTailsFree()
Returns whether or not all the Tails of all the outbound lanes of this Node are free or not

Returns:
DOCUMENT ME!

setShortestPath

public void setShortestPath(Drivelane lane,
                            int nodeId,
                            int ruType,
                            int length)
Sets the shortest path for an exitnode

Parameters:
lane - DOCUMENT ME!
nodeId - DOCUMENT ME!
ruType - DOCUMENT ME!
length - DOCUMENT ME!

addShortestPath

public void addShortestPath(Drivelane lane,
                            int nodeId,
                            int ruType,
                            int length)
Adds shortest path for an exitnode

Parameters:
lane - DOCUMENT ME!
nodeId - DOCUMENT ME!
ruType - DOCUMENT ME!
length - DOCUMENT ME!

getShortestPaths

public Drivelane[] getShortestPaths(int nodeID,
                                    int ruType)
Returns shortest paths for exitnode and Roaduser type

Parameters:
nodeID - DOCUMENT ME!
ruType - DOCUMENT ME!
Returns:
DOCUMENT ME!

getShortestPathDestinations

public int[] getShortestPathDestinations(int ruType)
Returns all the exitnode ids this Node has shortestpath data to

Parameters:
ruType - DOCUMENT ME!
Returns:
DOCUMENT ME!

remPaths

public void remPaths(int nodeId,
                     int ruType,
                     int length)
Removes all lanes on the path towards nodeId with length larger than length

Parameters:
nodeId - DOCUMENT ME!
ruType - DOCUMENT ME!
length - DOCUMENT ME!

zapShortestPaths

public void zapShortestPaths()
Removes all SPData, creating a new instance