vanetsim.scenario
Class KnownPenalties

java.lang.Object
  extended by vanetsim.scenario.KnownPenalties

public class KnownPenalties
extends java.lang.Object

Stores all known penalties for streets. The streets are stored together with their direction and a penalty in cm. Arrays are directly used here (in contrast to the KnownVehiclesList) as this allows easier and faster usage in the routing algorithm. Extensibility is not a major concern here.

Note for developers: You need to make sure, that all used arrays always have the same size!


Constructor Summary
KnownPenalties(Vehicle vehicle)
          Constructor.
 
Method Summary
 void checkValidUntil()
          Check for outdated entries and remove them.
 void clear()
          Clears everything from this data structure.
 int[] getDirections()
          Gets an array with the directions corresponding to the getStreets()-function.
 int[] getPenalties()
          Gets an array with the penalties corresponding to the getStreets()-function.
 int getSize()
          Gets the amount of known penalties stored.
 Street[] getStreets()
          Gets all streets with known penalties.
 void updatePenalty(Street street, int direction, int penalty, int validUntil)
          Updates or adds a penalty.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KnownPenalties

public KnownPenalties(Vehicle vehicle)
Constructor.

Parameters:
vehicle - the vehicle this data structure belongs to.
Method Detail

updatePenalty

public void updatePenalty(Street street,
                          int direction,
                          int penalty,
                          int validUntil)
Updates or adds a penalty. If a penalty already existed, the values for penalty and validUntil are overwritten! If the penalty is new or differs from the last one, a new route calculation is initiated.

Parameters:
street - the street
direction - the direction. 1 means from endNode to startNode, 0 means both directions and -1 means from startNode to endNode
penalty - the penalty in cm
validUntil - how long this entry will be valid. Measured in millseconds from simulation start

checkValidUntil

public void checkValidUntil()
Check for outdated entries and remove them. Note that this function is not synchronized! You need to make sure that no other thread uses any function on this object at the same time!


getStreets

public Street[] getStreets()
Gets all streets with known penalties.

Returns:
an array with all streets

getDirections

public int[] getDirections()
Gets an array with the directions corresponding to the getStreets()-function. 1 in the array means from endNode to startNode, 0 means both directions and -1 means from startNode to endNode

Returns:
an array with all directions

getPenalties

public int[] getPenalties()
Gets an array with the penalties corresponding to the getStreets()-function. Measured in cm.

Returns:
an array with all penalties

getSize

public int getSize()
Gets the amount of known penalties stored.

Returns:
the size

clear

public void clear()
Clears everything from this data structure.