opentripplanner / OpenTripPlanner

An open source multi-modal trip planner
http://www.opentripplanner.org
Other
2.21k stars 1.03k forks source link

MinTravelDurationRoutingStrategy.java and TripPatternsForDates issue with Madrid - EMT (urban buses) GTFS data #6060

Open danifgxcom opened 1 month ago

danifgxcom commented 1 month ago

Dear OTP Team,

I am trying to use Open Trip Planner with Madrid's mobility data, but it is not working properly. The first error that I see with local buses GTFS data is that I am getting the following exception: { "errors": [ { "message": "Exception while fetching data (/trip) : Cannot invoke \"org.opentripplanner.raptor.spi.RaptorBoardOrAlightEvent.boardWithFallback(java.util.function.Consumer, java.util.function.Consumer)\" because the return value of \"org.opentripplanner.raptor.rangeraptor.support.TimeBasedBoardingSupport.searchRegularTransfer(int, int, int, int)\" is null", "locations": [ { "line": 2, "column": 3 } ], "path": [ "trip" ], "extensions": { "classification": "DataFetchingException" } } ], "data": null }

I have cloned the repository and debug in my computer with IntelliJ, finding the class that throws the exception.´

For some reason that I still unknow, there is a problem with a call to public void boardWithRegularTransfer(int stopIndex, int stopPos, int boardSlack) since boardingSupport.searchRegularTransfer(prevArrivalTime, stopPos, boardSlack, onTripIndex); is returning null. This is making the API fail with this exception, and no route is shown at all.

I have added a check for that null value, and avoid the code in such case:

public void boardWithRegularTransfer(int stopIndex, int stopPos, int boardSlack) {
    int prevArrivalTime = prevArrivalTime(stopIndex);
    var transfer = boardingSupport.searchRegularTransfer(prevArrivalTime, stopPos, boardSlack, onTripIndex);

    if (transfer != null) {
      boardingSupport
        .searchRegularTransfer(prevArrivalTime, stopPos, boardSlack, onTripIndex)
        .boardWithFallback(
          boarding -> board(stopIndex, boarding),
          emptyBoarding -> boardSameTrip(emptyBoarding.earliestBoardTime(), stopPos, stopIndex)
        );
    }
  }

With this, at least is working for the rest of the routes.

Further investigation reveals that the issue comes from TripFrequencyAlightSearch.java, specifically: public RaptorBoardOrAlightEvent<T> search

When `pattern.getFrequencies().size()" equals 0, the for loop does not iterate as it has to reach that value minus 1 (resulting in -1), then is when it returns null.

It might be something related to the dataset, but still is inconvenient. Not sure if there should be more validation on this part from the dataset or the code.

Currently I am using version OTP 2.6.0 on Java 21, Ubuntu 24.04 64-bits.

Links to datasets:

To reproduce the issue, just click on two locations within Madrid area. The application is started with regular command line: java -jar -Xmx2G... The following call should fail:

Thank you very much in advance.

danifgxcom commented 1 month ago

UPDATE I restarted the server several times... And now the issue is not happening. I rebuilt the graphs using the same datasets. I have built the graphs in two ways:

Yesterday it was failing for some routes as explained in the initial message. Today it is working.

No change to the code (I rolled-back my changes), no change to the datasets...

Is there any chance that anything is non-deterministic in the process?

Thanks.

leonardehrenfried commented 1 month ago

Unfortunately, sometimes we discover that we have some non-determinism in the system but we working hard to remove it when we encounter it.

May I ask which organisation you work for? Or are you just an interested individual?

leonardehrenfried commented 1 month ago

In your case I would say it was an old fashioned bug.

danifgxcom commented 1 month ago

Hi Leonard, Thanks for your prompt answer. I tried several times and building in different ways. Also running from command line and IntelliJ. All these prior to opening the bug. But today I just saw that it was working fine after restarting again.

I am an individual who just discovered yesterday your amazing application and the GTFS format. I used open data before to position places in maps, but never for mobility. When I saw this, I immediately tried to use Madrid datasets to test. But it was failing due to different issues (I also opened bugs for Madrid Open Data Authority as there are inconsistencies in the inner data sets). But in this case, I validated the file with the GTFS web validator, and it seems right.

There are other things that I detected with the debug UI, but I understand that this UI is a best effort to try the API, which is great anyway.

I am fascinated with the amount of work around OTP and GTFS, as well as the open data availability.

Kind regards, Daniel.

leonardehrenfried commented 1 month ago

If you want a prettier frontend, there are some open source ones available: https://docs.opentripplanner.org/en/dev-2.x/Frontends/

If you want to chat to other OTP developers and users, we have a chat room: https://gitter.im/opentripplanner/OpenTripPlanner

danifgxcom commented 1 month ago

Super! Thanks a lot, it is much appreciated. As aforementioned, this is my very first time with OTP. I will try to make it work with Madrid datasets, but it is going to take some time... If I find any relevant bug (also with the datasets), I will inform the community and the authorities.

Best regards, Daniel.