Skip to content

Commit

Permalink
clean: work after review
Browse files Browse the repository at this point in the history
* unified naming of Pt vs PublicTransport
* moved `vehicle.PublicTransportData` to  `pt.PtVehicleData`.
* added missing javadoc
* fixed walking speed configuration in mapping
  • Loading branch information
kschrab committed Jan 23, 2025
1 parent a4ea233 commit 301fefc
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void useSharedVehicle(String vehicleId) {
public void usePublicTransport(PtRoute publicTransportRoute) {
final List<AgentRoute.Leg> agentLegs = publicTransportRoute.getLegs().stream().map(leg -> {
if (leg instanceof PtRoute.PtLeg ptLeg) {
return new AgentRoute.PublicTransportLeg(leg.getDepartureTime(), ptLeg.getStops());
return new AgentRoute.PtLeg(leg.getDepartureTime(), ptLeg.getStops());
}
if (leg instanceof PtRoute.WalkLeg walkLeg) {
return new AgentRoute.WalkLeg(leg.getDepartureTime(), walkLeg.getWaypoints());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void initialize() throws InternalFederateException {
}
if (routing instanceof DatabaseRouting dbRouting) {
Database database = dbRouting.getScenarioDatabase();
if (!database.getBuildings().isEmpty() && configuration.wallIndex != null) {
if (!database.getBuildings().isEmpty() && configuration.wallIndex != null && configuration.wallIndex.enabled) {
indexBuilder.withWallIndex(configuration.wallIndex.create(), database);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public interface AgentOperatingSystem
extends OperatingSystem, CellCommunicative, Routable, PtRoutable {

/**
* Changes the next leg of the agent to use a private vehicle. The {@link #getRoutingModule()} should be used
* to calculate {@link CandidateRoute}s for such vehicle trip.
* Changes the next leg of the agent to use a private vehicle. It will spawn a new vehicle and assigns this
* agent to it. The {@link #getRoutingModule()} should be used to calculate {@link CandidateRoute}s for such vehicle trip.
*/
void usePrivateVehicle(String vehicleType, CandidateRoute route);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@

package org.eclipse.mosaic.fed.mapping.ambassador.spawning;

import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;

import org.eclipse.mosaic.fed.mapping.ambassador.SpawningFramework;
import org.eclipse.mosaic.fed.mapping.config.CMappingConfiguration;
import org.eclipse.mosaic.fed.mapping.config.CPrototype;
import org.eclipse.mosaic.fed.mapping.config.units.CAgent;
import org.eclipse.mosaic.interactions.mapping.AgentRegistration;
import org.eclipse.mosaic.lib.geo.GeoPoint;
import org.eclipse.mosaic.lib.math.SpeedUtils;
import org.eclipse.mosaic.lib.objects.UnitNameGenerator;
import org.eclipse.mosaic.rti.TIME;
import org.eclipse.mosaic.rti.api.IllegalValueException;
Expand All @@ -38,11 +41,13 @@ public class AgentSpawner extends UnitSpawner implements Spawner {

private static final Logger LOG = LoggerFactory.getLogger(AgentSpawner.class);

private static final double DEFAULT_WALKING_SPEED = SpeedUtils.kmh2ms(5);

private final GeoPoint origin;
private final GeoPoint destination;

private long startingTime;
private double walkingSpeed;
private Double walkingSpeed;

public AgentSpawner(CAgent agentConfiguration) {
super(agentConfiguration.applications, agentConfiguration.name, agentConfiguration.group);
Expand All @@ -59,8 +64,10 @@ public void configure(CMappingConfiguration mappingParameterizationConfiguration
}

public void init(SpawningFramework spawningFramework) throws InternalFederateException {
String name = UnitNameGenerator.nextAgentName();
AgentRegistration interaction = new AgentRegistration(startingTime, name, group, origin, destination, getApplications(), walkingSpeed);
final String name = UnitNameGenerator.nextAgentName();
final AgentRegistration interaction = new AgentRegistration(
startingTime, name, group, origin, destination, getApplications(), defaultIfNull(walkingSpeed, DEFAULT_WALKING_SPEED)
);
try {
LOG.info("Creating Agent: {}", this);
spawningFramework.getRti().triggerInteraction(interaction);
Expand All @@ -74,8 +81,8 @@ public void init(SpawningFramework spawningFramework) throws InternalFederateExc
public void fillInPrototype(CPrototype prototypeConfiguration) {
super.fillInPrototype(prototypeConfiguration);

if (prototypeConfiguration != null && prototypeConfiguration.maxSpeed != null) {
walkingSpeed = prototypeConfiguration.maxSpeed;
if (prototypeConfiguration != null) {
walkingSpeed = defaultIfNull(walkingSpeed, prototypeConfiguration.maxSpeed);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.eclipse.mosaic.fed.mapping.config.units;

import org.eclipse.mosaic.lib.geo.GeoPoint;
import org.eclipse.mosaic.lib.math.SpeedUtils;
import org.eclipse.mosaic.lib.util.gson.TimeFieldAdapter;
import org.eclipse.mosaic.lib.util.gson.UnitFieldAdapter;

Expand Down Expand Up @@ -60,9 +59,9 @@ public class CAgent {
public GeoPoint destination;

/**
* Walking speed of this agent.
* Walking speed of this agent, in m/s.
*/
@JsonAdapter(UnitFieldAdapter.SpeedMS.class)
public double walkingSpeed = SpeedUtils.kmh2ms(5);
public Double walkingSpeed;

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

package org.eclipse.mosaic.fed.sumo.bridge.api.complex;

import org.eclipse.mosaic.lib.objects.vehicle.PublicTransportData;
import org.eclipse.mosaic.lib.objects.pt.PtVehicleData;
import org.eclipse.mosaic.lib.util.objects.Position;

import java.util.List;
Expand Down Expand Up @@ -51,7 +51,7 @@ public class VehicleSubscriptionResult extends AbstractSubscriptionResult {

public LeadFollowVehicle leadingVehicle = LeadFollowVehicle.NONE;
public LeadFollowVehicle followerVehicle = LeadFollowVehicle.NONE;
public List<PublicTransportData.StoppingPlace> nextStops;
public List<PtVehicleData.StoppingPlace> nextStops;
public String line;

public double length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.eclipse.mosaic.interactions.traffic.VehicleUpdates;
import org.eclipse.mosaic.lib.enums.DriveDirection;
import org.eclipse.mosaic.lib.enums.VehicleStopMode;
import org.eclipse.mosaic.lib.objects.pt.PtVehicleData;
import org.eclipse.mosaic.lib.objects.road.IRoadPosition;
import org.eclipse.mosaic.lib.objects.road.SimpleRoadPosition;
import org.eclipse.mosaic.lib.objects.traffic.InductionLoopInfo;
Expand All @@ -60,7 +61,6 @@
import org.eclipse.mosaic.lib.objects.trafficlight.TrafficLightState;
import org.eclipse.mosaic.lib.objects.vehicle.Consumptions;
import org.eclipse.mosaic.lib.objects.vehicle.Emissions;
import org.eclipse.mosaic.lib.objects.vehicle.PublicTransportData;
import org.eclipse.mosaic.lib.objects.vehicle.SurroundingVehicle;
import org.eclipse.mosaic.lib.objects.vehicle.VehicleConsumptions;
import org.eclipse.mosaic.lib.objects.vehicle.VehicleData;
Expand Down Expand Up @@ -579,8 +579,8 @@ private SumoVehicleState processVehicleSubscriptionResult(final long time,
return sumoVehicle;
}

private PublicTransportData extractTrainData(VehicleSubscriptionResult veh) {
return new PublicTransportData.Builder().withLineId(veh.line).nextStops(veh.nextStops).build();
private PtVehicleData extractTrainData(VehicleSubscriptionResult veh) {
return new PtVehicleData.Builder().withLineId(veh.line).nextStops(veh.nextStops).build();
}

private List<String> findRemovedVehicles(long time) throws CommandException, InternalFederateException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.eclipse.mosaic.fed.sumo.config.CSumo;
import org.eclipse.mosaic.lib.enums.VehicleStopMode;
import org.eclipse.mosaic.lib.geo.CartesianPoint;
import org.eclipse.mosaic.lib.objects.vehicle.PublicTransportData;
import org.eclipse.mosaic.lib.objects.pt.PtVehicleData;
import org.eclipse.mosaic.lib.util.objects.Position;
import org.eclipse.mosaic.rti.TIME;
import org.eclipse.mosaic.rti.api.InternalFederateException;
Expand Down Expand Up @@ -174,13 +174,13 @@ private void readVehicles(List<AbstractSubscriptionResult> results) {
}
}

private List<PublicTransportData.StoppingPlace> getNextStop(TraCINextStopDataVector2 stops) {
private List<PtVehicleData.StoppingPlace> getNextStop(TraCINextStopDataVector2 stops) {
if (stops.isEmpty()) {
return null;
}
List<PublicTransportData.StoppingPlace> nextStops = new ArrayList<>();
List<PtVehicleData.StoppingPlace> nextStops = new ArrayList<>();
for (TraCINextStopData stopData : stops) {
PublicTransportData.StoppingPlace stoppingPlace = new PublicTransportData.StoppingPlace.Builder()
PtVehicleData.StoppingPlace stoppingPlace = new PtVehicleData.StoppingPlace.Builder()
.stoppingPlaceId(stopData.getStoppingPlaceID())
.laneId(stopData.getLane())
.startPos(stopData.getStartPos()).endPos(stopData.getEndPos())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@
package org.eclipse.mosaic.fed.sumo.bridge.traci.reader;

import org.eclipse.mosaic.lib.enums.VehicleStopMode;
import org.eclipse.mosaic.lib.objects.vehicle.PublicTransportData;
import org.eclipse.mosaic.lib.objects.pt.PtVehicleData;

import java.io.DataInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;

public class StoppingPlaceReader extends AbstractTraciResultReader<List<PublicTransportData.StoppingPlace>> {
public class StoppingPlaceReader extends AbstractTraciResultReader<List<PtVehicleData.StoppingPlace>> {

public StoppingPlaceReader() {
this(null);
}

protected StoppingPlaceReader(@Nullable Matcher<List<PublicTransportData.StoppingPlace>> matcher) {
protected StoppingPlaceReader(@Nullable Matcher<List<PtVehicleData.StoppingPlace>> matcher) {
super(matcher);
}

@Override
protected List<PublicTransportData.StoppingPlace> readFromStream(DataInputStream in) throws IOException {
protected List<PtVehicleData.StoppingPlace> readFromStream(DataInputStream in) throws IOException {
int count = readIntWithType(in);
List<PublicTransportData.StoppingPlace> stoppingPlaces = new ArrayList<>();
List<PtVehicleData.StoppingPlace> stoppingPlaces = new ArrayList<>();
for (int i = 0; i < count; i++) {
PublicTransportData.StoppingPlace.Builder stoppingPlaceBuilder = new PublicTransportData.StoppingPlace.Builder();
PtVehicleData.StoppingPlace.Builder stoppingPlaceBuilder = new PtVehicleData.StoppingPlace.Builder();
stoppingPlaceBuilder.laneId(readStringWitType(in));
stoppingPlaceBuilder.endPos(readDoubleWithType(in));
stoppingPlaceBuilder.stoppingPlaceId(readStringWitType(in));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.eclipse.mosaic.fed.sumo.bridge.api.complex.LeadFollowVehicle;
import org.eclipse.mosaic.fed.sumo.bridge.api.complex.VehicleSubscriptionResult;
import org.eclipse.mosaic.fed.sumo.bridge.traci.constants.CommandRetrieveVehicleState;
import org.eclipse.mosaic.lib.objects.vehicle.PublicTransportData;
import org.eclipse.mosaic.lib.objects.pt.PtVehicleData;
import org.eclipse.mosaic.lib.util.objects.Position;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -105,7 +105,7 @@ protected void handleSubscriptionVariable(VehicleSubscriptionResult result, int
} else if (varId == CommandRetrieveVehicleState.VAR_MIN_GAP.var) {
result.minGap = (double) varValue;
} else if (varId == CommandRetrieveVehicleState.VAR_NEXT_STOPS.var) {
result.nextStops = (List<PublicTransportData.StoppingPlace>) varValue;
result.nextStops = (List<PtVehicleData.StoppingPlace>) varValue;
} else if (varId == CommandRetrieveVehicleState.VAR_LINE.var) {
result.line = (String) varValue;
} else if (varId == CommandRetrieveVehicleState.VAR_LENGTH.var) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
import org.eclipse.mosaic.lib.geo.UtmPoint;
import org.eclipse.mosaic.lib.geo.UtmZone;
import org.eclipse.mosaic.lib.junit.GeoProjectionRule;
import org.eclipse.mosaic.lib.objects.pt.PtVehicleData;
import org.eclipse.mosaic.lib.objects.traffic.InductionLoopInfo;
import org.eclipse.mosaic.lib.objects.trafficlight.TrafficLightGroup;
import org.eclipse.mosaic.lib.objects.vehicle.PublicTransportData;
import org.eclipse.mosaic.lib.objects.vehicle.VehicleData;
import org.eclipse.mosaic.lib.objects.vehicle.VehicleType;
import org.eclipse.mosaic.lib.objects.vehicle.sensor.SensorValue.SensorStatus;
Expand Down Expand Up @@ -242,9 +242,9 @@ public void trainInfoIncluded() throws Exception {
// ASSERT
VehicleData vehData = traci.getSimulationControl().getLastKnownVehicleData("2");
assertEquals("1_4_3", vehData.getRoadPosition().getConnection().getId());
PublicTransportData publicTransportData = (PublicTransportData) vehData.getAdditionalData();
assertEquals("bs_0", publicTransportData.getNextStops().get(0).getStoppingPlaceId());
assertEquals("testLine", publicTransportData.getLineId());
PtVehicleData ptData = (PtVehicleData) vehData.getAdditionalData();
assertEquals("bs_0", ptData.getNextStops().get(0).getStoppingPlaceId());
assertEquals("testLine", ptData.getLineId());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package org.eclipse.mosaic.lib.objects.agent;

import org.eclipse.mosaic.lib.geo.GeoPoint;
import org.eclipse.mosaic.lib.objects.traffic.PublicTransportStop;
import org.eclipse.mosaic.lib.objects.pt.PtStop;
import org.eclipse.mosaic.lib.objects.vehicle.VehicleDeparture;

import com.google.common.collect.Lists;
Expand Down Expand Up @@ -100,18 +100,18 @@ public String getVehicleId() {
}
}

public static class PublicTransportLeg extends Leg {
public static class PtLeg extends Leg {

private static final long serialVersionUID = 1L;

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

public PublicTransportLeg(long departureTime, List<PublicTransportStop> stops) {
public PtLeg(long departureTime, List<PtStop> stops) {
super(departureTime);
this.stops.addAll(stops);
}

public final List<PublicTransportStop> getStops() {
public final List<PtStop> getStops() {
return stops;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ public class AgentMapping extends UnitMapping {
* @param name name of the unit
* @param group group that the unit belongs to
* @param applications a list of applications to be mapped onto the unit
* @param walkingSpeed the speed this agent has when walking
* @param walkingSpeed the speed this agent has when walking, in m/s
*/
public AgentMapping(final String name, final String group, final List<String> applications, double walkingSpeed) {
super(name, group, applications);
this.walkingSpeed = walkingSpeed;
}

/**
* Returns the walking speed of the agent in m/s
*/
public double getWalkingSpeed() {
return walkingSpeed;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@
* Contact: [email protected]
*/

package org.eclipse.mosaic.lib.objects.traffic;
package org.eclipse.mosaic.lib.objects.pt;

import org.eclipse.mosaic.lib.geo.GeoPoint;

/**
* Each public transport stop consists of its geolocation and the planned arrival and departure time at the stop.
* A {@link PtStop} represents a stop along a public transport line or route, e.g., a bus stop or train station.
* This data structure consists of its geolocation and the planned arrival and departure time at the stop.
*
* @param location The geographic location of the stop.
* @param arrivalTime The time when arriving at this stop. {@code null} for the first stop of a leg.
* @param departureTime The time when leaving this stop. {@code null} for the last stop of a leg.
*/
public record PublicTransportStop(GeoPoint location, Long arrivalTime, Long departureTime) {
public record PtStop(GeoPoint location, Long arrivalTime, Long departureTime) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* Contact: [email protected]
*/

package org.eclipse.mosaic.lib.objects.vehicle;
package org.eclipse.mosaic.lib.objects.pt;

import org.eclipse.mosaic.lib.enums.VehicleStopMode;

Expand All @@ -22,19 +22,24 @@
import java.io.Serializable;
import java.util.List;

public class PublicTransportData {
/**
* Additional data holding information about the public transport line of the vehicle associated with this.
* The data is generated and filled by SumoAmbassador and can be consumed by any vehicle application
* which is mapped onto the public transport vehicle.
*/
public class PtVehicleData {

/**
* The line the train belongs to.
*/
private final String lineId;

/**
* Contains a list of the next stops of a train.
* Contains a list of the next stops of the vehicle, e.g., train or bus.
*/
private final List<StoppingPlace> nextStops;

private PublicTransportData(String lineId, List<StoppingPlace> nextStops) {
private PtVehicleData(String lineId, List<StoppingPlace> nextStops) {
this.lineId = lineId;
this.nextStops = nextStops;
}
Expand All @@ -61,8 +66,8 @@ public Builder nextStops(List<StoppingPlace> nextStops) {
return this;
}

public PublicTransportData build() {
return new PublicTransportData(lineId, nextStops);
public PtVehicleData build() {
return new PtVehicleData(lineId, nextStops);
}
}

Expand Down
Loading

0 comments on commit 301fefc

Please sign in to comment.