Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/shp-options-gpkg' into shp-optio…
Browse files Browse the repository at this point in the history
…ns-gpkg
  • Loading branch information
rakow committed Apr 23, 2024
2 parents 5f7371b + 296f525 commit fd27e72
Show file tree
Hide file tree
Showing 22 changed files with 86 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public ParkCSVehicles(QSim qSim,
this.mainModes = qsim.getScenario().getConfig().qsim().getMainModes();

for (String mode : mainModes) {
modeVehicleTypes.put(mode, VehicleUtils.getDefaultVehicleType());
modeVehicleTypes.put(mode, VehicleUtils.createDefaultVehicleType());
}
this.carsharingSupply = carsharingSupply;
modeVehicleTypes.put("twoway", VehicleUtils.getDefaultVehicleType());
modeVehicleTypes.put("freefloating", VehicleUtils.getDefaultVehicleType());
modeVehicleTypes.put("twoway", VehicleUtils.createDefaultVehicleType());
modeVehicleTypes.put("freefloating", VehicleUtils.createDefaultVehicleType());

modeVehicleTypes.put("oneway", VehicleUtils.getDefaultVehicleType());
modeVehicleTypes.put("oneway", VehicleUtils.createDefaultVehicleType());


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public FleetModule(String mode, URL fleetSpecificationUrl, boolean updateVehicle
this.fleetSpecificationUrl = fleetSpecificationUrl;
this.updateVehicleStartLinkToLastLink = updateVehicleStartLinkToLastLink;

vehicleType = VehicleUtils.getDefaultVehicleType();
vehicleType = VehicleUtils.createDefaultVehicleType();
}

public FleetModule(String mode, URL fleetSpecificationUrl, VehicleType vehicleType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void insertAgentsIntoMobsim() {
// qSim.createAndParkVehicleOnLink(qSimVehicleFactory.createVehicle(Id.create(id, Vehicle.class),
// VehicleUtils.getDefaultVehicleType()), startLinkId);

final Vehicle vehicle = qSimVehicleFactory.createVehicle( Id.create( id, Vehicle.class ), VehicleUtils.getDefaultVehicleType() ) ;
final Vehicle vehicle = qSimVehicleFactory.createVehicle( Id.create( id, Vehicle.class ), VehicleUtils.createDefaultVehicleType() ) ;
QVehicle qVehicle = new QVehicleImpl( vehicle ) ; // yyyyyy should use factory. kai, nov'18
qSim.addParkedVehicle( qVehicle, startLinkId );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ protected void configureQSim() {
//supply
addQSimComponentBinding(DynActivityEngine.COMPONENT_NAME).to(DynActivityEngine.class);
bindModal(Fleet.class).toInstance(fleet);
bindModal(VehicleType.class).toInstance(VehicleUtils.getDefaultVehicleType());
bindModal(VehicleType.class).toInstance(VehicleUtils.createDefaultVehicleType());
bindModal(VrpOptimizer.class).to(optimizerClass).asEagerSingleton();
bindModal(VrpAgentLogic.DynActionCreator.class).to(OneTaxiActionCreator.class)
.asEagerSingleton();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected void configureQSim() {
//supply
addQSimComponentBinding(DynActivityEngine.COMPONENT_NAME).to(DynActivityEngine.class);
bindModal(Fleet.class).toInstance(fleet);
bindModal(VehicleType.class).toInstance(VehicleUtils.getDefaultVehicleType());
bindModal(VehicleType.class).toInstance(VehicleUtils.createDefaultVehicleType());
bindModal(VrpOptimizer.class).to(optimizerClass).asEagerSingleton();
bindModal(VrpAgentLogic.DynActionCreator.class).to(OneTaxiActionCreator.class)
.asEagerSingleton();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ protected void configureQSim() {
return Fleets.createDefaultFleet(fleetSpecification, getter.getModal(Network.class).getLinks()::get);
})).in(Singleton.class);

bindModal(VehicleType.class).toInstance(VehicleUtils.getDefaultVehicleType());
bindModal(VehicleType.class).toInstance(VehicleUtils.createDefaultVehicleType());

install(new VrpAgentSourceQSimModule(getMode()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public final class FreightAgentSource implements AgentSource {

Vehicle vehicle;
if( CarriersUtils.getVehicle( freightDriverPlan ) == null ){
vehicle = VehicleUtils.getFactory().createVehicle( Id.create( agent.getId(), Vehicle.class ), VehicleUtils.getDefaultVehicleType() );
vehicle = VehicleUtils.getFactory().createVehicle( Id.create( agent.getId(), Vehicle.class ), VehicleUtils.createDefaultVehicleType() );
log.warn( "vehicle for agent " + freightDriverPlan.getPerson().getId() + " is missing. set default vehicle where maxVelocity is solely defined by link.speed." );
} else if( CarriersUtils.getVehicle( freightDriverPlan ).getType() == null ){
vehicle = VehicleUtils.getFactory().createVehicle( Id.create( agent.getId(), Vehicle.class ), VehicleUtils.getDefaultVehicleType() );
vehicle = VehicleUtils.getFactory().createVehicle( Id.create( agent.getId(), Vehicle.class ), VehicleUtils.createDefaultVehicleType() );
log.warn( "vehicleType for agent " + freightDriverPlan.getPerson().getId() + " is missing. set default vehicleType where maxVelocity is solely defined by link.speed." );
} else {
vehicle = CarriersUtils.getVehicle( freightDriverPlan );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.matsim.freight.carriers.*;
import org.matsim.testcases.MatsimTestUtils;
import org.matsim.vehicles.Vehicle;
import org.matsim.vehicles.VehicleType;
import org.matsim.vehicles.VehicleUtils;

import static org.matsim.testcases.MatsimTestUtils.EPSILON;
Expand All @@ -41,22 +42,24 @@ public class CarriersUtilsTest {

@Test
void testAddAndGetVehicleToCarrier() {
VehicleType vehicleType = VehicleUtils.createDefaultVehicleType();

Carrier carrier = new CarrierImpl(Id.create("carrier", Carrier.class));
Id<Vehicle> testVehicleId = Id.createVehicleId("testVehicle");
CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(testVehicleId, Id.createLinkId("link0"),VehicleUtils.getDefaultVehicleType());
CarrierVehicle carrierVehicle = CarrierVehicle.newInstance(testVehicleId, Id.createLinkId("link0"),vehicleType);
// carrierVehicle.setType(VehicleUtils.getDefaultVehicleType());

//add Vehicle
CarriersUtils.addCarrierVehicle(carrier, carrierVehicle);
Assertions.assertEquals(1, carrier.getCarrierCapabilities().getCarrierVehicles().size());
CarrierVehicle cv = (CarrierVehicle) carrier.getCarrierCapabilities().getCarrierVehicles().values().toArray()[0];
Assertions.assertEquals(VehicleUtils.getDefaultVehicleType(), cv.getType());
Assertions.assertEquals(vehicleType, cv.getType());
Assertions.assertEquals(Id.createLinkId("link0"), cv.getLinkId() );

//get Vehicle
CarrierVehicle carrierVehicle1 = CarriersUtils.getCarrierVehicle(carrier, testVehicleId );
Assertions.assertEquals(testVehicleId, carrierVehicle1.getId());
Assertions.assertEquals(VehicleUtils.getDefaultVehicleType(), carrierVehicle1.getType());
Assertions.assertEquals(vehicleType, carrierVehicle1.getType());
Assertions.assertEquals(Id.createLinkId("link0"), carrierVehicle1.getLinkId() );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public ParkingPopulationAgentSource(Population population, AgentFactory agentFac
case defaultVehicle:
for (String mode : mainModes) {
// initialize each mode with default vehicle type:
modeVehicleTypes.put(mode, VehicleUtils.getDefaultVehicleType());
modeVehicleTypes.put(mode, VehicleUtils.createDefaultVehicleType());
}
break;
case fromVehiclesData:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static <T> NetworkIndicators<T> calculateSkimMatrices(Network xy2lNetwork

private static class RowWorker<T> implements Runnable {

private final static Vehicle VEHICLE = VehicleUtils.getFactory().createVehicle(Id.create("theVehicle", Vehicle.class), VehicleUtils.getDefaultVehicleType());
private final static Vehicle VEHICLE = VehicleUtils.getFactory().createVehicle(Id.create("theVehicle", Vehicle.class), VehicleUtils.createDefaultVehicleType());
private final static Person PERSON = PopulationUtils.getFactory().createPerson(Id.create("thePerson", Person.class));
private final ConcurrentLinkedQueue<T> originZones;
private final Set<T> destinationZones;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void insertAgentsIntoMobsim() {
for (SharingVehicleSpecification veh : specification.getVehicles()) {
Id<Link> startLink = veh.getStartLinkId().get();
Id<Vehicle> vehId = Id.createVehicleId(veh.getId().toString());
Vehicle basicVehicle = factory.createVehicle(vehId, VehicleUtils.getDefaultVehicleType());
Vehicle basicVehicle = factory.createVehicle(vehId, VehicleUtils.createDefaultVehicleType());
QVehicleImpl qvehicle = new QVehicleImpl(basicVehicle);
qvehicle.setCurrentLink(this.qsim.getScenario().getNetwork().getLinks().get(startLink));
qsim.addParkedVehicle(qvehicle, startLink);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public PopulationAgentSourceWithVehicles(
this.modeVehicleTypes = new HashMap<>();
this.mainModes = qsim.getScenario().getConfig().qsim().getMainModes();
for (String mode : mainModes) {
modeVehicleTypes.put(mode, VehicleUtils.getDefaultVehicleType());
modeVehicleTypes.put(mode, VehicleUtils.createDefaultVehicleType());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public double getLinkTravelDisutility(final Link link, final double time, final
if (person == null){
// additionally, no person is given -> a default vehicle type is used
log.warn("No person and no vehicle is given to calculate the link travel disutility. The default vehicle type is used to estimate emission disutility.");
emissionVehicle = VehicleUtils.getFactory().createVehicle(Id.createVehicleId("defaultVehicle"), VehicleUtils.getDefaultVehicleType());
emissionVehicle = VehicleUtils.getFactory().createVehicle(Id.createVehicleId("defaultVehicle"), VehicleUtils.createDefaultVehicleType());
} else {
// a person is given -> use the vehicle for that person given in emissionModule
emissionVehicle = this.emissionVehicles.getVehicles().get(Id.createVehicleId(person.getId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public double getLinkTravelDisutility(final Link link, final double time, final
if (person == null){
// additionally, no person is given -> a default vehicle type is used
log.warn("No person and no vehicle is given to calculate the link travel disutility. The default vehicle type is used to estimate emission disutility.");
emissionVehicle = VehicleUtils.getFactory().createVehicle(Id.createVehicleId("defaultVehicle"), VehicleUtils.getDefaultVehicleType());
emissionVehicle = VehicleUtils.getFactory().createVehicle(Id.createVehicleId("defaultVehicle"), VehicleUtils.createDefaultVehicleType());
} else {
// a person is given -> use the vehicle for that person given in emissionModule
emissionVehicle = this.emissionVehicles.getVehicles().get(Id.createVehicleId(person.getId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private Map<String, VehicleType> getVehicleTypesForAllNetworkAndMainModes() {
VehicleType type;
switch (qSimConfigGroup.getVehiclesSource()) {
case defaultVehicle:
type = VehicleUtils.getDefaultVehicleType();
type = VehicleUtils.createDefaultVehicleType();
if (!scenario.getVehicles().getVehicleTypes().containsKey(type.getId())){
scenario.getVehicles().addVehicleType( type );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ private void processPlanNetworkRoute(
Id<org.matsim.api.core.v01.network.Link> endLId = netroute.getEndLinkId();
Map<Id<Vehicle>, Vehicle> vehicles = scenario.getVehicles().getVehicles();
Vehicle v = vehicles.get(VehicleUtils.getVehicleId(person, leg.getMode()));
Id<VehicleType> vtypeid = v == null ? VehicleUtils.getDefaultVehicleType().getId() : v.getType().getId();
Id<VehicleType> vtypeid = v == null ? VehicleUtils.createDefaultVehicleType().getId() : v.getType().getId();
int pcuCategory = this.vehicleTypeMapping.get(vtypeid);
Id<Vehicle> vid = v == null ? Id.createVehicleId("v" + person.getId()) : v.getId();
double velocity = v == null ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class LeastCostPathTree {
private final TravelDisutility tcFunction;
private IdMap<Node, NodeData> nodeData = null;

private final Vehicle VEHICLE = VehicleUtils.getFactory().createVehicle(Id.create("theVehicle", Vehicle.class), VehicleUtils.getDefaultVehicleType());
private final Vehicle VEHICLE = VehicleUtils.getFactory().createVehicle(Id.create("theVehicle", Vehicle.class), VehicleUtils.createDefaultVehicleType());
private final Person PERSON = PopulationUtils.getFactory().createPerson(Id.create("thePerson", Person.class));

// ////////////////////////////////////////////////////////////////////
Expand Down
15 changes: 8 additions & 7 deletions matsim/src/main/java/org/matsim/vehicles/VehicleUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
public final class VehicleUtils {
private static final Logger log = LogManager.getLogger( VehicleUtils.class ) ;

private static final VehicleType DEFAULT_VEHICLE_TYPE = VehicleUtils.getFactory().createVehicleType(Id.create("defaultVehicleType", VehicleType.class));
private static final String DEFAULT_VEHICLE_TYPE_ID = "defaultVehicleType";
private static final String VEHICLE_ATTRIBUTE_KEY = "vehicles";
private static final String VEHICLE_TYPES_ATTRIBUTE_KEY = "vehicleTypes";

Expand All @@ -62,10 +62,6 @@ public static VehicleType createVehicleType( Id<VehicleType> typeId ){
return new VehicleType( typeId );
}

static {
DEFAULT_VEHICLE_TYPE.getCapacity().setSeats( 4 );
}

public static VehiclesFactory getFactory() {
return new VehiclesFactoryImpl();
}
Expand All @@ -74,8 +70,13 @@ public static Vehicles createVehiclesContainer() {
return new VehiclesImpl();
}

public static VehicleType getDefaultVehicleType() {
return DEFAULT_VEHICLE_TYPE;
public static VehicleType createDefaultVehicleType() {
VehicleType defaultVehicleType = VehicleUtils.getFactory()
.createVehicleType(Id.create(DEFAULT_VEHICLE_TYPE_ID, VehicleType.class));

defaultVehicleType.getCapacity().setSeats(4);

return defaultVehicleType;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ void testRoutingVsSimulation() {
person.addPlan(plan);

Vehicle vehicle = scenario.getVehicles().getFactory().createVehicle(VehicleUtils.createVehicleId(person, TransportMode.car),
VehicleUtils.getDefaultVehicleType());
VehicleUtils.createDefaultVehicleType());
VehicleUtils.insertVehicleIdsIntoAttributes(person, Map.of(TransportMode.car, vehicle.getId()));
scenario.getVehicles().addVehicleType(VehicleUtils.getDefaultVehicleType());
scenario.getVehicles().addVehicleType(VehicleUtils.createDefaultVehicleType());
scenario.getVehicles().addVehicle(vehicle);

TravelTime travelTime = new FreeSpeedTravelTime();
Expand Down Expand Up @@ -251,8 +251,8 @@ void testRoutingVsSimulationFullStack() {
Arrays.asList(link12, link23, link34, link45).forEach(l -> l.setFreespeed(10.0));

Vehicle vehicle = scenario.getVehicles().getFactory().createVehicle(Id.createVehicleId("P"),
VehicleUtils.getDefaultVehicleType());
scenario.getVehicles().addVehicleType(VehicleUtils.getDefaultVehicleType());
VehicleUtils.createDefaultVehicleType());
scenario.getVehicles().addVehicleType(VehicleUtils.createDefaultVehicleType());
scenario.getVehicles().addVehicle(vehicle);

Population population = scenario.getPopulation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,14 @@ void calcRoute_defaultVehicle_defaultVehicleIsAssigned() {

Map<String, Id<Vehicle>> modeId = VehicleUtils.getVehicleIds(person);

VehicleType defaultVehicleType = scenario.getVehicles().getVehicleTypes()
.get(VehicleUtils.createDefaultVehicleType().getId());
assertNotNull(defaultVehicleType);

// should be only one, but however
for (Id<Vehicle> vehicleId : modeId.values()) {
assertTrue(scenario.getVehicles().getVehicles().containsKey(vehicleId));
assertEquals(VehicleUtils.getDefaultVehicleType(), scenario.getVehicles().getVehicles().get(vehicleId).getType());
assertEquals(defaultVehicleType, scenario.getVehicles().getVehicles().get(vehicleId).getType());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.matsim.vehicles;

import org.junit.jupiter.api.Test;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.vehicles.VehicleType;
import org.matsim.vehicles.VehicleUtils;
import org.matsim.vehicles.Vehicles;

class DefaultVehicleTypeTest {
@Test
void testFirst() {
Config config = ConfigUtils.createConfig();
Scenario scenario = ScenarioUtils.createScenario(config);

Vehicles vehicles = scenario.getVehicles();

VehicleType vehicleType = VehicleUtils.createDefaultVehicleType();
vehicles.addVehicleType(vehicleType);

VehicleType vehicleType2 = vehicles.getFactory().createVehicleType(Id.create("custom", VehicleType.class));
vehicles.addVehicleType(vehicleType2);
}

@Test
void testSecond() {
Config config = ConfigUtils.createConfig();
Scenario scenario = ScenarioUtils.createScenario(config);

Vehicles vehicles = scenario.getVehicles();

VehicleType vehicleType = VehicleUtils.createDefaultVehicleType();
vehicles.addVehicleType(vehicleType);

// this caused a clash in IDs before getDefaultVehicleType was fixed
VehicleType vehicleType2 = vehicles.getFactory().createVehicleType(Id.create("custom", VehicleType.class));
vehicles.addVehicleType(vehicleType2);
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.0</version>
<version>3.4.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down

0 comments on commit fd27e72

Please sign in to comment.