Skip to content

Commit 5d719e8

Browse files
wilfwilsonjames-d-mitchell
authored andcommitted
prop.gi: small improvements to IsSymmetricDigraph
1 parent 059cee2 commit 5d719e8

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

gap/prop.gi

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ InstallMethod(IsSymmetricDigraph, "for a digraph by out-neighbours",
199199
function(D)
200200
local out, inn, new, i;
201201

202+
if not IsMultiDigraph(D)
203+
and (DigraphNrEdges(D) - Length(DigraphLoops(D))) mod 2 = 1 then
204+
return false;
205+
elif HasAdjacencyMatrix(D) then
206+
TryNextMethod();
207+
fi;
208+
202209
out := OutNeighbours(D);
203210
inn := InNeighbours(D);
204211
if not ForAll(out, IsSortedList) then
@@ -211,6 +218,22 @@ function(D)
211218
return inn = out;
212219
end);
213220

221+
InstallMethod(IsSymmetricDigraph, "for a digraph with adjacency matrix",
222+
[IsDigraph and HasAdjacencyMatrix],
223+
function(D)
224+
local mat, n, i, j;
225+
mat := AdjacencyMatrix(D);
226+
n := DigraphNrVertices(D);
227+
for i in [1 .. n - 1] do
228+
for j in [i + 1 .. n] do
229+
if mat[i][j] <> mat[j][i] then
230+
return false;
231+
fi;
232+
od;
233+
od;
234+
return true;
235+
end);
236+
214237
# Functional: for every vertex v there is exactly one edge with source v
215238

216239
InstallMethod(IsFunctionalDigraph, "for a digraph by out-neighbours",

tst/standard/prop.tst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,30 @@ gap> gr := Digraph(rec(DigraphNrVertices := 3, DigraphSource := [1, 1, 2, 2, 2,
238238
> DigraphRange := [2, 2, 1, 1, 3, 3, 2, 2]));;
239239
gap> IsSymmetricDigraph(gr);
240240
true
241+
gap> D := Digraph([[2], [3], [2]]);;
242+
gap> IsSymmetricDigraph(D);
243+
false
244+
gap> D := Digraph([[2], [2], [2]]);;
245+
gap> IsSymmetricDigraph(D);
246+
false
247+
gap> D := Digraph([[2], [2], [1]]);;
248+
gap> IsSymmetricDigraph(D);
249+
false
250+
gap> D := CycleDigraph(3);;
251+
gap> AdjacencyMatrix(D);;
252+
gap> IsSymmetricDigraph(D);
253+
false
254+
gap> D := Digraph([[2, 3], [1, 2, 3], [1, 2]]);;
255+
gap> AdjacencyMatrix(D);;
256+
gap> IsSymmetricDigraph(D);
257+
true
258+
gap> D := Digraph([[2], [2], [2]]);;
259+
gap> AdjacencyMatrix(D);;
260+
gap> IsSymmetricDigraph(D);
261+
false
262+
gap> D := Digraph([[2], [2], [2, 1]]);;
263+
gap> IsSymmetricDigraph(D);
264+
false
241265

242266
# IsAntisymmetricDigraph
243267
gap> gr := Digraph(rec(DigraphNrVertices := 10,

0 commit comments

Comments
 (0)