@Override
  public TripRouter instantiateAndConfigureTripRouter(RoutingContext routingContext) {

    TripRouter instance = this.delegateFactory.instantiateAndConfigureTripRouter(routingContext);

    Network network = this.scenario.getNetwork();
    PopulationFactory populationFactory = this.scenario.getPopulation().getFactory();
    ModeRouteFactory modeRouteFactory =
        ((PopulationFactoryImpl) populationFactory).getModeRouteFactory();

    MultiModalConfigGroup multiModalConfigGroup =
        (MultiModalConfigGroup) scenario.getConfig().getModule(MultiModalConfigGroup.GROUP_NAME);
    Set<String> simulatedModes =
        CollectionUtils.stringToSet(multiModalConfigGroup.getSimulatedModes());
    for (String mode : simulatedModes) {

      if (instance.getRegisteredModes().contains(mode)) {
        log.warn("A routing algorithm for " + mode + " is already registered. It is replaced!");
      }

      TravelTime travelTime = this.multimodalTravelTimes.get(mode);
      if (travelTime == null) {
        throw new RuntimeException(
            "No travel time object was found for mode " + mode + "! Aborting.");
      }

      Network subNetwork = multimodalSubNetworks.get(mode);
      if (subNetwork == null) {
        subNetwork = NetworkImpl.createNetwork();
        Set<String> restrictions = new HashSet<>();
        restrictions.add(mode);
        TransportModeNetworkFilter networkFilter = new TransportModeNetworkFilter(network);
        networkFilter.filter(subNetwork, restrictions);
        this.multimodalSubNetworks.put(mode, subNetwork);
      }

      /*
       * We cannot use the travel disutility object from the routingContext since it
       * has not been created for the modes used here.
       */
      TravelDisutility travelDisutility =
          this.travelDisutilityFactory.createTravelDisutility(
              travelTime, scenario.getConfig().planCalcScore());
      LeastCostPathCalculator routeAlgo =
          this.leastCostPathCalculatorFactory.createPathCalculator(
              subNetwork, travelDisutility, travelTime);
      RoutingModule legRouterWrapper =
          DefaultRoutingModules.createNetworkRouter(mode, populationFactory, subNetwork, routeAlgo);
      instance.setRoutingModule(mode, legRouterWrapper);
    }

    return instance;
  }
  public static void run(Scenario scenario) {
    Config config = scenario.getConfig();
    log.info("setting up multi modal simulation");

    MultiModalConfigGroup multiModalConfigGroup =
        ConfigUtils.addOrGetModule(
            config, MultiModalConfigGroup.GROUP_NAME, MultiModalConfigGroup.class);

    // set Route Factories
    //		LinkNetworkRouteFactory factory = new LinkNetworkRouteFactory();
    //        for (String mode :
    // CollectionUtils.stringToArray(multiModalConfigGroup.getSimulatedModes())) {
    //			((PopulationFactoryImpl) scenario.getPopulation().getFactory()).setRouteFactory(mode,
    // factory);
    //		}

    if (multiModalConfigGroup.isCreateMultiModalNetwork()) {
      log.info("Creating multi modal network.");
      new MultiModalNetworkCreator(multiModalConfigGroup).run(scenario.getNetwork());
    }

    if (multiModalConfigGroup.isEnsureActivityReachability()) {
      log.info(
          "Relocating activities that cannot be reached by the transport modes of their from- and/or to-legs...");
      EnsureActivityReachability ensureActivityReachability =
          new EnsureActivityReachability(scenario);
      ensureActivityReachability.run(scenario.getPopulation());
      ensureActivityReachability.printRelocateCount();
    }

    if (multiModalConfigGroup.isDropNonCarRoutes()) {
      log.info(
          "Dropping existing routes of modes which are simulated with the multi modal mobsim.");
      new NonCarRouteDropper(multiModalConfigGroup).run(scenario.getPopulation());
    }
  }