Skip to content

Commit

Permalink
Simplify road model by removing Edge entity (#45)
Browse files Browse the repository at this point in the history
* Convert route to connection ids if the database originates from a Network file

Signed-off-by: Karl Schrab <[email protected]>

* First draft removing Edge from road model.

Signed-off-by: Karl Schrab <[email protected]>

* applied road model changes to integration tests

Signed-off-by: Karl Schrab <[email protected]>

* fixed error in RouteManagerTest due to merge

Signed-off-by: Karl Schrab <[email protected]>

* Edge class is only used for map-matching purposes

Signed-off-by: Karl Schrab <[email protected]>

* removed id field from Edge

Signed-off-by: Karl Schrab <[email protected]>

* fixed integration tests

Signed-off-by: Karl Schrab <[email protected]>

* fixed name of getter in output_config.xml

Signed-off-by: Karl Schrab <[email protected]>

* removed legacy code for old network files

Signed-off-by: Karl Schrab <[email protected]>

* re-exported netfile fixed initial depart position

Signed-off-by: Karl Schrab <[email protected]>

* Allow transformation to UTM with a target zone

this allows batch transformation of geographic points which
are spread across multiple UTM zones (e.g. neighboring zones)

Signed-off-by: Karl Schrab <[email protected]>

* use global option instead of additional method

Signed-off-by: Karl Schrab <[email protected]>

* Applied road model change on RoadPositionFactory and LazyLoadingRoadPosition

Signed-off-by: Karl Schrab <[email protected]>

* Removed "StartNodeId" from RoutingPosition as it is not needed anymore

Signed-off-by: Karl Schrab <[email protected]>

* fixed comment and renamed getter to match conventions

Signed-off-by: Karl Schrab <[email protected]>

* resolved findbugs warnings

Signed-off-by: Karl Schrab <[email protected]>

* resolved FIXMEs in code

Signed-off-by: Karl Schrab <[email protected]>

* do not add connection if already existing 🤞

Signed-off-by: Karl Schrab <[email protected]>

* Cleanup and minor renamings

Signed-off-by: Karl Schrab <[email protected]>

* clean code

Signed-off-by: Karl Schrab <[email protected]>
  • Loading branch information
kschrab authored Mar 10, 2021
1 parent 327f98f commit 84a4eac
Show file tree
Hide file tree
Showing 93 changed files with 74,310 additions and 154,803 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void onStartup() {
private void closeEdges(Route routeToClose, int numberOfLanesToClose) {
getLog().info("Closing {} lanes along route {}", numberOfLanesToClose, routeToClose.getId());

for (String edge : routeToClose.getEdgeIds()) {
for (String edge : routeToClose.getConnectionIds()) {
for (int lane = 0; lane < numberOfLanesToClose; lane++) {
getOs().changeLaneState(edge, lane).closeForAll();
}
Expand All @@ -72,7 +72,7 @@ private void closeEdges(Route routeToClose, int numberOfLanesToClose) {
private void openEdges(Route routeToClose, int numberOfLanesToClose) {
getLog().info("Opening {} lanes along route {}", numberOfLanesToClose, routeToClose.getId());

for (String edge : routeToClose.getEdgeIds()) {
for (String edge : routeToClose.getConnectionIds()) {
for (int lane = 0; lane < numberOfLanesToClose; lane++) {
getOs().changeLaneState(edge, lane).openForAll();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,17 @@

public final class TrafficLightApp extends AbstractApplication<TrafficLightOperatingSystem> implements CommunicationApplication {
public final static String SECRET = "open sesame!";
private final static long TIME_INTERVAL = TIME.SECOND;
private final static short GREEN_DURATION = 20;
private boolean switched = false;
private short ctr = 0;
private final static short GREEN_DURATION = 10;

@Override
public void processEvent(Event event) throws Exception {
sample();
}
private static final String DEFAULT_PROGRAM = "1";
private static final String GREEN_PROGRAM = "0";

@Override
public void onStartup() {
getLog().infoSimTime(this, "Initialize application");
getOs().getAdHocModule().enable();
getLog().infoSimTime(this, "Activated Wifi Module");
setRed();
sample();
}

private void sample() {
getOs().getEventManager().addEvent(
getOs().getSimulationTime() + TIME_INTERVAL, this
);
if (switched) {
if (++ctr == GREEN_DURATION) {
setRed();
}
}
}

@Override
Expand All @@ -64,28 +47,30 @@ public void onShutdown() {
}

private void setGreen() {
getOs().switchToProgram("0");
getOs().switchToProgram(GREEN_PROGRAM);
getLog().infoSimTime(this, "Setting traffic lights to GREEN");

getOs().getEventManager().addEvent(
getOs().getSimulationTime() + GREEN_DURATION * TIME.SECOND,
(e) -> setRed()
);
}

private void setRed() {
getOs().switchToProgram("1");
getOs().switchToProgram(DEFAULT_PROGRAM);
getLog().infoSimTime(this, "Setting traffic lights to RED");

}

@Override
public void onMessageReceived(ReceivedV2xMessage receivedV2xMessage) {
if (switched) {
return;
}
if (receivedV2xMessage.getMessage() instanceof GreenWaveMsg) {
getLog().infoSimTime(this, "Received GreenWaveMsg");
if (((GreenWaveMsg) receivedV2xMessage.getMessage()).getMessage().equals(SECRET)) {
getLog().infoSimTime(this, "Received correct passphrase: {}", SECRET);
setGreen();
switched = true;

if (DEFAULT_PROGRAM.equals(getOs().getCurrentProgram().getProgramId())) {
setGreen();
}
}
}
}
Expand All @@ -104,5 +89,10 @@ public void onCamBuilding(CamBuilder camBuilder) {
public void onMessageTransmitted(V2xMessageTransmission v2xMessageTransmission) {
// nop
}

@Override
public void processEvent(Event event) throws Exception {
// nop
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private void reactOnEnvironmentData(SensorType type, int strength) {
// longLat of the vehicle that detected an event.
GeoPoint vehicleLongLat = getOs().getPosition();

// roadId (connectionId) of the vehicle that detected an event.
// ID of the connection on which the vehicle detected an event.
String roadId = getOs().getVehicleData().getRoadPosition().getConnection().getId();

getLog().infoSimTime(this, "Sensor {} event detected", type);
Expand Down Expand Up @@ -246,7 +246,7 @@ private void reactUponDENMessageChangeRoute(Denm denm) {
* would decrease dramatically. This may change in the future.
* Until this, the routeChanged variable is used.
*/
final String affectedRoadId = denm.getEventRoadId();
final String affectedConnectionId = denm.getEventRoadId();
final VehicleRoute routeInfo = Objects.requireNonNull(getOs().getNavigationModule().getCurrentRoute());

// Print some useful DEN message information
Expand All @@ -260,14 +260,13 @@ private void reactUponDENMessageChangeRoute(Denm denm) {
}

// Retrieving whether the event we have been notified of is on the vehicle's route
for (final String edges : routeInfo.getEdgeIdList()) {
for (final String connection : routeInfo.getConnectionIds()) {
// Retrieve only the connection id and throw away the edge id
// NOTE: a route info id has the format connectionId_edgeId
final String v_roadId = edges.substring(0, edges.lastIndexOf("_"));
if (v_roadId.equals(affectedRoadId)) {
getLog().infoSimTime(this, "The Event is on the vehicle's route {} = {}", v_roadId, affectedRoadId);
if (connection.equals(affectedConnectionId)) {
getLog().infoSimTime(this, "The Event is on the vehicle's route {} = {}", connection, affectedConnectionId);

circumnavigateAffectedRoad(denm, affectedRoadId);
circumnavigateAffectedRoad(denm, affectedConnectionId);
routeChanged = true;
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"startingTime": 5.0,
"targetFlow": 1800,
"maxNumberVehicles": 120,
"pos": 1417,
"route": "1",
"lanes": [ 0, 1 ],
"types": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<entry>Updated:Slope</entry>
<entry>Updated:Stopped</entry>
<entry>Updated:RouteId</entry>
<entry>Updated:RoadPosition.EdgeId</entry>
<entry>Updated:RoadPosition.Connection.Id</entry>
<entry>Updated:RoadPosition.LaneIndex</entry>
<entry>Updated:VehicleEmissions.CurrentEmissions.Co2</entry>
<entry>Updated:VehicleEmissions.CurrentEmissions.Co</entry>
Expand Down Expand Up @@ -107,7 +107,7 @@
<entry>TrafficSign.GeoPosition.Longitude</entry>
<entry>TrafficSign.GeoPosition.Altitude</entry>
<entry>TrafficSign.Angle</entry>
<entry>TrafficSign.Edge</entry>
<entry>TrafficSign.ConnectionId</entry>
<entry>TrafficSign.Lane</entry>
<entry>TrafficSign.TypeId</entry>
<entry>TrafficSign.SignContents</entry>
Expand Down
Loading

0 comments on commit 84a4eac

Please sign in to comment.