Skip to content

Conversation

@devansh2605
Copy link
Contributor

Issue - https://github.com/digraphs/Digraphs/issues/683

Previously, 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:

  • Added CopyEdgeWeightsForSubdigraph helper function to reconstruct weights after vertex removals.
  • Updated DigraphRemoveVertex to copy edge weights.
  • Updated DigraphRemoveEdge to remove corresponding weight entries instead of dropping all weights.
  • Updated DigraphMutableCopy to copy edge weights when present.
  • Declared the new helper in digraph.gd.

@mtorpey
Copy link
Collaborator

mtorpey commented Oct 31, 2025

This looks like it's coming along. Could you please:

  1. take a look at the failing lint check
  2. add tests to oper.tst that use DigraphRemoveVertices etc. and verify that the edge weights are copied appropriately.

It'd be great if you could do this by next meeting, so we can do a proper review of your two PRs.

@mtorpey
Copy link
Collaborator

mtorpey commented Nov 12, 2025

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.
Copy link
Collaborator

@mtorpey mtorpey left a 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.

Comment on lines +3311 to +3312
gap> m2!.edgeweights;
[ [ 5 ], [ 15 ], [ ], [ ] ]
Copy link
Collaborator

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 !.edgeweights as 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.

@mtorpey
Copy link
Collaborator

mtorpey commented Nov 24, 2025

Documentation should be installed in doc/z-chap5.xml

end);

InstallMethod(RemoveDigraphEdgeWeight, "for an immutable digraph, pos int, pos int",
[IsImmutableDigraph, IsPosInt, IsPosInt],
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
[IsImmutableDigraph, IsPosInt, IsPosInt],
[IsImmutableDigraph and HasEdgeWeights, IsPosInt, IsPosInt],

local newD, w;
newD := DigraphMutableCopy(D);

if HasEdgeWeights(D) then
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
if HasEdgeWeights(D) then

function(D, v, pos)
local newD, w;
newD := DigraphMutableCopy(D);

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
weights := EdgeWeightsMutableCopy(D);

[IsImmutableDigraph, IsPosInt, IsPosInt],
function(D, v, pos)
local newD, w;
newD := DigraphMutableCopy(D);
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
newD := DigraphMutableCopy(D);
newD := DigraphImmutableCopy(D);


MakeImmutable(newD);
if HasEdgeWeights(D) then
SetEdgeWeights(newD, StructuralCopy(newD!.edgeweights));
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
SetEdgeWeights(newD, StructuralCopy(newD!.edgeweights));
SetEdgeWeights(newD, weights));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants