Repository navigation
test: self-loops and parallel edges across degree, matrices, cycles and planning (+ fixes) - #26
Merged
Merged
Conversation
…nd planning Narrative per graph type: baseline, add self-loop on the route, remove it, add parallel edges (planning must take the cheapest), add the loop back. Fails on current code; fixes follow in separate commits. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ions - path_UCS/path_Astar hung forever when a self-loop lay on the route (the expanded vertex was re-added to the frontier as its own parent) - path lengths used the first edge found, not the cheapest of parallel edges; edgeto() now returns the cheapest - path_BFS rebuilt the length with child->parent edgeto(), which raised ValueError on every DGraph; it now goes parent->child like UCS/A* - adjacency() counts edges (was 0/1), so rows sum to the degree and Laplacian() = degree() - adjacency() has zero row sums again - distance() takes the cheapest parallel edge rather than the last written - incidence() column for an undirected self-loop is 2, matching degree Identical results for simple graphs. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Adds a 'For graphs with parallel edges or loops' rubric to degree(), adjacency(), incidence(), Laplacian() and distance(); notes on edgeto() and the three planners. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…anner exceptions Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 35 |
| Duplication | 4 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #26 +/- ##
==========================================
+ Coverage 86.14% 87.37% +1.22%
==========================================
Files 2 2
Lines 787 800 +13
==========================================
+ Hits 678 699 +21
+ Misses 109 101 -8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.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.
Summary
Self-loops and parallel edges are permitted by
connect()/add_edge(), but several things derived from the edge set gave wrong answers or hung. This adds tests that pin down the behavior forUGraphandDGraph, fixes what they found, and documents the conventions.The narrative per graph type: simple acyclic network → add a self-loop on the route → remove it (must restore the baseline exactly) → add parallel edges (planning must take the cheapest) → add the loop back.
Bugs fixed
path_UCS/path_Astarwith a self-loop on the routeedgeto()returns the cheapestDGraph.path_BFSValueError: dest is not a neighbouron every directed graph (child→parentedgeto)adjacency()Laplacian()degree - (adjacency > 0), row sums non-zero with multi-edgesdegree - adjacency, rows sum to zerodistance()incidence()Output is identical for simple graphs.
Conventions (documented in the docstrings under "For graphs with parallel edges or loops")
UGraphvertex's degree, 1 to aDGraphvertex's out-degreeadjacency()[i, j]is the number of edges fromitojiscyclic(): a self-loop is a cycle; two parallel edges are a cycle in aUGraphbut not in aDGraphNotes for review
adjacency()andLaplacian()change for multigraphs, so this is worth a CHANGELOG line. I leftCHANGELOG.mdalone to avoid a conflict with Release 1.0.0 #14.tests/test_multigraph.py(15 tests); they fail onmainand pass here. They use aSIGALRMguard so a regression fails rather than hanging the suite.:return:text.🤖 Generated with Claude Code