Commit dc10deed authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Minor fixes in movement

parent 80c3581d
...@@ -141,7 +141,7 @@ public class RSUMovementModel implements MovementModel { ...@@ -141,7 +141,7 @@ public class RSUMovementModel implements MovementModel {
*/ */
protected void initializeModel() { protected void initializeModel() {
if (this.sumoExe != null) { if (this.sumoExe != null) {
_controller = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile); _controller = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile, 1);
_controller.init(Time.SECOND); _controller.init(Time.SECOND);
_controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height); _controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height);
_intersections = _controller.getAllIntersections(true); _intersections = _controller.getAllIntersections(true);
......
...@@ -67,6 +67,8 @@ public class VehicleMovementModel implements MovementModel, EventHandler { ...@@ -67,6 +67,8 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
private static VehicleMovementModel MOVEMENT; private static VehicleMovementModel MOVEMENT;
public static final int TIMESTEP_RATIO = 5;
private long timeBetweenMoveOperations; private long timeBetweenMoveOperations;
private final List<SimLocationActuator> components; private final List<SimLocationActuator> components;
...@@ -244,10 +246,10 @@ public class VehicleMovementModel implements MovementModel, EventHandler { ...@@ -244,10 +246,10 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
protected void initializeModel() { protected void initializeModel() {
// Schedule first step // Schedule first step
if (!initialized) { if (!initialized) {
Event.scheduleWithDelay(timeBetweenMoveOperations, this, null, 0); Event.scheduleWithDelay(timeBetweenMoveOperations * TIMESTEP_RATIO, this, null, 0);
if (sumoExe != null) { if (sumoExe != null) {
TraciSimulationController simulationController = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile); TraciSimulationController simulationController = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile, TIMESTEP_RATIO);
_controller = simulationController; _controller = simulationController;
_controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height); _controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height);
simulationController.setStartTime(_startTime); simulationController.setStartTime(_startTime);
...@@ -345,7 +347,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler { ...@@ -345,7 +347,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
} }
// Reschedule next step // Reschedule next step
Event.scheduleWithDelay(timeBetweenMoveOperations, this, null, 0); Event.scheduleWithDelay(timeBetweenMoveOperations * TIMESTEP_RATIO, this, null, 0);
} }
/** /**
......
...@@ -52,4 +52,8 @@ public class VehicleInformationContainer { ...@@ -52,4 +52,8 @@ public class VehicleInformationContainer {
public RoadNetworkRoute getRoute() { public RoadNetworkRoute getRoute() {
return _route; return _route;
} }
public void setRoute(RoadNetworkRoute pRoute) {
_route = pRoute;
}
} }
\ No newline at end of file
...@@ -60,7 +60,7 @@ import it.polito.appeal.traci.SumoTraciConnection; ...@@ -60,7 +60,7 @@ import it.polito.appeal.traci.SumoTraciConnection;
public class TraciSimulationController implements VehicleController, SimulationSetupExtractor, EdgeController, SimulatorObserver { public class TraciSimulationController implements VehicleController, SimulationSetupExtractor, EdgeController, SimulatorObserver {
private static final File TEMP_FILE = new File(new File(System.getProperty("user.home") + "/.simonstrator"), "road_network.tmp"); private static final File TEMP_FILE = new File(new File(System.getProperty("user.home") + "/.simonstrator"), "road_network.tmp");
private static final boolean TRAIN_PATH_PROBABILITIES = true; private static final boolean TRAIN_PATH_PROBABILITIES = false;
private Random _random = Randoms.getRandom(getClass()); private Random _random = Randoms.getRandom(getClass());
...@@ -95,16 +95,19 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -95,16 +95,19 @@ public class TraciSimulationController implements VehicleController, SimulationS
private RoutingAlgorithm _algorithm = new DijkstraAlgorithm(); private RoutingAlgorithm _algorithm = new DijkstraAlgorithm();
public static synchronized TraciSimulationController createSimulationController(String pSumoExe, String pConfigFile) { private int _timestepRatio;
public static synchronized TraciSimulationController createSimulationController(String pSumoExe, String pConfigFile, int pTimestepRatio) {
if (!CONTROLLER.containsKey(pConfigFile)) { if (!CONTROLLER.containsKey(pConfigFile)) {
CONTROLLER.put(pConfigFile, new TraciSimulationController(pSumoExe, pConfigFile)); CONTROLLER.put(pConfigFile, new TraciSimulationController(pSumoExe, pConfigFile, pTimestepRatio));
} }
return CONTROLLER.get(pConfigFile); return CONTROLLER.get(pConfigFile);
} }
private TraciSimulationController(String pSumoExe, String pConfigFile) { private TraciSimulationController(String pSumoExe, String pConfigFile, int pTimestepRatio) {
_sumoExe = pSumoExe; _sumoExe = pSumoExe;
_configFile = pConfigFile; _configFile = pConfigFile;
_timestepRatio = pTimestepRatio;
} }
public void setStartTime(int pStartTime) { public void setStartTime(int pStartTime) {
...@@ -127,6 +130,7 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -127,6 +130,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
* prevent vehicles form teleporting (http://sumo.dlr.de/wiki/Simulation/Why_Vehicles_are_teleporting) * prevent vehicles form teleporting (http://sumo.dlr.de/wiki/Simulation/Why_Vehicles_are_teleporting)
*/ */
_connection.addOption("time-to-teleport", Integer.toString(-1)); _connection.addOption("time-to-teleport", Integer.toString(-1));
_connection.addOption("step-length", String.valueOf(pTimeScale / (double)Time.SECOND));
try { try {
_connection.runServer(); _connection.runServer();
...@@ -146,7 +150,7 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -146,7 +150,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
if (TRAIN_PATH_PROBABILITIES) { if (TRAIN_PATH_PROBABILITIES) {
Map<String, VehicleInformationContainer> positions = nextStep(); Map<String, VehicleInformationContainer> positions = nextStep();
for (Entry<String, VehicleInformationContainer> entry : positions.entrySet()) { for (Entry<String, VehicleInformationContainer> entry : positions.entrySet()) {
VehiclePathTrackerFactory.getVehiclePathTracker().setEdge(entry.getKey(), entry.getValue().getRoute().getStart(), i * Time.SECOND); VehiclePathTrackerFactory.getVehiclePathTracker().setEdge(entry.getKey(), entry.getValue().getRoute().getStart(), i * pTimeScale);
} }
} else { } else {
try { try {
...@@ -246,7 +250,9 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -246,7 +250,9 @@ public class TraciSimulationController implements VehicleController, SimulationS
private Map<String, VehicleInformationContainer> nextStep() { private Map<String, VehicleInformationContainer> nextStep() {
try { try {
_connection.do_timestep(); for (int i = 0; i < _timestepRatio; i++) {
_connection.do_timestep();
}
try { try {
Map<String, VehicleInformationContainer> vehiclePositions = new HashMap<>(); Map<String, VehicleInformationContainer> vehiclePositions = new HashMap<>();
...@@ -453,7 +459,11 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -453,7 +459,11 @@ public class TraciSimulationController implements VehicleController, SimulationS
add = true; add = true;
} }
if (add) { if (add) {
streets.add(_roadNetwork.getEdge(street)); RoadNetworkEdge edge = _roadNetwork.getEdge(street);
streets.add(edge);
if (!edge.isUsable()) {
break;
}
} }
} }
...@@ -655,6 +665,7 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -655,6 +665,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
routeEdges.add(edge.getEdgeID()); routeEdges.add(edge.getEdgeID());
} }
execute(Vehicle.setRoute(pVehicle, routeEdges)); execute(Vehicle.setRoute(pVehicle, routeEdges));
_positons.get(pVehicle).setRoute(pRoute);
} }
@Override @Override
...@@ -888,10 +899,12 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -888,10 +899,12 @@ public class TraciSimulationController implements VehicleController, SimulationS
if (_observedAreaSet) { if (_observedAreaSet) {
List<RoadNetworkLane> lanes = _roadNetwork.getEdge(pEdgeID).getLanes(); List<RoadNetworkLane> lanes = _roadNetwork.getEdge(pEdgeID).getLanes();
if (lanes.size() > 0) { if (lanes.size() > 0) {
List<Location> laneShape = getLaneShape(lanes.get(0).getLaneID()); for (RoadNetworkLane lane : lanes) {
if (laneShape.size() > 1) { List<Location> laneShape = getLaneShape(lane.getLaneID());
return true; if (laneShape.size() > 1) {
} return true;
}
}
} }
return false; return false;
} }
......
...@@ -87,7 +87,7 @@ public class RSUPlacement implements PlacementModel { ...@@ -87,7 +87,7 @@ public class RSUPlacement implements PlacementModel {
*/ */
protected void initializeModel() { protected void initializeModel() {
if (this.sumoExe != null) { if (this.sumoExe != null) {
_controller = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile); _controller = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile, 1);
_controller.init(Time.SECOND); _controller.init(Time.SECOND);
_controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height); _controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height);
_intersections = _controller.getAllIntersections(true); _intersections = _controller.getAllIntersections(true);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment