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

Bug: Non pareto-optimal solution #145

Closed
munterfi opened this issue Oct 21, 2024 · 3 comments · Fixed by #153
Closed

Bug: Non pareto-optimal solution #145

munterfi opened this issue Oct 21, 2024 · 3 comments · Fixed by #153
Assignees
Labels
bug Something isn't working

Comments

@munterfi
Copy link
Member

image

@munterfi munterfi added the bug Something isn't working label Oct 21, 2024
@munterfi
Copy link
Member Author

munterfi commented Nov 5, 2024

To reproduce the issue, run the service with GTFS_STATIC_URI=https://opentransportdata.swiss/en/dataset/timetable-2024-gtfs2020/permalink.

Source: http://localhost:8080/schedule/stops/Parent8516161

{
  "id": "Parent8516161",
  "name": "Bern Wankdorf",
  "coordinates": {
    "latitude": 46.96782578,
    "longitude": 7.46547612
  }
}

Target: http://localhost:8080/schedule/stops/Parent8503000

{
  "id": "Parent8503000",
  "name": "Zürich HB",
  "coordinates": {
    "latitude": 47.3781762,
    "longitude": 8.54021154
  }
}

Connection: http://localhost:8080/routing/connections?sourceStopId=Parent8516161&targetStopId=Parent8503000&dateTime=2024-10-21T10:47:00

[
  {
    "legs": [
      {
        "type": "ROUTE",
        "from": {
          "latitude": 46.96776448,
          "longitude": 7.46572765
        },
        "to": {
          "latitude": 46.94785604,
          "longitude": 7.4350412
        },
        "fromStop": {
          "id": "8516161:0:5",
          "name": "Bern Wankdorf",
          "coordinates": {
            "latitude": 46.96776448,
            "longitude": 7.46572765
          }
        },
        "toStop": {
          "id": "8507000:0:1A-D",
          "name": "Bern",
          "coordinates": {
            "latitude": 46.94785604,
            "longitude": 7.4350412
          }
        },
        "departureTime": "2024-10-21T10:54:00",
        "arrivalTime": "2024-10-21T11:00:00",
        "trip": {
          "headSign": "Belp",
          "route": {
            "id": "91-3-F-j24-1",
            "name": "",
            "shortName": "S3",
            "transportMode": "RAIL",
            "transportModeDescription": "Suburban Railway"
          },
          "stopTimes": [
            {
              "stop": {
                "id": "8504300:0:9",
                "name": "Biel/Bienne",
                "coordinates": {
                  "latitude": 47.13174632,
                  "longitude": 7.24430191
                }
              },
              "arrivalTime": "2024-10-21T10:24:00",
              "departureTime": "2024-10-21T10:24:00"
            },
            {
              "stop": {
                "id": "8504416:0:2",
                "name": "Brügg BE",
                "coordinates": {
                  "latitude": 47.12309803,
                  "longitude": 7.27911163
                }
              },
              "arrivalTime": "2024-10-21T10:27:00",
              "departureTime": "2024-10-21T10:27:00"
            },
            {
              "stop": {
                "id": "8504441:0:2",
                "name": "Studen BE",
                "coordinates": {
                  "latitude": 47.11071293,
                  "longitude": 7.30150663
                }
              },
              "arrivalTime": "2024-10-21T10:29:00",
              "departureTime": "2024-10-21T10:29:00"
            },
            {
              "stop": {
                "id": "8504415:0:2",
                "name": "Busswil BE",
                "coordinates": {
                  "latitude": 47.09793969,
                  "longitude": 7.31799072
                }
              },
              "arrivalTime": "2024-10-21T10:32:00",
              "departureTime": "2024-10-21T10:32:00"
            },
            {
              "stop": {
                "id": "8504414:0:3",
                "name": "Lyss",
                "coordinates": {
                  "latitude": 47.07527785,
                  "longitude": 7.30704924
                }
              },
              "arrivalTime": "2024-10-21T10:36:00",
              "departureTime": "2024-10-21T10:37:00"
            },
            {
              "stop": {
                "id": "8504413:0:4",
                "name": "Suberg-Grossaffoltern",
                "coordinates": {
                  "latitude": 47.05723323,
                  "longitude": 7.33961316
                }
              },
              "arrivalTime": "2024-10-21T10:39:00",
              "departureTime": "2024-10-21T10:39:00"
            },
            {
              "stop": {
                "id": "8504412:0:2",
                "name": "Schüpfen",
                "coordinates": {
                  "latitude": 47.04153942,
                  "longitude": 7.38736761
                }
              },
              "arrivalTime": "2024-10-21T10:43:00",
              "departureTime": "2024-10-21T10:43:00"
            },
            {
              "stop": {
                "id": "8504411:0:2",
                "name": "Münchenbuchsee",
                "coordinates": {
                  "latitude": 47.02094807,
                  "longitude": 7.45334886
                }
              },
              "arrivalTime": "2024-10-21T10:47:00",
              "departureTime": "2024-10-21T10:47:00"
            },
            {
              "stop": {
                "id": "8504410:0:3",
                "name": "Zollikofen",
                "coordinates": {
                  "latitude": 47.00292182,
                  "longitude": 7.4637244
                }
              },
              "arrivalTime": "2024-10-21T10:51:00",
              "departureTime": "2024-10-21T10:51:00"
            },
            {
              "stop": {
                "id": "8516161:0:5",
                "name": "Bern Wankdorf",
                "coordinates": {
                  "latitude": 46.96776448,
                  "longitude": 7.46572765
                }
              },
              "arrivalTime": "2024-10-21T10:54:00",
              "departureTime": "2024-10-21T10:54:00"
            },
            {
              "stop": {
                "id": "8507000:0:1A-D",
                "name": "Bern",
                "coordinates": {
                  "latitude": 46.94785604,
                  "longitude": 7.4350412
                }
              },
              "arrivalTime": "2024-10-21T11:00:00",
              "departureTime": "2024-10-21T11:02:00"
            },
            {
              "stop": {
                "id": "8507082:0:1",
                "name": "Bern  Europaplatz",
                "coordinates": {
                  "latitude": 46.94385139,
                  "longitude": 7.40722936
                }
              },
              "arrivalTime": "2024-10-21T11:06:00",
              "departureTime": "2024-10-21T11:06:00"
            },
            {
              "stop": {
                "id": "8507079:0:1",
                "name": "Bern Weissenbühl",
                "coordinates": {
                  "latitude": 46.93594546,
                  "longitude": 7.42978605
                }
              },
              "arrivalTime": "2024-10-21T11:08:00",
              "departureTime": "2024-10-21T11:08:00"
            },
            {
              "stop": {
                "id": "8507078:0:1",
                "name": "Wabern bei Bern",
                "coordinates": {
                  "latitude": 46.92878679,
                  "longitude": 7.44498555
                }
              },
              "arrivalTime": "2024-10-21T11:11:00",
              "departureTime": "2024-10-21T11:11:00"
            },
            {
              "stop": {
                "id": "8507093:0:1",
                "name": "Kehrsatz Nord",
                "coordinates": {
                  "latitude": 46.91576133,
                  "longitude": 7.46620375
                }
              },
              "arrivalTime": "2024-10-21T11:13:00",
              "departureTime": "2024-10-21T11:13:00"
            },
            {
              "stop": {
                "id": "8507077:0:1",
                "name": "Kehrsatz",
                "coordinates": {
                  "latitude": 46.90883931,
                  "longitude": 7.47219552
                }
              },
              "arrivalTime": "2024-10-21T11:15:00",
              "departureTime": "2024-10-21T11:15:00"
            },
            {
              "stop": {
                "id": "8507092:0:1",
                "name": "Belp Steinbach",
                "coordinates": {
                  "latitude": 46.89513377,
                  "longitude": 7.49318915
                }
              },
              "arrivalTime": "2024-10-21T11:18:00",
              "departureTime": "2024-10-21T11:18:00"
            },
            {
              "stop": {
                "id": "8507076:0:2",
                "name": "Belp",
                "coordinates": {
                  "latitude": 46.88887826,
                  "longitude": 7.49851616
                }
              },
              "arrivalTime": "2024-10-21T11:21:00",
              "departureTime": "2024-10-21T11:21:00"
            }
          ],
          "bikesAllowed": false,
          "wheelchairAccessible": false
        }
      },
      {
        "type": "WALK",
        "from": {
          "latitude": 46.94785604,
          "longitude": 7.4350412
        },
        "to": {
          "latitude": 46.94908252,
          "longitude": 7.43911955
        },
        "fromStop": {
          "id": "8507000:0:1A-D",
          "name": "Bern",
          "coordinates": {
            "latitude": 46.94785604,
            "longitude": 7.4350412
          }
        },
        "toStop": {
          "id": "8507000:0:3",
          "name": "Bern",
          "coordinates": {
            "latitude": 46.94908252,
            "longitude": 7.43911955
          }
        },
        "departureTime": "2024-10-21T11:00:00",
        "arrivalTime": "2024-10-21T11:06:00",
        "trip": null
      },
      {
        "type": "ROUTE",
        "from": {
          "latitude": 46.94908252,
          "longitude": 7.43911955
        },
        "to": {
          "latitude": 47.37851077,
          "longitude": 8.537301
        },
        "fromStop": {
          "id": "8507000:0:3",
          "name": "Bern",
          "coordinates": {
            "latitude": 46.94908252,
            "longitude": 7.43911955
          }
        },
        "toStop": {
          "id": "8503000:0:34",
          "name": "Zürich HB",
          "coordinates": {
            "latitude": 47.37851077,
            "longitude": 8.537301
          }
        },
        "departureTime": "2024-10-21T11:31:00",
        "arrivalTime": "2024-10-21T12:28:00",
        "trip": {
          "headSign": "St. Gallen",
          "route": {
            "id": "91-1-D-j24-1",
            "name": "",
            "shortName": "IC1",
            "transportMode": "RAIL",
            "transportModeDescription": "Long Distance Trains"
          },
          "stopTimes": [
            {
              "stop": {
                "id": "8501026:0:4",
                "name": "Genève-Aéroport",
                "coordinates": {
                  "latitude": 46.23125029,
                  "longitude": 6.11034955
                }
              },
              "arrivalTime": "2024-10-21T09:32:00",
              "departureTime": "2024-10-21T09:32:00"
            },
            {
              "stop": {
                "id": "8501008:0:4",
                "name": "Genève",
                "coordinates": {
                  "latitude": 46.21215728,
                  "longitude": 6.14389264
                }
              },
              "arrivalTime": "2024-10-21T09:39:00",
              "departureTime": "2024-10-21T09:42:00"
            },
            {
              "stop": {
                "id": "8501120:0:1",
                "name": "Lausanne",
                "coordinates": {
                  "latitude": 46.51677456,
                  "longitude": 6.6295129
                }
              },
              "arrivalTime": "2024-10-21T10:17:00",
              "departureTime": "2024-10-21T10:20:00"
            },
            {
              "stop": {
                "id": "8504100:0:3",
                "name": "Fribourg/Freiburg",
                "coordinates": {
                  "latitude": 46.80101548,
                  "longitude": 7.14917931
                }
              },
              "arrivalTime": "2024-10-21T11:03:00",
              "departureTime": "2024-10-21T11:04:00"
            },
            {
              "stop": {
                "id": "8507000:0:3",
                "name": "Bern",
                "coordinates": {
                  "latitude": 46.94908252,
                  "longitude": 7.43911955
                }
              },
              "arrivalTime": "2024-10-21T11:26:00",
              "departureTime": "2024-10-21T11:31:00"
            },
            {
              "stop": {
                "id": "8503000:0:34",
                "name": "Zürich HB",
                "coordinates": {
                  "latitude": 47.37851077,
                  "longitude": 8.537301
                }
              },
              "arrivalTime": "2024-10-21T12:28:00",
              "departureTime": "2024-10-21T12:39:00"
            },
            {
              "stop": {
                "id": "8503006:0:5",
                "name": "Zürich Oerlikon",
                "coordinates": {
                  "latitude": 47.41089866,
                  "longitude": 8.54173868
                }
              },
              "arrivalTime": "2024-10-21T12:45:00",
              "departureTime": "2024-10-21T12:46:00"
            },
            {
              "stop": {
                "id": "8503016:0:1",
                "name": "Zürich Flughafen",
                "coordinates": {
                  "latitude": 47.44827868,
                  "longitude": 8.55988465
                }
              },
              "arrivalTime": "2024-10-21T12:51:00",
              "departureTime": "2024-10-21T12:53:00"
            },
            {
              "stop": {
                "id": "8506000:0:5",
                "name": "Winterthur",
                "coordinates": {
                  "latitude": 47.49883403,
                  "longitude": 8.722327
                }
              },
              "arrivalTime": "2024-10-21T13:06:00",
              "departureTime": "2024-10-21T13:08:00"
            },
            {
              "stop": {
                "id": "8506206:0:1",
                "name": "Wil SG",
                "coordinates": {
                  "latitude": 47.46167822,
                  "longitude": 9.04357353
                }
              },
              "arrivalTime": "2024-10-21T13:25:00",
              "departureTime": "2024-10-21T13:26:00"
            },
            {
              "stop": {
                "id": "8506208:0:4",
                "name": "Uzwil",
                "coordinates": {
                  "latitude": 47.43546514,
                  "longitude": 9.13091672
                }
              },
              "arrivalTime": "2024-10-21T13:33:00",
              "departureTime": "2024-10-21T13:34:00"
            },
            {
              "stop": {
                "id": "8506209:0:2",
                "name": "Flawil",
                "coordinates": {
                  "latitude": 47.41500805,
                  "longitude": 9.19025943
                }
              },
              "arrivalTime": "2024-10-21T13:39:00",
              "departureTime": "2024-10-21T13:39:00"
            },
            {
              "stop": {
                "id": "8506210:0:3",
                "name": "Gossau SG",
                "coordinates": {
                  "latitude": 47.41170719,
                  "longitude": 9.25689646
                }
              },
              "arrivalTime": "2024-10-21T13:44:00",
              "departureTime": "2024-10-21T13:45:00"
            },
            {
              "stop": {
                "id": "8506302:0:1",
                "name": "St. Gallen",
                "coordinates": {
                  "latitude": 47.42452651,
                  "longitude": 9.37104538
                }
              },
              "arrivalTime": "2024-10-21T13:52:00",
              "departureTime": "2024-10-21T13:52:00"
            }
          ],
          "bikesAllowed": false,
          "wheelchairAccessible": false
        }
      }
    ]
  }
]

Access using Python client:

import datetime
from public_transit_client.client import PublicTransitClient

NAVIQORE_SERVICE_URL = "http://localhost:8080"

client = PublicTransitClient(NAVIQORE_SERVICE_URL)
connections = client.get_connections(source="Parent8516161", target="Parent8503000", time=datetime.datetime(2024, 10, 21, 10, 47))

for connection in connections:
    print(f"Connection: {connection.first_stop.name} - {connection.last_stop.name}")
    for leg in connection.legs:
        if leg.is_walk:
            print(f"  - {leg.type.name} - {leg.departure_time}: {leg.from_coordinate.latitude, leg.from_coordinate.longitude} -> {leg.arrival_time}: {leg.to_coordinate.latitude, leg.to_coordinate.longitude}")
        else:
            print(f"  - {leg.trip.route.transport_mode.name} - {leg.departure_time}: {leg.from_stop.name} -> {leg.arrival_time}: {leg.to_stop.name}")
Connection: Bern Wankdorf - Zürich HB
  - RAIL - 2024-10-21 11:13:00: Bern Wankdorf -> 2024-10-21 11:18:00: Bern
  - WALK - 2024-10-21 11:18:00: (46.94785604, 7.4350412) -> 2024-10-21 11:24:00: (46.94908252, 7.43911955)
  - RAIL - 2024-10-21 11:31:00: Bern -> 2024-10-21 12:28:00: Zürich HB
Connection: Bern Wankdorf - Zürich HB
  - RAIL - 2024-10-21 10:53:00: Bern Wankdorf -> 2024-10-21 11:08:00: Burgdorf
  - WALK - 2024-10-21 11:08:00: (47.06082551, 7.62354368) -> 2024-10-21 11:11:00: (47.06072148, 7.6240108)
  - RAIL - 2024-10-21 11:21:00: Burgdorf -> 2024-10-21 11:54:00: Olten
  - WALK - 2024-10-21 11:54:00: (47.3545202, 7.9086959) -> 2024-10-21 11:59:00: (47.35387511, 7.90800419)
  - RAIL - 2024-10-21 11:59:00: Olten -> 2024-10-21 12:30:00: Zürich HB

@clukas1
Copy link
Member

clukas1 commented Nov 5, 2024

@munterfi: Seems like you have to fix this :)

Was feeling like a debugging session, but when I tried reproducing your error, I wasn't able to. Not sure how to proceed on my side. This is very weird.

image
image

@clukas1 clukas1 self-assigned this Nov 5, 2024
@clukas1
Copy link
Member

clukas1 commented Nov 5, 2024

Found the issue, the problem was only present in range raptor configurations and can be considered somewhat edge case.

In this exact case the problem was that there are many departures from Wankdorf and therefore a raptor routing request was made in 6 minute increments starting from the latest time (in my case range 1800s) --> 12:15 (when query time was set at 11:45). At 12:15 (or 12:09, 12:03, 11:57) the optimal earliest arrival time was found with 3 rounds and since the same bestLabelsPerRound data structure is used for all, there was a label set in round 3. And then even if the earliest arrival time is then later found with a 2 round connection, this label will never be removed, thus will be returned without post processing. This post processing / filtering is now done in ch.naviqore.raptor.router.LabelPostprocessor.reconstructParetoOptimalSolutions (commit: 48fb7c3).

A further minor bug (with no big effect) was also found in the process, the method ch.naviqore.raptor.router.QueryState.getActualBestTime did actually not return the actual best time, as it was looking for the highest round label which was not null for a given stop. Again for range raptor the highest round might not always be the actual best time and thus it's better to check all possible times to determine the best. Fix implemented in (d3895b1).

I haven't implemented any tests, as coming up with a dummy schedule to cover this in the raptor tests is currently beyond my mental capacity. And this seems to niche to justify using reflections to do real unit tests on underlying methods.

@clukas1 clukas1 linked a pull request Nov 5, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants