Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/maven/org.apache.maven.plugins-…
Browse files Browse the repository at this point in the history
…maven-surefire-plugin-3.5.0
  • Loading branch information
jfbischoff authored Sep 13, 2024
2 parents 498af6b + 3cafc63 commit 942181a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private void insertVehicles(Person person) {
}

// find the link ID of where to place the vehicle:
Id<Link> vehicleLinkId = findVehicleLink(person);
Id<Link> vehicleLinkId = findVehicleLink(person, vehicle);

// Checking if the vehicle has been seen before:
Id<Link> result = this.seenVehicleIds.get( vehicleId ) ;
Expand Down Expand Up @@ -190,7 +190,15 @@ private void insertVehicles(Person person) {
* than to ask agent.getCurrentLinkId() after creation.
* @param person TODO
*/
private Id<Link> findVehicleLink(Person person ) {
private Id<Link> findVehicleLink(Person person, Vehicle vehicle) {
/*
* Manual case: the initial link id of the vehicle is saved as an attribute
*/
Id<Link> initialLinkId = VehicleUtils.getInitialLinkId(vehicle);
if (initialLinkId != null) {
return initialLinkId;
}

/* Cases that come to mind:
* (1) multiple persons share car located at home, but possibly brought to different place by someone else.
* This is treated by the following algo.
Expand Down
17 changes: 14 additions & 3 deletions matsim/src/main/java/org/matsim/vehicles/VehicleUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,18 @@

package org.matsim.vehicles;

import java.util.HashMap;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.population.Person;
import org.matsim.core.gbl.Gbl;
import org.matsim.utils.objectattributes.attributable.AttributesUtils;

import java.util.HashMap;
import java.util.Map;


/**
* @author nagel
Expand All @@ -57,6 +58,7 @@ public final class VehicleUtils {
private static final String COST_PER_SECOND_WAITING = "costsPerSecondWaiting";
private static final String COST_PER_SECOND_INSERVICE = "costsPerSecondInService";
private static final String FUEL_TYPE = "fuelType";
private static final String INITIAL_LINK_ID = "initialLinkId";

public static VehicleType createVehicleType( Id<VehicleType> typeId ){
return new VehicleType( typeId );
Expand Down Expand Up @@ -432,4 +434,13 @@ public static void writeVehicles( Vehicles vehicles, String filename ) {
new MatsimVehicleWriter( vehicles ).writeFile( filename );

}

public static Id<Link> getInitialLinkId(Vehicle vehicle) {
String attribute = (String) vehicle.getAttributes().getAttribute(INITIAL_LINK_ID);
return attribute == null ? null : Id.createLinkId(attribute);
}

public static void setInitialLinkId(Vehicle vehicle, Id<Link> initialLinkId) {
vehicle.getAttributes().putAttribute(INITIAL_LINK_ID, initialLinkId.toString());
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.12.0</version>
<version>5.13.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down

0 comments on commit 942181a

Please sign in to comment.