Commit 4c5498cd authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Removed position and added comments to interfaces

parent 5695b105
......@@ -2,8 +2,33 @@ package de.tudarmstadt.maki.simonstrator.api.component.vehicular.api;
public interface EdgeController {
/**
* This method is used to restrict the shown vehicles to the vehicles in a
* certain area.
*
* @param pStartX
* the x-start of the observed area
* @param pStartY
* the y-start of the observed area
* @param pEndX
* the x-end of the observed area
* @param pEndY
* the x-end of the observed area
*/
void setObservedArea(double pStartX, double pStartY, double pEndX, double pEndY);
/**
* Initializes the controller
*/
void init();
/**
* set the maximum allowed edge speed, can be used for congestion etc.
*
* @param pEdgeID
* the id of the edge
* @param pMaxSpeed
* the new maximum allowed speed
*/
void setEdgeMaxSpeed(String pEdgeID, double pMaxSpeed);
}
......@@ -2,18 +2,64 @@ package de.tudarmstadt.maki.simonstrator.api.component.vehicular.api;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork;
/**
*
* @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de)
* @version 1.0 at 06.11.2017
*
*/
public interface SimulationSetupExtractor {
/**
* This method is used to restrict the shown vehicles to the vehicles in a
* certain area.
*
* @param pStartX
* the x-start of the observed area
* @param pStartY
* the y-start of the observed area
* @param pEndX
* the x-end of the observed area
* @param pEndY
* the x-end of the observed area
*/
void setObservedArea(double pStartX, double pStartY, double pEndX, double pEndY);
/**
* Initializes the controller
*/
void init();
List<Position> getAllIntersections(boolean pCluster);
/**
* get all intersections on the map
*
* @param pCluster
* true, if close intersections shall be clustered
* @return the list of all intersections
*/
List<Location> getAllIntersections(boolean pCluster);
/**
* get the width of the scenario
*
* @return the width of the scenario
*/
double getScenarioWidth();
/**
* get the height of the scenario
*
* @return the height of the scenario
*/
double getScenarioHeight();
/**
* get the road network
*
* @return the road network
*/
RoadNetwork getRoadNetwork();
}
......@@ -2,40 +2,180 @@ package de.tudarmstadt.maki.simonstrator.api.component.vehicular.api;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
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.exception.NoAdditionalRouteAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.exception.NoExitAvailableException;
/**
*
* @author Tobias Meuser (tobias.meuser@kom.tu-darmstadt.de)
* @version 1.0 at 06.11.2017
*
*/
public interface VehicleController {
/**
* This method is used to restrict the shown vehicles to the vehicles in a
* certain area.
*
* @param pStartX
* the x-start of the observed area
* @param pStartY
* the y-start of the observed area
* @param pEndX
* the x-end of the observed area
* @param pEndY
* the x-end of the observed area
*/
void setObservedArea(double pStartX, double pStartY, double pEndX, double pEndY);
Position getVehiclePosition(String pVehicleID);
Position getVehiclePosition(double pStep, String pVehicleID);
/**
* Get the position of a vehicle
*
* @param pVehicleID
* the vehicle id of the vehicle (provided by
* {@link #getAllVehicles()})
* @return the position of the vehicle
*/
Location getVehiclePosition(String pVehicleID);
/**
* Get the position of a vehicle at a certain timestep. The maximum
* available timestep can be requested with
* {@link #getMaximumAvailablePrediction()}
*
* @param pStep
* the timestep at which the position is requested
* @param pVehicleID
* the vehicle id of the vehicle (provided by
* {@link #getAllVehicles()})
* @return the position of the vehicle
*/
Location getVehiclePosition(double pStep, String pVehicleID);
/**
* Perform the next step of the simulator.
*
* @return True if successful, false otherwise
*/
boolean nextStep();
/**
* Get the ids of all vehicles in the streets.
*
* @return a list of all vehicles ids
*/
List<String> getAllVehicles();
/**
* Get the ids of all vehicles in the streets at a certain timestep.
*
* @param pStep
* the timestep at which the active vehicles are requested
* @return a list of all vehicles ids
*/
List<String> getAllVehicles(double pStep);
/**
* Returns the current route of the vehicle, only available for
* {@link de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.traci.TraciSimulationController}
*
* @param pVehicleID
* the vehicle id of the vehicle (provided by
* {@link #getAllVehicles()})
* @return The current route of the vehicle
*/
RoadNetworkRoute getCurrentRoute(String pVehicleID);
/**
* Returns the maximum available prediction
*
* @return the maximum available prediction
*/
double getMaximumAvailablePrediction();
/**
* Change the route of a vehicle
*
* @param pVehicle
* the vehicle id of the vehicle (provided by
* {@link #getAllVehicles()})
* @param pRoute
* the new route of the vehicle
*/
void rerouteVehicle(String pVehicle, RoadNetworkRoute pRoute);
/**
* Finds a new route of the vehicle towards the given destination
*
* @param pVehicle
* the vehicle id of the vehicle (provided by
* {@link #getAllVehicles()})
* @return a new route for the vehicle
* @throws NoAdditionalRouteAvailableException
* if no additional route is found
*/
RoadNetworkRoute findNewRoute(String pVehicle)
throws NoAdditionalRouteAvailableException;
/**
* Finds a new route of the vehicle towards the given destination
*
* @param pVehicle
* the vehicle id of the vehicle (provided by
* {@link #getAllVehicles()})
* @param pEdgesToAvoid
* Edges that must not be included in the route
* @param pKeepDestination
* should the destination be kept or is route possible
* @return a new route for the vehicle
* @throws NoAdditionalRouteAvailableException
* if no additional route is found
* @throws NoExitAvailableException
* if no exit is found
*/
RoadNetworkRoute findNewRoute(String pVehicle,
List<RoadNetworkEdge> pEdgesToAvoid, boolean pKeepDestination)
throws NoAdditionalRouteAvailableException,
NoExitAvailableException;
/**
* get the current step of the simulator
*
* @return the step of the simulator
*/
double getStep();
/**
* get the start time of the simulator
*
* @return the start time of the simulator
*/
double getStart();
/**
* Initializes the controller
*/
void init();
/**
* get speed of a vehicle speed
*
* @param pVehicleID
* the vehicle id of the vehicle (provided by
* {@link #getAllVehicles()})
* @return the current speed of the vehicle
*/
double getVehicleSpeed(String pVehicleID);
/**
* Stops the vehicle
*
* @param pVehicle
* the vehicle id of the vehicle (provided by
* {@link #getAllVehicles()})
*/
void stopVehicle(String pVehicle);
}
......@@ -3,6 +3,8 @@ package de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information
import java.util.HashMap;
import java.util.Map;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
public class LocationUtils {
private static boolean _saveID = false;
private static Map<String, Long> _ids = new HashMap<>();
......@@ -32,7 +34,8 @@ public class LocationUtils {
return numericalID;
}
public static double calculateDistance(Position start, Position end) {
return Math.sqrt(Math.pow(end.getY() - start.getY(), 2) + Math.pow(end.getX() - start.getX(), 2)) / 1000.0;
public static double calculateDistance(Location start, Location end) {
return Math.sqrt(Math.pow(end.getLatitude() - start.getLatitude(), 2)
+ Math.pow(end.getLongitude() - start.getLongitude(), 2)) / 1000.0;
}
}
package de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information;
import java.util.Comparator;
public class NoDublicatePositionComparator implements Comparator<Position> {
@Override
public int compare(Position pPos1, Position pPos2) {
int compare = Double.compare(pPos1.getY(), pPos2.getY());
if (compare == 0) {
compare = Double.compare(pPos1.getX(), pPos2.getX());
if (compare == 0) {
compare = Double.compare(pPos1.getAlt(), pPos2.getAlt());
if (compare == 0) {
compare = Double.compare(pPos1.getHeading(), pPos2.getHeading());
}
}
}
return compare;
}
}
package de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information;
import java.io.Serializable;
/**
* @deprecated We should not have a second representation of locations within
* the API. Try to mask the functionality behind Location (which now
* provides speed and heading)
*/
@Deprecated
public class Position implements Serializable, Comparable<Position> {
/**
*
*/
private static final long serialVersionUID = -5007352031660976321L;
public static final double EQUAL_DISTANCE = 0.0;
private static final double EQUAL_HEADING = 5;
private static final double EQUAL_ALT = 10;
private double _y;
private double _x;
private double _heading;
private double _alt;
private double _speed;
public Position(double pX, double pY, double pAlt, double pHeading, double pSpeed) {
_x = pX;
_y = pY;
_alt = pAlt;
_heading = pHeading;
_speed = pSpeed;
}
public Position(double pX, double pY, double pAlt, double pHeading) {
this(pX, pY, pAlt, pHeading, 0);
}
public double getY() {
return _y;
}
public void setY(double pY) {
_y = pY;
}
public double getX() {
return _x;
}
public void setX(double pX) {
_x = pX;
}
public double getHeading() {
return _heading;
}
public void setHeading(double pHeading) {
_heading = pHeading;
}
public double getAlt() {
return _alt;
}
public void setAlt(double pAlt) {
_alt = pAlt;
}
public double getSpeed() {
return _speed;
}
public void setSpeed(double pSpeed) {
_speed = pSpeed;
}
@Override
public String toString() {
return _y + "/" + _x + " (" + _heading + ")";
}
@Override
public int hashCode() {
return 0;
}
@Override
public boolean equals(Object pObj) {
if (pObj instanceof Position) {
Position start = (Position) pObj;
double difference = LocationUtils.calculateDistance(start, this);
if (difference <= EQUAL_DISTANCE) {
if (Math.abs(getAlt() - start.getAlt()) < EQUAL_ALT) {
if (Math.abs(getHeading() - start.getHeading()) < EQUAL_HEADING) {
return true;
}
}
}
}
return false;
}
@Override
public int compareTo(Position pPosition) {
if (Math.abs(_y - pPosition.getY()) < 1 / 1000.0
&& Math.abs(_x - pPosition.getX()) < 1 / 1000.0
&& Math.abs(_alt - pPosition.getAlt()) <= EQUAL_ALT
&& Math.abs(_heading - pPosition.getHeading()) <= EQUAL_HEADING) {
if (equals(pPosition)) {
return 0;
}
}
int compare = Double.compare(_y, pPosition.getY());
if (compare == 0) {
compare = Double.compare(_x, pPosition.getX());
if (compare == 0) {
compare = Double.compare(_alt, pPosition.getAlt());
if (compare == 0) {
compare = Double.compare(_heading, pPosition.getHeading());
}
}
}
return compare;
}
}
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