vanetsim.scenario
Class KnownVehiclesList

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

public class KnownVehiclesList
extends java.lang.Object

A list of all known vehicles which was discovered through beacons. In contrast to the KnownPenalties- class, an own class is used for storing the information about the vehicles. Although this means slightly more overhead, it should not be a big case and allows better extensibility.
A simple hash algorithm based on the vehicle ID is used to get better performance. The hash determines the corresponding linked list(beginnings of linked lists are found in head_). Known vehicles with the same hash are connected together through their next_ and previous_ values (see KnownVehicle-class).


Constructor Summary
KnownVehiclesList()
          Empty constructor.
 
Method Summary
 void checkOutdatedVehicles()
          Checks if a vehicle is too old so that it can be removed.
 void clear()
          Clears everything from this data structure.
 Vehicle findNearestVehicle(int vehicleX, int vehicleY, int destX, int destY, int maxDistance)
          Finds the nearest known vehicle to a destination.
 KnownVehicle[] getFirstKnownVehicle()
          Gets an hashed array with known vehicles (array length depends on the HASH_SIZE).
 int getSize()
          Gets the amount of known vehicles stored.
static void setTimePassed(int time)
          Sets the time passed since simulation start.
 void updateVehicle(Vehicle vehicle, long ID, int x, int y, double speed, long sourceID, boolean isEncrypted, boolean isARSU)
          Update a vehicle or add it if it doesn't exist yet.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KnownVehiclesList

public KnownVehiclesList()
Empty constructor.

Method Detail

updateVehicle

public void updateVehicle(Vehicle vehicle,
                          long ID,
                          int x,
                          int y,
                          double speed,
                          long sourceID,
                          boolean isEncrypted,
                          boolean isARSU)
Update a vehicle or add it if it doesn't exist yet.

Parameters:
vehicle - a reference to the vehicle
ID - the ID of the vehicle
x - the x coordinate
y - the y coordinate
speed - the speed
sourceID - ID of the source
isEncrypted - if Beacon was encrypted
isARSU - if Beacon was sent from an ARSU

checkOutdatedVehicles

public void checkOutdatedVehicles()
Checks if a vehicle is too old so that it can be removed. 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!


findNearestVehicle

public Vehicle findNearestVehicle(int vehicleX,
                                  int vehicleY,
                                  int destX,
                                  int destY,
                                  int maxDistance)
Finds the nearest known vehicle to a destination.

Parameters:
vehicleX - the x coordinate of the calling vehicle
vehicleY - the y coordinate of the calling vehicle
destX - the x coordinate of the destination
destY - the y coordinate of the destination
maxDistance - the maximum distance the nearest vehicle max have from the calling vehicle
Returns:
the nearest vehicle or null if the calling vehicle is the nearest

getFirstKnownVehicle

public KnownVehicle[] getFirstKnownVehicle()
Gets an hashed array with known vehicles (array length depends on the HASH_SIZE). You can iterate through all known vehicles by using getNext() until you get to a null element on all elements of this array

Returns:
the array with known vehicles

getSize

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

Returns:
the size

setTimePassed

public static void setTimePassed(int time)
Sets the time passed since simulation start.

Parameters:
time - the new time in milliseconds

clear

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