implement a random graph generator : layer by layer method#6
Open
huggingstar wants to merge 2755 commits into
Open
implement a random graph generator : layer by layer method#6huggingstar wants to merge 2755 commits into
huggingstar wants to merge 2755 commits into
Conversation
huggingstar
commented
Feb 11, 2018
…936) * [Tour] simplifications and improvements of HamiltonianCycleAlgorithms TwoOptHeuristicTSP: - use tour-copy free path swap - use VertexToIntegerMapping NearestNeighborHeuristicTSP: - use array based data structure PalmerHamiltonianCycle: - use array of vertices instead of left and right indices. - makes implementation more comprehensible, saves memory and makes it faster * Reduce number of changes TwoOptHeuristicTSP: revert changes in fields and initialization The intended change was already addressed with another PR. NearestNeighborHeuristicTSP: Also adjust the variable-names in NearestNeighborHeuristicTSP * Add ArrayUtil class
* [SCC] Improvements of StrongConnectivityInspector-algorithms GabowStrongConnectivityInspector: - replace Vector by ArrayList - create HashSets holding the SCC's vertices with the size of each SCC and use Collections.singleton() for single vertex SCCs - cosmetic changes: - simplify method signatures (just use graph field) - rename field "stack" to "S" to comply to paper of Gabow - use stack-methods (push()/pop()/peek()) instead of Dequeue methods - inline methods of VertexNumber (also could reduce Object creation) KosarajuStrongConnectivityInspector: - replace Vector by ArrayList AbstractStrongConnectivityInspector: - use edge-supplier - create HashMap with expected size StrongConnectivityAlgorithmTest: - use parameterized JUnit runner to test different implementations - simplify/unify graph creation and assertions/checks of computed SCCs - add more test cases * [Gabow-SCC] avoid Integer-objects and left behind initial node - use one-based vertex numbers instead of zero-based. Using zero-based numbers caused the first node of a DFS to be on the stacks twice and also to remain on stack S and B after DFS has completed, if the first node is part of an SCC. This also had the effect that cycles that contain the initial node are detected not before a successor of the initial node was explored. The example of a three vertex directed ring, makes this issue clear. - using one-based numbers allows to use VertexNumber objects in stack B too. This avoids creation of Integer-objects (which are only cached up to 127 by default. See Integer$IntegerCache). This is possible because each vertex is on stack S (and B) at most once and has a unique number (as long as it is on S). * [GabowStrongConnectivityInspector] prefix stack-fields with "stack" AbstractStrongConnectivityInspector use the class-argument constructor again. The SupplierUtil now uses a performant and a proper (serializable) supplier. * Create HashSet with expected size and make constructor protected
* updated dependency versions * deleted deprecated code * fixed few javadoc issues * updated history * updated release doc Co-authored-by: Joris Kinable <kinable@amazon.com>
DijkstraManyToManyShortestPaths
* Fix warnings in tests Replace deprecated code in order to fix deprecation warnings: - use hamcreset.MatcherAssert.assertThat instead of junit.Assert.asserThat - use assertThrows instead of ExpectedException - and many more like new Integer(int) oder new ModifiableInteger() Use assertEquals(expected, actual) instead of assertTrue(actual==expected) and fix argument order in calls assertEquals (actual and expected was swapped) Fix unused warnings by either removing the unused method/variable or by adding an suppress warning annotation, if removal would disturb the code structure. * Revert fix that accidentally broke the tests
… part 1) (#1066) * [Checkstyle] update to version 8.41 and update DTD-file links * [CheckStyle] enforce Variable/Method/Type-name conventions for non API Add variable/method/type naming-convention checkstyle rules. Fix all variable/method/type naming-convention violations that do not require modifications of the public API. * [CheckStyle] suppress Variable/Method/Type-name rules in API elements Suppress all Variable/Method/Type name violations on API elements. Fixing those rules requires API modifications. In case of (static) fields, the fields are already deprecated and a replacement is provided. org.jgrapht.nio.DefaultAttribute : make static field 'NULL' final. This is actually an API break, but I assume it was never intended to make it modifiable and it was not-final by accident.
* [TSPLIBImporter] Consider multi-space delimiters (#1060) + adjust the tests to cover this case + use FileReader in GraphImporter * [TSPLIBImporter] ignore everything after whitespace for metadata values * Fix accidentally wrong input-data for tests * Replace trim() by strip() to remove all leading/trailing whitespace trim() only removes spaces, strip() removes all whitespace.
Allowed are the characters in the Unicode-blocks BASIC_LATIN (equal to ASCII) and LATIN_1_SUPPLEMENT.
* Bump org.junit.jupiter:junit-jupiter from 5.10.1 to 6.0.3 Bumps [org.junit.jupiter:junit-jupiter](https://github.com/junit-team/junit-framework) from 5.10.1 to 6.0.3. - [Release notes](https://github.com/junit-team/junit-framework/releases) - [Commits](junit-team/junit-framework@r5.10.1...r6.0.3) --- updated-dependencies: - dependency-name: org.junit.jupiter:junit-jupiter dependency-version: 6.0.3 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * Remove outdated JUnit version from pom.xml Removed outdated JUnit version entries from pom.xml. --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: John Sichi <jsichi@gmail.com>
* deprecate(util): Deprecate CollectionUtil new*WithExpectedSize methods These methods are superseded by JDK 19 factory methods HashMap.newHashMap(int), HashSet.newHashSet(int), LinkedHashMap.newLinkedHashMap(int), and LinkedHashSet.newLinkedHashSet(int) which accept an expected size directly. * refactor(util): Replace CollectionUtil.new*WithExpectedSize with JDK 19 factory methods in utility and traversal classes * refactor(core): Replace all CollectionUtil.new*WithExpectedSize with JDK 19 factory methods Migrate all 64 call sites across generators, coloring, connectivity, cycle, flow, isomorphism, matching, shortest path, spanning, tour, and clique packages to use HashMap.newHashMap(int), HashSet.newHashSet(int), LinkedHashMap.newLinkedHashMap(int), and LinkedHashSet.newLinkedHashSet(int). * refactor(core): Apply Java 16 pattern matching instanceof across codebase Apply pattern matching to equals() methods in Pair, Triple, UnorderedPair, ModifiableInteger, GraphWalk, WeightedUnmodifiableSet, RatioVertex, ColorRefinementIsomorphismInspector, and AhujaOrlinSharmaCyclicExchange. Also apply to non-equals() sites in UniformIntrusiveEdgesSpecifics, WeightedIntrusiveEdgesSpecifics, CollectionUtil.getElement(), and AhujaOrlinSharmaCapacitatedMinimumSpanningTree. Eliminates redundant casts and @SuppressWarnings("unchecked") annotations. * refactor(core): Replace Arrays.asList with List.of, use named threads, use Map.entry() Replace Arrays.asList with List.of for fixed literal lists in cycle, shortest path, partition, and GraphTests. Use named daemon platform threads in ConcurrencyUtil. Replace AbstractMap.SimpleImmutableEntry with Map.entry() in RandomRegularGraphGenerator. --------- Co-authored-by: kinable <kinable@amazon.com>
* fix(io): Resolve 3 compiler warnings in jgrapht-io - Remove 'transitive' from ANTLR requires in module-info.java - Replace this.setParameter() with direct field access in GEXFExporter constructor to avoid this-escape warning - Make implicit int-to-byte cast explicit in Graph6Sparse6Exporter * refactor(demo): Extract KnightTour and TourType to own source file Move KnightTour class and TourType enum (now nested inside KnightTour) out of WarnsdorffRuleKnightTourHeuristic.java into KnightTour.java to resolve auxiliary-class-access and module-accessibility warnings. * fix(demo): Add private constructors to demo utility classes Prevents default constructors from being exposed in the module's public API. Affects: CompleteGraphDemo, DependencyDemo, DirectedGraphDemo, GraphBuilderDemo, GraphMLDemo, LabeledEdges, PerformanceDemo. * fix(demo): Migrate JGraphXAdapterDemo from JApplet to JFrame JApplet is deprecated for removal since Java 9. Rewrite the demo as a standalone JFrame application. Also make KnightTour and its inner classes public to match their use in public API signatures. Update TourType references in test file. * Fixed a ton of compile warnings * Fixed javadoc * Fixed more javadoc --------- Co-authored-by: kinable <kinable@amazon.com>
Bumps [org.apfloat:apfloat](https://github.com/mtommila/apfloat) from 1.14.0 to 1.15.0. - [Commits](mtommila/apfloat@1.14.0...1.15.0) --- updated-dependencies: - dependency-name: org.apfloat:apfloat dependency-version: 1.15.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [org.apache.maven.plugins:maven-compiler-plugin](https://github.com/apache/maven-compiler-plugin) from 3.14.1 to 3.15.0. - [Release notes](https://github.com/apache/maven-compiler-plugin/releases) - [Commits](apache/maven-compiler-plugin@maven-compiler-plugin-3.14.1...maven-compiler-plugin-3.15.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-compiler-plugin dependency-version: 3.15.0 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…1322) Bumps [org.apache.maven.plugins:maven-shade-plugin](https://github.com/apache/maven-shade-plugin) from 3.6.1 to 3.6.2. - [Release notes](https://github.com/apache/maven-shade-plugin/releases) - [Commits](apache/maven-shade-plugin@maven-shade-plugin-3.6.1...maven-shade-plugin-3.6.2) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-shade-plugin dependency-version: 3.6.2 dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…1323) Bumps [org.apache.maven.plugins:maven-jar-plugin](https://github.com/apache/maven-jar-plugin) from 3.4.2 to 3.5.0. - [Release notes](https://github.com/apache/maven-jar-plugin/releases) - [Commits](apache/maven-jar-plugin@maven-jar-plugin-3.4.2...maven-jar-plugin-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-jar-plugin dependency-version: 3.5.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps `maven-surefire-plugin.version` from 3.5.4 to 3.5.5. Updates `org.apache.maven.surefire:surefire-junit-platform` from 3.5.4 to 3.5.5 Updates `org.apache.maven.plugins:maven-surefire-plugin` from 3.5.4 to 3.5.5 - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](apache/maven-surefire@surefire-3.5.4...surefire-3.5.5) Updates `org.apache.maven.plugins:maven-failsafe-plugin` from 3.5.4 to 3.5.5 - [Release notes](https://github.com/apache/maven-surefire/releases) - [Commits](apache/maven-surefire@surefire-3.5.4...surefire-3.5.5) --- updated-dependencies: - dependency-name: org.apache.maven.surefire:surefire-junit-platform dependency-version: 3.5.5 dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.apache.maven.plugins:maven-surefire-plugin dependency-version: 3.5.5 dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.apache.maven.plugins:maven-failsafe-plugin dependency-version: 3.5.5 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [org.apache.commons:commons-text](https://github.com/apache/commons-text) from 1.14.0 to 1.15.0. - [Changelog](https://github.com/apache/commons-text/blob/master/RELEASE-NOTES.txt) - [Commits](apache/commons-text@rel/commons-text-1.14.0...rel/commons-text-1.15.0) --- updated-dependencies: - dependency-name: org.apache.commons:commons-text dependency-version: 1.15.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
#1327) Bumps [org.apache.maven.plugins:maven-release-plugin](https://github.com/apache/maven-release) from 3.1.1 to 3.3.1. - [Release notes](https://github.com/apache/maven-release/releases) - [Commits](apache/maven-release@maven-release-3.1.1...maven-release-3.3.1) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-release-plugin dependency-version: 3.3.1 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [org.xmlunit:xmlunit-core](https://github.com/xmlunit/xmlunit) from 2.10.3 to 2.11.0. - [Release notes](https://github.com/xmlunit/xmlunit/releases) - [Changelog](https://github.com/xmlunit/xmlunit/blob/main/RELEASE_NOTES.md) - [Commits](xmlunit/xmlunit@v2.10.3...v2.11.0) --- updated-dependencies: - dependency-name: org.xmlunit:xmlunit-core dependency-version: 2.11.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Bump com.google.guava:guava from 33.3.1-jre to 33.6.0-jre Bumps [com.google.guava:guava](https://github.com/google/guava) from 33.3.1-jre to 33.6.0-jre. - [Release notes](https://github.com/google/guava/releases) - [Commits](https://github.com/google/guava/commits) --- updated-dependencies: - dependency-name: com.google.guava:guava dependency-version: 33.6.0-jre dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Update pom.xml to remove failureaccess exclusion Removed exclusion for 'failureaccess' from dependencies. * Update pom.xml to add new exclusions Added exclusions for error_prone_annotations and jsap in pom.xml. --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: John Sichi <jsichi@gmail.com>
Bumps [com.puppycrawl.tools:checkstyle](https://github.com/checkstyle/checkstyle) from 13.4.0 to 13.4.2. - [Release notes](https://github.com/checkstyle/checkstyle/releases) - [Commits](checkstyle/checkstyle@checkstyle-13.4.0...checkstyle-13.4.2) --- updated-dependencies: - dependency-name: com.puppycrawl.tools:checkstyle dependency-version: 13.4.2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…#1330) Bumps [org.apache.maven.plugins:maven-source-plugin](https://github.com/apache/maven-source-plugin) from 3.3.1 to 3.4.0. - [Release notes](https://github.com/apache/maven-source-plugin/releases) - [Commits](apache/maven-source-plugin@maven-source-plugin-3.3.1...maven-source-plugin-3.4.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-source-plugin dependency-version: 3.4.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [org.sonatype.central:central-publishing-maven-plugin](https://github.com/sonatype/central-publishing-maven-plugin) from 0.9.0 to 0.10.0. - [Commits](https://github.com/sonatype/central-publishing-maven-plugin/commits) --- updated-dependencies: - dependency-name: org.sonatype.central:central-publishing-maven-plugin dependency-version: 0.10.0 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…5.0 (#1332) Bumps [org.apache.maven.plugins:maven-resources-plugin](https://github.com/apache/maven-resources-plugin) from 3.3.1 to 3.5.0. - [Release notes](https://github.com/apache/maven-resources-plugin/releases) - [Commits](apache/maven-resources-plugin@maven-resources-plugin-3.3.1...maven-resources-plugin-3.5.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-resources-plugin dependency-version: 3.5.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [org.apfloat:apfloat](https://github.com/mtommila/apfloat) from 1.15.0 to 1.16.0. - [Commits](mtommila/apfloat@1.15.0...1.16.0) --- updated-dependencies: - dependency-name: org.apfloat:apfloat dependency-version: 1.16.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…gable spur engines (#1338) Add a new exact Yen-family implementation, BoundedPrunedYenKShortestPath, alongside the existing YenKShortestPath, with two separable optimisations behind a single public class: 1. SpurShortestPathEngine abstraction with two adapter back-ends: - DijkstraSpurEngine: thin adapter delegating to DijkstraShortestPath via MaskSubgraph for ban handling. - AStarSpurEngine: thin adapter delegating to AStarShortestPath via MaskSubgraph + an AStarAdmissibleHeuristic built from a one-time reverse-distance precomputation. The heuristic is admissible by construction (reverse distances are computed on the original graph, and removing vertices/edges only increases shortest-path distances), so A* remains exact under bans. No shortest-path logic is duplicated. 2. BoundedPrunedYenKShortestPath: bounded-pruned Yen driver that defers each spur as a SpurTask keyed by an admissible lower bound and only materialises tasks that could still beat the cheapest known candidate. Includes an exact impossible-spur skip that eliminates doomed tasks before any spur shortest-path query is issued (resolves the path-chain pathology cleanly: every spur on a single-path chain has its only outgoing edge banned by the Yen rule, so all n-1 spurs are skipped). Defaults: the no-engine constructor uses DijkstraSpurEngine (mirrors the spur step of the existing YenKShortestPath); AStarSpurEngine is opt-in via the two-argument constructor and is recommended for dense graphs or larger k. The existing YenKShortestPath is unchanged. Tests (BoundedPrunedYenKShortestPathTest, 24 cases, JUnit 5): - hand-built edge cases: negative-k, k=0, unreachable sink, source==sink, zero-weight edges, single-edge graph, k larger than total paths, large-k stress, negative-weight rejection - explicit cross-engine smoke (Dijkstra + A* vs YenKShortestPath) - property-style fuzz suites (~115 random graph configurations across random DAGs, random cyclic digraphs, and grids), every case asserting the same ordered path-weight sequence as YenKShortestPath - impossible-spur skip behaviour assertions Benchmark: BoundedPrunedYenKShortestPathPerformance is a JMH benchmark at the canonical jgrapht-core/src/test/java/org/jgrapht/perf/shortestpath path, in the same style as KShortestPathsPerformance. On Gnp random digraphs, BoundedPrunedYenKShortestPath with AStarSpurEngine measures 10.9x faster than YenKShortestPath at n=500 and 27.3x faster at n=1500 (tight measurement: -f 2 -wi 2 -i 8, Cnt=16). The Dijkstra-backed bounded variant is slower on this workload, so the dense-random-graph win comes from the A* spur engine; the bounded scheduling layer is workload-conditional. References (in BoundedPrunedYenKShortestPath javadoc): - Yen, J. Y. (1971). Finding the k shortest loopless paths in a network. - Martins, E. Q. V., & Pascoal, M. M. B. (2003). A new implementation of Yen's ranking loopless paths algorithm. - Aljazzar, H., & Leue, S. (2011). K*: A heuristic search algorithm for finding the k shortest paths. Discussed on jgrapht-dev before opening this PR: https://groups.google.com/g/jgrapht-dev/c/JHFs5n7dMpI Co-authored-by: Claude Sonnet 4.7 <noreply@anthropic.com>
Bumps [nokogiri](https://github.com/sparklemotion/nokogiri) from 1.19.1 to 1.19.3. - [Release notes](https://github.com/sparklemotion/nokogiri/releases) - [Changelog](https://github.com/sparklemotion/nokogiri/blob/main/CHANGELOG.md) - [Commits](sparklemotion/nokogiri@v1.19.1...v1.19.3) --- updated-dependencies: - dependency-name: nokogiri dependency-version: 1.19.3 dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…1341) * perf(shortestpath): avoid unused pathVertices set and use ArrayDeque in AllDirectedPaths In AllDirectedPaths.generatePaths the per-pop pathVertices HashSet is only consulted by the simple-path self-intersection filter, but it was rebuilt unconditionally on every iteration of the main loop. In non-simple-paths mode the rebuild is wasted O(path length) work; guard it behind the simplePathsOnly check. Java short-circuit evaluation keeps the dereference safe. Also switch the incompletePaths queue from LinkedList to ArrayDeque to remove the per-node linked-list overhead. The queue is only used through the Deque interface (poll / addFirst / add / isEmpty), which ArrayDeque supports identically with better allocation behavior. Pure refactor; no behavioral difference. Already covered by testCycleBehavior on AllDirectedPathsTest, which exercises both simplePathsOnly modes on a cyclic toy graph. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * perf(shortestpath): add JMH bench for AllDirectedPaths non-simple mode * test(shortestpath): expand AllDirectedPaths non-simple-mode coverage with brute-force oracle --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
…(V) to run one source search (#1340) * perf(shortestpath): use one Dijkstra in DijkstraManyToManyShortestPaths.getPaths Override getPaths(V) on DijkstraManyToManyShortestPaths to run a single DijkstraClosestFirstIterator over the source via getShortestPathsTree, instead of inheriting the BaseManyToManyShortestPaths fallback that calls getPath(source, v) once per vertex of the graph (which re-runs Dijkstra from the same source via getManyToManyPaths each time, an O(|V| * (V log V + E)) cost for what should be O(V log V + E)). The base-class fallback is preserved unchanged for DefaultManyToManyShortestPaths (which would otherwise bypass the user-supplied algorithm function) and CHManyToManyShortestPaths (which would otherwise bypass its contraction-hierarchy preprocessing). Adds regression tests: - DijkstraManyToManyShortestPathsTest: oracle agreement vs DijkstraShortestPath on reachable/unreachable targets; precondition. - DefaultManyToManyShortestPathsTest: function-spy proving the user-supplied algorithm function is consulted on getPaths(source). - CHManyToManyShortestPathsTest: oracle agreement on getPaths(source) for every vertex of the test graph. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * perf(shortestpath): add JMH bench for DijkstraManyToManyShortestPaths.getPaths * test(shortestpath): expand DijkstraManyToManyShortestPaths.getPaths coverage with fuzz + edge cases * test(shortestpath): factor SingleSourcePaths assertCorrectPaths into shared base Per code review on #1340: extract the SingleSourcePaths oracle-agreement check into a new BaseManyToManyShortestPathsTest .assertCorrectPaths(graph, paths, source, targets) helper, alongside the existing ManyToManyShortestPaths variant. Replaces the inline DijkstraShortestPath oracle loops in: - CHManyToManyShortestPathsTest.testGetPathsMatchesDijkstraOracle - DefaultManyToManyShortestPathsTest .testGetPathsConsultsProvidedAlgorithmFunction - DijkstraManyToManyShortestPathsTest: * testGetPathsSingleSourceMatchesDijkstra * testGetPathsSingleVertexGraph * testGetPathsSourceHasNoOutgoingEdges * testGetPathsDisconnectedGraph * testGetPathsCyclicGraphWithSelfLoopOnSource * testGetPathsFuzzAgainstDijkstraOracle The helper handles the unreachable-target contract (null path / +Inf weight) so callers no longer hand-roll the per-target null/non-null branches. testGetPathsCalledTwiceReturnsConsistentResults keeps its bespoke pair-of-calls comparison since it does not verify against an oracle. Pure refactor. 40/40 m2m tests still pass; full jgrapht-core suite 6885/6885 green; checkstyle + javadoc clean. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
* perf(shortestpath): add forward-pruning preprocessing to AllDirectedPaths
Before this change, `edgeMinDistancesBackwards` walked back from every target
and decorated every edge whose head was backward-reachable to a target within
the budget, including edges whose tail is not forward-reachable from any source
within the budget. Such edges cannot lie on any feasible source -> target walk
and would never be traversed by the forward enumeration in `generatePaths` in
either simple or non-simple mode, so decorating them is wasted preprocessing
work that the subsequent enumeration pays for again per outgoing edge.
This change adds a forward BFS from the source set (`vertexMinDistancesForwards`)
and threads its result into `edgeMinDistancesBackwards`. An edge (u, v) is
retained only when u is forward-reachable from some source and the sandwich
inequality holds:
dF(u) + 1 + dB(v) <= maxPathLength
where dF(u) is the forward BFS distance from the source set to u and 1 + dB(v)
is the backward BFS distance from v to a target through this edge. Edges that
fail the sandwich cannot appear on any feasible source -> target walk within
the budget. The inequality is written as
`forwardOfSource > maxPathLength - childDistance` to avoid integer overflow at
extreme `maxPathLength` values; the BFS bounds guarantee
`childDistance <= maxPathLength` when `maxPathLength` is set, so the right-hand
side is non-negative.
The optimisation is enabled by default. A setter on the existing instance
exposes the toggle:
public void setForwardPruning(boolean forwardPruning)
public boolean isForwardPruning()
The two existing public constructors, `AllDirectedPaths(Graph)` and
`AllDirectedPaths(Graph, PathValidator)`, are unchanged. Callers that want the
historical backward-only preprocessing behaviour exactly can recover it with
`setForwardPruning(false)`. The prune is exact - it never drops an edge that
could lie on a feasible walk - so the produced path set is identical in both
modes. On graphs where the prune never fires (e.g. small dense strongly-
connected digraphs), enabling it adds the cost of one extra O(V + E) BFS per
`getAllPaths` call, which is dominated by the enumeration itself.
The class-level Javadoc is expanded to describe the two-phase preprocessing /
enumeration design and the forward-pruning preprocessing, so the IDE-visible
documentation explains when the toggle is useful without requiring the reader
to find the setter first.
Tests in `AllDirectedPathsTest` are extended with cases that exercise both
`forwardPruning=true` and `forwardPruning=false`:
- `testTargetReachableButSourceUnreachableBranchIsIgnored` -
canonical garden-vertex case
- `testMultipleSourcesPartialGarden` - one source reaches target,
another is isolated
- `testUnboundedSimplePathsWithUnreachableGarden` -
`maxPathLength=null` boundary
- `testSourceEqualsTargetInDisconnectedGraph` - trivial zero-length walk
- `testDenseStronglyConnectedLossCase` - bounded overhead, identical results
- `testFuzzAgainstBruteForce` - 8 seeded random graphs, both modes, simple
and non-simple, compared as path sets against a brute-force enumeration
Refs: https://groups.google.com/g/jgrapht-dev/c/fhhJk9FVFoo
Co-Authored-By: Claude <noreply@anthropic.com>
* perf(shortestpath): add JMH bench for AllDirectedPaths forward pruning
Two cell families, each parameterised over `forwardPruning` so the cost of
the optimisation is directly comparable to the historical preprocessing
path in the same JVM:
- Win case: forward chain of `chainLen` vertices 0 -> 1 -> ... -> T plus a
`gardenSize`-vertex source-disconnected garden whose every vertex has an
edge into T. Simple-paths mode, `maxPathLength = chainLen + 5`. The
garden is reachable backwards from T but no garden vertex is reachable
forwards from the source, so when forward pruning is off the backward
sweep marks every garden vertex.
- Loss case: small dense strongly-connected digraph where F = B = V, so
the forward BFS is pure overhead and the prune never drops anything.
Bounds the regression cost when forward pruning is enabled on a graph
it cannot help.
Sample numbers on JDK 21.0.10 (8 measurement iterations, 2s each):
Win case (chainLen=20):
gardenSize off (ms/op) on (ms/op) speedup
500 0.043 +/- 0.001 0.011 +/- 0.001 3.9x
1000 0.080 +/- 0.002 0.015 +/- 0.001 5.3x
2000 0.171 +/- 0.014 0.022 +/- 0.001 7.8x
Loss case (n=20, maxPathLength=3):
off: 0.137 +/- 0.008 ms/op on: 0.141 +/- 0.003 ms/op (within noise)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
Bumps [faraday](https://github.com/lostisland/faraday) from 2.14.1 to 2.14.2. - [Release notes](https://github.com/lostisland/faraday/releases) - [Changelog](https://github.com/lostisland/faraday/blob/main/CHANGELOG.md) - [Commits](lostisland/faraday@v2.14.1...v2.14.2) --- updated-dependencies: - dependency-name: faraday dependency-version: 2.14.2 dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.