Skip to content

Introduce generalizedCostPlusPenalty to make cost comparsion fairer#5483

Merged
leonardehrenfried merged 13 commits into
opentripplanner:dev-2.xfrom
leonardehrenfried:subtract-penalty
Feb 1, 2024
Merged

Introduce generalizedCostPlusPenalty to make cost comparsion fairer#5483
leonardehrenfried merged 13 commits into
opentripplanner:dev-2.xfrom
leonardehrenfried:subtract-penalty

Conversation

@leonardehrenfried

@leonardehrenfried leonardehrenfried commented Nov 6, 2023

Copy link
Copy Markdown
Member

Summary

This introduces a new method to Itinerary which allows you to get the cost but also subtract the access/egress penalty.

This means that street-only (direct) results don't have an unfair advantage over those that combine access/egress with transit.

Issue

Relates to #5381 #5337

Unit tests

Added.

Documentation

Javadoc added.

@leonardehrenfried leonardehrenfried added the !Improvement A functional improvement or micro feature label Nov 6, 2023
@leonardehrenfried leonardehrenfried requested a review from a team as a code owner November 6, 2023 14:35
@leonardehrenfried leonardehrenfried added this to the 2.5 (next release) milestone Nov 6, 2023
Bartosz-Kruba
Bartosz-Kruba previously approved these changes Nov 13, 2023
@codecov

codecov Bot commented Dec 20, 2023

Copy link
Copy Markdown

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (f38447c) 67.53% compared to head (22da0ee) 67.53%.

Files Patch % Lines
...odel/model/framework/PenaltyForStreetModeType.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             dev-2.x    #5483   +/-   ##
==========================================
  Coverage      67.53%   67.53%           
- Complexity     16282    16285    +3     
==========================================
  Files           1887     1886    -1     
  Lines          71583    71588    +5     
  Branches        7408     7408           
==========================================
+ Hits           48341    48350    +9     
+ Misses         20740    20736    -4     
  Partials        2502     2502           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@leonardehrenfried leonardehrenfried marked this pull request as ready for review December 20, 2023 21:23
@leonardehrenfried

Copy link
Copy Markdown
Member Author

@t2gran this is now ready for review again. I've tested the P+R case but we agreed a while ago that we will go through it together to check which filters need to use the version with and without penalty. Let me know when you're free.

@t2gran t2gran requested review from Bartosz-Kruba and t2gran January 2, 2024 09:13
@leonardehrenfried leonardehrenfried changed the title Introduce generalizedCostWithPenalty to make cost comparsion fairer Introduce generalizedCostPlusPenalty to make cost comparsion fairer Jan 9, 2024
@Bartosz-Kruba Bartosz-Kruba self-requested a review January 10, 2024 07:49
Bartosz-Kruba
Bartosz-Kruba previously approved these changes Jan 10, 2024
@leonardehrenfried

Copy link
Copy Markdown
Member Author

@t2gran went through this today and identified the cases in the filter chain where we want to compare with and without penalty. This is now ready for review again.

Comment on lines +681 to +685
if (penalty == null) {
return 0;
} else {
return penalty.cost().toSeconds();
}

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.

Suggested change
if (penalty == null) {
return 0;
} else {
return penalty.cost().toSeconds();
}
return (penalty == null ? Cost.ZERO : penalty.cost()).toSeconds();
}

Avoid magic numbers: 0

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.

A better way to do this is to make the penalty none null, and initialize it to TimeAndCost.ZERO. I do not think we need to differensiate between ZERO and NOT_SET.

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.

I replaced this earlier using the SortOrderComparator#generalizedCostComparator() - forgot to delete the class, so good to se this go :-)

@leonardehrenfried leonardehrenfried merged commit 14aca8a into opentripplanner:dev-2.x Feb 1, 2024
@leonardehrenfried leonardehrenfried deleted the subtract-penalty branch February 1, 2024 13:05
t2gran pushed a commit that referenced this pull request Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

!Improvement A functional improvement or micro feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants