Skip to content

Remove circular dependency between graph and vertex linker #6686

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

Open
wants to merge 9 commits into
base: dev-2.x
Choose a base branch
from

Conversation

leonardehrenfried
Copy link
Member

@leonardehrenfried leonardehrenfried commented Jun 5, 2025

Summary

As a follow up of #6605 I'm removing the circular dependency between graph and vertex linker.

Graphs now don't know anything about linking anymore and simply are repositories for street data.

The instantiation of the vertex linker is now managed by Dagger and there are two modules to do it:

  • one for graph building
  • one for routing

The vertex linker is now immutable so you don't need to take a lot of care to make sure that you only have a single instance. Nevertheless, Dagger makes sure.

To get an idea of the new relationships check the updated diagram.

Unit tests

Lots updated.

Documentation

Javadoc.

Bumping the serialization version id

Yes, Graph is changed.

@leonardehrenfried leonardehrenfried requested a review from a team as a code owner June 5, 2025 08:58
@leonardehrenfried leonardehrenfried added Skip Changelog bump serialization id Add this label if you want the serialization id automatically bumped after merging the PR labels Jun 5, 2025
Copy link

codecov bot commented Jun 5, 2025

Codecov Report

Attention: Patch coverage is 63.75000% with 29 lines in your changes missing coverage. Please review.

Project coverage is 71.58%. Comparing base (65e97b5) to head (b56591a).

Files with missing lines Patch % Lines
...anner/graph_builder/module/StreetLinkerModule.java 78.26% 5 Missing ⚠️
...a/service/DefaultViaCoordinateTransferFactory.java 16.66% 5 Missing ⚠️
...lanner/standalone/api/OtpServerRequestContext.java 0.00% 4 Missing ⚠️
.../opentripplanner/routing/linking/VertexLinker.java 75.00% 3 Missing ⚠️
...ing/configure/VertexLinkerGraphBuildingModule.java 0.00% 3 Missing ⚠️
...r/ext/transferanalyzer/DirectTransferAnalyzer.java 0.00% 2 Missing ⚠️
...g/linking/configure/VertexLinkerRoutingModule.java 0.00% 2 Missing ⚠️
...ner/standalone/configure/ConstructApplication.java 0.00% 2 Missing ⚠️
...planner/updater/configure/UpdaterConfigurator.java 33.33% 2 Missing ⚠️
...entripplanner/routing/graphfinder/GraphFinder.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             dev-2.x    #6686   +/-   ##
==========================================
  Coverage      71.57%   71.58%           
- Complexity     18930    18934    +4     
==========================================
  Files           2059     2061    +2     
  Lines          77467    77472    +5     
  Branches        7900     7902    +2     
==========================================
+ Hits           55449    55456    +7     
- Misses         19200    19202    +2     
+ Partials        2818     2814    -4     

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@leonardehrenfried leonardehrenfried force-pushed the vertex-linker branch 2 times, most recently from 9507b98 to f2a9eff Compare June 5, 2025 09:08
@leonardehrenfried
Copy link
Member Author

@vesameskanen You might be interested in this.

@optionsome
Copy link
Member

There are conflicts

Copy link
Contributor

@vesameskanen vesameskanen left a comment

Choose a reason for hiding this comment

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

Very good changes. My only remark was about graph indexing - which of the two index methods should a new builder module use? Maybe builder module execution order dictates that, but such a logic is hidden in the code.

Also, I see merge conflicts, please fix them.

index();
}
}

@Nullable
Copy link
Contributor

Choose a reason for hiding this comment

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

Difference between index and requestIndex feels a bit vague. Maybe some more/updated documentation? At least the index method docs seem to be outdated.

Copy link
Member

Choose a reason for hiding this comment

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

The strategy for indexing during graph build is as follows:

  • avoid indexing, this can be programaticly done by using builders and immutable repositories.

  • mappers in need of an index should create their own - this is in most cases cheeper than reindexing everything every time a mapper needs an index.

  • for real-time updated or request indexes a case-to-case strategy is needed.

I have not looked at the use-cases for the graph indexing, so I do not know what is the right strategy for it. But, leaving indexing to the user (calls like graph.index()) is domed to fail. Encapsulating the indexing (dirty flag strategy) is a little better, but it is also problematic since you risk reindexing a lot - the caller think he is safe - but if he uses the wrong combination of methods he might cause a lot of reindexing - without a clue before running the code.

# Conflicts:
#	application/src/main/java/org/opentripplanner/standalone/server/DefaultServerRequestContext.java

# Conflicts:
#	application/src/main/java/org/opentripplanner/routing/algorithm/raptoradapter/router/street/DirectStreetRouter.java
#	application/src/main/java/org/opentripplanner/routing/graphfinder/GraphFinder.java
#	application/src/main/java/org/opentripplanner/routing/graphfinder/StreetGraphFinder.java
#	application/src/main/java/org/opentripplanner/standalone/api/OtpServerRequestContext.java
#	application/src/main/java/org/opentripplanner/visualizer/GraphVisualizer.java
Comment on lines +782 to +793
public enum VisibilityMode {
COMPUTE_AREA_VISIBILITY,
SKIP_AREA_VISIBILITY;

public static VisibilityMode ofBoolean(boolean computeVisibility) {
if (computeVisibility) {
return COMPUTE_AREA_VISIBILITY;
} else {
return SKIP_AREA_VISIBILITY;
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Public classes (enums are classes) should be defined in their own file, not as inner classes - only private classes can be defined inside a class.

Comment on lines +783 to +784
COMPUTE_AREA_VISIBILITY,
SKIP_AREA_VISIBILITY;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
COMPUTE_AREA_VISIBILITY,
SKIP_AREA_VISIBILITY;
COMPUTE_AREA_VISIBILITY_LINES,
TRAVERS_AREA_EDGES;

Also this need JavaDoc

index();
}
}

@Nullable
Copy link
Member

Choose a reason for hiding this comment

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

The strategy for indexing during graph build is as follows:

  • avoid indexing, this can be programaticly done by using builders and immutable repositories.

  • mappers in need of an index should create their own - this is in most cases cheeper than reindexing everything every time a mapper needs an index.

  • for real-time updated or request indexes a case-to-case strategy is needed.

I have not looked at the use-cases for the graph indexing, so I do not know what is the right strategy for it. But, leaving indexing to the user (calls like graph.index()) is domed to fail. Encapsulating the indexing (dirty flag strategy) is a little better, but it is also problematic since you risk reindexing a lot - the caller think he is safe - but if he uses the wrong combination of methods he might cause a lot of reindexing - without a clue before running the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump serialization id Add this label if you want the serialization id automatically bumped after merging the PR Skip Changelog Technical Debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants