Commit 1024f054 authored by Tobias Meuser's avatar Tobias Meuser
Browse files

Added additional information to RoadNetworkEdge

parent 1d0530f6
......@@ -3,6 +3,7 @@ package de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.contr
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
......@@ -23,6 +24,7 @@ import de.tudresden.sumo.cmd.Simulation;
import de.tudresden.sumo.cmd.Vehicle;
import de.tudresden.sumo.util.SumoCommand;
import de.tudresden.ws.container.SumoBoundingBox;
import de.tudresden.ws.container.SumoGeometry;
import de.tudresden.ws.container.SumoLink;
import de.tudresden.ws.container.SumoLinkList;
import de.tudresden.ws.container.SumoPosition2D;
......@@ -485,26 +487,37 @@ public class TraciSimulationController implements VehicleController, SimulationS
Map<String, RoadNetworkEdge> roadNetwork = new HashMap<>();
SumoStringList laneIDStringList = (SumoStringList) requestObject(laneIDCommand);
//Requesting all lanes from sumo.
for (String laneID : laneIDStringList) {
SumoCommand edgeIDCommand = Lane.getEdgeID(laneID);
SumoLinkList linkStringList = (SumoLinkList) requestObject(Lane.getLinks(laneID));
double angle = getLaneAngle(laneID);
double maxSpeed = getMaxSpeed(laneID);
if (linkStringList.size() > 0) {
String edgeID = (String) requestObject(edgeIDCommand);
if (!roadNetwork.containsKey(edgeID)) {
roadNetwork.put(edgeID, new RoadNetworkEdge(edgeID));
roadNetwork.put(edgeID, new RoadNetworkEdge(edgeID, angle));
}
RoadNetworkEdge edge = roadNetwork.get(edgeID);
edge.setMaxSpeed(maxSpeed);
edge.increaseLaneAmount();
for (SumoLink link : linkStringList) {
String notInternalLane = link.notInternalLane;
String connectedEdge = (String) requestObject(Lane.getEdgeID(notInternalLane));
double linkAngle = getLaneAngle(laneID);
if (!roadNetwork.containsKey(connectedEdge)) {
roadNetwork.put(connectedEdge, new RoadNetworkEdge(connectedEdge));
roadNetwork.put(connectedEdge, new RoadNetworkEdge(connectedEdge, linkAngle));
}
edge.addConnectedEdge(roadNetwork.get(connectedEdge));
......@@ -517,4 +530,27 @@ public class TraciSimulationController implements VehicleController, SimulationS
}
}
public double getMaxSpeed(String laneID) {
SumoCommand maxSpeedCommand = Lane.getMaxSpeed(laneID);
double maxSpeed = (Double) requestObject(maxSpeedCommand);
return maxSpeed;
}
public double getLaneAngle(String laneID) {
SumoCommand shapeCommand = Lane.getShape(laneID);
SumoGeometry geometry = (SumoGeometry) requestObject(shapeCommand);
LinkedList<SumoPosition2D> coords = geometry.coords;
SumoPosition2D start = coords.getFirst();
SumoPosition2D end = coords.getLast();
double sin = (end.y - start.y) / Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2));
double angle = Math.asin(sin) * 180 / Math.PI;
if (end.x - start.x < 0) {
angle += 180;
}
return angle;
}
}
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