Digraphs icon indicating copy to clipboard operation
Digraphs copied to clipboard

Deleting vertices or edges from an `EdgeWeightedDigraph` deletes the weights, so does taking a mutable copy.

Open markuspf opened this issue 1 year ago • 2 comments

I am not sure this is intended.

Creating a digraph with edge weights and removing vertices, edges, or taking a mutable copy makes the resulting grpah not have weights.

gap> d := EdgeWeightedDigraph([[2], [3], [4], []], [[1], [1], [1], []]);
<immutable digraph with 4 vertices, 3 edges>
gap> HasEdgeWeights(d);
true
gap> e := DigraphRemoveVertex(d, 1);
<immutable digraph with 3 vertices, 2 edges>
gap> HasWeights(e);
Error, Variable: 'HasWeights' must have a value
not in any function at *stdin*:19
gap> HasEdgeWeights(e);
false
gap> f := DigraphRemoveEdge(d, 1, 2);
<immutable digraph with 4 vertices, 2 edges>
gap> HasEdgeWeights(f);              
false
gap> g := DigraphMutableCopy(d);
<mutable digraph with 4 vertices, 3 edges>
gap> HasEdgeWeights(g);
false

markuspf avatar Aug 28 '24 15:08 markuspf

Thanks for reporting this. This isn't exactly a bug, but something that should probably be improved.

Currently EdgeWeights is just an attribute of a digraph, and so it's not copied over when a new digraph is created. "Fixing" this would involve adding some extra code for the adding/removing/copying methods you used above, checking whether a digraph has edge weights and copying/modifying them appropriately.

Worth doing, and not too mathematically hard if there are any VIP people that fancy it.

mtorpey avatar Feb 05 '25 17:02 mtorpey

As mentioned before, this might be a good idea for a VIP student.

A few more hints:

  • The DigraphRemoveVertex, DigraphRemoveEdge and DigraphMutableCopy functions are the ones in question.
  • They are found in oper.gi and digraph.gi.
  • You can check whether a digraph has edge weights with if HasEdgeWeights(D).
  • Edge weights can be set on a new digraph with SetEdgeWeights.

mtorpey avatar Oct 15 '25 13:10 mtorpey