APPENDIX A. SOURCE CODE
76
A.2 countRoadUsers for the self organizing traffic
ligths
For updating kappa in the proposed self-organizing traffic light controllers it is
needed to count the vehicles of a specific lane.
public int countRoadusers ( Drivelane lane , int range) {
int cntr = 0;
Roaduser ru ;
boolean stop = false ;
LinkedList queue = lane . getQueue ();
ListIterator li = queue. listIterator ();
while ( li . hasNext () && !stop) {
try
{
ru = ( Roaduser) li . next ();
}
catch (Exception e)
{
// When this exception is thrown you removed the first element
// of the queue, therefore re -create the iterator .
System.out. println ("CME");
li = queue. listIterator ();
continue ;
}
if (ru . getPosition () <= range)
cntr ++;
else
stop = true ;
}
return cntr ;
}