-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(application): introduce agent unit and agent operating system
* spawning of agents via mapping_config.json * creating agent units in mosaic-application * provide AgentOperatingSystem with access to public transport routing and other really basic API * still no functionality, as the core Agent-Simulator is still missing
- Loading branch information
Showing
36 changed files
with
1,082 additions
and
345 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
...ion/src/main/java/org/eclipse/mosaic/fed/application/ambassador/simulation/AgentUnit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/* | ||
* Copyright (c) 2025 Fraunhofer FOKUS and others. All rights reserved. | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contact: [email protected] | ||
*/ | ||
|
||
package org.eclipse.mosaic.fed.application.ambassador.simulation; | ||
|
||
import org.eclipse.mosaic.fed.application.ambassador.ErrorRegister; | ||
import org.eclipse.mosaic.fed.application.ambassador.SimulationKernel; | ||
import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.CamBuilder; | ||
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.AgentPtRoutingModule; | ||
import org.eclipse.mosaic.fed.application.ambassador.simulation.navigation.RoutingNavigationModule; | ||
import org.eclipse.mosaic.fed.application.app.api.navigation.PtRoutingModule; | ||
import org.eclipse.mosaic.fed.application.app.api.navigation.RoutingModule; | ||
import org.eclipse.mosaic.fed.application.app.api.os.AgentOperatingSystem; | ||
import org.eclipse.mosaic.interactions.agent.AgentRouteChange; | ||
import org.eclipse.mosaic.lib.geo.GeoPoint; | ||
import org.eclipse.mosaic.lib.objects.agent.AgentRoute; | ||
import org.eclipse.mosaic.lib.objects.mapping.AgentMapping; | ||
import org.eclipse.mosaic.lib.objects.vehicle.VehicleDeparture; | ||
import org.eclipse.mosaic.lib.objects.vehicle.VehicleRoute; | ||
import org.eclipse.mosaic.lib.routing.CandidateRoute; | ||
import org.eclipse.mosaic.lib.routing.IllegalRouteException; | ||
import org.eclipse.mosaic.lib.routing.pt.PtRoute; | ||
import org.eclipse.mosaic.lib.util.scheduling.Event; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
import java.util.List; | ||
|
||
public class AgentUnit extends AbstractSimulationUnit implements AgentOperatingSystem { | ||
|
||
private final RoutingModule vehicleRoutingModule; | ||
private final PtRoutingModule ptRoutingModule; | ||
private final GeoPoint originPosition; | ||
private final GeoPoint destinationPosition; | ||
|
||
public AgentUnit(AgentMapping agentMapping, final GeoPoint originPosition, final GeoPoint destinationPosition) { | ||
super(agentMapping.getName(), originPosition); | ||
setRequiredOperatingSystem(AgentOperatingSystem.class); | ||
|
||
vehicleRoutingModule = new RoutingNavigationModule(this); | ||
ptRoutingModule = new AgentPtRoutingModule(agentMapping.getWalkingSpeed()); | ||
|
||
this.originPosition = originPosition; | ||
this.destinationPosition = destinationPosition; | ||
} | ||
|
||
@Override | ||
public void usePrivateVehicle(String vehicleType, CandidateRoute route) { | ||
try { | ||
VehicleRoute rtiRoute = SimulationKernel.SimulationKernel.getCentralNavigationComponent().createAndPropagateRoute( | ||
route, getSimulationTime() | ||
); | ||
|
||
if (rtiRoute == null) { | ||
throw new IllegalRouteException("Provided route could not be propagated to RTI."); | ||
} | ||
|
||
final List<AgentRoute.Leg> agentLegs = Lists.newArrayList(new AgentRoute.PrivateVehicleLeg( | ||
getSimulationTime(), | ||
vehicleType, | ||
new VehicleDeparture.Builder(rtiRoute.getId()) | ||
.departureSpeed(VehicleDeparture.DepartureSpeedMode.PRECISE, 0) | ||
.create() | ||
)); | ||
sendInteractionToRti(new AgentRouteChange( | ||
getSimulationTime(), getId(), new AgentRoute(agentLegs) | ||
)); | ||
|
||
} catch (IllegalRouteException e) { | ||
throw new RuntimeException("Invalid route provided.", e); | ||
} | ||
} | ||
|
||
@Override | ||
public void useSharedVehicle(String vehicleId) { | ||
final List<AgentRoute.Leg> agentLegs = Lists.newArrayList(new AgentRoute.SharedVehicleLeg( | ||
getSimulationTime(), | ||
vehicleId | ||
)); | ||
|
||
sendInteractionToRti(new AgentRouteChange( | ||
getSimulationTime(), getId(), new AgentRoute(agentLegs) | ||
)); | ||
} | ||
|
||
@Override | ||
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()); | ||
} | ||
if (leg instanceof PtRoute.WalkLeg walkLeg) { | ||
return new AgentRoute.WalkLeg(leg.getDepartureTime(), walkLeg.getWaypoints()); | ||
} | ||
throw new IllegalArgumentException("Unsupported leg type found in public transport route."); | ||
}).toList(); | ||
|
||
if (agentLegs.isEmpty()) { | ||
return; | ||
} | ||
sendInteractionToRti(new AgentRouteChange( | ||
getSimulationTime(), getId(), new AgentRoute(agentLegs) | ||
)); | ||
} | ||
|
||
@Override | ||
public GeoPoint getOriginPosition() { | ||
return originPosition; | ||
} | ||
|
||
@Override | ||
public GeoPoint getDestinationPosition() { | ||
return destinationPosition; | ||
} | ||
|
||
@Override | ||
public PtRoutingModule getPtRoutingModule() { | ||
return ptRoutingModule; | ||
} | ||
|
||
@Override | ||
public RoutingModule getRoutingModule() { | ||
return vehicleRoutingModule; | ||
} | ||
|
||
@Override | ||
public void processEvent(Event event) throws Exception { | ||
// never remove the preProcessEvent call! | ||
final boolean preProcessed = super.preProcessEvent(event); | ||
|
||
// failsafe | ||
if (preProcessed) { | ||
return; | ||
} | ||
|
||
final Object resource = event.getResource(); | ||
|
||
// failsafe | ||
if (resource == null) { | ||
getOsLog().error("Event has no resource: {}", event); | ||
throw new RuntimeException(ErrorRegister.AGENT_NoEventResource.toString()); | ||
} | ||
|
||
getOsLog().error("Unknown event resource: {}", event); | ||
throw new RuntimeException(ErrorRegister.AGENT_UnknownEvent.toString()); | ||
} | ||
|
||
@Override | ||
public CamBuilder assembleCamMessage(CamBuilder camBuilder) { | ||
throw new UnsupportedOperationException("Agents are not able to send CAMs"); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...eclipse/mosaic/fed/application/ambassador/simulation/navigation/AgentPtRoutingModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2025 Fraunhofer FOKUS and others. All rights reserved. | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contact: [email protected] | ||
*/ | ||
|
||
package org.eclipse.mosaic.fed.application.ambassador.simulation.navigation; | ||
|
||
import org.eclipse.mosaic.fed.application.ambassador.SimulationKernel; | ||
import org.eclipse.mosaic.fed.application.app.api.navigation.PtRoutingModule; | ||
import org.eclipse.mosaic.lib.geo.GeoPoint; | ||
import org.eclipse.mosaic.lib.routing.pt.PtRoutingParameters; | ||
import org.eclipse.mosaic.lib.routing.pt.PtRoutingRequest; | ||
import org.eclipse.mosaic.lib.routing.pt.PtRoutingResponse; | ||
|
||
public class AgentPtRoutingModule implements PtRoutingModule { | ||
|
||
private final double defaultWalkingSpeed; | ||
|
||
public AgentPtRoutingModule(double defaultWalkingSpeed) { | ||
this.defaultWalkingSpeed = defaultWalkingSpeed; | ||
} | ||
|
||
@Override | ||
public PtRoutingResponse calculateRoute(long requestTime, GeoPoint origin, GeoPoint destination, PtRoutingParameters routingParameters) { | ||
PtRoutingRequest routingRequest = new PtRoutingRequest(requestTime, origin, destination, routingParameters); | ||
if (routingParameters.getWalkingSpeedMps() == null) { | ||
routingParameters.walkingSpeedMps(defaultWalkingSpeed); | ||
} | ||
return SimulationKernel.SimulationKernel.getCentralNavigationComponent().findPtRoute(routingRequest); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.