-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Person vehicle types attribute (#2877)
* added todos * separate container class for vehicle types * add vehicle type logic and test for it * add a todo * put vehicle types into person attributes from commercial traffic * changes from ricardo
- Loading branch information
Showing
8 changed files
with
203 additions
and
30 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
42 changes: 42 additions & 0 deletions
42
...tsim/utils/objectattributes/attributeconverters/PersonVehicleTypesAttributeConverter.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,42 @@ | ||
package org.matsim.utils.objectattributes.attributeconverters; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.matsim.api.core.v01.Id; | ||
import org.matsim.utils.objectattributes.AttributeConverter; | ||
import org.matsim.vehicles.PersonVehicleTypes; | ||
import org.matsim.vehicles.VehicleType; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Converter to store vehicle types as person attribute. | ||
*/ | ||
public class PersonVehicleTypesAttributeConverter implements AttributeConverter<PersonVehicleTypes> { | ||
|
||
private final Logger logger = LogManager.getLogger(PersonVehicleTypesAttributeConverter.class); | ||
|
||
@Override | ||
public PersonVehicleTypes convert(String value) { | ||
PersonVehicleTypes vehicles = new PersonVehicleTypes(); | ||
Map<String, String> stringMap = new StringStringMapConverter().convert(value); | ||
for (Map.Entry<String, String> entry: stringMap.entrySet()) { | ||
vehicles.addModeVehicleType(entry.getKey(), Id.create(entry.getValue(), VehicleType.class)); | ||
} | ||
return vehicles; | ||
} | ||
|
||
@Override | ||
public String convertToString(Object o) { | ||
if(!(o instanceof PersonVehicleTypes vehicles)){ | ||
logger.error("Object is not of type PersonVehicles: " + o.getClass()); | ||
return null; | ||
} | ||
Map<String, String> stringMap = new HashMap<>(); | ||
for (Map.Entry<String, Id<VehicleType>> entry: vehicles.getModeVehicleTypes().entrySet()) { | ||
stringMap.put(entry.getKey(), entry.getValue().toString()); | ||
} | ||
return new StringStringMapConverter().convertToString(stringMap); | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
matsim/src/main/java/org/matsim/vehicles/PersonVehicleTypes.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,33 @@ | ||
package org.matsim.vehicles; | ||
|
||
import org.matsim.api.core.v01.Id; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Container class to store mode specific person vehicle types. | ||
*/ | ||
public final class PersonVehicleTypes { | ||
|
||
private final Map<String, Id<VehicleType>> modeVehicleTypes = new HashMap<>(); | ||
|
||
public PersonVehicleTypes() { | ||
} | ||
|
||
public void addModeVehicleType(String mode, Id<VehicleType> vehicleType) { | ||
modeVehicleTypes.put(mode, vehicleType); | ||
} | ||
|
||
public Id<VehicleType> getVehicleType(String mode) { | ||
return modeVehicleTypes.get(mode); | ||
} | ||
|
||
public Map<String, Id<VehicleType>> getModeVehicleTypes() { | ||
return modeVehicleTypes; | ||
} | ||
|
||
public void putModeVehicleTypes(Map<String, Id<VehicleType>> vehicleTypes) { | ||
modeVehicleTypes.putAll(vehicleTypes); | ||
} | ||
} |
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