Class RoadNetwork

java.lang.Object
  |
  +--RoadNetwork

public class RoadNetwork
extends java.lang.Object

The RoadNetwork class creates and stores all the road network infrastructure classes such as roads and junctions and how they inter-relate.


Field Summary
protected  CarGenerator carGenerator
           
protected  int currentIndex
           
protected  JunctionModel[] junctions
           
protected  LaneModel[] lanes
           
static int MAPEDGE
           
protected  RoadDesigner roadDesigner
           
protected  int totalJunctionNumber
           
protected  int totalLaneNumber
           
 
Constructor Summary
RoadNetwork(RoadDesigner roadDesigner, int speed)
          The RoadNetwork constructor pulls information from the Road-Editor and converts into a form the simulation can use.
 
Method Summary
 void addTimerToElements(TimeManager theTicker)
          Adds timed elements to the global clock.
 void drawNetworkComponents(java.awt.Graphics2D g2d)
          Draws all the cars known to the road network.
 void generateAdaptivePath()
          Tries to discover the longest path of junctions back to back.
 java.awt.Shape getAdaptivePath()
          Tries to syncronize the junctions on a junction path found earlier.
 int getAverageSpeed()
          Gets the speed of all the cars in the roadnetwork and calculates an average value to display on screen.
 Car getCar(java.awt.geom.Point2D p)
          Gets the car under the mouse click.
 int getInputQ(int x, int y)
           
 JunctionModel getJunction(int iD)
           
 java.lang.String getJunctionVars(java.awt.geom.Point2D p)
          Gives information to the user about whatever they clicked on.
 LaneModel getLane(int i)
           
 int getNumberInputs()
           
 int getTotalRoadLength()
           
 void kill()
          Removes all the cars from the network.
 void randomizeAdaptivePath()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAPEDGE

public static final int MAPEDGE

lanes

protected LaneModel[] lanes

junctions

protected JunctionModel[] junctions

currentIndex

protected int currentIndex

totalLaneNumber

protected int totalLaneNumber

totalJunctionNumber

protected int totalJunctionNumber

roadDesigner

protected RoadDesigner roadDesigner

carGenerator

protected CarGenerator carGenerator
Constructor Detail

RoadNetwork

public RoadNetwork(RoadDesigner roadDesigner,
                   int speed)
The RoadNetwork constructor pulls information from the Road-Editor and converts into a form the simulation can use. The editor uses vectors because the user can shrink and grow elements. The sim uses arrays has elements are fixed and arrays are faster.

Parameters:
roadDesigner - The road editor
speed - The speed of the cars in the simulation
Method Detail

getNumberInputs

public int getNumberInputs()
Returns:
Number of lane inputs to the road network.

getLane

public LaneModel getLane(int i)
Parameters:
i - A lane index
Returns:
A laneModel

getJunction

public JunctionModel getJunction(int iD)
Parameters:
iD - A junction ID
Returns:
a JunctionModel

drawNetworkComponents

public void drawNetworkComponents(java.awt.Graphics2D g2d)
Draws all the cars known to the road network.

Parameters:
g2d - a Graphics2D value

kill

public void kill()
Removes all the cars from the network.


addTimerToElements

public void addTimerToElements(TimeManager theTicker)
Adds timed elements to the global clock.

Parameters:
theTicker - a TimeManager

getTotalRoadLength

public int getTotalRoadLength()

generateAdaptivePath

public void generateAdaptivePath()
Tries to discover the longest path of junctions back to back. 1) For each signalled junction: 2) try to find a neighbour. 3) extend to another neightbour 4) Save the longest path found.


getAdaptivePath

public java.awt.Shape getAdaptivePath()
Tries to syncronize the junctions on a junction path found earlier.

Returns:
a Shape representing the path of junctions trying to synronize

randomizeAdaptivePath

public void randomizeAdaptivePath()

getInputQ

public int getInputQ(int x,
                     int y)
Parameters:
x - an int value
y - an int value
Returns:
an int representing cars queueing at the input near where the user clicked.

getJunctionVars

public java.lang.String getJunctionVars(java.awt.geom.Point2D p)
Gives information to the user about whatever they clicked on.

Parameters:
p - a Point2D value
Returns:
a String value

getAverageSpeed

public int getAverageSpeed()
Gets the speed of all the cars in the roadnetwork and calculates an average value to display on screen.

Returns:
an int value

getCar

public Car getCar(java.awt.geom.Point2D p)
Gets the car under the mouse click.

Parameters:
p - a Point2D value
Returns:
a Car value