Skip to content

Commit 3658703

Browse files
committed
Changes made to SwapDigraphs and DigraphRemoveAllEdges
1 parent 5f01400 commit 3658703

File tree

8 files changed

+65
-134
lines changed

8 files changed

+65
-134
lines changed

doc/attr.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,6 +2091,30 @@ gap> D;
20912091
</ManSection>
20922092
<#/GAPDoc>
20932093

2094+
<#GAPDoc Label="DigraphRemoveAllEdges">
2095+
<ManSection>
2096+
<Oper Name="DigraphRemoveAllEdges" Arg="digraph"/>
2097+
<Attr Name="DigraphRemoveAllEdgesAttr" Arg="digraph"/>
2098+
<Returns>An empty digraph.</Returns>
2099+
<Description>
2100+
This operation returns a digraph constructed from <A>digraph</A>, which is mutable,
2101+
by removing all of the edges in the original digraph
2102+
(see <Ref Oper="DigraphRemoveEdge" Label="for a digraph and an edge"/>).
2103+
<P/>
2104+
2105+
If <A>digraph</A> is immutable, then a new, empty immutable digraph with the same number of vertices is returned.
2106+
2107+
<Example><![CDATA[
2108+
gap> D3 := Digraph(IsMutableDigraph, [[2], [1], [2]]);
2109+
<mutable digraph with 3 vertices, 3 edges>
2110+
gap> DigraphRemoveAllEdges(D3);
2111+
<mutable empty digraph with 3 vertices>
2112+
true
2113+
]]></Example>
2114+
</Description>
2115+
</ManSection>
2116+
<#/GAPDoc>
2117+
20942118
<#GAPDoc Label="DigraphAddAllLoops">
20952119
<ManSection>
20962120
<Oper Name="DigraphAddAllLoops" Arg="digraph"/>

doc/oper.xml

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -733,27 +733,6 @@ true
733733
</ManSection>
734734
<#/GAPDoc>
735735

736-
<#GAPDoc Label="DigraphRemoveAllEdges">
737-
<ManSection>
738-
<Oper Name="DigraphRemoveAllEdges" Arg="digraph"/>
739-
<Returns>An empty digraph.</Returns>
740-
<Description>
741-
This operation returns a digraph constructed from <A>digraph</A>, which is mutable,
742-
by removing all of the edges in the original digraph.
743-
(see <Ref Oper="DigraphRemoveEdge" Label="for a digraph and an edge"/>).
744-
<P/>
745-
746-
<Example><![CDATA[
747-
gap> D3 := Digraph(IsMutableDigraph, [[2], [1], [2]]);
748-
<mutable digraph with 3 vertices, 3 edges>
749-
gap> DigraphRemoveAllEdges(D3);
750-
<mutable empty digraph with 3 vertices>
751-
true
752-
]]></Example>
753-
</Description>
754-
</ManSection>
755-
<#/GAPDoc>
756-
757736
<#GAPDoc Label="InducedSubdigraph">
758737
<ManSection>
759738
<Oper Name="InducedSubdigraph" Arg="digraph, verts"/>
@@ -2273,46 +2252,6 @@ gap> ConormalProduct(NullDigraph(0), CompleteDigraph(10));
22732252
</ManSection>
22742253
<#/GAPDoc>
22752254

2276-
<#GAPDoc Label="HomomorphicProduct">
2277-
<ManSection>
2278-
<Oper Name="HomomorphicProduct" Arg="D1, D2"/>
2279-
<Returns>A digraph.</Returns>
2280-
<Description>
2281-
If <A>D1</A> and <A>D2</A> are digraphs without multiple edges,
2282-
then <C>HomomorphicProduct</C> calculates the <E>homomorphic product digraph</E>
2283-
(<C>HPD</C>) of <A>D1</A> and <A>D2</A>.
2284-
2285-
<C>HPD</C> has vertex set <C>V1 x V2</C> where <C>V1</C> is the vertex set of
2286-
<A>D1</A> and <C>V2</C> is the vertex set of <A>D2</A> (a vertex
2287-
<C>[a, b]</C> has label <C>(a - 1) * |V2| + b</C> in the output). There is
2288-
an edge from <C>[a, b]</C> to <C>[c, d]</C> when at least one of the
2289-
following two conditions are satisfied:
2290-
<List>
2291-
<Item>
2292-
The vertices <C>a</C> and <C>c</C> of <A>D1</A> are equal.
2293-
</Item>
2294-
<Item>
2295-
There is an edge from <C>a</C> to <C>c</C> in <A>D1</A> and no edge from
2296-
<C>b</C> to <C>d</C> in <A>D2</A>.
2297-
</Item>
2298-
</List>
2299-
2300-
<Example><![CDATA[
2301-
gap> HomomorphicProduct(PetersenGraph(),
2302-
> DigraphSymmetricClosure(ChainDigraph(4)));
2303-
<immutable digraph with 40 vertices, 460 edges>
2304-
gap> D1 := Digraph([[2], [1, 3, 4], [2, 5], [2, 5], [3, 4]]);
2305-
<immutable digraph with 5 vertices, 10 edges>
2306-
gap> D2 := Digraph([[2], [1, 3], [2, 4], [3]]);
2307-
<immutable digraph with 4 vertices, 6 edges>
2308-
gap> HomomorphicProduct(D1, D2);
2309-
<immutable digraph with 20 vertices, 180 edges>
2310-
]]></Example>
2311-
</Description>
2312-
</ManSection>
2313-
<#/GAPDoc>
2314-
2315-
23162255
<#GAPDoc Label="HomomorphicProduct">
23172256
<ManSection>
23182257
<Oper Name="HomomorphicProduct" Arg="D1, D2"/>

gap/attr.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ DeclareAttributeThatReturnsDigraph("DigraphReverse", IsDigraph);
8989
DeclareAttributeThatReturnsDigraph("DigraphDual", IsDigraph);
9090
DeclareAttributeThatReturnsDigraph("ReducedDigraph", IsDigraph);
9191
DeclareAttributeThatReturnsDigraph("DigraphRemoveAllMultipleEdges", IsDigraph);
92+
DeclareAttributeThatReturnsDigraph("DigraphRemoveAllEdges", IsDigraph);
9293

9394
# TODO replace all DeclareOperations below to
9495
# DeclareAttributeThatReturnsDigraph, and remove the *Attr versions.

gap/attr.gi

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,6 +2537,26 @@ function(D)
25372537
return D;
25382538
end);
25392539

2540+
InstallMethodThatReturnsDigraph(DigraphRemoveAllEdges, "for a digraph",
2541+
[IsDigraph],
2542+
function(D)
2543+
local i, nbs, currentEdges, emptynbs;
2544+
nbs := OutNeighboursMutableCopy(D);
2545+
if IsImmutableDigraph(D) then
2546+
emptynbs := [];
2547+
for i in [1 .. Length(nbs)] do
2548+
Add(emptynbs, []);
2549+
od;
2550+
return Digraph(IsImmutableDigraph, emptynbs);
2551+
else
2552+
for i in [1 .. Length(nbs)] do
2553+
currentEdges := DigraphOutEdges(D, i);
2554+
DigraphRemoveEdges(D, currentEdges);
2555+
od;
2556+
return D;
2557+
fi;
2558+
end);
2559+
25402560
InstallMethod(DigraphAddAllLoops, "for a digraph", [IsDigraph],
25412561
function(D)
25422562
local C, v;

gap/oper.gd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ DeclareOperation("DigraphRemoveEdge", [IsDigraph, IsPosInt, IsPosInt]);
2929
DeclareOperation("DigraphRemoveEdge", [IsDigraph, IsList]);
3030
DeclareOperation("DigraphRemoveEdges", [IsDigraph, IsList]);
3131

32-
DeclareOperation("DigraphRemoveAllEdges", [IsDigraph]);
33-
3432
DeclareOperation("DigraphReverseEdge", [IsDigraph, IsList]);
3533
DeclareOperation("DigraphReverseEdge", [IsDigraph, IsPosInt, IsPosInt]);
3634
DeclareOperation("DigraphReverseEdges", [IsDigraph, IsList]);

gap/oper.gi

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -277,23 +277,6 @@ InstallMethod(DigraphRemoveEdges, "for an immutable digraph and a list",
277277
[IsImmutableDigraph, IsList],
278278
{D, edges} -> MakeImmutable(DigraphRemoveEdges(DigraphMutableCopy(D), edges)));
279279

280-
InstallMethod(DigraphRemoveAllEdges, "for a mutable digraph",
281-
[IsDigraph],
282-
function(D)
283-
local i, nbs, currentEdges;
284-
if IsImmutableDigraph(D) then
285-
ErrorNoReturn("Argument must be a mutable digraph");
286-
else
287-
nbs := OutNeighboursMutableCopy(D);
288-
for i in [1 .. Length(nbs)] do
289-
currentEdges := DigraphOutEdges(D, i);
290-
DigraphRemoveEdges(D, currentEdges);
291-
od;
292-
293-
return D;
294-
fi;
295-
end);
296-
297280
InstallMethod(DigraphReverseEdge,
298281
"for a mutable digraph by out-neighbours and two positive integers",
299282
[IsMutableDigraph and IsDigraphByOutNeighboursRep, IsPosInt, IsPosInt],
@@ -1008,43 +991,13 @@ end);
1008991

1009992
InstallMethod(SwapDigraphs,
1010993
"for a digraph and digraph",
1011-
[IsDigraph, IsDigraph],
994+
[IsMutableDigraph, IsMutableDigraph],
1012995
function(D1, D2)
1013-
local nb1, nb2, i;
1014-
1015-
if IsMutableDigraph(D1) and IsMutableDigraph(D2) then
996+
local nb1, nb2;
1016997
nb1 := OutNeighboursMutableCopy(D1);
1017998
nb2 := OutNeighboursMutableCopy(D2);
1018-
DigraphRemoveAllEdges(D1);
1019-
DigraphRemoveAllEdges(D2);
1020-
1021-
# If the second digraph has more vertices than the first
1022-
if Length(nb2) < Length(nb1) then
1023-
for i in [Length(nb2) .. Length(nb1) - 1] do
1024-
DigraphRemoveVertex(D1, Length(nb2) + 1);
1025-
DigraphAddVertex(D2);
1026-
od;
1027-
else
1028-
for i in [Length(nb1) .. Length(nb2) - 1] do
1029-
DigraphRemoveVertex(D2, Length(nb1) + 1);
1030-
DigraphAddVertex(D1);
1031-
od;
1032-
fi;
1033-
1034-
for i in [1 .. Length(nb2)] do
1035-
for neighbour in nb2[i] do
1036-
DigraphAddEdge(D1, i, neighbour);
1037-
od;
1038-
od;
1039-
1040-
for i in [1 .. Length(nb1)] do
1041-
for neighbour in nb1[i] do
1042-
DigraphAddEdge(D2, i, neighbour);
1043-
od;
1044-
od;
1045-
else
1046-
ErrorNoReturn("Arguments must be mutable digraphs");
1047-
fi;
999+
D1!.OutNeighbours := nb2;
1000+
D2!.OutNeighbours := nb1;
10481001
end);
10491002

10501003
###############################################################################

tst/standard/attr.tst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,6 +2548,22 @@ true
25482548
gap> IsChainDigraph(MaximalAntiSymmetricSubdigraph(D));
25492549
true
25502550

2551+
# DigraphRemoveAllEdges: for a digraph
2552+
gap> gr := Digraph(IsImmutableDigraph, [[2, 3], [3], [4], []]);
2553+
<immutable digraph with 4 vertices, 4 edges>
2554+
gap> DigraphRemoveAllEdges(gr);
2555+
<immutable empty digraph with 4 vertices>
2556+
gap> gr2 := Digraph(IsMutableDigraph, [[2, 3], [3], [4], []]);
2557+
<mutable digraph with 4 vertices, 4 edges>
2558+
gap> DigraphRemoveAllEdges(gr2);
2559+
<mutable empty digraph with 4 vertices>
2560+
gap> gr3 := Digraph(IsMutableDigraph, [[], [], [], []]);
2561+
<mutable empty digraph with 4 vertices>
2562+
gap> DigraphRemoveAllEdges(gr3);
2563+
<mutable empty digraph with 4 vertices>
2564+
gap> OutNeighbours(gr3);
2565+
[ [ ], [ ], [ ], [ ] ]
2566+
25512567
# CharacteristicPolynomial
25522568
gap> gr := Digraph([
25532569
> [2, 2, 2], [1, 3, 6, 8, 9, 10], [4, 6, 8],

tst/standard/oper.tst

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,6 @@ gap> gr := DigraphRemoveEdge(gr, [2, 1]);
109109
gap> DigraphEdges(gr);
110110
[ [ 1, 2 ] ]
111111

112-
# DigraphRemoveAllEdges: for a digraph
113-
gap> gr := Digraph(IsImmutableDigraph, [[2, 3], [3], [4], []]);
114-
<immutable digraph with 4 vertices, 4 edges>
115-
gap> DigraphRemoveAllEdges(gr);
116-
Error, Argument must be a mutable digraph
117-
gap> gr2 := Digraph(IsMutableDigraph, [[2, 3], [3], [4], []]);
118-
<mutable digraph with 4 vertices, 4 edges>
119-
gap> DigraphRemoveAllEdges(gr2);
120-
<mutable empty digraph with 4 vertices>
121-
gap> gr3 := Digraph(IsMutableDigraph, [[], [], [], []]);
122-
<mutable empty digraph with 4 vertices>
123-
gap> DigraphRemoveAllEdges(gr3);
124-
<mutable empty digraph with 4 vertices>
125-
gap> OutNeighbours(gr3);
126-
[ [ ], [ ], [ ], [ ] ]
127-
128112
# OnDigraphs: for a digraph and a perm
129113
gap> gr := Digraph([[2], [1], [3]]);
130114
<immutable digraph with 3 vertices, 3 edges>
@@ -2540,12 +2524,8 @@ gap> LexicographicProduct(ChainDigraph(3), CycleDigraph(7));
25402524
<immutable digraph with 21 vertices, 119 edges>
25412525

25422526
# SwapDigraphs
2543-
gap> D1 := Digraph([[2, 3, 4], [1, 3, 4, 5], [1, 2], [5], [4]]);
2544-
<immutable digraph with 5 vertices, 11 edges>
25452527
gap> D2 := Digraph(IsMutableDigraph, [[4], [5], [1, 2], [], []]);
25462528
<mutable digraph with 5 vertices, 4 edges>
2547-
gap> SwapDigraphs(D1, D2);
2548-
Error, Arguments must be mutable digraphs
25492529
gap> D1 := Digraph(IsMutableDigraph, [[2, 3, 4], [1, 3, 4, 5], [1, 2], [5], [4]]);
25502530
<mutable digraph with 5 vertices, 11 edges>
25512531
gap> SwapDigraphs(D1, D2);

0 commit comments

Comments
 (0)