Search in sources :

Example 1 with CityCrossroad

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;
}
Also used : CityCrossroad(il.ac.technion.cs.yp.btw.citysimulation.CityCrossroad)

Example 2 with CityCrossroad

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;
}
Also used : Logger(org.apache.log4j.Logger) java.util(java.util) CityRoad(il.ac.technion.cs.yp.btw.citysimulation.CityRoad) Road(il.ac.technion.cs.yp.btw.classes.Road) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CityCrossroad(il.ac.technion.cs.yp.btw.citysimulation.CityCrossroad) CityTrafficLight(il.ac.technion.cs.yp.btw.citysimulation.CityTrafficLight) Crossroad(il.ac.technion.cs.yp.btw.classes.Crossroad) Collectors(java.util.stream.Collectors) TrafficLight(il.ac.technion.cs.yp.btw.classes.TrafficLight) CityTrafficLight(il.ac.technion.cs.yp.btw.citysimulation.CityTrafficLight) CityRoad(il.ac.technion.cs.yp.btw.citysimulation.CityRoad) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CityCrossroad(il.ac.technion.cs.yp.btw.citysimulation.CityCrossroad)

Aggregations

CityCrossroad (il.ac.technion.cs.yp.btw.citysimulation.CityCrossroad)2 CityRoad (il.ac.technion.cs.yp.btw.citysimulation.CityRoad)1 CityTrafficLight (il.ac.technion.cs.yp.btw.citysimulation.CityTrafficLight)1 Crossroad (il.ac.technion.cs.yp.btw.classes.Crossroad)1 Road (il.ac.technion.cs.yp.btw.classes.Road)1 TrafficLight (il.ac.technion.cs.yp.btw.classes.TrafficLight)1 java.util (java.util)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 Logger (org.apache.log4j.Logger)1