From 0c7642c60cb8c3de8836aefbdb0dba85f277f427 Mon Sep 17 00:00:00 2001 From: Devansh Chopra Date: Wed, 29 Oct 2025 14:58:08 +0000 Subject: [PATCH 1/6] Implemented ^ operator for digraphs to delegate to OnDigraphs (issue #580) --- gap/oper.gi | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gap/oper.gi b/gap/oper.gi index 85b327d40..49f4be0ca 100644 --- a/gap/oper.gi +++ b/gap/oper.gi @@ -1138,6 +1138,16 @@ InstallMethod(DomainForAction, "for a digraph, list or collection and function", [IsDigraph, IsListOrCollection, IsFunction], ReturnTrue); +# Operator action: D^p and D^t +# Allow D ^ p (digraph and permutation) to call OnDigraphs(D, p) +# and D ^ t (digraph and transformation) to call OnDigraphs(D, t) + +InstallMethod(\^, "digraph acted on by a permutation", + [ IsDigraph, IsPerm ], OnDigraphs); + +InstallMethod(\^, "digraph acted on by a transformation", + [ IsDigraph, IsTransformation ], OnDigraphs); + ############################################################################# # 5. Substructures and quotients ############################################################################# From 1af31603ed8077b5fef72471284899f5894e7204 Mon Sep 17 00:00:00 2001 From: Devansh Chopra Date: Wed, 29 Oct 2025 15:50:37 +0000 Subject: [PATCH 2/6] Added a helper function and updated the existing methods to preserve edge weights when removing vertices, edges or copying digraphs (issue #683) --- gap/digraph.gd | 2 ++ gap/digraph.gi | 30 ++++++++++++++++++++++++++++++ gap/oper.gi | 29 ++++++++++++++++++++++++++--- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/gap/digraph.gd b/gap/digraph.gd index 46cb83d79..c46ac210d 100644 --- a/gap/digraph.gd +++ b/gap/digraph.gd @@ -152,3 +152,5 @@ DeclareOperation("RandomLattice", [IsFunction, IsPosInt]); # in the not-too-distant future! DeclareOperation("RandomMultiDigraph", [IsPosInt]); DeclareOperation("RandomMultiDigraph", [IsPosInt, IsPosInt]); + +DeclareGlobalFunction("CopyEdgeWeightsForSubdigraph"); \ No newline at end of file diff --git a/gap/digraph.gi b/gap/digraph.gi index 893d363bc..69aca3f0a 100644 --- a/gap/digraph.gi +++ b/gap/digraph.gi @@ -172,6 +172,11 @@ function(D) if HaveEdgeLabelsBeenAssigned(D) then SetDigraphEdgeLabelsNC(copy, StructuralCopy(DigraphEdgeLabelsNC(D))); fi; + + if HasEdgeWeights(D) then + SetEdgeWeights(copy, StructuralCopy(EdgeWeights(D))); + fi; + return copy; end); @@ -1837,3 +1842,28 @@ n -> RandomLatticeCons(IsImmutableDigraph, n)); InstallMethod(RandomLattice, "for a func and a pos int", [IsFunction, IsPosInt], RandomLatticeCons); + +InstallGlobalFunction(CopyEdgeWeightsForSubdigraph, +function(oldDigraph, newDigraph, removedVertices) + local oldWeights, newWeights, i, j, weight, shiftVertices; + + if not HasEdgeWeights(oldDigraph) then + return; + fi; + + oldWeights := EdgeWeights(oldDigraph); + newWeights := []; + for i in [1 .. DigraphNrVertices(newDigraph)] do + newWeights[i] := []; + + for j in OutNeighbours(newDigraph, i) do + shiftVertices := function(x) + return x + Length(Filtered(removedVertices, v -> v <= x)); + end; + weight := oldWeights[shiftVertices(i)][shiftVertices(j)]; + Add(newWeights[i], weight); + od; + od; + + SetEdgeWeights(newDigraph, newWeights); +end); diff --git a/gap/oper.gi b/gap/oper.gi index 49f4be0ca..67e188768 100644 --- a/gap/oper.gi +++ b/gap/oper.gi @@ -107,7 +107,8 @@ InstallMethod(DigraphRemoveVertex, "for a mutable digraph by out-neighbours and positive integer", [IsMutableDigraph and IsDigraphByOutNeighboursRep, IsPosInt], function(D, u) - local pos, w, v; + local pos, w, v, oldD; + oldD := StructuralCopy(D); if u > DigraphNrVertices(D) then return D; fi; @@ -131,6 +132,11 @@ function(D, u) fi; od; od; + + if HasEdgeWeights(D) then + CopyEdgeWeightsForSubdigraph(oldD, D, [u]); + fi; + return D; end); @@ -138,10 +144,18 @@ InstallMethod(DigraphRemoveVertex, "for an immutable digraph and positive integer", [IsImmutableDigraph, IsPosInt], function(D, u) + local newD; if u > DigraphNrVertices(D) then return D; fi; - return MakeImmutable(DigraphRemoveVertex(DigraphMutableCopy(D), u)); + + newD := DigraphRemoveVertex(DigraphMutableCopy(D), u); + if HasEdgeWeights(D) then + CopyEdgeWeightsForSubdigraph(D, newD, [u]); + fi; + MakeImmutable(newD); + + return newD; end); InstallMethod(DigraphRemoveVertices, "for a mutable digraph and a list", @@ -227,7 +241,7 @@ InstallMethod(DigraphRemoveEdge, "for a mutable digraph by out-neighbours and two positive integers", [IsMutableDigraph and IsDigraphByOutNeighboursRep, IsPosInt, IsPosInt], function(D, src, ran) - local pos; + local pos, weights; if IsMultiDigraph(D) then ErrorNoReturn("the 1st argument must be a digraph with no multiple ", "edges,"); @@ -243,6 +257,15 @@ function(D, src, ran) Remove(D!.OutNeighbours[src], pos); RemoveDigraphEdgeLabel(D, src, pos); fi; + + if HasEdgeWeights(D) then + weights := StructuralCopy(EdgeWeights(D)); + if IsBound(weights[src]) and IsBound(weights[src][ran]) then + weights[src][ran] := fail; + fi; + SetEdgeWeights(D, weights); + fi; + return D; end); From b39a548590a492b7027c08d1b7b952d7c5eafddf Mon Sep 17 00:00:00 2001 From: Devansh Chopra Date: Wed, 29 Oct 2025 15:56:56 +0000 Subject: [PATCH 3/6] Removed code for issue 580 committed by mistake in this branch --- gap/oper.gi | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/gap/oper.gi b/gap/oper.gi index 67e188768..990b44861 100644 --- a/gap/oper.gi +++ b/gap/oper.gi @@ -1161,16 +1161,6 @@ InstallMethod(DomainForAction, "for a digraph, list or collection and function", [IsDigraph, IsListOrCollection, IsFunction], ReturnTrue); -# Operator action: D^p and D^t -# Allow D ^ p (digraph and permutation) to call OnDigraphs(D, p) -# and D ^ t (digraph and transformation) to call OnDigraphs(D, t) - -InstallMethod(\^, "digraph acted on by a permutation", - [ IsDigraph, IsPerm ], OnDigraphs); - -InstallMethod(\^, "digraph acted on by a transformation", - [ IsDigraph, IsTransformation ], OnDigraphs); - ############################################################################# # 5. Substructures and quotients ############################################################################# From 469f7a4d1f8c2365839d769fe647634b8ca06ae3 Mon Sep 17 00:00:00 2001 From: Devansh Chopra Date: Tue, 11 Nov 2025 14:07:31 +0000 Subject: [PATCH 4/6] Converted shiftVertices to lambda expression and corrected lint formatting --- gap/digraph.gi | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/gap/digraph.gi b/gap/digraph.gi index 69aca3f0a..1d52bd9fd 100644 --- a/gap/digraph.gi +++ b/gap/digraph.gi @@ -1843,7 +1843,7 @@ n -> RandomLatticeCons(IsImmutableDigraph, n)); InstallMethod(RandomLattice, "for a func and a pos int", [IsFunction, IsPosInt], RandomLatticeCons); -InstallGlobalFunction(CopyEdgeWeightsForSubdigraph, +InstallGlobalFunction(CopyEdgeWeightsForSubdigraph, function(oldDigraph, newDigraph, removedVertices) local oldWeights, newWeights, i, j, weight, shiftVertices; @@ -1853,13 +1853,11 @@ function(oldDigraph, newDigraph, removedVertices) oldWeights := EdgeWeights(oldDigraph); newWeights := []; + shiftVertices := x -> x + Length(Filtered(removedVertices, v -> v <= x)); + for i in [1 .. DigraphNrVertices(newDigraph)] do newWeights[i] := []; - for j in OutNeighbours(newDigraph, i) do - shiftVertices := function(x) - return x + Length(Filtered(removedVertices, v -> v <= x)); - end; weight := oldWeights[shiftVertices(i)][shiftVertices(j)]; Add(newWeights[i], weight); od; From f0046405e7ed889af76ff037b90ee23a0121ba8b Mon Sep 17 00:00:00 2001 From: Devansh Chopra Date: Mon, 24 Nov 2025 13:51:03 +0000 Subject: [PATCH 5/6] Fixed weight preservation in DigraphMutableCopy, DigraphRemoveEdge, DigraphRemoveVertex and related immutable operations. Also added testing. --- gap/digraph.gd | 2 +- gap/digraph.gi | 57 +++++++++++++++++++---------- gap/oper.gi | 78 +++++++++++++++++++++------------------- tst/standard/digraph.tst | 59 +++++++++++++++++++++++++++++- tst/standard/oper.tst | 42 +++++++++++++++++++++- 5 files changed, 180 insertions(+), 58 deletions(-) diff --git a/gap/digraph.gd b/gap/digraph.gd index c46ac210d..758606213 100644 --- a/gap/digraph.gd +++ b/gap/digraph.gd @@ -153,4 +153,4 @@ DeclareOperation("RandomLattice", [IsFunction, IsPosInt]); DeclareOperation("RandomMultiDigraph", [IsPosInt]); DeclareOperation("RandomMultiDigraph", [IsPosInt, IsPosInt]); -DeclareGlobalFunction("CopyEdgeWeightsForSubdigraph"); \ No newline at end of file +DeclareOperation("RemoveDigraphEdgeWeight", [IsDigraph, IsPosInt, IsPosInt]); \ No newline at end of file diff --git a/gap/digraph.gi b/gap/digraph.gi index 1d52bd9fd..f44ae752f 100644 --- a/gap/digraph.gi +++ b/gap/digraph.gi @@ -167,14 +167,18 @@ InstallMethod(DigraphMutableCopy, "for a digraph by out-neighbours", [IsDigraphByOutNeighboursRep], function(D) local copy; + copy := ConvertToMutableDigraphNC(OutNeighboursMutableCopy(D)); SetDigraphVertexLabels(copy, StructuralCopy(DigraphVertexLabels(D))); + if HaveEdgeLabelsBeenAssigned(D) then SetDigraphEdgeLabelsNC(copy, StructuralCopy(DigraphEdgeLabelsNC(D))); fi; - if HasEdgeWeights(D) then - SetEdgeWeights(copy, StructuralCopy(EdgeWeights(D))); + if IsImmutableDigraph(D) and HasEdgeWeights(D) then + copy!.edgeweights := EdgeWeightsMutableCopy(D); + elif IsMutableDigraph(D) and IsBound(D!.edgeweights) then + copy!.edgeweights := StructuralCopy(D!.edgeweights); fi; return copy; @@ -184,11 +188,20 @@ InstallMethod(DigraphImmutableCopy, "for a digraph by out-neighbours", [IsDigraphByOutNeighboursRep], function(D) local copy; + copy := ConvertToImmutableDigraphNC(OutNeighboursMutableCopy(D)); SetDigraphVertexLabels(copy, StructuralCopy(DigraphVertexLabels(D))); + if HaveEdgeLabelsBeenAssigned(D) then SetDigraphEdgeLabelsNC(copy, StructuralCopy(DigraphEdgeLabelsNC(D))); fi; + + if IsImmutableDigraph(D) and HasEdgeWeights(D) then + SetEdgeWeights(copy, StructuralCopy(EdgeWeights(D))); + elif IsMutableDigraph(D) and IsBound(D!.edgeweights) then + SetEdgeWeights(copy, StructuralCopy(D!.edgeweights)); + fi; + return copy; end); @@ -1843,25 +1856,31 @@ n -> RandomLatticeCons(IsImmutableDigraph, n)); InstallMethod(RandomLattice, "for a func and a pos int", [IsFunction, IsPosInt], RandomLatticeCons); -InstallGlobalFunction(CopyEdgeWeightsForSubdigraph, -function(oldDigraph, newDigraph, removedVertices) - local oldWeights, newWeights, i, j, weight, shiftVertices; - - if not HasEdgeWeights(oldDigraph) then - return; +InstallMethod(RemoveDigraphEdgeWeight, "for a mutable digraph, pos int, pos int", +[IsMutableDigraph and IsDigraphByOutNeighboursRep, IsPosInt, IsPosInt], +function(D, v, pos) + if IsBound(D!.edgeweights) and v <= Length(D!.edgeweights) and pos <= Length(D!.edgeweights[v]) then + Remove(D!.edgeweights[v], pos); fi; +end); - oldWeights := EdgeWeights(oldDigraph); - newWeights := []; - shiftVertices := x -> x + Length(Filtered(removedVertices, v -> v <= x)); +InstallMethod(RemoveDigraphEdgeWeight, "for an immutable digraph, pos int, pos int", +[IsImmutableDigraph, IsPosInt, IsPosInt], +function(D, v, pos) + local newD, w; + newD := DigraphMutableCopy(D); - for i in [1 .. DigraphNrVertices(newDigraph)] do - newWeights[i] := []; - for j in OutNeighbours(newDigraph, i) do - weight := oldWeights[shiftVertices(i)][shiftVertices(j)]; - Add(newWeights[i], weight); - od; - od; + if IsBound(newD!.edgeweights) then + if v <= Length(newD!.edgeweights) + and pos <= Length(newD!.edgeweights[v]) then + Remove(newD!.edgeweights[v], pos); + fi; + fi; + + MakeImmutable(newD); + if IsBound(newD!.edgeweights) then + SetEdgeWeights(newD, StructuralCopy(newD!.edgeweights)); + fi; - SetEdgeWeights(newDigraph, newWeights); + return newD; end); diff --git a/gap/oper.gi b/gap/oper.gi index 990b44861..34a1a640f 100644 --- a/gap/oper.gi +++ b/gap/oper.gi @@ -103,58 +103,60 @@ function(D, m, labels) return DigraphAddVertices(D, labels); end); -InstallMethod(DigraphRemoveVertex, -"for a mutable digraph by out-neighbours and positive integer", +InstallMethod(DigraphRemoveVertex, "for a mutable digraph by out-neighbours and positive integer", [IsMutableDigraph and IsDigraphByOutNeighboursRep, IsPosInt], function(D, u) - local pos, w, v, oldD; - oldD := StructuralCopy(D); + local pos, w, v; + if u > DigraphNrVertices(D) then return D; fi; + RemoveDigraphVertexLabel(D, u); if IsBound(D!.edgelabels) then Remove(D!.edgelabels, u); fi; + Remove(D!.OutNeighbours, u); + if IsBound(D!.edgeweights) then + Remove(D!.edgeweights, u); + fi; + for v in DigraphVertices(D) do pos := 1; while pos <= Length(D!.OutNeighbours[v]) do w := D!.OutNeighbours[v][pos]; + if w = u then Remove(D!.OutNeighbours[v], pos); RemoveDigraphEdgeLabel(D, v, pos); + RemoveDigraphEdgeWeight(D, v, pos); + elif w > u then - D!.OutNeighbours[v][pos] := w - 1; - pos := pos + 1; + D!.OutNeighbours[v][pos] := w - 1; + pos := pos + 1; + else - pos := pos + 1; + pos := pos + 1; fi; od; od; - - if HasEdgeWeights(D) then - CopyEdgeWeightsForSubdigraph(oldD, D, [u]); - fi; - return D; end); -InstallMethod(DigraphRemoveVertex, -"for an immutable digraph and positive integer", +InstallMethod(DigraphRemoveVertex, "for an immutable digraph and positive integer", [IsImmutableDigraph, IsPosInt], function(D, u) local newD; - if u > DigraphNrVertices(D) then - return D; - fi; - newD := DigraphRemoveVertex(DigraphMutableCopy(D), u); - if HasEdgeWeights(D) then - CopyEdgeWeightsForSubdigraph(D, newD, [u]); - fi; + newD := DigraphMutableCopy(D); + DigraphRemoveVertex(newD, u); MakeImmutable(newD); + if IsBound(newD!.edgeweights) then + SetEdgeWeights(newD, StructuralCopy(newD!.edgeweights)); + fi; + return newD; end); @@ -237,11 +239,10 @@ InstallMethod(DigraphAddEdges, "for an immutable digraph and a list", [IsImmutableDigraph, IsList], {D, edges} -> MakeImmutable(DigraphAddEdges(DigraphMutableCopy(D), edges))); -InstallMethod(DigraphRemoveEdge, -"for a mutable digraph by out-neighbours and two positive integers", +InstallMethod(DigraphRemoveEdge, "for a mutable digraph by out-neighbours and two positive integers", [IsMutableDigraph and IsDigraphByOutNeighboursRep, IsPosInt, IsPosInt], function(D, src, ran) - local pos, weights; + local pos; if IsMultiDigraph(D) then ErrorNoReturn("the 1st argument must be a digraph with no multiple ", "edges,"); @@ -252,28 +253,33 @@ function(D, src, ran) ErrorNoReturn("the 3rd argument must be a vertex of the ", "digraph that is the 1st argument,"); fi; + pos := Position(D!.OutNeighbours[src], ran); + if pos <> fail then Remove(D!.OutNeighbours[src], pos); RemoveDigraphEdgeLabel(D, src, pos); - fi; - - if HasEdgeWeights(D) then - weights := StructuralCopy(EdgeWeights(D)); - if IsBound(weights[src]) and IsBound(weights[src][ran]) then - weights[src][ran] := fail; - fi; - SetEdgeWeights(D, weights); + RemoveDigraphEdgeWeight(D, src, pos); fi; return D; end); -InstallMethod(DigraphRemoveEdge, -"for a immutable digraph and two positive integers", +InstallMethod(DigraphRemoveEdge, "for a immutable digraph and two positive integers", [IsImmutableDigraph, IsPosInt, IsPosInt], -{D, src, ran} --> MakeImmutable(DigraphRemoveEdge(DigraphMutableCopy(D), src, ran))); +function(D, src, ran) + local newD; + + newD := DigraphMutableCopy(D); + DigraphRemoveEdge(newD, src, ran); + MakeImmutable(newD); + + if IsBound(newD!.edgeweights) then + SetEdgeWeights(newD, StructuralCopy(newD!.edgeweights)); + fi; + + return newD; +end); InstallMethod(DigraphRemoveEdge, "for a mutable digraph and a list", [IsMutableDigraph, IsList], diff --git a/tst/standard/digraph.tst b/tst/standard/digraph.tst index 25f8dcc53..311c80a32 100644 --- a/tst/standard/digraph.tst +++ b/tst/standard/digraph.tst @@ -13,7 +13,7 @@ #@local adjacencies, b, bin, c, c1, c2, d, di, digraph, divides, elms, eq #@local eq_distr, eq_new, error, f, failed, failed_names, failed_values, foo, g #@local gr, gr1, gr2, gr3, gr4, gr5, graph, graph1, graph2, grnc, group, h -#@local hom13, hom21, hom23, hom31, hom41, hom42, hom52, hom53, i, im, inn +#@local hom13, hom21, hom23, hom31, hom41, hom42, hom52, hom53, i, im, im2, inn #@local isGraph, iso, iso_distr, iso_new, j, k, list, m, main, mat, n, name #@local name2, names, new, order, p, prop, properties, r, r1, r2, record, rel1 #@local rel2, rel3, representatives, s, schreierVector, sgn, temp, test, v, x @@ -565,6 +565,63 @@ gap> OutNeighbours(D); gap> AsDigraph(AsPartialPerm((2, 5, 3)), 2); fail +# Tests for DigraphMutableCopy, DigraphImmutableCopy, RemoveDigraphEdgeWeight (mutable & immutable). +gap> d := EdgeWeightedDigraph([[2,3],[3],[],[]], [[5,10],[15],[],[]]); + +gap> HasEdgeWeights(d); +true +gap> EdgeWeights(d); +[ [ 5, 10 ], [ 15 ], [ ], [ ] ] +gap> m := DigraphMutableCopy(d); + +gap> IsMutableDigraph(m); +true +gap> OutNeighbours(m) = OutNeighbours(d); +true +gap> DigraphVertexLabels(m) = DigraphVertexLabels(d); +true +gap> HasEdgeWeights(m); +false +gap> IsBound(m!.edgeweights); +true +gap> m!.edgeweights = [[5,10],[15],[],[]]; +true +gap> m!.edgeweights[1][1] := 999; +999 +gap> EdgeWeights(d)[1][1]; +5 +gap> im := DigraphImmutableCopy(d); + +gap> IsImmutableDigraph(im); +true +gap> OutNeighbours(im) = OutNeighbours(d); +true +gap> HasEdgeWeights(im); +true +gap> EdgeWeights(im); +[ [ 5, 10 ], [ 15 ], [ ], [ ] ] +gap> EdgeWeights(im)[1][1] := 777; +Error, List Assignment: must be a mutable list +gap> EdgeWeights(d); +[ [ 5, 10 ], [ 15 ], [ ], [ ] ] +gap> m := DigraphMutableCopy(d); + +gap> RemoveDigraphEdgeWeight(m, 1, 2); +gap> m!.edgeweights; +[ [ 5 ], [ 15 ], [ ], [ ] ] +gap> EdgeWeights(d); +[ [ 5, 10 ], [ 15 ], [ ], [ ] ] +gap> im2 := DigraphImmutableCopy(d); + +gap> im2 := RemoveDigraphEdgeWeight(im2, 1, 2); + +gap> EdgeWeights(im2); +[ [ 5 ], [ 15 ], [ ], [ ] ] +gap> HasEdgeWeights(im2); +true +gap> EdgeWeights(d); +[ [ 5, 10 ], [ 15 ], [ ], [ ] ] + # RandomDigraph gap> IsImmutableDigraph(RandomDigraph(100, 0.2)); true diff --git a/tst/standard/oper.tst b/tst/standard/oper.tst index f4637c9a1..743b7e8e5 100644 --- a/tst/standard/oper.tst +++ b/tst/standard/oper.tst @@ -13,7 +13,7 @@ #@local G, G1, L, TestPartialOrderDigraph #@local TestPartialOrderDigraph2, TestUnion, a, adj, b, comps, copy, d, e #@local edges, edges2, func, g, gr, gr1, gr2, gr3, gr4, gri, grrt, grt, h, i -#@local i1, i2, id, idom, in1, in2, in3, iter, j1, j2, m, m1, m2, mat, n, nbs +#@local i1, i2, id, idom, in1, in2, in3, iter, j1, j2, m, m1, m2, m3, m4, im3, im4, mat, n, nbs #@local out, out1, out2, out3, p1, p2, path, preorder, qr, r, res, rtclosure, t #@local tclosure, u1, u2, x gap> START_TEST("Digraphs package: standard/oper.tst"); @@ -3299,6 +3299,46 @@ gap> DigraphEdges(D); gap> DigraphVertexLabels(D); [ 1, 2, 3, 6, [ 4, 5 ] ] +# Tests for DigraphRemoveVertex, DigraphRemoveVertex (immutable), DigraphRemoveEdge, DigraphRemoveEdge (immutable). +gap> d := EdgeWeightedDigraph([[2,3],[3],[],[]], [[5,10],[15],[],[]]); + +gap> m2 := DigraphMutableCopy(d); + +gap> DigraphRemoveEdge(m2, 1, 3); + +gap> OutNeighbours(m2); +[ [ 2 ], [ 3 ], [ ], [ ] ] +gap> m2!.edgeweights; +[ [ 5 ], [ 15 ], [ ], [ ] ] +gap> im3 := DigraphRemoveEdge(d, 1, 3); + +gap> IsImmutableDigraph(im3); +true +gap> OutNeighbours(im3); +[ [ 2 ], [ 3 ], [ ], [ ] ] +gap> EdgeWeights(im3); +[ [ 5 ], [ 15 ], [ ], [ ] ] +gap> m4 := DigraphMutableCopy(d); + +gap> DigraphRemoveVertex(m4, 1); + +gap> OutNeighbours(m4); +[ [ 2 ], [ ], [ ] ] +gap> m4!.edgeweights; +[ [ 15 ], [ ], [ ] ] +gap> im4 := DigraphRemoveVertex(d, 1); + +gap> IsImmutableDigraph(im4); +true +gap> OutNeighbours(im4); +[ [ 2 ], [ ], [ ] ] +gap> EdgeWeights(im4); +[ [ 15 ], [ ], [ ] ] +gap> OutNeighbours(d); +[ [ 2, 3 ], [ 3 ], [ ], [ ] ] +gap> EdgeWeights(d); +[ [ 5, 10 ], [ 15 ], [ ], [ ] ] + # gap> DIGRAPHS_StopTest(); gap> STOP_TEST("Digraphs package: standard/oper.tst", 0); From 3aa73d9dfbcdfb6a8413488f3c8468dad54d1762 Mon Sep 17 00:00:00 2001 From: Devansh Chopra Date: Wed, 26 Nov 2025 12:53:04 +0000 Subject: [PATCH 6/6] Resolved comment on pr --- gap/digraph.gi | 4 ++-- gap/oper.gi | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gap/digraph.gi b/gap/digraph.gi index f44ae752f..7108e68b6 100644 --- a/gap/digraph.gi +++ b/gap/digraph.gi @@ -1870,7 +1870,7 @@ function(D, v, pos) local newD, w; newD := DigraphMutableCopy(D); - if IsBound(newD!.edgeweights) then + if HasEdgeWeights(D) then if v <= Length(newD!.edgeweights) and pos <= Length(newD!.edgeweights[v]) then Remove(newD!.edgeweights[v], pos); @@ -1878,7 +1878,7 @@ function(D, v, pos) fi; MakeImmutable(newD); - if IsBound(newD!.edgeweights) then + if HasEdgeWeights(D) then SetEdgeWeights(newD, StructuralCopy(newD!.edgeweights)); fi; diff --git a/gap/oper.gi b/gap/oper.gi index 34a1a640f..556b89359 100644 --- a/gap/oper.gi +++ b/gap/oper.gi @@ -153,7 +153,7 @@ function(D, u) DigraphRemoveVertex(newD, u); MakeImmutable(newD); - if IsBound(newD!.edgeweights) then + if HasEdgeWeights(D) then SetEdgeWeights(newD, StructuralCopy(newD!.edgeweights)); fi; @@ -274,7 +274,7 @@ function(D, src, ran) DigraphRemoveEdge(newD, src, ran); MakeImmutable(newD); - if IsBound(newD!.edgeweights) then + if HasEdgeWeights(D) then SetEdgeWeights(newD, StructuralCopy(newD!.edgeweights)); fi;