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 {
*/
protected void initializeModel() {
if (this.sumoExe != null) {
_controller = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile);
_controller = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile, 1);
_controller.init(Time.SECOND);
_controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height);
_intersections = _controller.getAllIntersections(true);
......
......@@ -67,6 +67,8 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
private static VehicleMovementModel MOVEMENT;
public static final int TIMESTEP_RATIO = 5;
private long timeBetweenMoveOperations;
private final List<SimLocationActuator> components;
......@@ -244,10 +246,10 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
protected void initializeModel() {
// Schedule first step
if (!initialized) {
Event.scheduleWithDelay(timeBetweenMoveOperations, this, null, 0);
Event.scheduleWithDelay(timeBetweenMoveOperations * TIMESTEP_RATIO, this, null, 0);
if (sumoExe != null) {
TraciSimulationController simulationController = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile);
TraciSimulationController simulationController = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile, TIMESTEP_RATIO);
_controller = simulationController;
_controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height);
simulationController.setStartTime(_startTime);
......@@ -345,7 +347,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
}
// Reschedule next step
Event.scheduleWithDelay(timeBetweenMoveOperations, this, null, 0);
Event.scheduleWithDelay(timeBetweenMoveOperations * TIMESTEP_RATIO, this, null, 0);
}
/**
......
......@@ -52,4 +52,8 @@ public class VehicleInformationContainer {
public RoadNetworkRoute getRoute() {
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;
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 boolean TRAIN_PATH_PROBABILITIES = true;
private static final boolean TRAIN_PATH_PROBABILITIES = false;
private Random _random = Randoms.getRandom(getClass());
......@@ -95,16 +95,19 @@ public class TraciSimulationController implements VehicleController, SimulationS
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)) {
CONTROLLER.put(pConfigFile, new TraciSimulationController(pSumoExe, pConfigFile));
CONTROLLER.put(pConfigFile, new TraciSimulationController(pSumoExe, pConfigFile, pTimestepRatio));
}
return CONTROLLER.get(pConfigFile);
}
private TraciSimulationController(String pSumoExe, String pConfigFile) {
private TraciSimulationController(String pSumoExe, String pConfigFile, int pTimestepRatio) {
_sumoExe = pSumoExe;
_configFile = pConfigFile;
_timestepRatio = pTimestepRatio;
}
public void setStartTime(int pStartTime) {
......@@ -127,6 +130,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
* prevent vehicles form teleporting (http://sumo.dlr.de/wiki/Simulation/Why_Vehicles_are_teleporting)
*/
_connection.addOption("time-to-teleport", Integer.toString(-1));
_connection.addOption("step-length", String.valueOf(pTimeScale / (double)Time.SECOND));
try {
_connection.runServer();
......@@ -146,7 +150,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
if (TRAIN_PATH_PROBABILITIES) {
Map<String, VehicleInformationContainer> positions = nextStep();
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 {
try {
......@@ -246,7 +250,9 @@ public class TraciSimulationController implements VehicleController, SimulationS
private Map<String, VehicleInformationContainer> nextStep() {
try {
_connection.do_timestep();
for (int i = 0; i < _timestepRatio; i++) {
_connection.do_timestep();
}
try {
Map<String, VehicleInformationContainer> vehiclePositions = new HashMap<>();
......@@ -453,7 +459,11 @@ public class TraciSimulationController implements VehicleController, SimulationS
add = true;
}
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
routeEdges.add(edge.getEdgeID());
}
execute(Vehicle.setRoute(pVehicle, routeEdges));
_positons.get(pVehicle).setRoute(pRoute);
}
@Override
......@@ -888,10 +899,12 @@ public class TraciSimulationController implements VehicleController, SimulationS
if (_observedAreaSet) {
List<RoadNetworkLane> lanes = _roadNetwork.getEdge(pEdgeID).getLanes();
if (lanes.size() > 0) {
List<Location> laneShape = getLaneShape(lanes.get(0).getLaneID());
if (laneShape.size() > 1) {
return true;
}
for (RoadNetworkLane lane : lanes) {
List<Location> laneShape = getLaneShape(lane.getLaneID());
if (laneShape.size() > 1) {
return true;
}
}
}
return false;
}
......
......@@ -87,7 +87,7 @@ public class RSUPlacement implements PlacementModel {
*/
protected void initializeModel() {
if (this.sumoExe != null) {
_controller = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile);
_controller = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile, 1);
_controller.init(Time.SECOND);
_controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height);
_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