Commit a7ade2b5 authored by Tobias Meuser's avatar Tobias Meuser Committed by Jose Ignacio Monreal Bailey
Browse files

Removed Position class

parent 08a789ee
...@@ -24,7 +24,6 @@ import java.util.HashMap; ...@@ -24,7 +24,6 @@ import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import de.tud.kom.p2psim.api.network.SimNetInterface; import de.tud.kom.p2psim.api.network.SimNetInterface;
import de.tud.kom.p2psim.api.topology.movement.MovementModel; import de.tud.kom.p2psim.api.topology.movement.MovementModel;
...@@ -33,23 +32,14 @@ import de.tud.kom.p2psim.impl.network.routed.RoutedNetLayer; ...@@ -33,23 +32,14 @@ import de.tud.kom.p2psim.impl.network.routed.RoutedNetLayer;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.traci.TraciSimulationController; import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.traci.TraciSimulationController;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.XMLSimulationController; import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.XMLSimulationController;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Time; import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID; import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.future_location.FutureLocationSensor;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSDataCallback;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInfoProperties;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationProvider.SiSProviderHandle;
import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class RSUMovementModel implements MovementModel, FutureLocationSensor { public class RSUMovementModel implements MovementModel {
private final List<SimLocationActuator> components; private final List<SimLocationActuator> components;
...@@ -69,7 +59,7 @@ public class RSUMovementModel implements MovementModel, FutureLocationSensor { ...@@ -69,7 +59,7 @@ public class RSUMovementModel implements MovementModel, FutureLocationSensor {
private SimulationSetupExtractor _controller; private SimulationSetupExtractor _controller;
private List<Position> _intersections; private List<Location> _intersections;
private int _currentIndex = 0; private int _currentIndex = 0;
private final Map<INodeID, Integer> hostIntersectionMatching = new HashMap<>(); private final Map<INodeID, Integer> hostIntersectionMatching = new HashMap<>();
...@@ -107,40 +97,6 @@ public class RSUMovementModel implements MovementModel, FutureLocationSensor { ...@@ -107,40 +97,6 @@ public class RSUMovementModel implements MovementModel, FutureLocationSensor {
@Override @Override
public final void addComponent(SimLocationActuator comp) { public final void addComponent(SimLocationActuator comp) {
components.add(comp); components.add(comp);
try {
final SiSComponent sis = comp.getHost().getComponent(SiSComponent.class);
sis.provide().nodeState(SiSTypes.FUTURE_PHY_LOCATION,
new SiSDataCallback<Location>() {
Set<INodeID> localID = INodeID
.getSingleIDSet(comp.getHost().getId());
@Override
public Location getValue(INodeID nodeID,
SiSProviderHandle providerHandle)
throws InformationNotAvailableException {
if (nodeID.equals(comp.getHost().getId())) {
return getFutureLocation(comp.getHost());
} else {
throw new InformationNotAvailableException();
}
}
@Override
public Set<INodeID> getObservedNodes() {
return localID;
}
@Override
public SiSInfoProperties getInfoProperties() {
return new SiSInfoProperties();
}
});
} catch (ComponentNotAvailableException e) {
// Nothing to do
}
} }
@Override @Override
...@@ -156,8 +112,8 @@ public class RSUMovementModel implements MovementModel, FutureLocationSensor { ...@@ -156,8 +112,8 @@ public class RSUMovementModel implements MovementModel, FutureLocationSensor {
} }
if (_currentIndex < _intersections.size()) { if (_currentIndex < _intersections.size()) {
// Initial placement // Initial placement
Position intersection = _intersections.get(_currentIndex); Location intersection = _intersections.get(_currentIndex);
actuator.updateCurrentLocation(new PositionVector(intersection.getX(), intersection.getY())); actuator.updateCurrentLocation(new PositionVector(intersection.getLongitude(), intersection.getLatitude()));
hostIntersectionMatching.put(actuator.getHost().getId(), _currentIndex); hostIntersectionMatching.put(actuator.getHost().getId(), _currentIndex);
...@@ -198,17 +154,4 @@ public class RSUMovementModel implements MovementModel, FutureLocationSensor { ...@@ -198,17 +154,4 @@ public class RSUMovementModel implements MovementModel, FutureLocationSensor {
// System.out.println("Require " + _intersections.size() + " RSUs"); // System.out.println("Require " + _intersections.size() + " RSUs");
} }
@Override
public Location getFutureLocation(Host pHost) {
if (hostIntersectionMatching.containsKey(pHost.getId())) {
int intersection = hostIntersectionMatching.get(pHost.getId());
Position intersectionPosition = _intersections.get(intersection);
if (intersectionPosition != null) {
return new PositionVector(intersectionPosition.getX(), intersectionPosition.getY());
}
}
return null;
}
} }
\ No newline at end of file
...@@ -26,7 +26,6 @@ import java.util.LinkedList; ...@@ -26,7 +26,6 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Queue; import java.util.Queue;
import java.util.Set;
import de.tud.kom.p2psim.api.network.SimNetInterface; import de.tud.kom.p2psim.api.network.SimNetInterface;
import de.tud.kom.p2psim.api.topology.movement.MovementModel; import de.tud.kom.p2psim.api.topology.movement.MovementModel;
...@@ -42,22 +41,14 @@ import de.tudarmstadt.maki.simonstrator.api.Host; ...@@ -42,22 +41,14 @@ import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Time; import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID; import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.future_location.FutureLocationSensor;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSComponent;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSDataCallback;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInfoProperties;
import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationProvider.SiSProviderHandle;
import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.VehicleInformationComponent; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.VehicleInformationComponent;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.VehicleController; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.VehicleController;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class VehicleMovementModel implements MovementModel, EventHandler, FutureLocationSensor { public class VehicleMovementModel 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);
...@@ -95,7 +86,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future ...@@ -95,7 +86,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
private VehicleController _controller; private VehicleController _controller;
private SimulationSetupExtractor _extractor; private SimulationSetupExtractor _extractor;
private List<Position> intersections; private List<Location> intersections;
/** /**
* Constructor for the movement model using the sumo TraCI API * Constructor for the movement model using the sumo TraCI API
...@@ -200,40 +191,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future ...@@ -200,40 +191,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
initialized = true; initialized = true;
} }
// Initial placement // Initial placement
actuator.updateCurrentLocation(DEFAULT_LOCATION); actuator.updateCurrentLocation(new PositionVector(Double.NaN, Double.NaN));
try {
final SiSComponent sis = actuator.getHost().getComponent(SiSComponent.class);
sis.provide().nodeState(SiSTypes.FUTURE_PHY_LOCATION,
new SiSDataCallback<Location>() {
Set<INodeID> localID = INodeID
.getSingleIDSet(actuator.getHost().getId());
@Override
public Location getValue(INodeID nodeID,
SiSProviderHandle providerHandle)
throws InformationNotAvailableException {
if (nodeID.equals(actuator.getHost().getId())) {
return getFutureLocation(actuator.getHost());
} else {
throw new InformationNotAvailableException();
}
}
@Override
public Set<INodeID> getObservedNodes() {
return localID;
}
@Override
public SiSInfoProperties getInfoProperties() {
return new SiSInfoProperties();
}
});
} catch (ComponentNotAvailableException e) {
// Nothing to do
}
} }
/** /**
...@@ -302,7 +260,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future ...@@ -302,7 +260,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
for (int i = 0; i < allVehicles.size(); i++) { for (int i = 0; i < allVehicles.size(); i++) {
String vehicle = allVehicles.get(i); String vehicle = allVehicles.get(i);
Position position = _controller.getVehiclePosition(vehicle); Location position = _controller.getVehiclePosition(vehicle);
if (position == null) { if (position == null) {
allVehicles.remove(i--); allVehicles.remove(i--);
...@@ -311,10 +269,10 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future ...@@ -311,10 +269,10 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
SimLocationActuator component = requestSimActuator(vehicle); SimLocationActuator component = requestSimActuator(vehicle);
if (scenarioHeight != -1) { if (scenarioHeight != -1) {
component.updateCurrentLocation(new PositionVector(position.getX(), Math.min(scenarioHeight, height) - position.getY())); component.updateCurrentLocation(new PositionVector(position.getLongitude(), Math.min(scenarioHeight, height) - position.getLatitude()));
} else { } else {
// This would be vertically mirrored // This would be vertically mirrored
component.updateCurrentLocation(new PositionVector(position.getX(), position.getY())); component.updateCurrentLocation(new PositionVector(position.getLongitude(), position.getLatitude()));
} }
component.setMovementSpeed(position.getSpeed()); component.setMovementSpeed(position.getSpeed());
...@@ -420,22 +378,4 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future ...@@ -420,22 +378,4 @@ public class VehicleMovementModel implements MovementModel, EventHandler, Future
public static RoadNetwork getRoadNetwork() { public static RoadNetwork getRoadNetwork() {
return MOVEMENT._extractor.getRoadNetwork(); return MOVEMENT._extractor.getRoadNetwork();
} }
/**
* Returns the future location of a certain host.
* @param pHost The host for which the location is being requested.
* @return The future location of the host.
*/
@Override
public Location getFutureLocation(Host pHost) {
if (hostVehicleIDMatching.containsKey(pHost.getId())) {
String vehicleID = hostVehicleIDMatching.get(pHost.getId());
Position vehiclePosition = _controller.getVehiclePosition(_controller.getMaximumAvailablePrediction(), vehicleID);
if (vehiclePosition != null) {
return new PositionVector(vehiclePosition.getX(), vehiclePosition.getY());
}
}
return null;
}
} }
...@@ -11,7 +11,7 @@ import org.xml.sax.SAXException; ...@@ -11,7 +11,7 @@ import org.xml.sax.SAXException;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.CancelParsingSAXException; import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.CancelParsingSAXException;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.SimulationSetupInformationHandler; import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.SimulationSetupInformationHandler;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
public class SimulationSetupInformationProvider { public class SimulationSetupInformationProvider {
private static final SimulationSetupInformationProvider ONLY_INSTANCE = new SimulationSetupInformationProvider(); private static final SimulationSetupInformationProvider ONLY_INSTANCE = new SimulationSetupInformationProvider();
...@@ -25,11 +25,11 @@ public class SimulationSetupInformationProvider { ...@@ -25,11 +25,11 @@ public class SimulationSetupInformationProvider {
return ONLY_INSTANCE; return ONLY_INSTANCE;
} }
public Position getUpperLeft() { public Location getUpperLeft() {
return _handler.getUpperLeft(); return _handler.getUpperLeft();
} }
public Position getLowerRight() { public Location getLowerRight() {
return _handler.getLowerRight(); return _handler.getLowerRight();
} }
......
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
public class VehicleInformationContainer {
private Location _position;
private double _heading;
private double _speed;
public VehicleInformationContainer(Location pPosition, double pHeading,
double pSpeed) {
_position = pPosition;
_heading = pHeading;
_speed = pSpeed;
}
public Location getPosition() {
return _position;
}
public double getHeading() {
return _heading;
}
public double getSpeed() {
return _speed;
}
}
\ No newline at end of file
...@@ -7,11 +7,12 @@ import java.util.ArrayList; ...@@ -7,11 +7,12 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Scanner; import java.util.Scanner;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
public class RoadSideUnitInformationHandler { public class RoadSideUnitInformationHandler {
private List<Position> _positions = new ArrayList<>(); private List<Location> _positions = new ArrayList<>();
private boolean _observedAreaSet = false; private boolean _observedAreaSet = false;
private double _startX = -1; private double _startX = -1;
...@@ -19,15 +20,15 @@ public class RoadSideUnitInformationHandler { ...@@ -19,15 +20,15 @@ public class RoadSideUnitInformationHandler {
private double _endX = -1; private double _endX = -1;
private double _endY = -1; private double _endY = -1;
public List<Position> getIntersections() { public List<Location> getIntersections() {
if (!_observedAreaSet) { if (!_observedAreaSet) {
return _positions; return _positions;
} else { } else {
List<Position> result = new ArrayList<>(); List<Location> result = new ArrayList<>();
for (Position position : _positions) { for (Location position : _positions) {
if (_startX <= position.getX() && position.getX() <= _endX && _startY <= position.getY() && position.getY() <= _endY) { if (_startX <= position.getLongitude() && position.getLongitude() <= _endX && _startY <= position.getLatitude() && position.getLatitude() <= _endY) {
result.add(new Position(position.getX() - _startX, position.getY() - _startY, 0, 0)); result.add(new PositionVector(position.getLongitude() - _startX, position.getLatitude() - _startY, 0));
} }
} }
...@@ -49,7 +50,7 @@ public class RoadSideUnitInformationHandler { ...@@ -49,7 +50,7 @@ public class RoadSideUnitInformationHandler {
if (split.length == 2) { if (split.length == 2) {
double x = Double.parseDouble(split[0]); double x = Double.parseDouble(split[0]);
double y = Double.parseDouble(split[1]); double y = Double.parseDouble(split[1]);
_positions.add(new Position(x, y, 0, 0)); _positions.add(new PositionVector(x, y, 0));
} }
} }
} }
......
...@@ -16,14 +16,14 @@ import java.util.Random; ...@@ -16,14 +16,14 @@ import java.util.Random;
import de.tud.kom.p2psim.api.simengine.SimulatorObserver; import de.tud.kom.p2psim.api.simengine.SimulatorObserver;
import de.tud.kom.p2psim.impl.simengine.Simulator; import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tudarmstadt.maki.simonstrator.api.Event; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.EventHandler; import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleInformationContainer;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.EdgeController; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.EdgeController;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.VehicleController; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.VehicleController;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.LocationUtils; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.LocationUtils;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkLane; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkLane;
...@@ -52,6 +52,8 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -52,6 +52,8 @@ public class TraciSimulationController implements VehicleController, SimulationS
private Random _random = Randoms.getRandom(getClass()); private Random _random = Randoms.getRandom(getClass());
private List<RoadNetworkEdge> modifiedEdges = new ArrayList<>();
private static final Map<String, TraciSimulationController> CONTROLLER = new HashMap<>(); private static final Map<String, TraciSimulationController> CONTROLLER = new HashMap<>();
private static final double CLUSTERING_DISTANCE = 50; private static final double CLUSTERING_DISTANCE = 50;
...@@ -69,7 +71,8 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -69,7 +71,8 @@ public class TraciSimulationController implements VehicleController, SimulationS
private double _endX; private double _endX;
private double _endY; private double _endY;
private Map<Double, Map<String, Position>> _positonsByTimestamp = new HashMap<>(); private Map<Double, Map<String, VehicleInformationContainer>> _positonsByTimestamp = new HashMap<>();
private int _futureInformation = 0; private int _futureInformation = 0;
private boolean _initalized = false; private boolean _initalized = false;
...@@ -141,20 +144,20 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -141,20 +144,20 @@ public class TraciSimulationController implements VehicleController, SimulationS
} }
@Override @Override
public Position getVehiclePosition(String pVehicleID) { public Location getVehiclePosition(String pVehicleID) {
return getVehiclePosition(_step, pVehicleID); return getVehiclePosition(_step, pVehicleID);
} }
@Override @Override
public Position getVehiclePosition(double pStep, String pVehicleID) { public Location getVehiclePosition(double pStep, String pVehicleID) {
Map<String, Position> map = _positonsByTimestamp.get(pStep); Map<String, VehicleInformationContainer> map = _positonsByTimestamp.get(pStep);
return map.get(pVehicleID); return map.get(pVehicleID).getPosition();
} }
@Override @Override
public List<Position> getAllIntersections(boolean pCluster) { public List<Location> getAllIntersections(boolean pCluster) {
List<Position> result = new ArrayList<>(); List<Location> result = new ArrayList<>();
SumoCommand intersectionCommand = Junction.getIDList(); SumoCommand intersectionCommand = Junction.getIDList();
...@@ -169,21 +172,21 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -169,21 +172,21 @@ public class TraciSimulationController implements VehicleController, SimulationS
if (_observedAreaSet) { if (_observedAreaSet) {
if (_startX <= sumoPosition.x && sumoPosition.x <= _endX && _startY <= sumoPosition.y && sumoPosition.y <= _endY) { if (_startX <= sumoPosition.x && sumoPosition.x <= _endX && _startY <= sumoPosition.y && sumoPosition.y <= _endY) {
result.add(new Position(sumoPosition.x - _startX, sumoPosition.y - _startY, 0, 0)); result.add(new PositionVector(sumoPosition.x - _startX, sumoPosition.y - _startY, 0));
} }
} else { } else {
result.add(new Position(sumoPosition.x, sumoPosition.y, 0, 0)); result.add(new PositionVector(sumoPosition.x, sumoPosition.y, 0));
} }
} }
if (pCluster) { if (pCluster) {
List<Position> tempResult = new ArrayList<>(); List<Location> tempResult = new ArrayList<>();
outer:for (int i = 0; i < result.size(); i++) { outer:for (int i = 0; i < result.size(); i++) {
Position position = result.get(i); Location position = result.get(i);
for (int j = 0; j < tempResult.size(); j++) { for (int j = 0; j < tempResult.size(); j++) {
Position addedPosition = tempResult.get(j); Location addedPosition = tempResult.get(j);
if (position != addedPosition && LocationUtils.calculateDistance(position, addedPosition) < CLUSTERING_DISTANCE / 1000.0) { if (position != addedPosition && LocationUtils.calculateDistance(position, addedPosition) < CLUSTERING_DISTANCE / 1000.0) {
continue outer; continue outer;
} }
...@@ -204,13 +207,6 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -204,13 +207,6 @@ public class TraciSimulationController implements VehicleController, SimulationS
return false; return false;
} }
try { try {
// for (RoadNetworkEdge roadNetworkEdge : modifiedEdges) {
// SumoCommand setMaxSpeedCommand = Edge.setMaxSpeed(roadNetworkEdge.getEdgeID(), roadNetworkEdge.getOriginalMaxSpeed());
//
// execute(setMaxSpeedCommand);
// }
_connection.do_timestep(); _connection.do_timestep();
try { try {
...@@ -224,14 +220,19 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -224,14 +220,19 @@ public class TraciSimulationController implements VehicleController, SimulationS
double newStep = _step + _futureInformation; double newStep = _step + _futureInformation;
if (!_positonsByTimestamp.containsKey(newStep)) { if (!_positonsByTimestamp.containsKey(newStep)) {
Map<String, Position> vehiclePositions = new HashMap<>(); Map<String, VehicleInformationContainer> vehiclePositions = new HashMap<>();
_positonsByTimestamp.put(newStep, vehiclePositions); _positonsByTimestamp.put(newStep, vehiclePositions);
List<String> allVehicles = requestAllVehicles(); List<String> allVehicles = requestAllVehicles();
for (String vehicle : allVehicles) { for (String vehicle : allVehicles) {
Position vehiclePosition = requestVehiclePosition(vehicle); Location position = requestVehiclePosition(vehicle);
if (vehiclePosition != null) { if (position != null) {
vehiclePositions.put(vehicle, vehiclePosition); double heading = requestVehicleHeading(vehicle);
double speed = requestVehicleSpeed(vehicle);
VehicleInformationContainer informationContainer = new VehicleInformationContainer(position, heading, speed);
vehiclePositions.put(vehicle, informationContainer);
} }
} }
} }
...@@ -243,12 +244,6 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -243,12 +244,6 @@ public class TraciSimulationController implements VehicleController, SimulationS
e.printStackTrace(); e.printStackTrace();
} }
// for (RoadNetworkEdge roadNetworkEdge : modifiedEdges) {
// SumoCommand setMaxSpeedCommand = Edge.setMaxSpeed(roadNetworkEdge.getEdgeID(), roadNetworkEdge.getMaxSpeed());
//
// execute(setMaxSpeedCommand);
// }
return true; return true;
} catch (RuntimeException e) { } catch (RuntimeException e) {
throw e; throw e;
...@@ -258,7 +253,7 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -258,7 +253,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
return false; return false;
} }
private Position requestVehiclePosition(String pVehicleID) { private Location requestVehiclePosition(String pVehicleID) {
if (_vehiclesOutOfRange.containsKey(pVehicleID)) { if (_vehiclesOutOfRange.containsKey(pVehicleID)) {
if (_vehiclesOutOfRange.get(pVehicleID) < _step) { if (_vehiclesOutOfRange.get(pVehicleID) < _step) {
return null; return null;
...@@ -268,20 +263,14 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -268,20 +263,14 @@ public class TraciSimulationController implements VehicleController, SimulationS
} }
SumoCommand positionCommand = Vehicle.getPosition(pVehicleID); SumoCommand positionCommand = Vehicle.getPosition(pVehicleID);
SumoCommand angleCommand = Vehicle.getAngle(pVehicleID);
SumoCommand speedCommand = Vehicle.getSpeed(pVehicleID);
Object positionObject = requestObject(positionCommand); Object positionObject = requestObject(positionCommand);
Object angleObject = requestObject(angleCommand);
Object speedObject = requestObject(speedCommand);
SumoPosition2D sumoPosition = (SumoPosition2D) positionObject; SumoPosition2D sumoPosition = (SumoPosition2D) positionObject;
double angle = (Double) angleObject;
double speed = (Double) speedObject;
if (_observedAreaSet) { if (_observedAreaSet) {
if (_startX <= sumoPosition.x && sumoPosition.x <= _endX && _startY <= sumoPosition.y && sumoPosition.y <= _endY) { if (_startX <= sumoPosition.x && sumoPosition.x <= _endX && _startY <= sumoPosition.y && sumoPosition.y <= _endY) {
return new Position(sumoPosition.x - _startX, sumoPosition.y - _startY, 0, angle, speed); return new PositionVector(sumoPosition.x - _startX, sumoPosition.y - _startY, 0);
} else { } else {
double diffX = _startX - sumoPosition.x; double diffX = _startX - sumoPosition.x;
if (diffX < 0 || sumoPosition.x - _endX < diffX) { if (diffX < 0 || sumoPosition.x - _endX < diffX) {
...@@ -306,8 +295,48 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -306,8 +295,48 @@ public class TraciSimulationController implements VehicleController, SimulationS
return null; return null;
} }
} else { } else {
return new Position(sumoPosition.x, sumoPosition.y, 0, angle); return new PositionVector(sumoPosition.x, sumoPosition.y, 0);
}
} }
private double requestVehicleHeading(String pVehicleID) {
if (_vehiclesOutOfRange.containsKey(pVehicleID)) {
if (_vehiclesOutOfRange.get(pVehicleID) < _step) {
return -1;
} else {
_vehiclesOutOfRange.remove(pVehicleID);
}
}
SumoCommand angleCommand = Vehicle.getAngle(pVehicleID);
Object angleObject = requestObject(angleCommand);
if (angleObject != null) {
return (Double) angleObject;
}
return -1;
}
private double requestVehicleSpeed(String pVehicleID) {
if (_vehiclesOutOfRange.containsKey(pVehicleID)) {
if (_vehiclesOutOfRange.get(pVehicleID) < _step) {
return -1;
} else {
_vehiclesOutOfRange.remove(pVehicleID);
}
}
SumoCommand speedCommand = Vehicle.getSpeed(pVehicleID);
Object speedObject = requestObject(speedCommand);
if (speedObject != null) {
return (Double) speedObject;
}
return -1;
} }
private List<String> requestAllVehicles() { private List<String> requestAllVehicles() {
...@@ -331,7 +360,7 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -331,7 +360,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
@Override @Override
public List<String> getAllVehicles(double pStep) { public List<String> getAllVehicles(double pStep) {
Map<String, Position> map = _positonsByTimestamp.get(pStep); Map<String, VehicleInformationContainer> map = _positonsByTimestamp.get(pStep);
return new ArrayList<>(map.keySet()); return new ArrayList<>(map.keySet());
} }
......
...@@ -4,12 +4,13 @@ import org.xml.sax.Attributes; ...@@ -4,12 +4,13 @@ import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.DefaultHandler;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
public class SimulationSetupInformationHandler extends DefaultHandler { public class SimulationSetupInformationHandler extends DefaultHandler {
private Position _upperLeft; private Location _upperLeft;
private Position _lowerRight; private Location _lowerRight;
@Override @Override
public void startElement(String pUri, String pLocalName, String pQName, Attributes pAttributes) public void startElement(String pUri, String pLocalName, String pQName, Attributes pAttributes)
...@@ -18,18 +19,18 @@ public class SimulationSetupInformationHandler extends DefaultHandler { ...@@ -18,18 +19,18 @@ public class SimulationSetupInformationHandler extends DefaultHandler {
String meterBoundary = pAttributes.getValue("convBoundary"); String meterBoundary = pAttributes.getValue("convBoundary");
if (meterBoundary != null) { if (meterBoundary != null) {
String[] edges = meterBoundary.split(","); String[] edges = meterBoundary.split(",");
_upperLeft = new Position(Double.valueOf(edges[0]), Double.valueOf(edges[1]), 0, 0); _upperLeft = new PositionVector(Double.valueOf(edges[0]), Double.valueOf(edges[1]), 0);
_lowerRight = new Position(Double.valueOf(edges[2]), Double.valueOf(edges[3]), 0, 0); _lowerRight = new PositionVector(Double.valueOf(edges[2]), Double.valueOf(edges[3]), 0);
} }
throw new CancelParsingSAXException(); throw new CancelParsingSAXException();
} }
} }
public Position getLowerRight() { public Location getLowerRight() {
return _lowerRight; return _lowerRight;
} }
public Position getUpperLeft() { public Location getUpperLeft() {
return _upperLeft; return _upperLeft;
} }
} }
...@@ -6,12 +6,13 @@ import org.xml.sax.Attributes; ...@@ -6,12 +6,13 @@ import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.DefaultHandler;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleInformationContainer;
public class VehicleDataInformationHandler extends DefaultHandler { public class VehicleDataInformationHandler extends DefaultHandler {
private boolean _next = true; private boolean _next = true;
private boolean _run = true; private boolean _run = true;
private HashMap<String, Position> _vehiclePositions = new HashMap<>(); private HashMap<String, VehicleInformationContainer> _vehiclePositions = new HashMap<>();
private double _currentStep = -1; private double _currentStep = -1;
private boolean _observedAreaSet = false; private boolean _observedAreaSet = false;
...@@ -20,7 +21,7 @@ public class VehicleDataInformationHandler extends DefaultHandler { ...@@ -20,7 +21,7 @@ public class VehicleDataInformationHandler extends DefaultHandler {
private double _endX = -1; private double _endX = -1;
private double _endY = -1; private double _endY = -1;
private HashMap<String, Position> _nextVehiclePositions = new HashMap<>(); private HashMap<String, VehicleInformationContainer> _nextVehiclePositions = new HashMap<>();
private double _nextStep = -1; private double _nextStep = -1;
private static final String doublePattern = "-?[0-9]*\\.?[0-9]+"; private static final String doublePattern = "-?[0-9]*\\.?[0-9]+";
...@@ -57,10 +58,10 @@ public class VehicleDataInformationHandler extends DefaultHandler { ...@@ -57,10 +58,10 @@ public class VehicleDataInformationHandler extends DefaultHandler {
if (_observedAreaSet) { if (_observedAreaSet) {
if (_startX <= lon && lon <= _endX && _startY <= lat && lat <= _endY) { if (_startX <= lon && lon <= _endX && _startY <= lat && lat <= _endY) {
_nextVehiclePositions.put(id, new Position(lon - _startX, lat - _startY, 0, heading, speed)); _nextVehiclePositions.put(id, new VehicleInformationContainer(new PositionVector(lon - _startX, lat - _startY, 0), heading, speed));
} }
} else { } else {
_nextVehiclePositions.put(id, new Position(lon, lat, 0, heading, speed)); _nextVehiclePositions.put(id, new VehicleInformationContainer(new PositionVector(lon, lat, 0), heading, speed));
} }
} }
} }
...@@ -97,7 +98,7 @@ public class VehicleDataInformationHandler extends DefaultHandler { ...@@ -97,7 +98,7 @@ public class VehicleDataInformationHandler extends DefaultHandler {
return _terminated; return _terminated;
} }
public HashMap<String, Position> getVehiclePositions() { public HashMap<String, VehicleInformationContainer> getVehiclePositions() {
return _vehiclePositions; return _vehiclePositions;
} }
......
...@@ -10,10 +10,11 @@ import java.util.Map; ...@@ -10,10 +10,11 @@ import java.util.Map;
import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory; import javax.xml.parsers.SAXParserFactory;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleInformationContainer;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.csv.RoadSideUnitInformationHandler; import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.csv.RoadSideUnitInformationHandler;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.VehicleController; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.VehicleController;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkEdge;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
...@@ -26,7 +27,7 @@ public class XMLSimulationController implements VehicleController, SimulationSet ...@@ -26,7 +27,7 @@ public class XMLSimulationController implements VehicleController, SimulationSet
private List<String> _vehicles; private List<String> _vehicles;
private Map<Double, Map<String, Position>> _positonsByTimestamp = new HashMap<>(); private Map<Double, Map<String, VehicleInformationContainer>> _positonsByTimestamp = new HashMap<>();
private int _futureInformation = 10; private int _futureInformation = 10;
private boolean _initalized = false; private boolean _initalized = false;
...@@ -67,11 +68,11 @@ public class XMLSimulationController implements VehicleController, SimulationSet ...@@ -67,11 +68,11 @@ public class XMLSimulationController implements VehicleController, SimulationSet
} }
@Override @Override
public Position getVehiclePosition(String pVehicleID) { public Location getVehiclePosition(String pVehicleID) {
return getVehiclePosition(_step, pVehicleID); return getVehiclePosition(_step, pVehicleID);
} }
public Position requestVehiclePosition(String pVehicleID) { public VehicleInformationContainer requestVehicleInformation(String pVehicleID) {
return _vehicleDataInformationHandler.getVehiclePositions().get(pVehicleID); return _vehicleDataInformationHandler.getVehiclePositions().get(pVehicleID);
} }
...@@ -86,12 +87,12 @@ public class XMLSimulationController implements VehicleController, SimulationSet ...@@ -86,12 +87,12 @@ public class XMLSimulationController implements VehicleController, SimulationSet
double newStep = _step + _futureInformation; double newStep = _step + _futureInformation;
if (!_positonsByTimestamp.containsKey(newStep)) { if (!_positonsByTimestamp.containsKey(newStep)) {
Map<String, Position> vehiclePositions = new HashMap<>(); Map<String, VehicleInformationContainer> vehiclePositions = new HashMap<>();
_positonsByTimestamp.put(newStep, vehiclePositions); _positonsByTimestamp.put(newStep, vehiclePositions);
List<String> allVehicles = new ArrayList<>(_vehicleDataInformationHandler.getVehiclePositions().keySet()); List<String> allVehicles = new ArrayList<>(_vehicleDataInformationHandler.getVehiclePositions().keySet());
for (String vehicle : allVehicles) { for (String vehicle : allVehicles) {
Position vehiclePosition = requestVehiclePosition(vehicle); VehicleInformationContainer vehiclePosition = requestVehicleInformation(vehicle);
if (vehiclePosition != null) { if (vehiclePosition != null) {
vehiclePositions.put(vehicle, vehiclePosition); vehiclePositions.put(vehicle, vehiclePosition);
} }
...@@ -135,15 +136,15 @@ public class XMLSimulationController implements VehicleController, SimulationSet ...@@ -135,15 +136,15 @@ public class XMLSimulationController implements VehicleController, SimulationSet
} }
@Override @Override
public Position getVehiclePosition(double pStep, String pVehicleID) { public Location getVehiclePosition(double pStep, String pVehicleID) {
Map<String, Position> map = _positonsByTimestamp.get(pStep); Map<String, VehicleInformationContainer> map = _positonsByTimestamp.get(pStep);
return map.get(pVehicleID); return map.get(pVehicleID).getPosition();
} }
@Override @Override
public List<String> getAllVehicles(double pStep) { public List<String> getAllVehicles(double pStep) {
Map<String, Position> map = _positonsByTimestamp.get(pStep); Map<String, VehicleInformationContainer> map = _positonsByTimestamp.get(pStep);
return new ArrayList<>(map.keySet()); return new ArrayList<>(map.keySet());
} }
...@@ -156,7 +157,7 @@ public class XMLSimulationController implements VehicleController, SimulationSet ...@@ -156,7 +157,7 @@ public class XMLSimulationController implements VehicleController, SimulationSet
} }
@Override @Override
public List<Position> getAllIntersections(boolean pCluster) { public List<Location> getAllIntersections(boolean pCluster) {
return _roadSideUnitInformationHandler.getIntersections(); return _roadSideUnitInformationHandler.getIntersections();
} }
......
...@@ -25,11 +25,10 @@ import java.util.List; ...@@ -25,11 +25,10 @@ import java.util.List;
import de.tud.kom.p2psim.api.topology.TopologyComponent; import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.placement.PlacementModel; import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.VehicleMovementModel;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.traci.TraciSimulationController; import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.traci.TraciSimulationController;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.XMLSimulationController; import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.xml.XMLSimulationController;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/** /**
...@@ -48,7 +47,7 @@ public class RSUPlacement implements PlacementModel { ...@@ -48,7 +47,7 @@ public class RSUPlacement implements PlacementModel {
private SimulationSetupExtractor _controller; private SimulationSetupExtractor _controller;
private List<Position> _intersections; private List<Location> _intersections;
private int _currentIndex = 0; private int _currentIndex = 0;
@XMLConfigurableConstructor({ "sumoExe", "sumoConfigFile", "offsetX", "offsetY", "width", "height" }) @XMLConfigurableConstructor({ "sumoExe", "sumoConfigFile", "offsetX", "offsetY", "width", "height" })
...@@ -107,9 +106,9 @@ public class RSUPlacement implements PlacementModel { ...@@ -107,9 +106,9 @@ public class RSUPlacement implements PlacementModel {
@Override @Override
public PositionVector place(TopologyComponent comp) { public PositionVector place(TopologyComponent comp) {
if (_currentIndex < _intersections.size()) { if (_currentIndex < _intersections.size()) {
Position intersection = _intersections.get(_currentIndex); Location intersection = _intersections.get(_currentIndex);
_currentIndex++; _currentIndex++;
return new PositionVector(intersection.getX(), intersection.getY()); return new PositionVector(intersection.getLongitude(), intersection.getLatitude());
} else { } else {
return new PositionVector(Double.NaN, Double.NaN); return new PositionVector(Double.NaN, Double.NaN);
} }
......
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