Skip to content

Commit

Permalink
clean(routing): define default navigationConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
kschrab committed Dec 5, 2024
1 parent 2cc5bee commit b8e1def
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public ApplicationAmbassador(AmbassadorParameter ambassadorParameter) {
// set the CNC (central navigation component)
CentralNavigationComponent cnc = new CentralNavigationComponent(
ambassadorParameter,
ambassadorConfig.navigationConfiguration,
ambassadorConfig.publicTransportConfiguration
Validate.notNull(ambassadorConfig.navigationConfiguration, "Field navigationConfiguration must not be null."),
Validate.notNull(ambassadorConfig.publicTransportConfiguration, "Field publicTransportConfiguration must not be null.")
);
SimulationKernel.SimulationKernel.setCentralNavigationComponent(cnc);
}
Expand Down Expand Up @@ -227,6 +227,7 @@ public void initialize(final long startTime, final long endTime) throws Internal

private void shutdownSimulationUnits(Event event) {
SimulationKernel.SimulationKernel.setCurrentSimulationTime(event.getTime());
SimulationKernel.SimulationKernel.getCentralNavigationComponent().close();

log.debug("remaining events: {}", eventScheduler.getAllEvents());
UnitSimulator.UnitSimulator.removeAllSimulationUnits();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import javax.annotation.Nonnull;

/**
* The {@link CentralNavigationComponent} unites functionality concerned with
Expand Down Expand Up @@ -114,8 +115,8 @@ public class CentralNavigationComponent {
*/
public CentralNavigationComponent(
final AmbassadorParameter ambassadorParameter,
CApplicationAmbassador.CRoutingByType navigationConfiguration,
CPublicTransportRouting publicTransportConfiguration
@Nonnull CApplicationAmbassador.CRoutingByType navigationConfiguration,
@Nonnull CPublicTransportRouting publicTransportConfiguration
) {
this.applicationAmbassadorParameter = ambassadorParameter;
this.configuration = navigationConfiguration;
Expand All @@ -138,7 +139,7 @@ public void initialize(RtiAmbassador rtiAmbassador) throws InternalFederateExcep
try {
this.log.info("Initializing CNC-Navigation");

routing = createFromType(this.configuration != null ? this.configuration.type : null);
routing = createFromType(configuration.type);
routing.initialize(configuration, applicationAmbassadorParameter.configuration.getParentFile());

ptRouting = new PtRouting();
Expand Down Expand Up @@ -167,6 +168,12 @@ public void initialize(RtiAmbassador rtiAmbassador) throws InternalFederateExcep
}
}

public void close() {
if (ptRouting != null) {
ptRouting.close();
}
}

/**
* Returns an unmodifiable view of all routes known to the {@link SimulationKernel}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class CApplicationAmbassador implements Serializable {
* Class containing the information for the configuration of the
* Routing/Navigation (CentralNavigationComponent).
*/
public CRoutingByType navigationConfiguration = null;
public CRoutingByType navigationConfiguration = new CRoutingByType();

/**
* Configuration for the perception backend used in the ApplicationSimulator
Expand All @@ -84,7 +84,7 @@ public static class CRoutingByType extends CVehicleRouting implements Serializab
* to use for navigation. Possible values are {@code "database" or "no-routing"},
* or any full-qualified java class name.
*/
public String type = null;
public String type = "database";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
"description": "Configuration options for the route calculation.",
"$ref": "#/definitions/routingByType"
},
"publicTransportConfiguration": {
"description": "Configuration options for the public transport route calculation.",
"$ref": "#/definitions/ptRouting"
},
"perceptionConfiguration": {
"description": "Configuration options for perception backend",
"$ref": "#/definitions/perceptionConfiguration"
Expand All @@ -48,6 +52,38 @@
}
}
},
"ptRouting": {
"title": "ptRouting",
"description": "Object to define the configuration for the public transport route calculation.",
"type": "object",
"properties": {
"enabled": {
"description": "Defines, if public transport routing is enabled.",
"default": false,
"type": "boolean"
},
"osmFile": {
"description": "The relative path to the OSM file to load with the GTFS feed.",
"default": "map.osm",
"type": "string"
},
"gtfsFile": {
"description": "The relative path to the GTFS feed (ZIP archive).",
"default": "gtfs.zip",
"type": "string"
},
"scheduleDateTime": {
"description": "The real time in ISO format at which the beginning of the simulation should point at. Example format: 2024-11-27T10:15:30",
"default": "2024-12-03T10:15:30",
"type": "string"
},
"timeZone": {
"description": " The time zone of the location where the PT system is implemented, e.g., \"ECT\".",
"default": "ECT",
"type": "string"
}
}
},
"perceptionConfiguration": {
"title": "perceptionConfiguration",
"description": "Configuration options for perception backend",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.ArgumentMatchers.same;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -126,7 +125,7 @@ public void initialize_vehicleRoutesInitializationSent() throws InternalFederate
cnc.initialize(rtiAmbassadorMock);

//ASSERT
verify(routingMock).initialize(isNull(CVehicleRouting.class), isA(File.class));
verify(routingMock).initialize(isA(CVehicleRouting.class), isA(File.class));
verify(rtiAmbassadorMock).triggerInteraction(isA(VehicleRoutesInitialization.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import static org.hamcrest.CoreMatchers.startsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -58,8 +57,8 @@ public void readValidConfig_assertProperties() throws InstantiationException {
assertNotNull(applicationAmbassadorConfiguration); // assert that configuration is created
assertEquals(40 * TIME.SECOND, applicationAmbassadorConfiguration.messageCacheTime);
assertTrue(applicationAmbassadorConfiguration.encodePayloads);
assertNull(applicationAmbassadorConfiguration.navigationConfiguration);

assertNotNull(applicationAmbassadorConfiguration.navigationConfiguration);
assertEquals("database", applicationAmbassadorConfiguration.navigationConfiguration.type);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

package org.eclipse.mosaic.lib.routing.config;

public class CPublicTransportRouting {
import java.io.Serializable;

public class CPublicTransportRouting implements Serializable {

/**
* Declares if PT routing is enabled (default=false).
Expand All @@ -33,7 +35,7 @@ public class CPublicTransportRouting {
public String gtfsFile = "gtfs.zip";

/**
* The time in ISO format at which the simulation should start.
* The real time in ISO format at which the beginning of the simulation should point at.
* Example format: 2024-11-27T10:15:30
*/
public String scheduleDateTime = "2024-12-03T10:15:30";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class CVehicleRouting implements Serializable {

/**
* The source for the route calculation, e.g. the path to the database containing the road network.
* The source for the route calculation, e.g., the path to the database containing the road network.
*/
public String source = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public enum Type {
WALKING, VEHICLE_SHARED, VEHICLE_PRIVATE, PUBLIC_TRANSPORT
}

private Type legType;
private final Type legType;

// For legs where a vehicle needs to be spawned
private VehicleDeparture vehicleLeg = null;

// For PTlegs
// For public transport legs
private PtLeg publicTransportationLeg = null;

// For walk legs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public class PtLeg {

public record PtStop(GeoPoint location, Long departureTime, Long arrivalTime) {}

private final List<PtStop> legs = new ArrayList<>();
private final List<PtStop> stops = new ArrayList<>();

public PtLeg(List<PtStop> legs) {
this.legs.addAll(legs);
public PtLeg(List<PtStop> stops) {
this.stops.addAll(stops);
}

public List<PtStop> getLegs() {
return legs;
public List<PtStop> getStops() {
return stops;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class PtRouting {

Expand Down Expand Up @@ -186,18 +188,20 @@ private Instant toScheduleTime(long simTime) {
return scheduleDateTime.plusNanos(simTime).atZone(timeZone).toInstant();
}

private Long fromScheduleTime(Date date) {
private Long fromScheduleTime(@Nullable Date date) {
if (date == null) {
return null;
}
return fromScheduleTime(date.toInstant());
}

private long fromScheduleTime(Instant instant) {
private long fromScheduleTime(@Nonnull Instant instant) {
return scheduleDateTime.until(LocalDateTime.ofInstant(instant, timeZone), ChronoUnit.NANOS);
}

public void close() {
graphHopperGtfs.close();
if (graphHopperGtfs != null) {
graphHopperGtfs.close();
}
}
}

0 comments on commit b8e1def

Please sign in to comment.