Skip to content

Commit

Permalink
finished some todos, added config check
Browse files Browse the repository at this point in the history
  • Loading branch information
rakow committed Mar 12, 2024
1 parent e70140c commit 928d276
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package org.matsim.contrib.drt.estimator;

import com.google.inject.Binder;
import com.google.inject.Key;
import com.google.inject.Singleton;
import com.google.inject.binder.LinkedBindingBuilder;
import com.google.inject.multibindings.MapBinder;
import org.matsim.contrib.drt.analysis.DrtEventSequenceCollector;
import org.matsim.contrib.drt.estimator.impl.BasicDrtEstimator;
import org.matsim.contrib.drt.estimator.impl.PessimisticDrtEstimator;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.dvrp.run.AbstractDvrpModeModule;
import org.matsim.contrib.dvrp.run.DvrpMode;
import org.matsim.contrib.dvrp.run.DvrpModes;
import org.matsim.core.modal.ModalProviders;
import org.matsim.core.modal.ModalAnnotationCreator;

import java.lang.annotation.Annotation;

/**
* Main module that needs to be installed if any estimator is to be used.
Expand All @@ -26,14 +28,17 @@ public DrtEstimatorModule(String mode, DrtConfigGroup drtCfg, DrtEstimatorParams
this.params = params;
}

public static Object bindEstimator(Binder binder, String mode){

// TODO create helper method for binding
/**
* Create binder for estimator to a specific mode. This is a helper method to use binding without creating
* a separate modal module.
*/
public static LinkedBindingBuilder<DrtEstimator> bindEstimator(Binder binder, String mode) {
Key<DrtEstimator> key = modalKey(DvrpModes::mode, mode);
return binder.bind(key);
}

// DvrpMode key = DvrpModes.mode(mode);
// binder.bind(key)
// ModalProviders.createProvider(mode, DvrpModes::mode);
return null;
private static <T, M extends Annotation> Key<DrtEstimator> modalKey(ModalAnnotationCreator<M> f, String mode) {
return f.key(DrtEstimator.class, mode);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public enum OperationalScheme {


public enum SimulationType {
fullSimulation, drtSpeedup, estimateAndTeleport
fullSimulation, estimateAndTeleport
}

@Parameter
Expand Down Expand Up @@ -344,7 +344,10 @@ protected void checkConsistency(Config config) {
DvrpModeRoutingNetworkModule.checkUseModeFilteredSubnetworkAllowed(config, mode);
}

// TODO: check for new speed up params
if (simulationType == SimulationType.estimateAndTeleport) {
Verify.verify(drtSpeedUpParams == null, "Simulation type is estimateAndTeleport, but drtSpeedUpParams is set. " +
"Please remove drtSpeedUpParams from the config, as these two functionalities are not compatible.");
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class DrtTeleportedRouteCalculator implements TeleportedRouteCalculator {
// it could be possible to integrate the drt estimators used by the informed mode-choice
// this router should probably not use the beeline distance but the direct travel route
// speed-up would still be significant (oct'23)
// estimator have been moved to drt contrib, one can now use estimateAndTeleport for new functionality (mar'24)

@Override
public Route calculateRoute(PassengerRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import org.assertj.core.data.Offset;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.matsim.contrib.drt.estimator.DrtEstimator;
import org.matsim.contrib.drt.estimator.DrtEstimatorModule;
import org.matsim.contrib.drt.estimator.impl.PessimisticDrtEstimator;
import org.matsim.contrib.drt.fare.DrtFareParams;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.drt.run.DrtControlerCreator;
import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup;
import org.matsim.contrib.dvrp.run.AbstractDvrpModeModule;
import org.matsim.contrib.dvrp.run.DvrpConfigGroup;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.Controler;
import org.matsim.core.utils.io.IOUtils;
import org.matsim.examples.ExamplesUtils;
Expand Down Expand Up @@ -53,10 +53,12 @@ void testTeleportationEngine() throws IOException {

// Setup to enable estimator and teleportation
drtConfigGroup.simulationType = DrtConfigGroup.SimulationType.estimateAndTeleport;
controler.addOverridingModule(new AbstractDvrpModeModule(drtConfigGroup.mode) {

// This uses the helper method to bind an estimator. Alternatively a separate modal module could also be created.
controler.addOverridingModule(new AbstractModule() {
@Override
public void install() {
bindModal(DrtEstimator.class).toInstance(new PessimisticDrtEstimator(drtConfigGroup));
DrtEstimatorModule.bindEstimator(binder(), drtConfigGroup.mode).toInstance(new PessimisticDrtEstimator(drtConfigGroup));
}
});

Expand Down

0 comments on commit 928d276

Please sign in to comment.