vanetsim.map
Class Junction

java.lang.Object
  extended by vanetsim.map.Junction

public final class Junction
extends java.lang.Object

A junction which always belongs to one specific node. If vehicles move from one priority street to another, they don't have to wait. Otherwise one vehicle can pass this junction every JUNCTION_PASS_INTERVAL. Vehicles coming from priority streets are preferred to pass this junction.

To store the rules, one-dimensional arrays are used as they are very efficient here. Originally, a double-dimensional IdentityHashMap was used but they need more RAM and are in most cases slower as there are only relatively few junction rules and linear searching through the arrays is faster than the IdentityHashMap-overhead with autoboxing, function calls and so on.


Field Summary
 int vehicleAllowedSetTime_
          When (in simulation time) the vehicleAllowedThisStep-variable was last set.
 Vehicle vehicleAllowedThisStep_
          The vehicle which is allowed to pass the junction in this step.
 
Constructor Summary
Junction(Node node, Street[] priorityStreets)
          Constructor
 
Method Summary
 void addJunctionRule(Node startNode, Node targetNode, int priority)
          Adds a junction rule.
 void addWaitingVehicle(Vehicle vehicle, int priority)
          Adds a waiting vehicle to the junction.
 void allowOtherVehicle()
          Allows another vehicle to pass the junction by setting vehicleOnJunction_ to false.
 boolean canPassJunction(Vehicle vehicle, int priority, Node nextNode)
          Returns if a vehicle may pass.
 boolean canPassTrafficLight(Vehicle vehicle, Street tmpStreet, Node nextNode)
          Returns if a vehicle may pass a Traffic Light.
 void delTrafficLight()
          Deletes the traffic light on this junction an resets the street values
 int getJunctionPriority(Node startNode, Node targetNode)
          Gets the priority for going over this node.
 Node getNode()
           
 Street[] getPriorityStreets()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

vehicleAllowedThisStep_

public Vehicle vehicleAllowedThisStep_
The vehicle which is allowed to pass the junction in this step. Used against synchronization problems.


vehicleAllowedSetTime_

public int vehicleAllowedSetTime_
When (in simulation time) the vehicleAllowedThisStep-variable was last set.

Constructor Detail

Junction

public Junction(Node node,
                Street[] priorityStreets)
Constructor

Parameters:
node - the node associated with this junction
priorityStreets - the priority streets of this junction
Method Detail

addJunctionRule

public void addJunctionRule(Node startNode,
                            Node targetNode,
                            int priority)
Adds a junction rule.

Parameters:
startNode - the start node
targetNode - the target node
priority - the priority (see getJunctionPriority(Node, Node) for details)

getJunctionPriority

public int getJunctionPriority(Node startNode,
                               Node targetNode)
Gets the priority for going over this node.

Parameters:
startNode - the node you're coming from
targetNode - the node you're going to
Returns:
1 if it's possible to go over without any notice, 2 if it's a right turnoff from a priority street, 3 if it's a left turnoff from a priority street or 4 if it's just a normal street (forced to stop at junction) with no need to look for vehicles at target street. 5 is the same as 4 but with a need to look for vehicles on target street.

addWaitingVehicle

public void addWaitingVehicle(Vehicle vehicle,
                              int priority)
Adds a waiting vehicle to the junction.
Note: This function sets the vehicle which is allowed to pass in the current simulation step. Thus, it is absolutely necessary, that this function is the first one in each step which is called on this object!

Parameters:
vehicle - the vehicle
priority - the priority of the vehicle to pass this junction

allowOtherVehicle

public void allowOtherVehicle()
Allows another vehicle to pass the junction by setting vehicleOnJunction_ to false.


canPassTrafficLight

public boolean canPassTrafficLight(Vehicle vehicle,
                                   Street tmpStreet,
                                   Node nextNode)
Returns if a vehicle may pass a Traffic Light.

Parameters:
vehicle - the vehicle
tmpStreet - the street
nextNode - the next node the vehicle will go to
Returns:
true if passing is allowed, else false

canPassJunction

public boolean canPassJunction(Vehicle vehicle,
                               int priority,
                               Node nextNode)
Returns if a vehicle may pass. Passing is only allowed every 2,5s and if there's no vehicle coming from the priority streets.

Parameters:
vehicle - the vehicle
priority - the priority of the vehicle to pass this junction
nextNode - the next node the vehicle will go to
Returns:
true if passing is allowed, else false

delTrafficLight

public void delTrafficLight()
Deletes the traffic light on this junction an resets the street values. *


getNode

public Node getNode()

getPriorityStreets

public Street[] getPriorityStreets()