Skip to content

Commit b76171d

Browse files
committed
Merge branch 'bellmanford' of https://github.com/baydrea/Digraphs into bellmanford
2 parents 07a5cd7 + 6da9d7a commit b76171d

File tree

17 files changed

+510
-22
lines changed

17 files changed

+510
-22
lines changed

doc/oper.xml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,56 @@ gap> OutNeighbours(D2);
257257
</ManSection>
258258
<#/GAPDoc>
259259

260+
<#GAPDoc Label="OnTuplesDigraphs">
261+
<ManSection>
262+
<Oper Name="OnTuplesDigraphs" Arg="list, perm"
263+
Label="for a list of digraphs and a perm"/>
264+
<Oper Name="OnSetsDigraphs" Arg="list, perm"
265+
Label="for a set of digraphs and a perm"/>
266+
<Returns>A list or set of digraphs.</Returns>
267+
<Description>
268+
If <A>list</A> is a list of digraphs, and <A>perm</A> is a
269+
<E>permutation</E> of the vertices of the digraphs in <A>list</A>, then
270+
<Ref Oper="OnTuplesDigraphs" Label="for a list of digraphs and a perm"/>
271+
returns a new list constructed by applying <A>perm</A> via
272+
<Ref Oper="OnDigraphs" Label="for a digraph and a perm"/>
273+
to a copy (with the same mutability) of each entry of <A>list</A> in turn.
274+
<P/>
275+
276+
More precisely, <C>OnTuplesDigraphs(<A>list</A>,<A>perm</A>)</C> is a list
277+
of length <C>Length(<A>list</A>)</C>, whose <C>i</C>-th entry is
278+
<C>OnDigraphs(DigraphCopy(<A>list</A>[i]), <A>perm</A>)</C>.
279+
<P/>
280+
281+
If <A>list</A> is moreover a &GAP; set (i.e. a duplicate-free sorted list),
282+
then <Ref Oper="OnSetsDigraphs" Label="for a set of digraphs and a perm"/>
283+
returns the sorted output of
284+
<Ref Oper="OnTuplesDigraphs" Label="for a list of digraphs and a perm"/>,
285+
which is therefore again a set.
286+
<Example><![CDATA[
287+
gap> list := [CycleDigraph(IsMutableDigraph, 6),
288+
> DigraphReverse(CycleDigraph(6))];
289+
[ <mutable digraph with 6 vertices, 6 edges>,
290+
<immutable digraph with 6 vertices, 6 edges> ]
291+
gap> p := (1, 6)(2, 5)(3, 4);;
292+
gap> result_tuples := OnTuplesDigraphs(list, p);
293+
[ <mutable digraph with 6 vertices, 6 edges>,
294+
<immutable digraph with 6 vertices, 6 edges> ]
295+
gap> result_tuples[2] = OnDigraphs(list[2], p);
296+
true
297+
gap> result_tuples = list;
298+
false
299+
gap> result_tuples = Reversed(list);
300+
true
301+
gap> result_sets := OnSetsDigraphs(list, p);
302+
[ <immutable digraph with 6 vertices, 6 edges>,
303+
<mutable digraph with 6 vertices, 6 edges> ]
304+
gap> result_sets = list;
305+
true]]></Example>
306+
</Description>
307+
</ManSection>
308+
<#/GAPDoc>
309+
260310
<#GAPDoc Label="DigraphAddVertex">
261311
<ManSection>
262312
<Oper Name="DigraphAddVertex" Arg="digraph[, label ]"/>

doc/prop.xml

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,8 @@ false
717717
<K>false</K> if it is not. A digraph is <E>empty</E> if it has no
718718
edges.<P/>
719719

720-
<C>IsNullDigraph</C> is a synonym for <C>IsEmptyDigraph</C>.
720+
<Ref Prop="IsNullDigraph"/> is a synonym for <Ref Prop="IsEmptyDigraph"/>.
721+
See also <Ref Prop="IsNonemptyDigraph"/>.
721722
<P/>
722723

723724
&MUTABLE_RECOMPUTED_PROP;
@@ -739,6 +740,93 @@ false]]></Example>
739740
</ManSection>
740741
<#/GAPDoc>
741742

743+
<#GAPDoc Label="IsNonemptyDigraph">
744+
<ManSection>
745+
<Prop Name="IsNonemptyDigraph" Arg="digraph"/>
746+
<Returns><K>true</K> or <K>false</K>.</Returns>
747+
<Description>
748+
Returns <K>true</K> if the digraph <A>digraph</A> is nonempty, and
749+
<K>false</K> if it is not. A digraph is <E>nonempty</E> if it has at
750+
least one edge.<P/>
751+
752+
See also <Ref Prop="IsEmptyDigraph"/>.
753+
<P/>
754+
755+
&MUTABLE_RECOMPUTED_PROP;
756+
757+
<Example><![CDATA[
758+
gap> D := Digraph([[], []]);
759+
<immutable empty digraph with 2 vertices>
760+
gap> IsNonemptyDigraph(D);
761+
false
762+
gap> D := Digraph([[], [1]]);
763+
<immutable digraph with 2 vertices, 1 edge>
764+
gap> IsNonemptyDigraph(D);
765+
true]]></Example>
766+
</Description>
767+
</ManSection>
768+
<#/GAPDoc>
769+
770+
<#GAPDoc Label="DigraphHasAVertex">
771+
<ManSection>
772+
<Prop Name="DigraphHasAVertex" Arg="digraph"/>
773+
<Returns><K>true</K> or <K>false</K>.</Returns>
774+
<Description>
775+
Returns <K>true</K> if the digraph <A>digraph</A> has at least one vertex,
776+
and <K>false</K> if it does not.<P/>
777+
778+
See also <Ref Prop="DigraphHasNoVertices"/>.
779+
<P/>
780+
781+
&MUTABLE_RECOMPUTED_PROP;
782+
783+
<Example><![CDATA[
784+
gap> D := Digraph([]);
785+
<immutable empty digraph with 0 vertices>
786+
gap> DigraphHasAVertex(D);
787+
false
788+
gap> D := Digraph([[]]);
789+
<immutable empty digraph with 1 vertex>
790+
gap> DigraphHasAVertex(D);
791+
true
792+
gap> D := Digraph([[], [1]]);
793+
<immutable digraph with 2 vertices, 1 edge>
794+
gap> DigraphHasAVertex(D);
795+
true]]></Example>
796+
</Description>
797+
</ManSection>
798+
<#/GAPDoc>
799+
800+
<#GAPDoc Label="DigraphHasNoVertices">
801+
<ManSection>
802+
<Prop Name="DigraphHasNoVertices" Arg="digraph"/>
803+
<Returns><K>true</K> or <K>false</K>.</Returns>
804+
<Description>
805+
Returns <K>true</K> if the digraph <A>digraph</A> is the unique digraph
806+
with zero vertices, and <K>false</K> otherwise.<P/>
807+
808+
See also <Ref Prop="DigraphHasAVertex"/>.
809+
<P/>
810+
811+
&MUTABLE_RECOMPUTED_PROP;
812+
813+
<Example><![CDATA[
814+
gap> D := Digraph([]);
815+
<immutable empty digraph with 0 vertices>
816+
gap> DigraphHasNoVertices(D);
817+
true
818+
gap> D := Digraph([[]]);
819+
<immutable empty digraph with 1 vertex>
820+
gap> DigraphHasNoVertices(D);
821+
false
822+
gap> D := Digraph([[], [1]]);
823+
<immutable digraph with 2 vertices, 1 edge>
824+
gap> DigraphHasNoVertices(D);
825+
false]]></Example>
826+
</Description>
827+
</ManSection>
828+
<#/GAPDoc>
829+
742830
<#GAPDoc Label="IsEulerianDigraph">
743831
<ManSection>
744832
<Prop Name="IsEulerianDigraph" Arg="digraph"/>

doc/z-chap5.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<Chapter Label="Properties of digraphs"><Heading>Properties of digraphs</Heading>
22

3+
<Section><Heading>Vertex properties</Heading>
4+
<#Include Label="DigraphHasAVertex">
5+
<#Include Label="DigraphHasNoVertices">
6+
</Section>
7+
38
<Section><Heading>Edge properties</Heading>
49
<#Include Label="DigraphHasLoops">
510
<#Include Label="IsAntisymmetricDigraph">
@@ -12,6 +17,7 @@
1217
<#Include Label="IsFunctionalDigraph">
1318
<#Include Label="IsPermutationDigraph">
1419
<#Include Label="IsMultiDigraph">
20+
<#Include Label="IsNonemptyDigraph">
1521
<#Include Label="IsReflexiveDigraph">
1622
<#Include Label="IsSymmetricDigraph">
1723
<#Include Label="IsTournament">

doc/z-chap6.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ from} $E_a$ \emph{to} $E_b$. In this case we say that $E_a$ and $E_b$ are
1111
<Section><Heading>Acting on digraphs</Heading>
1212
<#Include Label="OnDigraphs">
1313
<#Include Label="OnMultiDigraphs">
14+
<#Include Label="OnTuplesDigraphs">
1415
</Section>
1516

1617
<Section Label="Isomorphisms and canonical labellings">

gap/attr.gi

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ function(D)
11281128
# alter the answer for the diameter/girth if necessary. This function is
11291129
# called, if appropriate, by DigraphDiameter and DigraphUndirectedGirth.
11301130

1131-
if DigraphNrVertices(D) = 0 and IsImmutableDigraph(D) then
1131+
if DigraphHasNoVertices(D) and IsImmutableDigraph(D) then
11321132
SetDigraphDiameter(D, fail);
11331133
SetDigraphUndirectedGirth(D, infinity);
11341134
return rec(diameter := fail, girth := infinity);
@@ -1539,10 +1539,10 @@ end);
15391539

15401540
InstallMethod(DegreeMatrix, "for a digraph", [IsDigraph],
15411541
function(D)
1542-
if DigraphNrVertices(D) = 0 then
1543-
return [];
1542+
if DigraphHasAVertex(D) then
1543+
return DiagonalMat(OutDegrees(D));
15441544
fi;
1545-
return DiagonalMat(OutDegrees(D));
1545+
return [];
15461546
end);
15471547

15481548
InstallMethod(LaplacianMatrix, "for a digraph", [IsDigraph],
@@ -1863,7 +1863,7 @@ function(D)
18631863
SetDigraphAddAllLoopsAttr(D, C);
18641864
SetIsReflexiveDigraph(C, true);
18651865
SetIsMultiDigraph(C, ismulti);
1866-
SetDigraphHasLoops(C, DigraphNrVertices(C) > 0);
1866+
SetDigraphHasLoops(C, DigraphHasAVertex(C));
18671867
fi;
18681868
return C;
18691869
end);
@@ -2312,7 +2312,7 @@ InstallMethod(UndirectedSpanningForest, "for a digraph by out-neighbours",
23122312
[IsDigraphByOutNeighboursRep],
23132313
function(D)
23142314
local C;
2315-
if DigraphNrVertices(D) = 0 then
2315+
if DigraphHasNoVertices(D) then
23162316
return fail;
23172317
fi;
23182318
C := MaximalSymmetricSubdigraph(D)!.OutNeighbours;
@@ -2341,9 +2341,9 @@ InstallMethod(UndirectedSpanningForestAttr, "for an immutable digraph",
23412341
InstallMethod(UndirectedSpanningTree, "for a mutable digraph",
23422342
[IsMutableDigraph],
23432343
function(D)
2344-
if DigraphNrVertices(D) = 0
2345-
or not IsStronglyConnectedDigraph(D)
2346-
or not IsConnectedDigraph(UndirectedSpanningForest(DigraphMutableCopy(D)))
2344+
if not (DigraphHasAVertex(D)
2345+
and IsStronglyConnectedDigraph(D)
2346+
and IsConnectedDigraph(UndirectedSpanningForest(DigraphMutableCopy(D))))
23472347
then
23482348
return fail;
23492349
fi;
@@ -2357,7 +2357,7 @@ InstallMethod(UndirectedSpanningTreeAttr, "for an immutable digraph",
23572357
[IsImmutableDigraph],
23582358
function(D)
23592359
local out;
2360-
if DigraphNrVertices(D) = 0
2360+
if DigraphHasNoVertices(D)
23612361
or not IsStronglyConnectedDigraph(D)
23622362
or (HasMaximalSymmetricSubdigraphAttr(D)
23632363
and not IsStronglyConnectedDigraph(MaximalSymmetricSubdigraph(D)))

gap/digraph.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ DeclareCategory("IsDigraphWithAdjacencyFunction", IsDigraph);
1414
DeclareCategory("IsCayleyDigraph", IsDigraph);
1515
DeclareCategory("IsImmutableDigraph", IsDigraph);
1616
DeclareSynonym("IsMutableDigraph", IsDigraph and IsMutable);
17+
DeclareCategoryCollections("IsDigraph");
1718

1819
DeclareAttribute("DigraphMutabilityFilter", IsDigraph);
1920

gap/digraph.gi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ p -> AsDigraph(AsTransformation(p)));
10651065
InstallMethod(AsBinaryRelation, "for a digraph", [IsDigraphByOutNeighboursRep],
10661066
function(D)
10671067
local rel;
1068-
if DigraphNrVertices(D) = 0 then
1068+
if DigraphHasNoVertices(D) then
10691069
ErrorNoReturn("the argument <D> must be a digraph with at least 1 ",
10701070
"vertex,");
10711071
elif IsMultiDigraph(D) then

gap/grahom.gi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ function(D, n)
107107
fi;
108108
fi;
109109

110-
# Only the null D with 0 vertices can be coloured with 0 colours
110+
# Only the null digraph with 0 vertices can be coloured with 0 colours
111111
if n = 0 then
112-
if DigraphNrVertices(D) = 0 then
112+
if DigraphHasNoVertices(D) then
113113
return IdentityTransformation;
114114
fi;
115115
return fail;

gap/isomorph.gi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ if DIGRAPHS_NautyAvailable then
142142
colors);
143143
colors := NautyColorData(colors);
144144
fi;
145-
if DigraphNrVertices(D) = 0 then
145+
if DigraphHasNoVertices(D) then
146146
# This circumvents Issue #17 in NautyTracesInterface, whereby a graph
147147
# with 0 vertices causes a seg fault.
148148
return [Group(()), ()];

gap/oper.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ DeclareOperation("DIGRAPHS_GraphProduct", [IsDigraph, IsDigraph, IsFunction]);
5959
# 4. Actions . . .
6060
DeclareOperation("OnDigraphs", [IsDigraph, IsPerm]);
6161
DeclareOperation("OnDigraphs", [IsDigraph, IsTransformation]);
62+
DeclareOperation("OnTuplesDigraphs", [IsDigraphCollection, IsPerm]);
63+
DeclareOperation("OnSetsDigraphs", [IsDigraphCollection, IsPerm]);
6264
DeclareOperation("OnMultiDigraphs", [IsDigraph, IsPermCollection]);
6365
DeclareOperation("OnMultiDigraphs", [IsDigraph, IsPerm, IsPerm]);
6466

0 commit comments

Comments
 (0)