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

[feature] keep forbidden pickup/dropoff on stay in #730

Merged
merged 23 commits into from
Jan 25, 2021

Conversation

antoine-de
Copy link
Contributor

To keep to data as clean as possible, the model was sanitized to add restrictions on drop off at first stop time / pick up at last stop time.
Since for stay in this could remove valid journeys, the pick up at last stop time / drop off at first stop time was possible for stay in.

The previous implementation was removing explicitly set constraints on those stay in stop times.
As a side effect we now also correctly handle restrictions on stay in of different calendars (see example 4)

Note 1: the new implementation is quadratic in term of trip on the same block_id. However the number of vj on the same block_id seems quite limited thus the runtime penalty is quite small.
I tested it on the bretagne dataset, so biggest dataset I know with block_id (106k trips, 2M+ stoptimes, max number of vehicle journeys with same block_id: 76) there is a small impact on the run time import (not on the memory footprint).
On my computer the best of 3 runs (there are ~1s of difference on the same runs) before: 17s to read the GTFS, after: 18s to read the GTFS.

Note 2:
this reactivate the use of the model_builder and add some utilities to it

internally linked to ND-1088

@antoine-de
Copy link
Contributor Author

I should definitly have split this PR in 2, one for the builder and one for the bug.

I can still do it if you prefer.

I'd be happy to have a review on the builder's API

@pbougue pbougue requested review from woshilapin and pbougue January 12, 2021 09:51
Copy link
Contributor

@pbougue pbougue left a comment

Choose a reason for hiding this comment

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

Did not review the model-builder part (vote for a separate PR, as we are not in a hurry to merge any of this work).

👍 Despite remarks on twisted cases, it's better than what we had on staying as it respects data more.

src/model.rs Outdated
// The stay in is not really possible when timing overlaps
// between arrival of first vehicle journey and departure of
// next vehicle journey (see Example 2 above).
last_stop.departure_time <= first_stop.arrival_time
Copy link
Contributor

Choose a reason for hiding this comment

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

If one is past-midnight and the next is at the beginning of the day after, I guess it won't work but it "only" matters for night-bus lines
🙈 becomes a bit too complex for the gain I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

after giving it some thoughts, past midnight are usually implemented as time > 24h (like "25:00:00" for 1am) no? and this case is handled no 🤔 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

It would not be handled I think, as the first VJ would end at 25:00 and the second would start at 02:00.
They would be possible stay-in, but we wouldn't "see" that.
But that's OK for now (and possibly for ever 😝 )
I do not resolve the comment just to have it quick if we ever come back later to that work to improve those tricky cases.

src/model.rs Outdated
Comment on lines 840 to 845
if can_chain_without_overlap(vj, other_vj) {
allowed_first_drop_off_vj.insert(*other_vj_idx);
allowed_last_pick_up_vj.insert(vj_idx);
} else if can_chain_without_overlap(other_vj, vj) {
allowed_first_drop_off_vj.insert(vj_idx);
allowed_last_pick_up_vj.insert(*other_vj_idx);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure how twisted this example is (all vjs are on the same block_id, same calendar):
vj1 ends at spA (10:00-11:00)
vj2 starts at spA (10:00-11:00) ends at spB (12:00-13:00)
vj3 starts at spC (14:00-15:00)

Because of vj1-vj3 test, the outcome from your code is that all vj1's last dropoff is allowed at spA which is not what we want, no?
(we would have the same for vj2's first pickup if we had a vj0).

This probably implies building a chain first (tree if you consider calendars), then check what's possible... then decide what matters more in case of conflict (probably being safe and forbid).
And it's actually what's done in Navitia as the next vj is unique and check is done once it's affected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hum interesting edge case, I don't know if it's a valid GTFS 🤔
I'm not sure it's worth implementing something this tricky as this is meant only for strengthening the data if we do in transit_model I don't think we should be "safe and forbid" (like we should in navitia) since we are only adding additional constraints on the data. So we should just forbid impossible cases, and if a particular case can happen sometimes but not always, we should let it be possible and be handled by the journey planner

Copy link
Contributor

@pbougue pbougue Jan 13, 2021

Choose a reason for hiding this comment

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

I think this should be split into 2 parts :

  1. Is it a realistic case to have chained blocks (so every extremity would endup being qualified as a valid stay-in in this algo) ? I think we get block_id corresponding to vehicles, so yes (so an algo without determining "real-life" chains would not change data much from original).
  2. Is it realistic to have calendars that would make "real-life" chaining of trips being stay-in some days and not stay-in some other days? I think we should not care about that until we have the problem as it's too edgy 🙈 . And OK to stay closer to data in that conflicting case, you make a good point contradicting my "safe" argument.

Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed:

  1. Not addressing that for now, so authorize a bit too much pickup/dropoff which is OK (still better to respect data). To be documented but that's all.
  2. If calendars introduce a contradictory case (stay-in should be authorized on sunday, not on saturday) : authorise to respect data. To be tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

test added block_id_on_non_overlaping_calendar_with_overlaping_stops (and I think the current implementation handles it quite nicely after testing it 😜 )

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, it's nice : what's consistent is handle, and what's not stays close to initial data 👍
Letting the discussion unresolved for the "chaining" part if we later come back to that work, but you did all that could reasonably be done ✔️

Copy link
Contributor

@woshilapin woshilapin left a comment

Choose a reason for hiding this comment

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

Overall, it's an improvement since we keep existing values and there is more test. But I feel like there is still a bunch of work to do to make it maintainable.

antoine-de and others added 8 commits January 13, 2021 08:48
Co-authored-by: Jean SIMARD <[email protected]>
Co-authored-by: Jean SIMARD <[email protected]>
Co-authored-by: Jean SIMARD <[email protected]>
Co-authored-by: Jean SIMARD <[email protected]>
Co-authored-by: Jean SIMARD <[email protected]>
Co-authored-by: Jean SIMARD <[email protected]>
Co-authored-by: Jean SIMARD <[email protected]>
Co-authored-by: Jean SIMARD <[email protected]>
@ArnaudOggy
Copy link
Contributor

To bump in 0.34 and its sub-crates 😉

Copy link
Contributor

@pbougue pbougue left a comment

Choose a reason for hiding this comment

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

ModelBuilder interface with default attributes + muter looks fine, and to me we settled on something good for functionnal stay-in part 👍
Not sure about the fallible IntoDate, and didn't look at all @woshilapin's unresolved comments, but that's the only review left before approval.

@antoine-de antoine-de force-pushed the odt_kept branch 2 times, most recently from a86382c to 156a9a2 Compare January 18, 2021 09:44
@antoine-de
Copy link
Contributor Author

antoine-de commented Jan 18, 2021

I think I resolved all issues, feel free to poke me again if I missed something (apart from the cfg(test) but I'm not convinced it is needed and I did not manage to add it (I did not dig much I confess though 😜 ))

pbougue
pbougue previously approved these changes Jan 18, 2021
Copy link
Contributor

@pbougue pbougue left a comment

Choose a reason for hiding this comment

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

Looks like all is addressed indeed (let @woshilapin check his last opened comments, though)

Copy link
Contributor

@woshilapin woshilapin left a comment

Choose a reason for hiding this comment

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

Still need to bump Cargo.toml to 0.33.1 at least (or 0.34.0 as @ArnaudOggy suggested, but I would say this is bug fix so 0.33.1 is probably enough). The rest of the PR is good-to-go for me.

@ArnaudOggy
Copy link
Contributor

ArnaudOggy commented Jan 18, 2021

Still need to bump Cargo.toml to 0.33.1 at least (or 0.34.0 as @ArnaudOggy suggested, but I would say this is bug fix so 0.33.1 is probably enough). The rest of the PR is good-to-go for me.

No need 0.34.0 with the re-entry of model-builder? I let you decide what is best 😉

@antoine-de antoine-de merged commit 663c273 into hove-io:master Jan 25, 2021
@antoine-de antoine-de deleted the odt_kept branch January 25, 2021 10:07
@pbougue pbougue changed the title keep forbidden pickup/dropoff on stay in [feat] keep forbidden pickup/dropoff on stay in Feb 1, 2021
@datanel datanel changed the title [feat] keep forbidden pickup/dropoff on stay in [feature] keep forbidden pickup/dropoff on stay in Feb 1, 2021
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.

4 participants