use of il.ac.technion.cs.yp.btw.citysimulation.CityCrossroad in project BTW by TechnionYearlyProject.
the class SmartTrafficLightManagerTest method configureCrossroad.
public CityCrossroad configureCrossroad(String name, double coordX, double coordY, Set<CityTrafficLight> trafficLights) {
CityCrossroad crossroad = mock(CityCrossroad.class);
Mockito.when(crossroad.getName()).thenReturn(name);
Mockito.when(crossroad.getCoordinateX()).thenReturn(coordX);
Mockito.when(crossroad.getCoordinateY()).thenReturn(coordY);
Mockito.when(crossroad.getRealTrafficLights()).thenReturn(trafficLights);
return crossroad;
}
use of il.ac.technion.cs.yp.btw.citysimulation.CityCrossroad in project BTW by TechnionYearlyProject.
the class SmartTrafficLightManager method insertCrossroads.
/*
* @Author: Sharon Hadar
* @Date: 2/06/2018
* here the crossroads are the real crossroads in the map
* */
@Override
public SmartTrafficLightManager insertCrossroads(Set<CityCrossroad> crossroads) {
// for every cross road attach all its roads and initialize their time to 0.0
// get all roads in map
Set<CityRoad> roadsSet = new HashSet<>();
crossroads.stream().map(crossroad -> (crossroad.getRealTrafficLights().stream().map(trafficlight -> roadsSet.add(trafficlight.getSourceRoad())).collect(Collectors.toSet()))).collect(Collectors.toSet());
// for every road attach all its trafficlights
Map<CityRoad, Set<CityTrafficLight>> roadToTrafficlightsMap = new HashMap<>();
roadsSet.stream().map(road -> roadToTrafficlightsMap.put(road, road.getDestinationCrossroad().getRealTrafficLightsFromRoad(road))).collect(Collectors.toSet());
// for every crossroad attach all roads that it ends
Map<CityCrossroad, List<CityRoad>> crossRoadsToRoadsMap = new HashMap<>();
crossroads.stream().map(crossroad -> crossRoadsToRoadsMap.put(crossroad, crossroad.getRealTrafficLights().stream().map(trafficLight -> trafficLight.getSourceRoad()).collect(Collectors.toSet()).stream().collect(Collectors.toList()))).collect(Collectors.toSet());
// create a set of CrossroadManagers
this.crossroadsManagers = crossRoadsToRoadsMap.entrySet().stream().map(entry -> {
CityCrossroad crossroad = entry.getKey();
List<CityRoad> roadsList = entry.getValue();
AtomicInteger roadSerialNumber = new AtomicInteger(0);
List<RoadManager> roadManagers = roadsList.stream().map(road -> new RoadManager(road, roadToTrafficlightsMap.get(road), roadSerialNumber.getAndIncrement())).collect(Collectors.toList());
return new CrossroadManager(crossroad, roadManagers);
}).collect(Collectors.toSet());
this.minimumOpenTime = crossroads.stream().flatMap(crossroad -> crossroad.getRealTrafficLights().stream()).mapToInt(CityTrafficLight::getMinimumOpenTime).max().getAsInt() + // may throw - need to catch
1;
return this;
}
Aggregations