-
Notifications
You must be signed in to change notification settings - Fork 61
Added a helper function and updated the existing methods to preserve edge weights when removing vertices, edges or copying digraphs (issue #683) #877
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
base: main
Are you sure you want to change the base?
Conversation
…edge weights when removing vertices, edges or copying digraphs (issue digraphs#683)
|
This looks like it's coming along. Could you please:
It'd be great if you could do this by next meeting, so we can do a proper review of your two PRs. |
|
Looks like linting is improved! If you could now add tests, that should satisfy the codecov check. |
…igraphRemoveVertex and related immutable operations. Also added testing.
mtorpey
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Subject to what we've said above, it'd be nice to see documentation. But this is coming along well.
| gap> m2!.edgeweights; | ||
| [ [ 5 ], [ 15 ], [ ], [ ] ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a design decision here!
Either:
- mutable digraphs cannot hold EdgeWeights (because they can't hold attributes); or
- mutable digraphs can store edge weights internally using
!.edgeweightsas a workaround.
The second approach has been taken in this PR, and we should review whether it's a good idea when we finally merge.
|
Documentation should be installed in doc/z-chap5.xml |
| end); | ||
|
|
||
| InstallMethod(RemoveDigraphEdgeWeight, "for an immutable digraph, pos int, pos int", | ||
| [IsImmutableDigraph, IsPosInt, IsPosInt], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| [IsImmutableDigraph, IsPosInt, IsPosInt], | |
| [IsImmutableDigraph and HasEdgeWeights, IsPosInt, IsPosInt], |
| local newD, w; | ||
| newD := DigraphMutableCopy(D); | ||
|
|
||
| if HasEdgeWeights(D) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if HasEdgeWeights(D) then |
| function(D, v, pos) | ||
| local newD, w; | ||
| newD := DigraphMutableCopy(D); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| weights := EdgeWeightsMutableCopy(D); |
| [IsImmutableDigraph, IsPosInt, IsPosInt], | ||
| function(D, v, pos) | ||
| local newD, w; | ||
| newD := DigraphMutableCopy(D); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| newD := DigraphMutableCopy(D); | |
| newD := DigraphImmutableCopy(D); |
|
|
||
| MakeImmutable(newD); | ||
| if HasEdgeWeights(D) then | ||
| SetEdgeWeights(newD, StructuralCopy(newD!.edgeweights)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| SetEdgeWeights(newD, StructuralCopy(newD!.edgeweights)); | |
| SetEdgeWeights(newD, weights)); |
Issue -
https://github.com/digraphs/Digraphs/issues/683Previously, deleting vertices or edges from an EdgeWeightedDigraph or taking a mutable copy caused the resulting digraph to lose its edge weights. This commit is just a layout for which I'll add tests and debug.
Changes include:
CopyEdgeWeightsForSubdigraphhelper function to reconstruct weights after vertex removals.DigraphRemoveVertexto copy edge weights.DigraphRemoveEdgeto remove corresponding weight entries instead of dropping all weights.DigraphMutableCopyto copy edge weights when present.digraph.gd.