Exemple #1
0
  /**
   * Finds direct paths between from and to coordinates in request and adds them to option
   *
   * @param request
   * @param option
   */
  private void findDirectPaths(ProfileRequest request, ProfileOption option) {
    // For direct modes
    for (LegMode mode : request.directModes) {
      StreetRouter streetRouter = new StreetRouter(transportNetwork.streetLayer);
      StreetPath streetPath;
      streetRouter.profileRequest = request;
      if (mode == LegMode.BICYCLE_RENT) {
        if (!transportNetwork.streetLayer.bikeSharing) {
          LOG.warn("Bike sharing trip requested but no bike sharing stations in the streetlayer");
          continue;
        }
        streetRouter = findBikeRentalPath(request, streetRouter, true);
        if (streetRouter != null) {
          StreetRouter.State lastState = streetRouter.getState(request.toLat, request.toLon);
          if (lastState != null) {
            streetPath =
                new StreetPath(lastState, streetRouter, LegMode.BICYCLE_RENT, transportNetwork);

          } else {
            LOG.warn(
                "MODE:{}, Edge near the destination coordinate wasn't found. Routing didn't start!",
                mode);
            continue;
          }
        } else {
          LOG.warn("Not found path from cycle to end");
          continue;
        }
      } else {
        streetRouter.streetMode = StreetMode.valueOf(mode.toString());
        streetRouter.timeLimitSeconds = request.streetTime * 60;
        if (streetRouter.setOrigin(request.fromLat, request.fromLon)) {
          if (!streetRouter.setDestination(request.toLat, request.toLon)) {
            LOG.warn("Direct mode {} destination wasn't found!", mode);
            continue;
          }
          streetRouter.route();
          StreetRouter.State lastState = streetRouter.getState(streetRouter.getDestinationSplit());
          if (lastState == null) {
            LOG.warn("Direct mode {} last state wasn't found", mode);
            continue;
          }
          streetPath = new StreetPath(lastState, transportNetwork);
        } else {
          LOG.warn("Direct mode {} origin wasn't found!", mode);
          continue;
        }
      }

      StreetSegment streetSegment =
          new StreetSegment(streetPath, mode, transportNetwork.streetLayer);
      option.addDirect(streetSegment, request.getFromTimeDateZD());
    }
  }
Exemple #2
0
  // Does point to point routing with data from request
  public ProfileResponse getPlan(ProfileRequest request) {
    long startRouting = System.currentTimeMillis();
    request.zoneId = transportNetwork.getTimeZone();
    // Do the query and return result
    ProfileResponse profileResponse = new ProfileResponse();

    ProfileOption option = new ProfileOption();

    findDirectPaths(request, option);
    option.summary = option.generateSummary();
    profileResponse.addOption(option);

    if (request.hasTransit()) {
      Map<LegMode, StreetRouter> accessRouter = new HashMap<>(request.accessModes.size());
      Map<LegMode, StreetRouter> egressRouter = new HashMap<>(request.egressModes.size());

      // This map saves which access mode was used to access specific stop in access mode
      TIntObjectMap<LegMode> stopModeAccessMap = new TIntObjectHashMap<>();
      // This map saves which egress mode was used to access specific stop in egress mode
      TIntObjectMap<LegMode> stopModeEgressMap = new TIntObjectHashMap<>();

      findAccessPaths(request, accessRouter);

      findEgressPaths(request, egressRouter);

      // fold access and egress times into single maps
      TIntIntMap accessTimes =
          combineMultimodalRoutingAccessTimes(accessRouter, stopModeAccessMap, request);
      TIntIntMap egressTimes =
          combineMultimodalRoutingAccessTimes(egressRouter, stopModeEgressMap, request);

      McRaptorSuboptimalPathProfileRouter router =
          new McRaptorSuboptimalPathProfileRouter(
              transportNetwork, request, accessTimes, egressTimes);
      List<PathWithTimes> usefullpathList = new ArrayList<>();

      // getPaths actually returns a set, which is important so that things are deduplicated.
      // However we need a list
      // so we can sort it below.
      usefullpathList.addAll(router.getPaths());

      // This sort is necessary only for text debug output so it will be disabled when it is
      // finished

      /**
       * Orders first no transfers then one transfers 2 etc - then orders according to first trip: -
       * board stop - alight stop - alight time - same for one transfer trip
       */
      usefullpathList.sort(
          (o1, o2) -> {
            int c;
            c = Integer.compare(o1.patterns.length, o2.patterns.length);
            if (c == 0) {
              c = Integer.compare(o1.boardStops[0], o2.boardStops[0]);
            }
            if (c == 0) {
              c = Integer.compare(o1.alightStops[0], o2.alightStops[0]);
            }
            if (c == 0) {
              c = Integer.compare(o1.alightTimes[0], o2.alightTimes[0]);
            }
            if (c == 0 && o1.patterns.length == 2) {
              c = Integer.compare(o1.boardStops[1], o2.boardStops[1]);
              if (c == 0) {
                c = Integer.compare(o1.alightStops[1], o2.alightStops[1]);
              }
              if (c == 0) {
                c = Integer.compare(o1.alightTimes[1], o2.alightTimes[1]);
              }
            }
            return c;
          });
      LOG.info("Usefull paths:{}", usefullpathList.size());
      int seen_paths = 0;
      int boardStop = -1, alightStop = -1;
      for (PathWithTimes path : usefullpathList) {
        profileResponse.addTransitPath(
            accessRouter,
            egressRouter,
            stopModeAccessMap,
            stopModeEgressMap,
            path,
            transportNetwork,
            request.getFromTimeDateZD());
        // LOG.info("Num patterns:{}", path.patterns.length);
        // ProfileOption transit_option = new ProfileOption();

        /*if (path.patterns.length == 1) {
            continue;
        }*/

        /*if (seen_paths > 20) {
            break;
        }*/

        if (LOG.isDebugEnabled()) {
          LOG.debug(" ");
          for (int i = 0; i < path.patterns.length; i++) {
            // TransitSegment transitSegment = new TransitSegment(transportNetwork.transitLayer,
            // path.boardStops[i], path.alightStops[i], path.patterns[i]);
            if (!(((boardStop == path.boardStops[i] && alightStop == path.alightStops[i])))) {
              LOG.debug(
                  "   BoardStop: {} pattern: {} allightStop: {}",
                  path.boardStops[i],
                  path.patterns[i],
                  path.alightStops[i]);
            }
            TripPattern pattern = transportNetwork.transitLayer.tripPatterns.get(path.patterns[i]);
            if (pattern.routeIndex >= 0) {
              RouteInfo routeInfo = transportNetwork.transitLayer.routes.get(pattern.routeIndex);
              LOG.debug(
                  "     Pattern:{} on route:{} ({}) with {} stops",
                  path.patterns[i],
                  routeInfo.route_long_name,
                  routeInfo.route_short_name,
                  pattern.stops.length);
            }
            LOG.debug(
                "     {}->{} ({}:{})",
                transportNetwork.transitLayer.stopNames.get(path.boardStops[i]),
                transportNetwork.transitLayer.stopNames.get(path.alightStops[i]),
                path.alightTimes[i] / 3600,
                path.alightTimes[i] % 3600 / 60);
            // transit_option.addTransit(transitSegment);
          }
          boardStop = path.boardStops[0];
          alightStop = path.alightStops[0];
        }
        seen_paths++;
      }
      profileResponse.generateStreetTransfers(transportNetwork, request);
    }

    LOG.info("Returned {} options", profileResponse.getOptions().size());
    LOG.info("Took {} ms", System.currentTimeMillis() - startRouting);

    return profileResponse;
  }