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

Moved classes to api to enable manipulation of edges

parent aec314dd
......@@ -31,8 +31,6 @@ import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.network.routed.RoutedNetLayer;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.Position;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.SimulationSetupExtractor;
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.tudarmstadt.maki.simonstrator.api.Host;
......@@ -47,6 +45,8 @@ 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.information.Position;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
public class RSUMovementModel implements MovementModel, FutureLocationSensor {
......
......@@ -33,9 +33,6 @@ import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.network.routed.RoutedNetLayer;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.Position;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.SimulationSetupExtractor;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleController;
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.vehicular.DefaultVehicleInformationComponent;
......@@ -54,6 +51,9 @@ import de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationProvider
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.api.SimulationSetupExtractor;
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.util.XMLConfigurableConstructor;
......
package de.tud.kom.p2psim.impl.topology.movement.vehicular.information;
import java.awt.geom.Point2D;
import java.util.HashMap;
import java.util.Map;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.SimulationSetupInformationProvider;
public class LocationUtils {
private static boolean _saveID = false;
private static Map<String, Long> _ids = new HashMap<>();
private static long _currentID = 0;
public static Position createPosition(Point2D pPosition, double pHeading) {
Position position = SimulationSetupInformationProvider.getOnlyInstance().getUpperLeft();
double lat = position.getY() + pPosition.getY() / 10000000 * 90;
double lon = position.getX() + pPosition.getX()
/ (20000000 * Math.cos(position.getY() / 180 * Math.PI)) * 180;
return new Position(lon, lat, position.getAlt(), pHeading);
}
public static long calculateID(String pID) {
long numericalID = -1;
if (!_saveID) {
try {
String[] split = pID.split("_");
for (int i = 0; i < split.length; i++) {
numericalID *= 100000;
numericalID += Integer.valueOf(split[i]);
}
} catch (NumberFormatException e) {
_saveID = true;
}
}
if (_saveID) {
synchronized (_ids) {
if (!_ids.containsKey(pID)) {
_ids.put(pID, _currentID++);
}
numericalID = _ids.get(pID);
}
}
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;
}
}
package de.tud.kom.p2psim.impl.topology.movement.vehicular.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.tud.kom.p2psim.impl.topology.movement.vehicular.information;
import java.io.Serializable;
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;
}
}
package de.tud.kom.p2psim.impl.topology.movement.vehicular.information;
import java.util.ArrayList;
import java.util.List;
public class Route {
private List<Street> _waypoints;
public Route() {
_waypoints = new ArrayList<>();
}
public List<Street> getStreets() {
return _waypoints;
}
}
package de.tud.kom.p2psim.impl.topology.movement.vehicular.information;
public class Street {
private String _edgeID;
public Street(String pEdgeID) {
_edgeID = pEdgeID;
}
public String getEdgeID() {
return _edgeID;
}
}
package de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller;
import java.util.List;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.Position;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetwork;
public interface SimulationSetupExtractor {
void setObservedArea(double pStartX, double pStartY, double pEndX, double pEndY);
void init();
List<Position> getAllIntersections(boolean pCluster);
double getScenarioWidth();
double getScenarioHeight();
RoadNetwork getRoadNetwork();
}
......@@ -9,9 +9,9 @@ import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.SAXException;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.Position;
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.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
public class SimulationSetupInformationProvider {
private static final SimulationSetupInformationProvider ONLY_INSTANCE = new SimulationSetupInformationProvider();
......
package de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller;
import java.util.List;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.Position;
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;
public interface VehicleController {
void setObservedArea(double pStartX, double pStartY, double pEndX, double pEndY);
Position getVehiclePosition(String pVehicleID);
Position getVehiclePosition(double pStep, String pVehicleID);
boolean nextStep();
List<String> getAllVehicles();
List<String> getAllVehicles(double pStep);
RoadNetworkRoute getCurrentRoute(String pVehicleID);
double getMaximumAvailablePrediction();
void rerouteVehicle(String pVehicle, RoadNetworkRoute pRoute);
RoadNetworkRoute findNewRoute(String pVehicle)
throws NoAdditionalRouteAvailableException;
RoadNetworkRoute findNewRoute(String pVehicle,
List<RoadNetworkEdge> pEdgesToAvoid, boolean pKeepDestination)
throws NoAdditionalRouteAvailableException,
NoExitAvailableException;
double getStep();
double getStart();
void init();
double getVehicleSpeed(String pVehicleID);
void stopVehicle(String pVehicle);
}
......@@ -7,7 +7,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.Position;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
public class RoadSideUnitInformationHandler {
......
......@@ -13,10 +13,11 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.LocationUtils;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.Position;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.SimulationSetupExtractor;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleController;
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.VehicleController;
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.RoadNetworkEdge;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.RoadNetworkRoute;
......@@ -39,7 +40,7 @@ import de.tudresden.ws.container.SumoPosition2D;
import de.tudresden.ws.container.SumoStringList;
import it.polito.appeal.traci.SumoTraciConnection;
public class TraciSimulationController implements VehicleController, SimulationSetupExtractor {
public class TraciSimulationController implements VehicleController, SimulationSetupExtractor, EdgeController {
private static final File TEMP_FILE = new File(new File(System.getProperty("java.io.tmpdir")), "road_network.tmp");
private static final Map<String, TraciSimulationController> CONTROLLER = new HashMap<>();
......@@ -543,7 +544,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
if (readObject instanceof SerializableRoadNetwork) {
SerializableRoadNetwork serializedRoadNetwork = (SerializableRoadNetwork) readObject;
_roadNetwork = new RoadNetwork(serializedRoadNetwork);
_roadNetwork = new RoadNetwork(serializedRoadNetwork, this);
}
inputStream.close();
......@@ -591,12 +592,12 @@ public class TraciSimulationController implements VehicleController, SimulationS
String edgeID = (String) requestObject(edgeIDCommand);
if (!roadNetwork.containsKey(edgeID)) {
roadNetwork.put(edgeID, new RoadNetworkEdge(edgeID, angle));
roadNetwork.put(edgeID, new RoadNetworkEdge(edgeID, angle, this));
}
RoadNetworkEdge edge = roadNetwork.get(edgeID);
edge.setMaxSpeed(maxSpeed);
edge.setOriginalMaxSpeed(maxSpeed);
edge.increaseLaneAmount();
for (SumoLink link : linkStringList) {
......@@ -606,7 +607,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
double linkAngle = getLaneAngle(laneID);
if (!roadNetwork.containsKey(connectedEdge)) {
roadNetwork.put(connectedEdge, new RoadNetworkEdge(connectedEdge, linkAngle));
roadNetwork.put(connectedEdge, new RoadNetworkEdge(connectedEdge, linkAngle, this));
}
edge.addConnectedEdge(roadNetwork.get(connectedEdge));
......@@ -662,4 +663,11 @@ public class TraciSimulationController implements VehicleController, SimulationS
return (Double)object;
}
@Override
public void setEdgeMaxSpeed(String pEdgeID, double pMaxSpeed) {
SumoCommand setMaxSpeedCommand = Edge.setMaxSpeed(pEdgeID, pMaxSpeed);
execute(setMaxSpeedCommand);
}
}
......@@ -4,7 +4,7 @@ import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.Position;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
public class SimulationSetupInformationHandler extends DefaultHandler {
......
......@@ -6,7 +6,7 @@ import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.Position;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.information.Position;
public class VehicleDataInformationHandler extends DefaultHandler {
private boolean _next = true;
......
......@@ -10,10 +10,10 @@ import java.util.Map;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.information.Position;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.SimulationSetupExtractor;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleController;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.csv.RoadSideUnitInformationHandler;
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.information.Position;
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.RoadNetworkRoute;
......
......@@ -26,10 +26,10 @@ import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
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.information.Position;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.SimulationSetupExtractor;
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.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;
/**
......
......@@ -22,10 +22,10 @@ package de.tud.kom.p2psim.impl.vehicular;
import java.util.List;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.SimulationSetupExtractor;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleController;
import de.tudarmstadt.maki.simonstrator.api.Host;
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.VehicleController;
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;
......
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