Skip to content

N-nearest offsets#1496

Draft
aff3npirat wants to merge 15 commits into
motis-project:masterfrom
aff3npirat:dynamic-offsets
Draft

N-nearest offsets#1496
aff3npirat wants to merge 15 commits into
motis-project:masterfrom
aff3npirat:dynamic-offsets

Conversation

@aff3npirat

Copy link
Copy Markdown
Contributor

Change routing behaviour to always find a mimium number of start/end stations or transfer options.

Closes #1477

@aff3npirat aff3npirat self-assigned this Jun 23, 2026
@aff3npirat

aff3npirat commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Why are we not searching for stops with traffic when using radius compared to here, wouldnt it make sense to always look at stops with traffic?

And should I also increase the search radius when using radius_offsets?

@aff3npirat
aff3npirat marked this pull request as draft June 24, 2026 14:27

@traines-source traines-source left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the general approach makes sense, but there are some things I noticed

Comment thread src/endpoints/routing.cc Outdated
Comment thread include/motis/endpoints/routing.h Outdated
Comment thread src/endpoints/routing.cc Outdated
Comment thread src/endpoints/routing.cc Outdated
Comment thread openapi.yaml
@traines-source

Copy link
Copy Markdown
Contributor

Why are we not searching for stops with traffic when using radius compared to here, wouldnt it make sense to always look at stops with traffic?

And should I also increase the search radius when using radius_offsets?

This is a niche feature that some people wanted where we skip the OSR calculation entirely and just use beeline distances to discover nearby locations. Maybe it's not worth the effort to change this, although I think this could also benefit from the n-nearest feature.

@aff3npirat

aff3npirat commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

This is a niche feature that some people wanted where we skip the OSR calculation entirely and just use beeline distances to discover nearby locations. Maybe it's not worth the effort to change this, although I think this could also benefit from the n-nearest feature.

So I still dont get why we return locations that have no routes in radius_offsets?

And either way I think we could merge radius_offsets and get_stops_with_traffic into a single function (maybe provide a flag traffic_only) and implement the expanding logic there.

* add all paths in initial max walking distance
* decrease radius expansion
@traines-source

Copy link
Copy Markdown
Contributor

So I still dont get why we return locations that have no routes in radius_offsets?

I don't think there is a good reason other than that in most cases it probably doesn't really make a difference performance wise or otherwise.

And either way I think we could merge radius_offsets and get_stops_with_traffic into a single function (maybe provide a flag traffic_only) and implement the expanding logic there.

They are not really returning the same things (offsets vs location)? But feel free to refactor if you see fit.

Comment thread src/endpoints/routing.cc Outdated
Comment thread src/endpoints/routing.cc Outdated
@mority

mority commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

btw, this is the notorious repertoire filter idea: motis-project/nigiri@master...mority:nigiri:repertoire-filter

@felixguendling felixguendling left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implementation doesn't feel clean to me
it seems to also not guarantee the same behavior as before if the parameter is not set?

not sure if inside get_offsets is the right place to implement this

double const distance,
nigiri::location_idx_t const not_equal_to =
nigiri::location_idx_t::invalid());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep

Comment thread src/endpoints/routing.cc
get_stops_with_traffic(*r.tt_, rtt, *r.loc_tree_, pos, max_dist);
constexpr unsigned const kBeelineNearStationsFactor = 4U;

auto const max_beeline_seconds = std::max(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max? this will go beyond street_routing_max_near_stops_seconds_

shouldn't we throw 400 so the user knows that parameters were bad?

Comment thread src/endpoints/routing.cc
get_stops_with_traffic(*r.tt_, rtt, *r.loc_tree_, pos, expanded_dist);
while (expanded_time * 2 <= max_beeline_seconds &&
near_stops.size() < min_near_stations * kBeelineNearStationsFactor) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no new line loop start

Suggested change

Comment thread openapi.yaml
default: 900
minimum: 0

- name: minNearStations

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inconsistent - sometimes stops, sometimes stations
-> always stops

Comment thread openapi.yaml
- name: minNearStations
in: query
required: false
description: |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description doesn't help me to understand what's actually happening

Comment thread src/endpoints/routing.cc
gbfs::gbfs_routing_data& gbfs_rd,
stats_map_t& stats) {
stats_map_t& stats,
unsigned const min_near_stations) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep stats last, add close to max param

#include "motis/get_stops_with_traffic.h"

#include "osr/location.h"
#include "utl/helpers/algorithm.h"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

header grouping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

N-nearest stops for pre/post/transfers

4 participants