Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions doc/attr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2091,6 +2091,28 @@ gap> D;
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="DigraphRemoveAllEdges">
<ManSection>
<Oper Name="DigraphRemoveAllEdges" Arg="digraph"/>
<Attr Name="DigraphRemoveAllEdgesAttr" Arg="digraph"/>
<Returns>An empty digraph.</Returns>
<Description>
This operation returns a digraph constructed from <A>digraph</A>. If <A>digraph</A> is mutable,
its list of neighbours will be replaced with an empty 2D list of the same length.
<P/>

If <A>digraph</A> is immutable, then a new, empty immutable digraph with the same number of vertices is returned.

<Example><![CDATA[
gap> D3 := Digraph(IsMutableDigraph, [[2], [1], [2]]);
<mutable digraph with 3 vertices, 3 edges>
gap> DigraphRemoveAllEdges(D3);
<mutable empty digraph with 3 vertices>
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="DigraphAddAllLoops">
<ManSection>
<Oper Name="DigraphAddAllLoops" Arg="digraph"/>
Expand Down
23 changes: 23 additions & 0 deletions doc/oper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2291,6 +2291,29 @@ gap> HomomorphicProduct(D1, D2);
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="SwapDigraphs">
<ManSection>
<Oper Name="SwapDigraphs" Arg="D1, D2"/>
<Description>
If <A>D1</A> and <A>D2</A> are mutable digraphs,
then <C>SwapDigraphs</C> will swap the contents of
<A>D1</A> and <A>D2</A>.

<Example><![CDATA[
gap> D1 := Digraph(IsMutableDigraph, [[4], [5], [1, 2], [], []]);
<mutable digraph with 5 vertices, 4 edges>
gap> D2 := Digraph(IsMutableDigraph, [[2, 3, 4], [1, 3, 4, 5], [1, 2], [5], [4]]);
<mutable digraph with 5 vertices, 11 edges>
gap> SwapDigraphs(D1, D2);
gap> OutNeighbours(D2);
[ [ 4 ], [ 5 ], [ 1, 2 ], [ ], [ ] ]
gap> OutNeighbours(D1);
[ [ 2, 3, 4 ], [ 1, 3, 4, 5 ], [ 1, 2 ], [ 5 ], [ 4 ] ]
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="LexicographicProduct">
<ManSection>
<Oper Name="LexicographicProduct" Arg="D1, D2"/>
Expand Down
1 change: 1 addition & 0 deletions gap/attr.gd
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ DeclareAttributeThatReturnsDigraph("DigraphReverse", IsDigraph);
DeclareAttributeThatReturnsDigraph("DigraphDual", IsDigraph);
DeclareAttributeThatReturnsDigraph("ReducedDigraph", IsDigraph);
DeclareAttributeThatReturnsDigraph("DigraphRemoveAllMultipleEdges", IsDigraph);
DeclareAttributeThatReturnsDigraph("DigraphRemoveAllEdges", IsDigraph);

# TODO replace all DeclareOperations below to
# DeclareAttributeThatReturnsDigraph, and remove the *Attr versions.
Expand Down
13 changes: 13 additions & 0 deletions gap/attr.gi
Original file line number Diff line number Diff line change
Expand Up @@ -2537,6 +2537,19 @@ function(D)
return D;
end);

InstallMethodThatReturnsDigraph(DigraphRemoveAllEdges,
"for an immutable digraph",
[IsImmutableDigraph],
D -> NullDigraph(DigraphNrVertices(D)));

InstallMethodThatReturnsDigraph(DigraphRemoveAllEdges,
"for a mutable digraph",
[IsMutableDigraph],
function(D)
D!.OutNeighbours := List(DigraphVertices(D), v -> []);
return D;
end);

InstallMethod(DigraphAddAllLoops, "for a digraph", [IsDigraph],
function(D)
local C, v;
Expand Down
2 changes: 2 additions & 0 deletions gap/oper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ DeclareSynonym("DigraphLexicographicProduct", LexicographicProduct);
DeclareGlobalFunction("DIGRAPHS_CombinationOperProcessArgs");
DeclareOperation("DIGRAPHS_GraphProduct", [IsDigraph, IsDigraph, IsFunction]);

DeclareOperation("SwapDigraphs", [IsMutableDigraph, IsMutableDigraph]);

# 4. Actions . . .
DeclareOperation("OnDigraphs", [IsDigraph, IsPerm]);
DeclareOperation("OnDigraphs", [IsDigraph, IsTransformation]);
Expand Down
11 changes: 11 additions & 0 deletions gap/oper.gi
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,17 @@ function(D1, D2, edge_function)
return Digraph(edges);
end);

InstallMethod(SwapDigraphs,
"for two mutable digraphs",
[IsMutableDigraph, IsMutableDigraph],
function(D1, D2)
local nb1, nb2;
nb1 := OutNeighbours(D1);
nb2 := OutNeighbours(D2);
D1!.OutNeighbours := nb2;
D2!.OutNeighbours := nb1;
end);

###############################################################################
# 4. Actions
###############################################################################
Expand Down
16 changes: 16 additions & 0 deletions tst/standard/attr.tst
Original file line number Diff line number Diff line change
Expand Up @@ -2548,6 +2548,22 @@ true
gap> IsChainDigraph(MaximalAntiSymmetricSubdigraph(D));
true

# DigraphRemoveAllEdges: for a digraph
gap> gr := Digraph(IsImmutableDigraph, [[2, 3], [3], [4], []]);
<immutable digraph with 4 vertices, 4 edges>
gap> DigraphRemoveAllEdges(gr);
<immutable empty digraph with 4 vertices>
gap> gr2 := Digraph(IsMutableDigraph, [[2, 3], [3], [4], []]);
<mutable digraph with 4 vertices, 4 edges>
gap> DigraphRemoveAllEdges(gr2);
<mutable empty digraph with 4 vertices>
gap> gr3 := Digraph(IsMutableDigraph, [[], [], [], []]);
<mutable empty digraph with 4 vertices>
gap> DigraphRemoveAllEdges(gr3);
<mutable empty digraph with 4 vertices>
gap> OutNeighbours(gr3);
[ [ ], [ ], [ ], [ ] ]

# CharacteristicPolynomial
gap> gr := Digraph([
> [2, 2, 2], [1, 3, 6, 8, 9, 10], [4, 6, 8],
Expand Down
30 changes: 30 additions & 0 deletions tst/standard/oper.tst
Original file line number Diff line number Diff line change
Expand Up @@ -2523,6 +2523,36 @@ gap> OutNeighbours(last);
gap> LexicographicProduct(ChainDigraph(3), CycleDigraph(7));
<immutable digraph with 21 vertices, 119 edges>

# SwapDigraphs
gap> D2 := Digraph(IsMutableDigraph, [[4], [5], [1, 2], [], []]);
<mutable digraph with 5 vertices, 4 edges>
gap> D1 := Digraph(IsMutableDigraph, [[2, 3, 4], [1, 3, 4, 5], [1, 2], [5], [4]]);
<mutable digraph with 5 vertices, 11 edges>
gap> SwapDigraphs(D1, D2);
gap> OutNeighbours(D1);
[ [ 4 ], [ 5 ], [ 1, 2 ], [ ], [ ] ]
gap> OutNeighbours(D2);
[ [ 2, 3, 4 ], [ 1, 3, 4, 5 ], [ 1, 2 ], [ 5 ], [ 4 ] ]
gap> D3 := Digraph(IsMutableDigraph, [[2], [1], [2]]);
<mutable digraph with 3 vertices, 3 edges>
gap> SwapDigraphs(D1, D3);
gap> OutNeighbours(D1);
[ [ 2 ], [ 1 ], [ 2 ] ]
gap> OutNeighbours(D3);
[ [ 4 ], [ 5 ], [ 1, 2 ], [ ], [ ] ]
gap> SwapDigraphs(D1, D3);
gap> OutNeighbours(D1);
[ [ 4 ], [ 5 ], [ 1, 2 ], [ ], [ ] ]
gap> OutNeighbours(D3);
[ [ 2 ], [ 1 ], [ 2 ] ]
gap> D2 := Digraph(IsMutableDigraph, [[], [], []]);
<mutable empty digraph with 3 vertices>
gap> SwapDigraphs(D3, D2);
gap> OutNeighbours(D2);
[ [ 2 ], [ 1 ], [ 2 ] ]
gap> OutNeighbours(D3);
[ [ ], [ ], [ ] ]

# DigraphShortestPathSpanningTree
gap> D := Digraph([[2, 3, 4], [1, 3, 4, 5], [1, 2], [5], [4]]);
<immutable digraph with 5 vertices, 11 edges>
Expand Down
14 changes: 14 additions & 0 deletions tst/testinstall.tst
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ gap> DigraphNrEdges(gr2);
gap> DigraphNrAdjacencies(gr2);
21

# DigraphRemoveAllEdges
gap> gr := Digraph(IsMutableDigraph, [[3], [4], [5], [1, 5], [1, 2]]);;
gap> DigraphRemoveAllEdges(gr);
<mutable empty digraph with 5 vertices>

# Fix seg fault cause by wrong handling of no edges in
# FuncDIGRAPH_SOURCE_RANGE
gap> gr := Digraph([[]]);
Expand Down Expand Up @@ -536,6 +541,15 @@ gap> AutomorphismGroup(D)
> = Group([(1, 2, 3), (1, 2), (4, 5, 6), (4, 5), (1, 4)(2, 5)(3, 6)]);
true

# SwapDigraphs
gap> C := Digraph(IsMutableDigraph, [[4], [5], [1, 2], [], []]);;
gap> D := Digraph(IsMutableDigraph, [[2, 3, 4], [1, 3, 4, 5], [1, 2], [5], [4]]);;
gap> SwapDigraphs(C, D);
gap> OutNeighbours(D);
[ [ 4 ], [ 5 ], [ 1, 2 ], [ ], [ ] ]
gap> OutNeighbours(C);
[ [ 2, 3, 4 ], [ 1, 3, 4, 5 ], [ 1, 2 ], [ 5 ], [ 4 ] ]

#
gap> DIGRAPHS_StopTest();
gap> STOP_TEST("Digraphs package: testinstall.tst", 0);
Loading