Skip to content

Commit

Permalink
Merge branch 'master' into updateFreespeedCachePath
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuehnel authored Jan 6, 2025
2 parents d54cbe5 + b757f83 commit 0c1ca6b
Show file tree
Hide file tree
Showing 51 changed files with 2,386 additions and 494 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.matsim.application.options;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -38,7 +39,9 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.function.Predicate;
import java.util.zip.ZipEntry;
Expand Down Expand Up @@ -118,6 +121,19 @@ public static DataStore openDataStore(String shp) throws IOException {
if (shp.endsWith(".shp"))
ds = factory.createDataStore(url);
else if (shp.endsWith(".gpkg")) {

// GeoPackage does not work with URLs, need to download it first
if (url.getProtocol().startsWith("http")) {

String name = FilenameUtils.getBaseName(url.getFile());

Path tmp = Files.createTempFile(name, ".gpkg");
Files.copy(url.openStream(), tmp, StandardCopyOption.REPLACE_EXISTING);
tmp.toFile().deleteOnExit();

shp = tmp.toString();
}

ds = DataStoreFinder.getDataStore(Map.of(
GeoPkgDataStoreFactory.DBTYPE.key, "geopkg",
GeoPkgDataStoreFactory.DATABASE.key, shp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@

package org.matsim.contrib.drt.extension;

import java.util.Optional;
import java.util.function.Supplier;

import javax.annotation.Nullable;

import org.matsim.contrib.drt.extension.companions.DrtCompanionParams;
import org.matsim.contrib.drt.extension.services.services.params.DrtServicesParams;
import org.matsim.contrib.drt.extension.insertion.spatialFilter.DrtSpatialRequestFleetFilterParams;
import org.matsim.contrib.drt.extension.operations.DrtOperationsParams;
import org.matsim.contrib.drt.extension.services.services.params.DrtServicesParams;
import org.matsim.contrib.drt.optimizer.constraints.DefaultDrtOptimizationConstraintsSet;
import org.matsim.contrib.drt.optimizer.constraints.DrtOptimizationConstraintsSet;
import org.matsim.contrib.drt.run.DrtConfigGroup;

import javax.annotation.Nullable;
import java.util.Optional;
import java.util.function.Supplier;

/**
* @author Steffen Axer
* <p>
Expand All @@ -47,6 +47,9 @@ public class DrtWithExtensionsConfigGroup extends DrtConfigGroup {
@Nullable
private DrtServicesParams drtServicesParams;

@Nullable
private DrtSpatialRequestFleetFilterParams drtSpatialRequestFleetFilterParams;

public DrtWithExtensionsConfigGroup() {
this(DefaultDrtOptimizationConstraintsSet::new);
}
Expand All @@ -64,6 +67,10 @@ public DrtWithExtensionsConfigGroup(Supplier<DrtOptimizationConstraintsSet> drtO
// Optional
addDefinition(DrtServicesParams.SET_TYPE, DrtServicesParams::new, () -> drtServicesParams,
params -> drtServicesParams = (DrtServicesParams) params);

// Optional
addDefinition(DrtSpatialRequestFleetFilterParams.SET_NAME, DrtSpatialRequestFleetFilterParams::new, () -> drtSpatialRequestFleetFilterParams,
params -> drtSpatialRequestFleetFilterParams = (DrtSpatialRequestFleetFilterParams) params);
}

public Optional<DrtCompanionParams> getDrtCompanionParams() {
Expand All @@ -78,4 +85,7 @@ public Optional<DrtServicesParams> getServicesParams() {
return Optional.ofNullable(drtServicesParams);
}

public Optional<DrtSpatialRequestFleetFilterParams> getSpatialRequestFleetFilterParams() {
return Optional.ofNullable(drtSpatialRequestFleetFilterParams);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

package org.matsim.contrib.drt.extension.edrt.run;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.matsim.api.core.v01.network.Network;
import org.matsim.contrib.drt.extension.edrt.EDrtActionCreator;
import org.matsim.contrib.drt.extension.edrt.optimizer.EDrtOptimizer;
Expand All @@ -29,18 +31,12 @@
import org.matsim.contrib.drt.extension.edrt.schedule.EDrtTaskFactoryImpl;
import org.matsim.contrib.drt.extension.edrt.scheduler.EmptyVehicleChargingScheduler;
import org.matsim.contrib.drt.optimizer.*;
import org.matsim.contrib.drt.optimizer.constraints.DefaultDrtOptimizationConstraintsSet;
import org.matsim.contrib.drt.optimizer.constraints.DrtOptimizationConstraintsSet;
import org.matsim.contrib.drt.optimizer.depot.DepotFinder;
import org.matsim.contrib.drt.optimizer.insertion.CostCalculationStrategy;
import org.matsim.contrib.drt.optimizer.insertion.DefaultInsertionCostCalculator;
import org.matsim.contrib.drt.optimizer.insertion.DefaultUnplannedRequestInserter;
import org.matsim.contrib.drt.optimizer.insertion.DrtInsertionSearch;
import org.matsim.contrib.drt.optimizer.insertion.InsertionCostCalculator;
import org.matsim.contrib.drt.optimizer.insertion.UnplannedRequestInserter;
import org.matsim.contrib.drt.optimizer.insertion.*;
import org.matsim.contrib.drt.optimizer.rebalancing.RebalancingStrategy;
import org.matsim.contrib.drt.passenger.DrtOfferAcceptor;
import org.matsim.contrib.drt.passenger.DefaultOfferAcceptor;
import org.matsim.contrib.drt.passenger.DrtOfferAcceptor;
import org.matsim.contrib.drt.prebooking.PrebookingActionCreator;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.drt.schedule.DrtTaskFactory;
Expand Down Expand Up @@ -69,9 +65,6 @@
import org.matsim.core.router.util.TravelDisutility;
import org.matsim.core.router.util.TravelTime;

import com.google.inject.Inject;
import com.google.inject.Singleton;

/**
* @author Michal Maciejewski (michalm)
*/
Expand Down Expand Up @@ -128,14 +121,16 @@ public EmptyVehicleChargingScheduler get() {
addModalComponent(QSimScopeForkJoinPoolHolder.class,
() -> new QSimScopeForkJoinPoolHolder(drtCfg.numberOfThreads));

bindModal(RequestFleetFilter.class).toProvider(modalProvider(getter -> RequestFleetFilter.none));

bindModal(UnplannedRequestInserter.class).toProvider(modalProvider(
getter -> new DefaultUnplannedRequestInserter(drtCfg, getter.getModal(Fleet.class),
getter.get(MobsimTimer.class), getter.get(EventsManager.class),
getter.getModal(RequestInsertionScheduler.class),
getter.getModal(VehicleEntry.EntryFactory.class), getter.getModal(DrtInsertionSearch.class),
getter.getModal(DrtRequestInsertionRetryQueue.class), getter.getModal(DrtOfferAcceptor.class),
getter.getModal(QSimScopeForkJoinPoolHolder.class).getPool(),
getter.getModal(PassengerStopDurationProvider.class)))).asEagerSingleton();
getter.getModal(PassengerStopDurationProvider.class), getter.getModal(RequestFleetFilter.class)))).asEagerSingleton();

bindModal(InsertionCostCalculator.class).toProvider(modalProvider(
getter -> new DefaultInsertionCostCalculator(getter.getModal(CostCalculationStrategy.class),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* *********************************************************************** *
* project: org.matsim.*
* *
* *********************************************************************** *
* *
* copyright : (C) 2024 by the members listed in the COPYING, *
* LICENSE and WARRANTY file. *
* email : info at matsim dot org *
* *
* *********************************************************************** *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* See also COPYING, LICENSE and WARRANTY file *
* *
* *********************************************************************** */

package org.matsim.contrib.drt.extension.insertion.spatialFilter;

import com.google.common.base.Verify;
import jakarta.validation.constraints.Positive;
import jakarta.validation.constraints.PositiveOrZero;
import org.matsim.contrib.common.util.ReflectiveConfigGroupWithConfigurableParameterSets;
import org.matsim.core.config.Config;

/**
* @author steffenaxer
*/
public class DrtSpatialRequestFleetFilterParams extends ReflectiveConfigGroupWithConfigurableParameterSets {

public static final String SET_NAME = "spatialRequestFleetFilter";

public DrtSpatialRequestFleetFilterParams() {
super(SET_NAME);
}

@Parameter
@Positive
@Comment("Expansion factor for the iterative expansion of search radius until max expansion or the" +
"minimum number of candidates is reached. Must be positive.")
public double expansionFactor = 2;

@Parameter
@PositiveOrZero
@Comment("Minimum expansion in map units (meters in most projections).")
public double minExpansion = 1000;

@Parameter
@PositiveOrZero
@Comment("Maximum expansion in map units (meters in most projections).")
public double maxExpansion = 5000;

@Parameter
@Comment("Returns the unfiltered fleet if the filter did not keep enough candidates.")
public boolean returnAllIfEmpty = true;

@Parameter
@Positive
@Comment("Minimum number of vehicle candidates the filter has to find.")
public int minCandidates = 1;

@Parameter
@PositiveOrZero
@Comment("Update interval of the periodically built spatial search tree of vehicle positions.")
public double updateInterval = 5 * 600;

@Override
protected void checkConsistency(Config config) {
super.checkConsistency(config);
Verify.verify(expansionFactor > 0, "Expansion factor must be greater than zero");
Verify.verify(minExpansion <= maxExpansion, "Max expansion must not be smaller than minimum expansion");
Verify.verify(minExpansion >= 0, "Expansion must be greater than zero");
Verify.verify(minCandidates > 0, "Minimum number of candidates must be positive");
Verify.verify(updateInterval >= 0, "Update interval must not be negative");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* *********************************************************************** *
* project: org.matsim.*
* *
* *********************************************************************** *
* *
* copyright : (C) 2024 by the members listed in the COPYING, *
* LICENSE and WARRANTY file. *
* email : info at matsim dot org *
* *
* *********************************************************************** *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* See also COPYING, LICENSE and WARRANTY file *
* *
* *********************************************************************** */

package org.matsim.contrib.drt.extension.insertion.spatialFilter;

import org.matsim.contrib.drt.extension.DrtWithExtensionsConfigGroup;
import org.matsim.contrib.drt.optimizer.insertion.RequestFleetFilter;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.dvrp.fleet.Fleet;
import org.matsim.contrib.dvrp.run.AbstractDvrpModeQSimModule;
import org.matsim.core.mobsim.framework.MobsimTimer;

/**
* @author nkuehnel | MOIA
*/
public class SpatialFilterInsertionSearchQSimModule extends AbstractDvrpModeQSimModule {


private final DrtSpatialRequestFleetFilterParams drtSpatialRequestFleetFilterParams;

public SpatialFilterInsertionSearchQSimModule(DrtConfigGroup drtCfg) {
super(drtCfg.getMode());
if(drtCfg instanceof DrtWithExtensionsConfigGroup withExtensionsConfigGroup &&
withExtensionsConfigGroup.getSpatialRequestFleetFilterParams().isPresent()) {
drtSpatialRequestFleetFilterParams = withExtensionsConfigGroup.getSpatialRequestFleetFilterParams().get();
} else {
throw new RuntimeException("Requires DrtSpatialRequestFleetFilterParams to be set. Use DrtWithExtensionsConfigGroup " +
"to do so.");
}
}

public record SpatialInsertionFilterSettings(double expansionIncrement, double minExpansion, double maxExpansion,
boolean returnAllIfEmpty, int minCandidates, double updateInterval){}

@Override
protected void configureQSim() {
bindModal(RequestFleetFilter.class).toProvider(modalProvider(getter ->
new SpatialRequestFleetFilter(getter.getModal(Fleet.class), getter.get(MobsimTimer.class), drtSpatialRequestFleetFilterParams)
));
}
}
Loading

0 comments on commit 0c1ca6b

Please sign in to comment.