Digraphs
Digraphs copied to clipboard
Deleting vertices or edges from an `EdgeWeightedDigraph` deletes the weights, so does taking a mutable copy.
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
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.
As mentioned before, this might be a good idea for a VIP student.
A few more hints:
- The
DigraphRemoveVertex,DigraphRemoveEdgeandDigraphMutableCopyfunctions are the ones in question. - They are found in
oper.gianddigraph.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.