/************************************************************************************
* Copyright (C) 2008 by Politehnica University of Bucharest and Rutgers University
* All rights reserved.
* Refer to LICENSE for terms and conditions of use.
***********************************************************************************/
package vnsim.vehicular.simulator.intersections;
import java.util.Collections;
import java.util.Comparator;
import java.util.Random;
import java.util.ArrayList;
import vnsim.map.object.Globals;
import vnsim.vehicular.simulator.RouteSegment;
public class IntersectionWithoutTrafficLights extends Intersection {
/** serialVersionUID
*/
private static final long serialVersionUID = -5883719321862303634L;
public ArrayList mustStop; //indices corresponding with "segments" = must stop or not
public IntersectionWithoutTrafficLights() {
}
public void addCrossingSegment(DirectedRoadSegment drs) {
if(segments==null) {
segments=new ArrayList ();
mustStop=new ArrayList ();
}
if(!segments.contains(drs)) {
segments.add(drs);
mustStop.add(true);
}
}
public boolean mustStop(RouteSegment seg1, RouteSegment seg2) {
for(int i=0;i yieldFor(RouteSegment seg1,
RouteSegment seg2) {
//a vehicle coming on "seg1", going on "seg2"
//must yield to vehicles coming on which segments?
int i;
for(i=0;i();
if(i==0 || i==1) {
//yield to the other priority road, and only if going on "seg2"
//means crossing it (to the left)
if(i==0) {
if(isOrder(0,1,j)) {
ArrayList ret=new ArrayList ();
ret.add(segments.get(1));
return ret;
} else
return new ArrayList ();
}
if(i==1) {
if(isOrder(1,0,j)) {
ArrayList ret=new ArrayList ();
ret.add(segments.get(0));
return ret;
} else
return new ArrayList ();
}
}
//I have an "yield" sign
ArrayList ret=new ArrayList ();
//I must yield to all roads which are between "seg1" and "seg2"
//(counter-clock-wise);
//Furthermore, if one of the priority roads is between "seg1" and "seg2", including "seg2",
//then I must also yield to the other priority road!
for(int k=0;k(){
public int compare(DirectedRoadSegment s1,DirectedRoadSegment s2){
int r1,r2,p1,p2;
//System.out.println("COMPAR: "+s1+" CU "+s2);
r1=s1.roadIndex;
r2=s2.roadIndex;
byte b1[];
byte b2[];
b1=Globals.map.roads.get(r1).getRoadinfo();
b2=Globals.map.roads.get(r2).getRoadinfo();
if(b1[1]b2[1]){
return 1;
}else{
p1=Globals.map.roads.get(r1).getPoints().size();
p2=Globals.map.roads.get(r2).getPoints().size();
if(p1>p2){
return -1;
} else {
if(p1();
this.mustStop.add(false);
this.mustStop.add(false);
for(int ll=2;ll