コード例 #1
0
  @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;
  }
コード例 #2
0
  @Override
  public TripRouter instantiateAndConfigureTripRouter(RoutingContext routingContext) {
    // TODO Auto-generated method stub

    final TripRouter router = delegate.instantiateAndConfigureTripRouter(routingContext);

    // add our module to the instance
    router.setRoutingModule("movingpathways", new AAMRoutingModule(this.scenario));

    /*
    router.setRoutingModule(TransportMode.pt,
    		new TransitMultiModalAccessRoutingModule(
    				scenario,
    				new InitialNodeRouter(
    					router.getRoutingModule( "movingpathways" ),
    					scenario.getConfig().transitRouter().getSearchRadius(),
    					1,
    					scoringParams )

    				) );

    */
    final MainModeIdentifier defaultModeIdentifier = router.getMainModeIdentifier();
    router.setMainModeIdentifier(
        new MainModeIdentifier() {
          @Override
          public String identifyMainMode(final List<? extends PlanElement> tripElements) {
            boolean hadMovingPathway = false;
            for (PlanElement pe : tripElements) {
              if (pe instanceof Leg) {
                final Leg l = (Leg) pe;
                if (l.getMode().equals("movingpathways")) {
                  hadMovingPathway = true;
                }
                if (l.getMode().equals(TransportMode.transit_walk)) {
                  return TransportMode.pt;
                }
              }
            }

            if (hadMovingPathway) {
              // there were bike sharing legs but no transit walk
              return "movingpathways";
            }

            return defaultModeIdentifier.identifyMainMode(tripElements);
          }
        });

    return router;
  }
コード例 #3
0
  @Override
  public TripRouter get() {
    final TripRouter tripRouter = defaultFactory.get();

    final TransitRouterWrapper routingModule =
        new TransitRouterWrapper(
            transitRouterFactory.get(),
            scenario.getTransitSchedule(),
            scenario.getNetwork(), // use a walk router in case no PT path is found
            DefaultRoutingModules.createTeleportationRouter(
                TransportMode.transit_walk,
                scenario.getPopulation().getFactory(),
                scenario
                    .getConfig()
                    .plansCalcRoute()
                    .getModeRoutingParams()
                    .get(TransportMode.walk)));

    tripRouter.setRoutingModule(TransportMode.pt, routingModule);

    return tripRouter;
  }