Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTP2: First itinerary returned is often an implausible walk only trip #3289

Closed
marcusyoung opened this issue Dec 11, 2020 · 14 comments · Fixed by #3425
Closed

OTP2: First itinerary returned is often an implausible walk only trip #3289

marcusyoung opened this issue Dec 11, 2020 · 14 comments · Fixed by #3425
Labels
Milestone

Comments

@marcusyoung
Copy link
Contributor

marcusyoung commented Dec 11, 2020

Expected behavior

That the top suggested itinerary should be the "best" as determined by OTP

Observed behavior

For example, a two hour walk is suggested as the top itinerary when the fastest transit trip is 40 minutes

Version of OTP used (exact commit hash or JAR name)

v2.0.0

Example attached.
2020-12-11_20-37-12

Query used:

http://localhost:8080/?module=planner&fromPlace=53.4820190316094%2C-2.2446441650390625&toPlace=53.41863787930069%2C-2.2063636779785156&time=7%3A11pm&date=12-11-2020&mode=TRANSIT%2CWALK&arriveBy=false

@marcusyoung
Copy link
Contributor Author

marcusyoung commented Dec 11, 2020

To add to this:

  • The second option is also suboptimal, with about 2 miles of walking
  • Using the walkReluctance parameter has no discernable effect, whatever the value set
  • The only way to get back to decent results is to specify maxWalkDistance to, say, 800m. Yet the documentation says that this parameter is not the preferred way to reduce the amount of walking in OTP2.

@gmellemstrand gmellemstrand added this to Issues for discussion/in progress in OTP2 Development Dec 16, 2020
@t2gran t2gran added this to the 2.1 milestone Dec 18, 2020
@t2gran
Copy link
Member

t2gran commented Dec 18, 2020

Lett me clarify a few things here:

  • OTP2 only include a walk all the way alternative if WALK is used as direct mode, but if so, it is returned if found - we do not compare it with transit options at all. Many travel planners like to present bike and walk option, even if they are not pareto-optimal. We consider WALK and BIKE all-the-way to be a criteria by it´s own, then becoming pareto-optimal. OTP2 have a filter-chain that is applied to all itineraries and it is possible to add a filter that do this filtering. Note! That if you are not intrested in WALK option all you have to do is to remove the WALK from direct mode.

  • Sort order in OTP2:

        STREET_ONLY_FIRST,
       arriveBy ? DEPARTURE_TIME : ARRIVAL_TIME,
       GENERALIZED_COST,
       NUM_OF_TRANSFERS,
       arriveBy ? ARRIVAL_TIME : DEPARTURE_TIME

(OtpDefaultSortOrder.java)

As you can see, any street all the way is sorted first - this is done because it does not naturally blend in with the transit options. Providing another sort order would be easy - Most of the task would be to document it. The sorting is applied in the filter-chain and the max-limit-itinerary will remove itineraries of the "tail" (after it is sorted).

  • walkReluctance only have an effect if you mix modes, here there is a separate direct search done on WALK and an other search done with WALK and TRANSIT, this is a fundamental change in OTP2, compared with OTP1. As you noticed maxWalkDistance is the only parameter that limit the "street" result.

I hope this was useful, and let us know witch of these features are a MUST for you.

@marcusyoung
Copy link
Contributor Author

@t2gran Thanks. Can you clarify what you mean by 'direct mode'? Do you mean that the mode parameter sent to the API call should just contain "TRANSIT" and not "TRANSIT,WALK" if you don't want a WALK only option always returned? Would this still return a WALK-only option if the trip was very short and walking was a better option than transit? Does this apply to all the separate transit modes as well where in OTPv1 you needed to include "WALK". Presumbaly BICYCLE still needs to be treated as before and provided along with TRANSIT etc?

This change doesn't seem to be documented anywhere. In the API docs it says: "For a more complete discussion of this parameter see Routing modes." But the internal bookmark doesn't seem to exist.

@t2gran
Copy link
Member

t2gran commented Dec 18, 2020

Sorry, for the term "direct mode" i thought we changed it on the REST API, but it is only changed in the other APIs and in the internal router. I looked at the rest API and it "try" to map the list of modes to the new internal set of mode parameters: access+transit+egress and/or direct. I think we should remove the WALK from direct if you do not pass it in with together transit:

Mode
TRANSIT -> access=WALK, transit=TRANSIT, egress=WALK, direct=null
TRANSIT,WALK -> access=WALK, transit=TRANSIT, egress=WALK, direct=WALK

If I read the code correct the current implementation is:

TRANSIT -> access=WALK, transit=TRANSIT, egress=WALK, direct=WALK

Since the REST API is missing the access, egress, and direct parameters the only thing we can do is to make it as close to the old OTP1 API as we can. The GraphQL APIs have this.

I will try to ask about this at the next OTP2 dev meeting on Tue 22.12.2020 at 10:00 CET, feel free to join: https://meet.google.com/qwh-xzbz-atr

@marcusyoung
Copy link
Contributor Author

@t2gran, I tried passing just "TRANSIT" as the mode and get no itineraries returned, so I don't think WALK is included? Which I think is what you are saying (for the REST API)?

@t2gran
Copy link
Member

t2gran commented Dec 18, 2020

Yes I think this is a bug, we should add WALK to the access and egress modes if not street mode is set. Can you live with this until the next OTP2 release, hopefully by the end of Q1 2021?

@t2gran t2gran added the bug label Dec 18, 2020
@marcusyoung
Copy link
Contributor Author

marcusyoung commented Dec 18, 2020

@t2gran Yes, fine to wait for the next release, now I'm aware of what's happening. Thanks.

@marcusyoung
Copy link
Contributor Author

@t2gran Not sure if this is related to this, or whether I should create a new issue. But maxWalkDistance is imposed as a hard limit for CAR or BICYCLE modes in OTP2.

@ghost
Copy link

ghost commented Apr 21, 2023

It seems that this issue has returned (for me) on 2.2 and 2.3, I mention it here: #5062

Is there any way to fix this?

@leonardehrenfried
Copy link
Member

You can configure when exactly you want to see a walking leg: https://docs.opentripplanner.org/en/dev-2.x/RouteRequest/?h=itin#rd_if_nonTransitGeneralizedCostLimit

It's a little complex so read the docs carefully.

@ghost
Copy link

ghost commented Apr 21, 2023

Thanks for that suggestion, unfortunately it doesn't seem to work in my case. As paging next/previous does return the correct itinerary (related issue #5062 ) I have the feeling it's not a router problem, but something else.

I will note down my steps and understanding of the nonTransitGeneralizedCostLimit carefully, to make sure that I use that option as intended.

The request I run is:

http://my.domain.name/otp/routers/current/plan?fromPlace=52.073605%2C4.303689&toPlace=52.070959889346696%2C4.285032749176026&time=3%3A32pm&date=04-21-2023&mode=TRANSIT%2CWALK
Fold out for API response
{
  "requestParameters": {
    "date": "04-21-2023",
    "mode": "TRANSIT,WALK",
    "fromPlace": "52.073605,4.303689",
    "toPlace": "52.070959889346696,4.285032749176026",
    "time": "3:32pm"
  },
  "plan": {
    "date": 1682083920000,
    "from": {
      "name": "Origin",
      "lon": 4.303689,
      "lat": 52.073605,
      "vertexType": "NORMAL"
    },
    "to": {
      "name": "Destination",
      "lon": 4.2850327,
      "lat": 52.0709599,
      "vertexType": "NORMAL"
    },
    "itineraries": [
      {
        "duration": 1173,
        "startTime": 1682083920000,
        "endTime": 1682085093000,
        "walkTime": 1173,
        "transitTime": 0,
        "waitingTime": 0,
        "walkDistance": 1475.23,
        "walkLimitExceeded": false,
        "generalizedCost": 2238,
        "elevationLost": 0.0,
        "elevationGained": 0.0,
        "transfers": 0,
        "fare": {
          "fare": {
            
          },
          "details": {
            
          }
        },
        "legs": [
          {
            "startTime": 1682083920000,
            "endTime": 1682085093000,
            "departureDelay": 0,
            "arrivalDelay": 0,
            "realTime": false,
            "distance": 1475.23,
            "generalizedCost": 2238,
            "pathway": false,
            "mode": "WALK",
            "transitLeg": false,
            "route": "",
            "agencyTimeZoneOffset": 7200000,
            "interlineWithPreviousLeg": false,
            "from": {
              "name": "Origin",
              "lon": 4.303689,
              "lat": 52.073605,
              "departure": 1682083920000,
              "vertexType": "NORMAL"
            },
            "to": {
              "name": "Destination",
              "lon": 4.2850327,
              "lat": 52.0709599,
              "arrival": 1682085093000,
              "vertexType": "NORMAL"
            },
            "legGeometry": {
              "points": "csy|H}pgYRt@GDNh@@H\\pAt@xCHZnA~ER|@F^CXIVKNcBtAs@j@CB[ZY^S^Ud@Ul@I\\GZEPANALCPAX@Z?NJx@@L?BHh@?D?@BPDX@R@DDZ@HbAjHt@|FFd@h@~DBN@HHd@BP@L@HRnABPF`@D^BHb@bDNv@Rx@t@rCFPTz@|@fDNt@`@|BP`AF^Jj@TtAJf@@FBN@JBF",
              "length": 76
            },
            "steps": [
              {
                "distance": 20.85,
                "relativeDirection": "DEPART",
                "streetName": "Brouwersgracht",
                "absoluteDirection": "SOUTHWEST",
                "stayOn": false,
                "area": false,
                "bogusName": false,
                "lon": 4.3036743,
                "lat": 52.073621,
                "elevation": "",
                "walkingBike": false
              },
              {
                "distance": 4.3,
                "relativeDirection": "RIGHT",
                "streetName": "path",
                "absoluteDirection": "NORTHWEST",
                "stayOn": false,
                "area": false,
                "bogusName": true,
                "lon": 4.3034086,
                "lat": 52.0735288,
                "elevation": "",
                "walkingBike": false
              },
              {
                "distance": 258.4,
                "relativeDirection": "LEFT",
                "streetName": "Prinsegracht",
                "absoluteDirection": "SOUTHWEST",
                "stayOn": false,
                "area": false,
                "bogusName": false,
                "lon": 4.3033797,
                "lat": 52.0735632,
                "elevation": "",
                "walkingBike": false
              },
              {
                "distance": 321.06,
                "relativeDirection": "SLIGHTLY_RIGHT",
                "streetName": "Lijnbaan",
                "absoluteDirection": "NORTHWEST",
                "stayOn": false,
                "area": false,
                "bogusName": false,
                "lon": 4.3000719,
                "lat": 52.0724851,
                "elevation": "",
                "walkingBike": false
              },
              {
                "distance": 870.67,
                "relativeDirection": "CONTINUE",
                "streetName": "Loosduinseweg",
                "absoluteDirection": "WEST",
                "stayOn": false,
                "area": false,
                "bogusName": false,
                "lon": 4.296729,
                "lat": 52.0740016,
                "elevation": "",
                "walkingBike": false
              }
            ],
            "rentedBike": false,
            "walkingBike": false,
            "duration": 1173.0
          }
        ],
        "tooSloped": false,
        "arrivedAtDestinationWithRentedBicycle": false
      },
      {
        "duration": 346,
        "startTime": 1682084099000,
        "endTime": 1682084445000,
        "walkTime": 30,
        "transitTime": 316,
        "waitingTime": 0,
        "walkDistance": 28.2,
        "walkLimitExceeded": false,
        "generalizedCost": 969,
        "elevationLost": 0.0,
        "elevationGained": 0.0,
        "transfers": 0,
        "fare": {
          "fare": {
            
          },
          "details": {
            
          }
        },
        "legs": [
          {
            "startTime": 1682084099000,
            "endTime": 1682084415000,
            "departureDelay": 0,
            "arrivalDelay": 0,
            "realTime": false,
            "distance": 1307.94,
            "generalizedCost": 916,
            "pathway": false,
            "mode": "TRAM",
            "transitLeg": true,
            "route": "Lijn 4",
            "agencyName": "HTM",
            "agencyUrl": "http://www.htm.nl",
            "agencyTimeZoneOffset": 7200000,
            "routeColor": "ef7100",
            "routeType": 0,
            "routeId": "NL:84735",
            "routeTextColor": "000000",
            "interlineWithPreviousLeg": false,
            "tripShortName": "40119",
            "headsign": "DH De Uithof",
            "agencyId": "NL:HTM",
            "tripId": "NL:166141799",
            "serviceDate": "2023-04-21",
            "from": {
              "name": "Den Haag, Brouwersgracht",
              "stopId": "NL:2506373",
              "stopCode": "2824",
              "lon": 4.303689,
              "lat": 52.073605,
              "departure": 1682084099000,
              "stopIndex": 19,
              "stopSequence": 20,
              "vertexType": "TRANSIT"
            },
            "to": {
              "name": "Den Haag, De la Reyweg",
              "stopId": "NL:2506413",
              "stopCode": "3003",
              "lon": 4.285331,
              "lat": 52.070944,
              "arrival": 1682084415000,
              "departure": 1682084415000,
              "stopIndex": 22,
              "stopSequence": 23,
              "vertexType": "TRANSIT"
            },
            "legGeometry": {
              "points": "}ry|H_qgYx@l[??`Adi@??tK`k@",
              "length": 6
            },
            "steps": [
              
            ],
            "routeShortName": "4",
            "routeLongName": "Lijn 4",
            "duration": 316.0
          },
          {
            "startTime": 1682084415000,
            "endTime": 1682084445000,
            "departureDelay": 0,
            "arrivalDelay": 0,
            "realTime": false,
            "distance": 28.2,
            "generalizedCost": 51,
            "pathway": false,
            "mode": "WALK",
            "transitLeg": false,
            "route": "",
            "agencyTimeZoneOffset": 7200000,
            "interlineWithPreviousLeg": false,
            "from": {
              "name": "Den Haag, De la Reyweg",
              "stopId": "NL:2506413",
              "stopCode": "3003",
              "lon": 4.285331,
              "lat": 52.070944,
              "arrival": 1682084415000,
              "departure": 1682084415000,
              "vertexType": "TRANSIT"
            },
            "to": {
              "name": "Destination",
              "lon": 4.2850327,
              "lat": 52.0709599,
              "arrival": 1682084445000,
              "vertexType": "NORMAL"
            },
            "legGeometry": {
              "points": "kby|Hi~cYBA@FBRAB??MF@JBF",
              "length": 9
            },
            "steps": [
              {
                "distance": 28.2,
                "relativeDirection": "DEPART",
                "streetName": "Loosduinseweg",
                "absoluteDirection": "SOUTHWEST",
                "stayOn": false,
                "area": false,
                "bogusName": false,
                "lon": 4.2853418,
                "lat": 52.0709292,
                "elevation": "",
                "walkingBike": false
              }
            ],
            "rentedBike": false,
            "walkingBike": false,
            "duration": 30.0
          }
        ],
        "tooSloped": false,
        "arrivedAtDestinationWithRentedBicycle": false
      },
      {
        "duration": 346,
        "startTime": 1682084102000,
        "endTime": 1682084448000,
        "walkTime": 30,
        "transitTime": 316,
        "waitingTime": 0,
        "walkDistance": 28.2,
        "walkLimitExceeded": false,
        "generalizedCost": 969,
        "elevationLost": 0.0,
        "elevationGained": 0.0,
        "transfers": 0,
        "fare": {
          "fare": {
            
          },
          "details": {
            
          }
        },
        "legs": [
          {
            "startTime": 1682084102000,
            "endTime": 1682084418000,
            "departureDelay": 0,
            "arrivalDelay": 0,
            "realTime": false,
            "distance": 1307.94,
            "generalizedCost": 916,
            "pathway": false,
            "mode": "TRAM",
            "transitLeg": true,
            "route": "Kraaijenstein - Leidschendam Leidsenhage",
            "agencyName": "HTM",
            "agencyUrl": "http://www.htm.nl",
            "agencyTimeZoneOffset": 7200000,
            "routeType": 0,
            "routeId": "NL:84732",
            "interlineWithPreviousLeg": false,
            "tripShortName": "20092",
            "headsign": "DH Kraayenstein",
            "agencyId": "NL:HTM",
            "tripId": "NL:166143554",
            "serviceDate": "2023-04-21",
            "from": {
              "name": "Den Haag, Brouwersgracht",
              "stopId": "NL:2506373",
              "stopCode": "2824",
              "lon": 4.303689,
              "lat": 52.073605,
              "departure": 1682084102000,
              "stopIndex": 14,
              "stopSequence": 15,
              "vertexType": "TRANSIT"
            },
            "to": {
              "name": "Den Haag, De la Reyweg",
              "stopId": "NL:2506413",
              "stopCode": "3003",
              "lon": 4.285331,
              "lat": 52.070944,
              "arrival": 1682084418000,
              "departure": 1682084418000,
              "stopIndex": 17,
              "stopSequence": 18,
              "vertexType": "TRANSIT"
            },
            "legGeometry": {
              "points": "}ry|H_qgYx@l[??`Adi@??tK`k@",
              "length": 6
            },
            "steps": [
              
            ],
            "routeShortName": "2",
            "routeLongName": "Kraaijenstein - Leidschendam Leidsenhage",
            "duration": 316.0
          },
          {
            "startTime": 1682084418000,
            "endTime": 1682084448000,
            "departureDelay": 0,
            "arrivalDelay": 0,
            "realTime": false,
            "distance": 28.2,
            "generalizedCost": 51,
            "pathway": false,
            "mode": "WALK",
            "transitLeg": false,
            "route": "",
            "agencyTimeZoneOffset": 7200000,
            "interlineWithPreviousLeg": false,
            "from": {
              "name": "Den Haag, De la Reyweg",
              "stopId": "NL:2506413",
              "stopCode": "3003",
              "lon": 4.285331,
              "lat": 52.070944,
              "arrival": 1682084418000,
              "departure": 1682084418000,
              "vertexType": "TRANSIT"
            },
            "to": {
              "name": "Destination",
              "lon": 4.2850327,
              "lat": 52.0709599,
              "arrival": 1682084448000,
              "vertexType": "NORMAL"
            },
            "legGeometry": {
              "points": "kby|Hi~cYBA@FBRAB??MF@JBF",
              "length": 9
            },
            "steps": [
              {
                "distance": 28.2,
                "relativeDirection": "DEPART",
                "streetName": "Loosduinseweg",
                "absoluteDirection": "SOUTHWEST",
                "stayOn": false,
                "area": false,
                "bogusName": false,
                "lon": 4.2853418,
                "lat": 52.0709292,
                "elevation": "",
                "walkingBike": false
              }
            ],
            "rentedBike": false,
            "walkingBike": false,
            "duration": 30.0
          }
        ],
        "tooSloped": false,
        "arrivedAtDestinationWithRentedBicycle": false
      },
      {
        "duration": 346,
        "startTime": 1682084699000,
        "endTime": 1682085045000,
        "walkTime": 30,
        "transitTime": 316,
        "waitingTime": 0,
        "walkDistance": 28.2,
        "walkLimitExceeded": false,
        "generalizedCost": 969,
        "elevationLost": 0.0,
        "elevationGained": 0.0,
        "transfers": 0,
        "fare": {
          "fare": {
            
          },
          "details": {
            
          }
        },
        "legs": [
          {
            "startTime": 1682084699000,
            "endTime": 1682085015000,
            "departureDelay": 0,
            "arrivalDelay": 0,
            "realTime": false,
            "distance": 1307.94,
            "generalizedCost": 916,
            "pathway": false,
            "mode": "TRAM",
            "transitLeg": true,
            "route": "Lijn 4",
            "agencyName": "HTM",
            "agencyUrl": "http://www.htm.nl",
            "agencyTimeZoneOffset": 7200000,
            "routeColor": "ef7100",
            "routeType": 0,
            "routeId": "NL:84735",
            "routeTextColor": "000000",
            "interlineWithPreviousLeg": false,
            "tripShortName": "40121",
            "headsign": "DH De Uithof",
            "agencyId": "NL:HTM",
            "tripId": "NL:166141801",
            "serviceDate": "2023-04-21",
            "from": {
              "name": "Den Haag, Brouwersgracht",
              "stopId": "NL:2506373",
              "stopCode": "2824",
              "lon": 4.303689,
              "lat": 52.073605,
              "departure": 1682084699000,
              "stopIndex": 19,
              "stopSequence": 20,
              "vertexType": "TRANSIT"
            },
            "to": {
              "name": "Den Haag, De la Reyweg",
              "stopId": "NL:2506413",
              "stopCode": "3003",
              "lon": 4.285331,
              "lat": 52.070944,
              "arrival": 1682085015000,
              "departure": 1682085015000,
              "stopIndex": 22,
              "stopSequence": 23,
              "vertexType": "TRANSIT"
            },
            "legGeometry": {
              "points": "}ry|H_qgYx@l[??`Adi@??tK`k@",
              "length": 6
            },
            "steps": [
              
            ],
            "routeShortName": "4",
            "routeLongName": "Lijn 4",
            "duration": 316.0
          },
          {
            "startTime": 1682085015000,
            "endTime": 1682085045000,
            "departureDelay": 0,
            "arrivalDelay": 0,
            "realTime": false,
            "distance": 28.2,
            "generalizedCost": 51,
            "pathway": false,
            "mode": "WALK",
            "transitLeg": false,
            "route": "",
            "agencyTimeZoneOffset": 7200000,
            "interlineWithPreviousLeg": false,
            "from": {
              "name": "Den Haag, De la Reyweg",
              "stopId": "NL:2506413",
              "stopCode": "3003",
              "lon": 4.285331,
              "lat": 52.070944,
              "arrival": 1682085015000,
              "departure": 1682085015000,
              "vertexType": "TRANSIT"
            },
            "to": {
              "name": "Destination",
              "lon": 4.2850327,
              "lat": 52.0709599,
              "arrival": 1682085045000,
              "vertexType": "NORMAL"
            },
            "legGeometry": {
              "points": "kby|Hi~cYBA@FBRAB??MF@JBF",
              "length": 9
            },
            "steps": [
              {
                "distance": 28.2,
                "relativeDirection": "DEPART",
                "streetName": "Loosduinseweg",
                "absoluteDirection": "SOUTHWEST",
                "stayOn": false,
                "area": false,
                "bogusName": false,
                "lon": 4.2853418,
                "lat": 52.0709292,
                "elevation": "",
                "walkingBike": false
              }
            ],
            "rentedBike": false,
            "walkingBike": false,
            "duration": 30.0
          }
        ],
        "tooSloped": false,
        "arrivedAtDestinationWithRentedBicycle": false
      }
    ]
  },
  "metadata": {
    "searchWindowUsed": 2400,
    "nextDateTime": 1682084820000,
    "prevDateTime": 1682081520000
  },
  "previousPageCursor": "rO0ABXc1AQANUFJFVklPVVNfUEFHRQY2pfCAAAAAAAAJYAAXU1RSRUVUX0FORF9BUlJJVkFMX1RJTUU=",
  "nextPageCursor": "rO0ABXcxAQAJTkVYVF9QQUdFBjay1IAAAAAAAAlgABdTVFJFRVRfQU5EX0FSUklWQUxfVElNRQ==",
  "debugOutput": {
    "precalculationTime": 148690,
    "directStreetRouterTime": 9792032,
    "transitRouterTime": 632385842,
    "filteringTime": 1594812,
    "renderingTime": 1019426,
    "totalTime": 645004536,
    "transitRouterTimes": {
      "tripPatternFilterTime": 99954918,
      "accessEgressTime": 120800178,
      "raptorSearchTime": 409956304,
      "itineraryCreationTime": 1653727
    }
  },
  "elevationMetadata": {
    "ellipsoidToGeoidDifference": 47.694913775834976,
    "geoidElevation": false
  }
}

I use the text from the docs as a guide:

The max-limit is applied to itineraries with no transit legs, however all itineraries (including those with transit legs) are considered when calculating the minimum cost.

OK, my request returns 4 itineraries (I capped that with numItineraries in the router-config) which have the following modes and generalized costs:

  • WALK; 2238
  • TRAM+WALK: 969
  • TRAM+WALK: 969
  • TRAM+WALK: 969

The smallest generalized-cost value is used as input to the function.

That is 969 in my case.

The function is used to calculate a max-limit.

The default function is f(x) = 3,600 + 2.0 x. Filling in the current minimum of 969: f(969) = 3,600 + 2.0*969 = 5538.

The max-limit is then used to filter non-transit itineraries by generalized-cost. Itineraries with a cost higher than the max-limit are dropped from the result set.

None of the returned generalized costs is larger than 5538, so nothing is dropped. Works as expected.

Add `nonTransitGeneralizedCostLimit``

Now I add the nonTransitGeneralizedCostLimit to my request. My goal is to drop the 2238 weight given a 969 weight, so I assume a function of f(x) = 1.5 x

http://my.domain.name/otp/routers/current/plan?fromPlace=52.073605%2C4.303689&toPlace=52.070959889346696%2C4.285032749176026&time=3%3A32pm&date=04-21-2023&mode=TRANSIT%2CWALK&nonTransitGeneralizedCostLimit=f(x)%20=%201.5%20x
API response
{
  "requestParameters": {
    "date": "04-21-2023",
    "mode": "TRANSIT,WALK",
    "fromPlace": "52.073605,4.303689",
    "nonTransitGeneralizedCostLimit": "f(x) = 1.5 x",
    "toPlace": "52.070959889346696,4.285032749176026",
    "time": "3:32pm"
  },
  "plan": {
    "date": 1682083920000,
    "from": {
      "name": "Origin",
      "lon": 4.303689,
      "lat": 52.073605,
      "vertexType": "NORMAL"
    },
    "to": {
      "name": "Destination",
      "lon": 4.2850327,
      "lat": 52.0709599,
      "vertexType": "NORMAL"
    },
    "itineraries": [
      {
        "duration": 1173,
        "startTime": 1682083920000,
        "endTime": 1682085093000,
        "walkTime": 1173,
        "transitTime": 0,
        "waitingTime": 0,
        "walkDistance": 1475.23,
        "walkLimitExceeded": false,
        "generalizedCost": 2238,
        "elevationLost": 0.0,
        "elevationGained": 0.0,
        "transfers": 0,
        "fare": {
          "fare": {
            
          },
          "details": {
            
          }
        },
        "legs": [
          {
            "startTime": 1682083920000,
            "endTime": 1682085093000,
            "departureDelay": 0,
            "arrivalDelay": 0,
            "realTime": false,
            "distance": 1475.23,
            "generalizedCost": 2238,
            "pathway": false,
            "mode": "WALK",
            "transitLeg": false,
            "route": "",
            "agencyTimeZoneOffset": 7200000,
            "interlineWithPreviousLeg": false,
            "from": {
              "name": "Origin",
              "lon": 4.303689,
              "lat": 52.073605,
              "departure": 1682083920000,
              "vertexType": "NORMAL"
            },
            "to": {
              "name": "Destination",
              "lon": 4.2850327,
              "lat": 52.0709599,
              "arrival": 1682085093000,
              "vertexType": "NORMAL"
            },
            "legGeometry": {
              "points": "csy|H}pgYRt@GDNh@@H\\pAt@xCHZnA~ER|@F^CXIVKNcBtAs@j@CB[ZY^S^Ud@Ul@I\\GZEPANALCPAX@Z?NJx@@L?BHh@?D?@BPDX@R@DDZ@HbAjHt@|FFd@h@~DBN@HHd@BP@L@HRnABPF`@D^BHb@bDNv@Rx@t@rCFPTz@|@fDNt@`@|BP`AF^Jj@TtAJf@@FBN@JBF",
              "length": 76
            },
            "steps": [
              {
                "distance": 20.85,
                "relativeDirection": "DEPART",
                "streetName": "Brouwersgracht",
                "absoluteDirection": "SOUTHWEST",
                "stayOn": false,
                "area": false,
                "bogusName": false,
                "lon": 4.3036743,
                "lat": 52.073621,
                "elevation": "",
                "walkingBike": false
              },
              {
                "distance": 4.3,
                "relativeDirection": "RIGHT",
                "streetName": "path",
                "absoluteDirection": "NORTHWEST",
                "stayOn": false,
                "area": false,
                "bogusName": true,
                "lon": 4.3034086,
                "lat": 52.0735288,
                "elevation": "",
                "walkingBike": false
              },
              {
                "distance": 258.4,
                "relativeDirection": "LEFT",
                "streetName": "Prinsegracht",
                "absoluteDirection": "SOUTHWEST",
                "stayOn": false,
                "area": false,
                "bogusName": false,
                "lon": 4.3033797,
                "lat": 52.0735632,
                "elevation": "",
                "walkingBike": false
              },
              {
                "distance": 321.06,
                "relativeDirection": "SLIGHTLY_RIGHT",
                "streetName": "Lijnbaan",
                "absoluteDirection": "NORTHWEST",
                "stayOn": false,
                "area": false,
                "bogusName": false,
                "lon": 4.3000719,
                "lat": 52.0724851,
                "elevation": "",
                "walkingBike": false
              },
              {
                "distance": 870.67,
                "relativeDirection": "CONTINUE",
                "streetName": "Loosduinseweg",
                "absoluteDirection": "WEST",
                "stayOn": false,
                "area": false,
                "bogusName": false,
                "lon": 4.296729,
                "lat": 52.0740016,
                "elevation": "",
                "walkingBike": false
              }
            ],
            "rentedBike": false,
            "walkingBike": false,
            "duration": 1173.0
          }
        ],
        "tooSloped": false,
        "arrivedAtDestinationWithRentedBicycle": false
      },
      {
        "duration": 346,
        "startTime": 1682084099000,
        "endTime": 1682084445000,
        "walkTime": 30,
        "transitTime": 316,
        "waitingTime": 0,
        "walkDistance": 28.2,
        "walkLimitExceeded": false,
        "generalizedCost": 969,
        "elevationLost": 0.0,
        "elevationGained": 0.0,
        "transfers": 0,
        "fare": {
          "fare": {
            
          },
          "details": {
            
          }
        },
        "legs": [
          {
            "startTime": 1682084099000,
            "endTime": 1682084415000,
            "departureDelay": 0,
            "arrivalDelay": 0,
            "realTime": false,
            "distance": 1307.94,
            "generalizedCost": 916,
            "pathway": false,
            "mode": "TRAM",
            "transitLeg": true,
            "route": "Lijn 4",
            "agencyName": "HTM",
            "agencyUrl": "http://www.htm.nl",
            "agencyTimeZoneOffset": 7200000,
            "routeColor": "ef7100",
            "routeType": 0,
            "routeId": "NL:84735",
            "routeTextColor": "000000",
            "interlineWithPreviousLeg": false,
            "tripShortName": "40119",
            "headsign": "DH De Uithof",
            "agencyId": "NL:HTM",
            "tripId": "NL:166141799",
            "serviceDate": "2023-04-21",
            "from": {
              "name": "Den Haag, Brouwersgracht",
              "stopId": "NL:2506373",
              "stopCode": "2824",
              "lon": 4.303689,
              "lat": 52.073605,
              "departure": 1682084099000,
              "stopIndex": 19,
              "stopSequence": 20,
              "vertexType": "TRANSIT"
            },
            "to": {
              "name": "Den Haag, De la Reyweg",
              "stopId": "NL:2506413",
              "stopCode": "3003",
              "lon": 4.285331,
              "lat": 52.070944,
              "arrival": 1682084415000,
              "departure": 1682084415000,
              "stopIndex": 22,
              "stopSequence": 23,
              "vertexType": "TRANSIT"
            },
            "legGeometry": {
              "points": "}ry|H_qgYx@l[??`Adi@??tK`k@",
              "length": 6
            },
            "steps": [
              
            ],
            "routeShortName": "4",
            "routeLongName": "Lijn 4",
            "duration": 316.0
          },
          {
            "startTime": 1682084415000,
            "endTime": 1682084445000,
            "departureDelay": 0,
            "arrivalDelay": 0,
            "realTime": false,
            "distance": 28.2,
            "generalizedCost": 51,
            "pathway": false,
            "mode": "WALK",
            "transitLeg": false,
            "route": "",
            "agencyTimeZoneOffset": 7200000,
            "interlineWithPreviousLeg": false,
            "from": {
              "name": "Den Haag, De la Reyweg",
              "stopId": "NL:2506413",
              "stopCode": "3003",
              "lon": 4.285331,
              "lat": 52.070944,
              "arrival": 1682084415000,
              "departure": 1682084415000,
              "vertexType": "TRANSIT"
            },
            "to": {
              "name": "Destination",
              "lon": 4.2850327,
              "lat": 52.0709599,
              "arrival": 1682084445000,
              "vertexType": "NORMAL"
            },
            "legGeometry": {
              "points": "kby|Hi~cYBA@FBRAB??MF@JBF",
              "length": 9
            },
            "steps": [
              {
                "distance": 28.2,
                "relativeDirection": "DEPART",
                "streetName": "Loosduinseweg",
                "absoluteDirection": "SOUTHWEST",
                "stayOn": false,
                "area": false,
                "bogusName": false,
                "lon": 4.2853418,
                "lat": 52.0709292,
                "elevation": "",
                "walkingBike": false
              }
            ],
            "rentedBike": false,
            "walkingBike": false,
            "duration": 30.0
          }
        ],
        "tooSloped": false,
        "arrivedAtDestinationWithRentedBicycle": false
      },
      {
        "duration": 346,
        "startTime": 1682084102000,
        "endTime": 1682084448000,
        "walkTime": 30,
        "transitTime": 316,
        "waitingTime": 0,
        "walkDistance": 28.2,
        "walkLimitExceeded": false,
        "generalizedCost": 969,
        "elevationLost": 0.0,
        "elevationGained": 0.0,
        "transfers": 0,
        "fare": {
          "fare": {
            
          },
          "details": {
            
          }
        },
        "legs": [
          {
            "startTime": 1682084102000,
            "endTime": 1682084418000,
            "departureDelay": 0,
            "arrivalDelay": 0,
            "realTime": false,
            "distance": 1307.94,
            "generalizedCost": 916,
            "pathway": false,
            "mode": "TRAM",
            "transitLeg": true,
            "route": "Kraaijenstein - Leidschendam Leidsenhage",
            "agencyName": "HTM",
            "agencyUrl": "http://www.htm.nl",
            "agencyTimeZoneOffset": 7200000,
            "routeType": 0,
            "routeId": "NL:84732",
            "interlineWithPreviousLeg": false,
            "tripShortName": "20092",
            "headsign": "DH Kraayenstein",
            "agencyId": "NL:HTM",
            "tripId": "NL:166143554",
            "serviceDate": "2023-04-21",
            "from": {
              "name": "Den Haag, Brouwersgracht",
              "stopId": "NL:2506373",
              "stopCode": "2824",
              "lon": 4.303689,
              "lat": 52.073605,
              "departure": 1682084102000,
              "stopIndex": 14,
              "stopSequence": 15,
              "vertexType": "TRANSIT"
            },
            "to": {
              "name": "Den Haag, De la Reyweg",
              "stopId": "NL:2506413",
              "stopCode": "3003",
              "lon": 4.285331,
              "lat": 52.070944,
              "arrival": 1682084418000,
              "departure": 1682084418000,
              "stopIndex": 17,
              "stopSequence": 18,
              "vertexType": "TRANSIT"
            },
            "legGeometry": {
              "points": "}ry|H_qgYx@l[??`Adi@??tK`k@",
              "length": 6
            },
            "steps": [
              
            ],
            "routeShortName": "2",
            "routeLongName": "Kraaijenstein - Leidschendam Leidsenhage",
            "duration": 316.0
          },
          {
            "startTime": 1682084418000,
            "endTime": 1682084448000,
            "departureDelay": 0,
            "arrivalDelay": 0,
            "realTime": false,
            "distance": 28.2,
            "generalizedCost": 51,
            "pathway": false,
            "mode": "WALK",
            "transitLeg": false,
            "route": "",
            "agencyTimeZoneOffset": 7200000,
            "interlineWithPreviousLeg": false,
            "from": {
              "name": "Den Haag, De la Reyweg",
              "stopId": "NL:2506413",
              "stopCode": "3003",
              "lon": 4.285331,
              "lat": 52.070944,
              "arrival": 1682084418000,
              "departure": 1682084418000,
              "vertexType": "TRANSIT"
            },
            "to": {
              "name": "Destination",
              "lon": 4.2850327,
              "lat": 52.0709599,
              "arrival": 1682084448000,
              "vertexType": "NORMAL"
            },
            "legGeometry": {
              "points": "kby|Hi~cYBA@FBRAB??MF@JBF",
              "length": 9
            },
            "steps": [
              {
                "distance": 28.2,
                "relativeDirection": "DEPART",
                "streetName": "Loosduinseweg",
                "absoluteDirection": "SOUTHWEST",
                "stayOn": false,
                "area": false,
                "bogusName": false,
                "lon": 4.2853418,
                "lat": 52.0709292,
                "elevation": "",
                "walkingBike": false
              }
            ],
            "rentedBike": false,
            "walkingBike": false,
            "duration": 30.0
          }
        ],
        "tooSloped": false,
        "arrivedAtDestinationWithRentedBicycle": false
      },
      {
        "duration": 346,
        "startTime": 1682084699000,
        "endTime": 1682085045000,
        "walkTime": 30,
        "transitTime": 316,
        "waitingTime": 0,
        "walkDistance": 28.2,
        "walkLimitExceeded": false,
        "generalizedCost": 969,
        "elevationLost": 0.0,
        "elevationGained": 0.0,
        "transfers": 0,
        "fare": {
          "fare": {
            
          },
          "details": {
            
          }
        },
        "legs": [
          {
            "startTime": 1682084699000,
            "endTime": 1682085015000,
            "departureDelay": 0,
            "arrivalDelay": 0,
            "realTime": false,
            "distance": 1307.94,
            "generalizedCost": 916,
            "pathway": false,
            "mode": "TRAM",
            "transitLeg": true,
            "route": "Lijn 4",
            "agencyName": "HTM",
            "agencyUrl": "http://www.htm.nl",
            "agencyTimeZoneOffset": 7200000,
            "routeColor": "ef7100",
            "routeType": 0,
            "routeId": "NL:84735",
            "routeTextColor": "000000",
            "interlineWithPreviousLeg": false,
            "tripShortName": "40121",
            "headsign": "DH De Uithof",
            "agencyId": "NL:HTM",
            "tripId": "NL:166141801",
            "serviceDate": "2023-04-21",
            "from": {
              "name": "Den Haag, Brouwersgracht",
              "stopId": "NL:2506373",
              "stopCode": "2824",
              "lon": 4.303689,
              "lat": 52.073605,
              "departure": 1682084699000,
              "stopIndex": 19,
              "stopSequence": 20,
              "vertexType": "TRANSIT"
            },
            "to": {
              "name": "Den Haag, De la Reyweg",
              "stopId": "NL:2506413",
              "stopCode": "3003",
              "lon": 4.285331,
              "lat": 52.070944,
              "arrival": 1682085015000,
              "departure": 1682085015000,
              "stopIndex": 22,
              "stopSequence": 23,
              "vertexType": "TRANSIT"
            },
            "legGeometry": {
              "points": "}ry|H_qgYx@l[??`Adi@??tK`k@",
              "length": 6
            },
            "steps": [
              
            ],
            "routeShortName": "4",
            "routeLongName": "Lijn 4",
            "duration": 316.0
          },
          {
            "startTime": 1682085015000,
            "endTime": 1682085045000,
            "departureDelay": 0,
            "arrivalDelay": 0,
            "realTime": false,
            "distance": 28.2,
            "generalizedCost": 51,
            "pathway": false,
            "mode": "WALK",
            "transitLeg": false,
            "route": "",
            "agencyTimeZoneOffset": 7200000,
            "interlineWithPreviousLeg": false,
            "from": {
              "name": "Den Haag, De la Reyweg",
              "stopId": "NL:2506413",
              "stopCode": "3003",
              "lon": 4.285331,
              "lat": 52.070944,
              "arrival": 1682085015000,
              "departure": 1682085015000,
              "vertexType": "TRANSIT"
            },
            "to": {
              "name": "Destination",
              "lon": 4.2850327,
              "lat": 52.0709599,
              "arrival": 1682085045000,
              "vertexType": "NORMAL"
            },
            "legGeometry": {
              "points": "kby|Hi~cYBA@FBRAB??MF@JBF",
              "length": 9
            },
            "steps": [
              {
                "distance": 28.2,
                "relativeDirection": "DEPART",
                "streetName": "Loosduinseweg",
                "absoluteDirection": "SOUTHWEST",
                "stayOn": false,
                "area": false,
                "bogusName": false,
                "lon": 4.2853418,
                "lat": 52.0709292,
                "elevation": "",
                "walkingBike": false
              }
            ],
            "rentedBike": false,
            "walkingBike": false,
            "duration": 30.0
          }
        ],
        "tooSloped": false,
        "arrivedAtDestinationWithRentedBicycle": false
      }
    ]
  },
  "metadata": {
    "searchWindowUsed": 2400,
    "nextDateTime": 1682084820000,
    "prevDateTime": 1682081520000
  },
  "previousPageCursor": "rO0ABXc1AQANUFJFVklPVVNfUEFHRQY2pfCAAAAAAAAJYAAXU1RSRUVUX0FORF9BUlJJVkFMX1RJTUU=",
  "nextPageCursor": "rO0ABXcxAQAJTkVYVF9QQUdFBjay1IAAAAAAAAlgABdTVFJFRVRfQU5EX0FSUklWQUxfVElNRQ==",
  "debugOutput": {
    "precalculationTime": 83168,
    "directStreetRouterTime": 8183940,
    "transitRouterTime": 589834714,
    "filteringTime": 1053999,
    "renderingTime": 671756,
    "totalTime": 599870349,
    "transitRouterTimes": {
      "tripPatternFilterTime": 90307955,
      "accessEgressTime": 103007135,
      "raptorSearchTime": 395519902,
      "itineraryCreationTime": 995137
    }
  },
  "elevationMetadata": {
    "ellipsoidToGeoidDifference": 47.694913775834976,
    "geoidElevation": false
  }
}

The max-limit is applied to itineraries with no transit legs, however all itineraries (including those with transit legs) are considered when calculating the minimum cost.

OK, my request returns 4 itineraries (I capped that with numItineraries in the router-config) which have the following modes and generalized costs:

  • WALK; 2238
  • TRAM+WALK: 969
  • TRAM+WALK: 969
  • TRAM+WALK: 969

The smallest generalized-cost value is used as input to the function.

That is 969 in my case.

The function is used to calculate a max-limit.

My function is f(x) = 1.5 x. Filling in the current minimum of 969: f(969) =1.5*969 = 1453.5.

The max-limit is then used to filter non-transit itineraries by generalized-cost. Itineraries with a cost higher than the max-limit are dropped from the result set.

The WALK itinerary has a cost of 2238, which is larger than 1453.5. However, it is not dropped. This works different than I expected.

Other things I tried that didn't make a difference:

  • To be sure I tried URL encoding the parameter as well: nonTransitGeneralizedCostLimit=f%28x%29%20%3D%201.5%20x.
  • I tried just passing the function (without the f(x) part): nonTransitGeneralizedCostLimit=1.5%20x
  • Tried adding quotes: nonTransitGeneralizedCostLimit=%221.5%20x%22 and nonTransitGeneralizedCostLimit=%22f%28x%29%20%3D%201.5%20x%22
  • Tried changing the function to f(x) = 10 + 1.0 x

@leonardehrenfried
Copy link
Member

This parameter is not available though the API.

You need to add it to router-config.json.

The docs have an example file. It's easy to nest the params incorrectly so look at the example quite carefully.

@leonardehrenfried
Copy link
Member

https://docs.opentripplanner.org/en/dev-2.x/RouterConfiguration/#router-config-example

The example is here but it appears there is no example value for your exact parameter.

@ghost
Copy link

ghost commented Apr 23, 2023

This parameter is not available though the API.

You need to add it to router-config.json.

Thank you very much! Tthat was the information I was missing.

With the following router-config.json:

{
  "routingDefaults": {
    "numItineraries": 4,
    "itineraryFilters": {
      "nonTransitGeneralizedCostLimit": "0 + 1.5 x"
    }
  }
}

The route request

http://my.domain.name?module=planner&fromPlace=52.073605%2C4.303689&toPlace=52.070959889346696%2C4.285032749176026&time=3%3A32pm&date=04-21-2023&mode=TRANSIT%2CWALK&arriveBy=false&wheelchair=false&showIntermediateStops=true&debugItineraryFilter=true&locale=en&baseLayer=OSM%20Standard%20Tiles

Filters out the option for walking succesfully:

image

The other issue (#5062) remains though, as the paging seems to invoke a call to the planner with a different directMode resulting in a more "realistic" (to me) outcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
OTP2 Development
  
Issues for discussion/in progress
Development

Successfully merging a pull request may close this issue.

3 participants