Commit 290a11b9 authored by Jose Ignacio Monreal Bailey's avatar Jose Ignacio Monreal Bailey
Browse files

Adding trip output file

parent 24efeba1
...@@ -382,7 +382,7 @@ ...@@ -382,7 +382,7 @@
<dependency> <dependency>
<groupId>TraaS</groupId> <groupId>TraaS</groupId>
<artifactId>TraaS</artifactId> <artifactId>TraaS</artifactId>
<version>2.0</version> <version>2.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
......
...@@ -53,6 +53,7 @@ public class RSUMovementModel implements MovementModel, EventHandler { ...@@ -53,6 +53,7 @@ public class RSUMovementModel implements MovementModel, EventHandler {
private final String sumoExe; private final String sumoExe;
private final String sumoConfigFile; private final String sumoConfigFile;
private final String sumoTripOutputFile;
private final String sumoIntersections; private final String sumoIntersections;
...@@ -76,8 +77,8 @@ public class RSUMovementModel implements MovementModel, EventHandler { ...@@ -76,8 +77,8 @@ public class RSUMovementModel implements MovementModel, EventHandler {
private static final Location DEFAULT_LOCATION = new PositionVector(Double.NaN, Double.NaN); private static final Location DEFAULT_LOCATION = new PositionVector(Double.NaN, Double.NaN);
@XMLConfigurableConstructor({ "timeBetweenMoveOperations", "sumoExe", "sumoConfigFile", "offsetX", "offsetY", "width", "height" }) @XMLConfigurableConstructor({ "timeBetweenMoveOperations", "sumoExe", "sumoConfigFile", "sumoTripOutputFile", "offsetX", "offsetY", "width", "height" })
public RSUMovementModel(long timeBetweenMoveOperations, String sumoExe, String sumoConfigFile, String offsetX, String offsetY, String width, String height) { public RSUMovementModel(long timeBetweenMoveOperations, String sumoExe, String sumoConfigFile, String sumoTripOutputFile, String offsetX, String offsetY, String width, String height) {
this.components = new LinkedList<>(); this.components = new LinkedList<>();
this.idComponentMatcher = new HashMap<>(); this.idComponentMatcher = new HashMap<>();
this.freeComponents = new LinkedList<>(); this.freeComponents = new LinkedList<>();
...@@ -88,6 +89,7 @@ public class RSUMovementModel implements MovementModel, EventHandler { ...@@ -88,6 +89,7 @@ public class RSUMovementModel implements MovementModel, EventHandler {
this.sumoExe = sumoExe; this.sumoExe = sumoExe;
this.sumoConfigFile = sumoConfigFile; this.sumoConfigFile = sumoConfigFile;
this.sumoTripOutputFile = sumoTripOutputFile;
this.sumoIntersections = null; this.sumoIntersections = null;
...@@ -110,6 +112,7 @@ public class RSUMovementModel implements MovementModel, EventHandler { ...@@ -110,6 +112,7 @@ public class RSUMovementModel implements MovementModel, EventHandler {
this.sumoExe = null; this.sumoExe = null;
this.sumoConfigFile = null; this.sumoConfigFile = null;
this.sumoTripOutputFile = null;
this.offsetX = Integer.parseInt(offsetX); this.offsetX = Integer.parseInt(offsetX);
this.offsetY = Integer.parseInt(offsetY); this.offsetY = Integer.parseInt(offsetY);
...@@ -160,7 +163,7 @@ public class RSUMovementModel implements MovementModel, EventHandler { ...@@ -160,7 +163,7 @@ public class RSUMovementModel implements MovementModel, EventHandler {
Event.scheduleWithDelay(timeBetweenMoveOperations, this, null, 0); Event.scheduleWithDelay(timeBetweenMoveOperations, this, null, 0);
if (this.sumoExe != null) { if (this.sumoExe != null) {
_controller = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile); _controller = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile, null);
_controller.init(); _controller.init();
_controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height); _controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height);
_intersections = _controller.getAllIntersections(true); _intersections = _controller.getAllIntersections(true);
......
...@@ -80,6 +80,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler { ...@@ -80,6 +80,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
private final String sumoExe; private final String sumoExe;
private final String sumoConfigFile; private final String sumoConfigFile;
private final String sumoTripOutputFile;
private final String sumoTrace; private final String sumoTrace;
private String sumoIntersections; private String sumoIntersections;
...@@ -102,8 +103,8 @@ public class VehicleMovementModel implements MovementModel, EventHandler { ...@@ -102,8 +103,8 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
* @param width The width of the scenario. * @param width The width of the scenario.
* @param height The height of the scenario. * @param height The height of the scenario.
*/ */
@XMLConfigurableConstructor({ "timeBetweenMoveOperations", "sumoExe", "sumoConfigFile", "offsetX", "offsetY", "width", "height" }) @XMLConfigurableConstructor({ "timeBetweenMoveOperations", "sumoExe", "sumoConfigFile", "sumoTripOutputFile", "offsetX", "offsetY", "width", "height" })
public VehicleMovementModel(long timeBetweenMoveOperations, String sumoExe, String sumoConfigFile, String offsetX, String offsetY, String width, String height) { public VehicleMovementModel(long timeBetweenMoveOperations, String sumoExe, String sumoConfigFile, String sumoTripOutputFile, String offsetX, String offsetY, String width, String height) {
MOVEMENT = this; MOVEMENT = this;
this.timeBetweenMoveOperations = timeBetweenMoveOperations; this.timeBetweenMoveOperations = timeBetweenMoveOperations;
...@@ -112,6 +113,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler { ...@@ -112,6 +113,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
this.idComponentMatcher = new HashMap<>(); this.idComponentMatcher = new HashMap<>();
this.sumoExe = sumoExe; this.sumoExe = sumoExe;
this.sumoConfigFile = sumoConfigFile; this.sumoConfigFile = sumoConfigFile;
this.sumoTripOutputFile = sumoTripOutputFile;
this.sumoTrace = null; this.sumoTrace = null;
this.offsetX = Integer.parseInt(offsetX); this.offsetX = Integer.parseInt(offsetX);
this.offsetY = Integer.parseInt(offsetY); this.offsetY = Integer.parseInt(offsetY);
...@@ -139,6 +141,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler { ...@@ -139,6 +141,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
this.idComponentMatcher = new HashMap<>(); this.idComponentMatcher = new HashMap<>();
this.sumoExe = null; this.sumoExe = null;
this.sumoConfigFile = null; this.sumoConfigFile = null;
this.sumoTripOutputFile = null;
this.sumoTrace = sumoTrace; this.sumoTrace = sumoTrace;
this.sumoIntersections = sumoIntersections; this.sumoIntersections = sumoIntersections;
this.offsetX = offsetX; this.offsetX = offsetX;
...@@ -218,7 +221,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler { ...@@ -218,7 +221,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
Event.scheduleWithDelay(timeBetweenMoveOperations, this, null, 0); Event.scheduleWithDelay(timeBetweenMoveOperations, this, null, 0);
if (sumoExe != null) { if (sumoExe != null) {
TraciSimulationController simulationController = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile); TraciSimulationController simulationController = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile, sumoTripOutputFile);
_controller = simulationController; _controller = simulationController;
_controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height); _controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height);
_controller.init(); _controller.init();
......
...@@ -54,6 +54,7 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -54,6 +54,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
private String _sumoExe; private String _sumoExe;
private String _configFile; private String _configFile;
private String _tripOutputFile;
private SumoTraciConnection _connection; private SumoTraciConnection _connection;
...@@ -77,18 +78,20 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -77,18 +78,20 @@ 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) { public static synchronized TraciSimulationController createSimulationController(String pSumoExe, String pConfigFile, String pTripOutputFile) {
if (!CONTROLLER.containsKey(pConfigFile)) { if (!CONTROLLER.containsKey(pConfigFile)) {
CONTROLLER.put(pConfigFile, new TraciSimulationController(pSumoExe, pConfigFile)); CONTROLLER.put(pConfigFile, new TraciSimulationController(pSumoExe, pConfigFile, pTripOutputFile));
} }
return CONTROLLER.get(pConfigFile); return CONTROLLER.get(pConfigFile);
} }
private TraciSimulationController(String pSumoExe, String pConfigFile) { private TraciSimulationController(String pSumoExe, String pConfigFile, String pTripOutputFile) {
_sumoExe = pSumoExe; _sumoExe = pSumoExe;
_configFile = pConfigFile; _configFile = pConfigFile;
_tripOutputFile = pTripOutputFile;
} }
public static VehicleController getSimulationController() { public static VehicleController getSimulationController() {
return CONTROLLER.values().iterator().next(); return CONTROLLER.values().iterator().next();
} }
...@@ -104,11 +107,12 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -104,11 +107,12 @@ public class TraciSimulationController implements VehicleController, SimulationS
// This will only work with the updated version of the TraaS API for sumo // This will only work with the updated version of the TraaS API for sumo
// It is available for download at https://dev.kom.e-technik.tu-darmstadt.de/gitlab/tobiasm/TraaS.git // It is available for download at https://dev.kom.e-technik.tu-darmstadt.de/gitlab/tobiasm/TraaS.git
_connection = new SumoTraciConnection(_sumoExe, _configFile, random.nextInt()); _connection = new SumoTraciConnection(_sumoExe, _configFile, random.nextInt(), _tripOutputFile);
/* /*
* 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.printSumoError(true);
try { try {
_connection.runServer(); _connection.runServer();
...@@ -135,6 +139,16 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -135,6 +139,16 @@ public class TraciSimulationController implements VehicleController, SimulationS
} }
} }
private double getVehicleWaitingTime(String vehicleId) {
double waitingTime = 0;
SumoCommand waitingTimeCommand = Vehicle.getWaitingTime(vehicleId);
Object waitingTimeObject = requestObject(waitingTimeCommand);
waitingTime = (double) waitingTimeObject;
return waitingTime;
}
@Override @Override
public Location getVehiclePosition(String pVehicleID) { public Location getVehiclePosition(String pVehicleID) {
return _positons.get(pVehicleID).getPosition(); return _positons.get(pVehicleID).getPosition();
...@@ -278,9 +292,7 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -278,9 +292,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
public String getVehicleType(String pVehicleID) { public String getVehicleType(String pVehicleID) {
String vehicleType = "default"; String vehicleType = "default";
SumoCommand typeCommand = Vehicle.getTypeID(pVehicleID); SumoCommand typeCommand = Vehicle.getTypeID(pVehicleID);
Object typeObject = requestObject(typeCommand); Object typeObject = requestObject(typeCommand);
if (typeObject != null) { if (typeObject != null) {
...@@ -302,6 +314,15 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -302,6 +314,15 @@ public class TraciSimulationController implements VehicleController, SimulationS
execute(typeCommand); execute(typeCommand);
} }
@Override
public long getWaitingTime(String vehicleID) {
SumoCommand waitingTimeCommand = Vehicle.getWaitingTime(vehicleID);
Object waitingTimeObject = requestObject(waitingTimeCommand);
String waitingTime = (String)waitingTimeObject;
return Long.parseLong(waitingTime);
}
@Override @Override
public void setVehicleMaxSpeed(String pVehicleID, double pVehicleSpeed) { public void setVehicleMaxSpeed(String pVehicleID, double pVehicleSpeed) {
SumoCommand maxSpeedCommand = Vehicle.setMaxSpeed(pVehicleID, pVehicleSpeed); SumoCommand maxSpeedCommand = Vehicle.setMaxSpeed(pVehicleID, pVehicleSpeed);
......
...@@ -289,6 +289,11 @@ public class XMLSimulationController implements VehicleController, SimulationSet ...@@ -289,6 +289,11 @@ public class XMLSimulationController implements VehicleController, SimulationSet
_vehicleDataInformationHandler.getVehiclePositions().get(pVehicleID).setGap(gap); _vehicleDataInformationHandler.getVehiclePositions().get(pVehicleID).setGap(gap);
} }
@Override
public long getWaitingTime(String vehicleID) {
return 0;
}
@Override @Override
public void setVehicleMaxSpeed(String pVehicleID, double pVehicleSpeed) { public void setVehicleMaxSpeed(String pVehicleID, double pVehicleSpeed) {
_vehicleDataInformationHandler.getVehiclePositions().get(pVehicleID).setSpeed(pVehicleSpeed); _vehicleDataInformationHandler.getVehiclePositions().get(pVehicleID).setSpeed(pVehicleSpeed);
......
...@@ -37,6 +37,7 @@ public class RSUPlacement implements PlacementModel { ...@@ -37,6 +37,7 @@ public class RSUPlacement implements PlacementModel {
private final String sumoExe; private final String sumoExe;
private final String sumoConfigFile; private final String sumoConfigFile;
private final String sumoTripInfoOutputFile;
private final String sumoIntersections; private final String sumoIntersections;
...@@ -50,10 +51,11 @@ public class RSUPlacement implements PlacementModel { ...@@ -50,10 +51,11 @@ public class RSUPlacement implements PlacementModel {
private List<Location> _intersections; private List<Location> _intersections;
private int _currentIndex = 0; private int _currentIndex = 0;
@XMLConfigurableConstructor({ "sumoExe", "sumoConfigFile", "offsetX", "offsetY", "width", "height" }) @XMLConfigurableConstructor({ "sumoExe", "sumoConfigFile", "sumoTripOutputFile", "offsetX", "offsetY", "width", "height" })
public RSUPlacement(String sumoExe, String sumoConfigFile, String offsetX, String offsetY, String width, String height) { public RSUPlacement(String sumoExe, String sumoConfigFile, String sumoTripInfoOutputFile, String offsetX, String offsetY, String width, String height) {
this.sumoExe = sumoExe; this.sumoExe = sumoExe;
this.sumoConfigFile = sumoConfigFile; this.sumoConfigFile = sumoConfigFile;
this.sumoTripInfoOutputFile = sumoTripInfoOutputFile;
this.sumoIntersections = null; this.sumoIntersections = null;
...@@ -71,6 +73,7 @@ public class RSUPlacement implements PlacementModel { ...@@ -71,6 +73,7 @@ public class RSUPlacement implements PlacementModel {
this.sumoExe = null; this.sumoExe = null;
this.sumoConfigFile = null; this.sumoConfigFile = null;
this.sumoTripInfoOutputFile = null;
this.offsetX = Integer.parseInt(offsetX); this.offsetX = Integer.parseInt(offsetX);
this.offsetY = Integer.parseInt(offsetY); this.offsetY = Integer.parseInt(offsetY);
...@@ -86,7 +89,7 @@ public class RSUPlacement implements PlacementModel { ...@@ -86,7 +89,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, sumoTripInfoOutputFile);
_controller.init(); _controller.init();
_controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height); _controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height);
_intersections = _controller.getAllIntersections(true); _intersections = _controller.getAllIntersections(true);
......
...@@ -44,7 +44,7 @@ public class TrafficLightPlacementModel implements PlacementModel, EventHandler ...@@ -44,7 +44,7 @@ public class TrafficLightPlacementModel implements PlacementModel, EventHandler
protected void initializeModel() { protected void initializeModel() {
if (this.sumoExe != null) { if (this.sumoExe != null) {
controller = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile); controller = TraciSimulationController.createSimulationController(sumoExe, sumoConfigFile, null);
controller.init(); controller.init();
controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height); controller.setObservedArea(offsetX, offsetY, offsetX + width, offsetY + height);
intersections = controller.getAllIntersections(true); intersections = controller.getAllIntersections(true);
......
...@@ -149,6 +149,11 @@ public class DefaultVehicleInformationComponent implements VehicleInformationCom ...@@ -149,6 +149,11 @@ public class DefaultVehicleInformationComponent implements VehicleInformationCom
controller.setVehicleMaxSpeed(vehicleID, vehicleSpeed); controller.setVehicleMaxSpeed(vehicleID, vehicleSpeed);
} }
@Override
public long getWaitingTime() {
return controller.getWaitingTime(vehicleID);
}
@Override @Override
public void resetVehicleID() { public void resetVehicleID() {
vehicleID = null; vehicleID = null;
......
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