Skip to content

CT2 - Cost on transfer in Raptor#3617

Closed
t2gran wants to merge 35 commits into
opentripplanner:dev-2.xfrom
entur:otp2_cost_transfer
Closed

CT2 - Cost on transfer in Raptor#3617
t2gran wants to merge 35 commits into
opentripplanner:dev-2.xfrom
entur:otp2_cost_transfer

Conversation

@t2gran

@t2gran t2gran commented Sep 21, 2021

Copy link
Copy Markdown
Member

Summary

This PR clean up the Optimize transfer, path building and add cost calculation for guaranteed and stay-seated transfers during the Raptor routing. It is the base for adding some of the reminding features for constrained transfer support.

A CONSTRAINED transfer is a transfer with extra constraints. These are imported from GTFS transfers.txt and NeTEx Interchanges. Example of constraints are stay-seated (blocks in GTFS), guaranteed, transfer priority, max-wait-time. This PR only changes the Raptor and post Raptor code, it does not do anything with the import.

Review
Most of the commits are simple refacorings, I recommend doing review commit by commit. The las. commit contain almost all feature changes, this is a bit large, but unfortunally it would be time consuming to split it.

Do PR #3619 first, this PR build on that - 3619 have all commits, except the last one - which contains the feature set.

Issue

closes #3478

Unit tests

  • The test coverage is in general very good for this feature and most classes and modules changed have their own unit test. So fare there is one exception, the new PathBuilder, witch have good indirect coverage, but no proper test on the class. I intend to add unit test on the builder.

I have not done any performance testing on this, but with few constrained transfers the performance change should be minimal. Also, the OTPFeature#TransferConstraints can be turned off - in witch case the performance should be the same as before.

Documentation

All relevant documentation should be up to date, there is very little doc on this in the documentation.

Changelog

TODO Add Changelog item

This will enforce the scope of some of the variables passed to the
transit worker, and simplify the already complex `route()` method.
Raptor calculate a onBoardRelativeCost and a transitArrivalCost.
These calculations is done with out reusing any logic. But, when
this become problematic when we want to add a "sophisticated" transfer
calculation - we do not want to do it twice and the transfer information
is lost at the time we calculate the transit stop arrival cost. To solve
this we can calculate the cost at board time and reuse this value when
calculating the onBoardRelativeCost and a transitArrivalCost.
Internal refactor the PatternGuaranteedTransferProvider to make the
transfer instance available at the root in the call hierarchy. We will
use this to calculate a cost for the transit boarding later.
This is a pure refactor and no functionality is changed. The cost
calculation belong to the OTP internal model and should not be part of
the Raptor algorithm implementation. This enable us to switch the cost
calculation and use OTP model information in the cost calculation
without passing the information through Raptor. In the future we would
like to extend Raptor to use 2 or more cost criteria, this commit is a
step in that direction.
All results in tests using the stops in the RaptorTestConstants is
translated so the asserts are done on stop names, not stop index.
This make the asserts use the same "language" as the test
specifications, where we use constants like `STOP_A`.
The name clashes with standard Java class.
Move the generalized-cost formatter to OtpNumberFormat and reuse it.
Only print "cent" part if not zero, this make a ton of test a bit easier
 to read.
From PatternTransferConstraintsProvider
From RaptorTransferConstraintsProvider. Also, try to find better names
on a few related methods and fields.
Fix spelling BoarAndAlightTime to BoardAndAlightTime and move to
appropriate package. Fix BoardAndAlightTime#toString as well.
Rename waitTimeAdjustedGeneralizedCost to waitTimeOptimizedCost and
make transferPriorityCost available on the Itinerary (OTP internal
model and TransModel API). These two fields are for debugging the
travel search.
The ThrottleLoggerTest should be run manually, not by Maven. But the old
 @ignore junit do not worh with the juoiter @test, so this test was run
 every time.
The TransferConstraint is extracted into a immutable value-object. To do
routing in Raptor the cost calculator only need the value object, while
the path builder and itinerary still need the extended transfer
information, but we should get rid of this - since it is redundant.

Guaranteed and stay-seated transfers are "facilitated" transfers where
we ignore board-, transfer-, and alight-slack. We will also add a grace
period in the future for these transfers.
Fis reminding places where the rename of Guaranteed to Constrained
transfer is missing.
The MAX_WAIT_TIME_NOT_SET belong to the TransferConstraint class, not
the ConstrainedTransfer class.
  - Use getTransferConstraint, not just getConstraint (ConstrainedTransfer)
  - Remove unused method ConstrainedTransfer#getMaxWaitTime
  - Remove unused field OptimizedPath#originalPath
  - Update div JavaDoc
  - Remove redundant List.copyOf in TransferOptimizedFilterFactory
  - Improve naming in TransitPathLegSelector, McTransitWorker
  - Improve tests
@t2gran t2gran added !New Feature A functional feature targeting the end user. Entur Test This is currently being tested at Entur +NeTEx This issue is related to the Netex model/import. labels Sep 21, 2021
@t2gran t2gran added this to the 2.1 milestone Sep 21, 2021
@t2gran t2gran requested a review from a team as a code owner September 21, 2021 23:59
@t2gran t2gran marked this pull request as draft September 22, 2021 12:41
@t2gran t2gran changed the title Cost on transfer in Raptor CT2 - Cost on transfer in Raptor Sep 22, 2021
t2gran and others added 4 commits September 29, 2021 16:16
Co-authored-by: Leonard Ehrenfried <mail@leonard.io>
The interface is given a long name, while the implementing classes is
given relatively short names.
Just logging "System error" as a WARNING and the logging the real cause
to ERROR is strange. I removed the WARNING and improved the ERROR.
- Support for reduced cost in Raptor for constrained transfers
- New Path builder, used in Raptor mappers(FWD & RWS), Optimize
  transfers and in TestPathBuilder.
Unit tests are added on OptimizedPathTail and OptimizedPath.
Clean up how transfer constraint is added to path toStrings. Make
utility methods for adding cost w/unit.
There is an error in the logic in OptimizedPathTail line 195 and the
OptimizedPath line 90, when adding the priority cost. In both places a
cost was added for path legs witch did not represent a transfer. Since
the transfer constraint is on the transit-leg BEFORE the optional transfer,
this logic is a bit complicated. This commit fixes this, and refactor
the priority cost calculation, so the cost is always positive.

Previously the transfer priority cost was calculated in the
TransferPriority enum, but part of the information is in the
TransferConstraint, so it make sense to move some of the logic up to he
TransferConstraint.
This commit add the ability to log the stop id and name as part of the
Raptor returned path. This is continent when logging and debugging in
Raptor.
@t2gran t2gran marked this pull request as ready for review September 30, 2021 09:09
@t2gran

t2gran commented Sep 30, 2021

Copy link
Copy Markdown
Member Author

GitHub does not seem that most of the commits are merged, the diff is 35 commits and 200 files. I will close this an create a new one.

@t2gran t2gran closed this Sep 30, 2021
@t2gran t2gran removed this from the 2.1 milestone Sep 30, 2021
@hannesj

hannesj commented Sep 30, 2021

Copy link
Copy Markdown
Contributor

Just for future. It works correctly when you have merged master back to this branch, as Github always creates a new merge commit when merging pull requests.

@abyrd abyrd mentioned this pull request Oct 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Entur Test This is currently being tested at Entur +NeTEx This issue is related to the Netex model/import. !New Feature A functional feature targeting the end user.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for redused cost for guaranteed interchange

3 participants