Skip to content

Commit f10e594

Browse files
committed
Merge branch 'amalgamDigraphs' of github.com:finnbuck/Digraphs into amalgamDigraphs
2 parents 781dcb9 + 53716a0 commit f10e594

15 files changed

+144
-32
lines changed

.VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.0
1+
1.5.2

CHANGELOG.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11
# CHANGELOG – Digraphs package for GAP
2-
Copyright © 2014-21 by Jan De Beule, Julius Jonušas, James D. Mitchell,
2+
Copyright © 2014-22 by Jan De Beule, Julius Jonušas, James D. Mitchell,
33
Wilf A. Wilson, Michael Young et al.
44

55
Licensing information can be found in the `LICENSE` file.
66

7+
## Version 1.5.2 (released 30/03/2022)
8+
9+
This is a very minor release containing technical changes for maintaining compatibility with other GAP packages.
10+
11+
## Version 1.5.1 (released 29/03/2022)
12+
13+
This minor release contains several bugfixes and technical changes. This includes:
14+
15+
* Bugfix: vertex labels are no longer wrongly retained when using `DigraphEdgeUnion`. This was reported by [Wilf A. Wilson][] in [Issue #496](https://github.com/digraphs/Digraphs/issues/496) and fixed by Joseph Edwards in [PR #507](https://github.com/digraphs/Digraphs/pull/507).
16+
* Bugfix: a segfault could be caused by calling `OutNeighbours` with an inappropriate argument. This was reported by [Wilf A. Wilson][] in [Issue #518](https://github.com/digraphs/Digraphs/issues/518) and fixed by [James D. Mitchell][] in [PR #519](https://github.com/digraphs/Digraphs/pull/519).
17+
* [Wilf A. Wilson][] improved the performance of `DigraphAddEdge` for digraphs without edge labels in [PR #509](https://github.com/digraphs/Digraphs/pull/509).
18+
* [Max Horn][] changed the declaration of the variable `Vertices` to improve compatibility with Grape in [PR #530](https://github.com/digraphs/Digraphs/pull/530).
19+
720
## Version 1.5.0 (released 27/10/2021)
821

922
This is a fairly major release of the Digraphs package, containing some bugfixes and several new features.

PackageInfo.g

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
#############################################################################
22
##
33
## PackageInfo.g
4-
## Copyright (C) 2015-21 James D. Mitchell
4+
## Copyright (C) 2015-22 James D. Mitchell
55
##
66
## Licensing information can be found in the README.md file of this package.
77
##
88
#############################################################################
99
##
1010

1111
## <#GAPDoc Label="PKGVERSIONDATA">
12-
## <!ENTITY VERSION "1.5.0">
12+
## <!ENTITY VERSION "1.5.2">
1313
## <!ENTITY GAPVERS "4.10.0">
1414
## <!ENTITY GRAPEVERS "4.8.1">
1515
## <!ENTITY IOVERS "4.5.1">
1616
## <!ENTITY ORBVERS "4.8.2">
1717
## <!ENTITY DATASTRUCTURESVERS "0.2.5">
1818
## <!ENTITY NAUTYTRACESINTERFACEVERS "0.2">
19-
## <!ENTITY ARCHIVENAME "digraphs-1.5.0">
20-
## <!ENTITY COPYRIGHTYEARS "2014-21">
19+
## <!ENTITY ARCHIVENAME "digraphs-1.5.2">
20+
## <!ENTITY COPYRIGHTYEARS "2014-22">
2121
## <#/GAPDoc>
2222

2323
_STANDREWSMATHS := Concatenation(["Mathematical Institute, North Haugh, ",
@@ -28,8 +28,8 @@ _STANDREWSCS := Concatenation(["Jack Cole Building, North Haugh, ",
2828
SetPackageInfo(rec(
2929
PackageName := "Digraphs",
3030
Subtitle := "Graphs, digraphs, and multidigraphs in GAP",
31-
Version := "1.5.0",
32-
Date := "27/10/2021", # dd/mm/yyyy format
31+
Version := "1.5.2",
32+
Date := "30/03/2022", # dd/mm/yyyy format
3333
License := "GPL-3.0-or-later",
3434
ArchiveFormats := ".tar.gz",
3535

VERSIONS

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
#############################################################################
22
##
33
#W VERSIONS
4-
#Y Copyright (C) 2015-21 James D. Mitchell
4+
#Y Copyright (C) 2015-22 James D. Mitchell
55
##
66
## Licensing information can be found in the README.md file of this package.
77
##
88
#############################################################################
99
##
1010

11+
release 1.5.2 - 30/03/2022
12+
release 1.5.1 - 29/03/2022
1113
release 1.5.0 - 27/10/2021
1214
release 1.4.1 - 14/05/2021
1315
release 1.4.0 - 27/01/2021

doc/oper.xml

+30
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,36 @@ gap> DigraphShortestPath(D, 1, 1);
15351535
</ManSection>
15361536
<#/GAPDoc>
15371537

1538+
<#GAPDoc Label="DigraphRandomWalk">
1539+
<ManSection>
1540+
<Oper Name="DigraphRandomWalk" Arg="digraph, v, t"/>
1541+
<Returns>A pair of lists.</Returns>
1542+
<Description>
1543+
Returns a directed path corresponding to a <E>random walk</E> in the digraph
1544+
<A>digraph</A>, starting at vertex <A>v</A> and having length no more than
1545+
<A>t</A>.
1546+
<P/>
1547+
1548+
A random walk is defined as follows. The path begins at <A>v</A>, and at
1549+
each step it follows a random edge leaving the current vertex. It continues
1550+
through the digraph in this way until it has traversed <A>t</A> edges, or
1551+
until it reaches a vertex with no out-edges (a <E>sink</E>) and therefore
1552+
cannot continue.
1553+
<P/>
1554+
1555+
The output has the same form as that of <Ref Oper="DigraphPath"/>.
1556+
<P/>
1557+
1558+
<Log><![CDATA[
1559+
gap> D := Digraph([[1, 2], [3], [2, 4], [1], [2, 4]]);
1560+
<immutable digraph with 5 vertices, 8 edges>
1561+
gap> DigraphRandomWalk(D, 1, 4);
1562+
[ [ 1, 2, 3, 2, 3 ], [ 2, 1, 1, 1 ] ]
1563+
]]></Log>
1564+
</Description>
1565+
</ManSection>
1566+
<#/GAPDoc>
1567+
15381568
<#GAPDoc Label="IteratorOfPaths">
15391569
<ManSection>
15401570
<Oper Name="IteratorOfPaths" Arg="digraph, u, v"/>

doc/z-chap4.xml

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
<#Include Label="VerticesReachableFrom">
6969
<#Include Label="DigraphPath">
7070
<#Include Label="DigraphShortestPath">
71+
<#Include Label="DigraphRandomWalk">
7172
<#Include Label="Dominators">
7273
<#Include Label="DominatorTree">
7374
<#Include Label="IteratorOfPaths">

gap/grape.gi

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function(D)
132132
"the Grape graph will have fewer\n#I edges than the original,");
133133
fi;
134134

135-
if not DIGRAPHS_IsGrapeLoaded then
135+
if not DIGRAPHS_IsGrapeLoaded() then
136136
Info(InfoWarning, 1, "Grape is not loaded,");
137137
fi;
138138

gap/oper.gd

+5-4
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ DeclareOperation("LexicographicProduct", [IsDigraph, IsDigraph]);
4949
DeclareOperation("AmalgamDigraphs",
5050
[IsDigraph, IsDigraph, IsDigraph,
5151
IsTransformation, IsTransformation]);
52-
DeclareOperation("AmalgamDigraphs",
52+
DeclareOperation("AmalgamDigraphs",
5353
[IsDigraph, IsDigraph, IsDigraph, IsTransformation]);
54-
DeclareOperation("AmalgamDigraphs",
55-
[IsDigraph, IsDigraph, IsDigraph,]);
54+
DeclareOperation("AmalgamDigraphs",
55+
[IsDigraph, IsDigraph, IsDigraph]);
5656

5757
DeclareSynonym("DigraphModularProduct", ModularProduct);
5858
DeclareSynonym("DigraphStrongProduct", StrongProduct);
@@ -62,7 +62,7 @@ DeclareSynonym("DigraphLexicographicProduct", LexicographicProduct);
6262

6363
DeclareGlobalFunction("DIGRAPHS_CombinationOperProcessArgs");
6464
DeclareOperation("DIGRAPHS_GraphProduct", [IsDigraph, IsDigraph, IsFunction]);
65-
DeclareOperation("NOCHECKS_AmalgamDigraphs",
65+
DeclareOperation("NOCHECKS_AmalgamDigraphs",
6666
[IsDigraph, IsDigraph, IsDigraph,
6767
IsTransformation, IsTransformation]);
6868

@@ -135,6 +135,7 @@ DeclareOperation("IteratorOfPaths", [IsList, IsPosInt, IsPosInt]);
135135
DeclareOperation("IteratorOfPathsNC", [IsList, IsPosInt, IsPosInt]);
136136
DeclareOperation("IsReachable", [IsDigraph, IsPosInt, IsPosInt]);
137137
DeclareOperation("DigraphLongestDistanceFromVertex", [IsDigraph, IsPosInt]);
138+
DeclareOperation("DigraphRandomWalk", [IsDigraph, IsPosInt, IsInt]);
138139

139140
DeclareOperation("DigraphLayers", [IsDigraph, IsPosInt]);
140141
DeclareAttribute("DIGRAPHS_Layers", IsDigraph, "mutable");

gap/oper.gi

+38-3
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ function(D1, D2, S, map1, map2)
802802

803803
n := DigraphNrVertices(D2) + DigraphNrVertices(D1) - DigraphNrVertices(S);
804804

805-
# 'map' is an embedding of D2 into the final output graph.
805+
# 'map' is an embedding of D2 into the final output graph.
806806
# The embedding of D1 into the final output graph is the identity mapping.
807807

808808
map := [1 .. n];
@@ -856,7 +856,7 @@ function(D1, D2, S, map1)
856856
if map2 = fail then
857857
ErrorNoReturn(
858858
"no embeddings could be found from the 3rd argument ",
859-
"(a digraph) to the 2nd argument (a digraph)");
859+
"(a digraph) to the 2nd argument (a digraph)");
860860
fi;
861861

862862
return NOCHECKS_AmalgamDigraphs(D1, D2, S, map1, map2);
@@ -890,7 +890,7 @@ function(D1, D2, S)
890890
if map2 = fail then
891891
ErrorNoReturn(
892892
"no embeddings could be found from the 3rd argument ",
893-
"(a digraph) to the 2nd argument (a digraph)");
893+
"(a digraph) to the 2nd argument (a digraph)");
894894
fi;
895895

896896
return NOCHECKS_AmalgamDigraphs(D1, D2, S, map1, map2);
@@ -1891,6 +1891,41 @@ function(D, v)
18911891
return dist;
18921892
end);
18931893

1894+
InstallMethod(DigraphRandomWalk,
1895+
"for a digraph, a pos int and a non-negative int",
1896+
[IsDigraph, IsPosInt, IsInt],
1897+
function(D, v, t)
1898+
local vertices, edge_indices, i, neighbours, index;
1899+
1900+
# Check input
1901+
if v > DigraphNrVertices(D) then
1902+
ErrorNoReturn("the 2nd argument <v> must be ",
1903+
"a vertex of the 1st argument <D>,");
1904+
elif t < 0 then
1905+
ErrorNoReturn("the 3rd argument <t> must be a non-negative int,");
1906+
fi;
1907+
1908+
# Prepare output lists
1909+
vertices := [v];
1910+
edge_indices := [];
1911+
1912+
# Iterate to desired length
1913+
for i in [1 .. t] do
1914+
neighbours := OutNeighboursOfVertex(D, v);
1915+
if IsEmpty(neighbours) then
1916+
break; # Sink: path ends here
1917+
fi;
1918+
# Follow a random edge
1919+
index := Random(1, Length(neighbours));
1920+
v := neighbours[index];
1921+
vertices[i + 1] := v;
1922+
edge_indices[i] := index;
1923+
od;
1924+
1925+
# Format matches that of DigraphPath
1926+
return [vertices, edge_indices];
1927+
end);
1928+
18941929
InstallMethod(DigraphLayers, "for a digraph, and a positive integer",
18951930
[IsDigraph, IsPosInt],
18961931
function(D, v)

init.g

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ if not IsBound(DIGRAPH_OUT_NBS) and
2525
fi;
2626

2727
BindGlobal("DIGRAPHS_IsGrapeLoaded",
28-
IsPackageMarkedForLoading("grape", "4.8.1"));
28+
{} -> IsPackageMarkedForLoading("grape", "4.8.1"));
2929

3030
# To avoid warnings when GRAPE is not loaded
3131
if not IsBound(IsGraph) then
3232
IsGraph := ReturnFalse;
3333
fi;
3434
if not IsBound(Vertices) then
35-
Vertices := IdFunc;
35+
DeclareOperation("Vertices", [IsRecord]);
3636
fi;
3737
if not IsBound(Adjacency) then
3838
Adjacency := IdFunc;

read.g

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#############################################################################
99
##
1010

11-
if not DIGRAPHS_IsGrapeLoaded then
11+
if not DIGRAPHS_IsGrapeLoaded() then
1212
Add(DIGRAPHS_OmitFromTests, "Graph(");
1313
fi;
1414

tst/standard/digraph.tst

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ gap> DigraphRange(gr);
211211
[ 2, 3, 2 ]
212212
gap> gr;
213213
<immutable digraph with 3 vertices, 3 edges>
214-
gap> if DIGRAPHS_IsGrapeLoaded then
214+
gap> if DIGRAPHS_IsGrapeLoaded() then
215215
> g := Graph(gr);
216216
> if not Digraph(g) = gr then
217217
> Print("fail");
@@ -1663,7 +1663,7 @@ gap> MakeImmutable(D);
16631663
#
16641664
gap> D := NullDigraph(10);
16651665
<immutable empty digraph with 10 vertices>
1666-
gap> if DIGRAPHS_IsGrapeLoaded then
1666+
gap> if DIGRAPHS_IsGrapeLoaded() then
16671667
> D := Graph(D);
16681668
> if D <> rec(
16691669
> adjacencies := [[]],

tst/standard/grape.tst

+4-4
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ rec( adjacencies := [ [ 2, 4 ] ], group := Group([ (1,3), (1,2)(3,4) ]),
129129
schreierVector := [ -1, 2, 1, 2 ] )
130130

131131
# Digraph: copying group from Grape
132-
gap> if DIGRAPHS_IsGrapeLoaded then
132+
gap> if DIGRAPHS_IsGrapeLoaded() then
133133
> gr := Digraph(JohnsonGraph(5, 3));
134134
> else
135135
> gr := JohnsonDigraph(5, 3);
@@ -140,7 +140,7 @@ gap> HasDigraphGroup(gr);
140140
true
141141
gap> DigraphGroup(gr);
142142
Group([ (1,7,10,6,3)(2,8,4,9,5), (4,7)(5,8)(6,9) ])
143-
gap> if DIGRAPHS_IsGrapeLoaded then
143+
gap> if DIGRAPHS_IsGrapeLoaded() then
144144
> gr := Digraph(CompleteGraph(Group((1, 2, 3), (1, 2))));
145145
> else
146146
> gr := Digraph([[2, 3], [1, 3], [1, 2]]);
@@ -150,7 +150,7 @@ gap> HasDigraphGroup(gr);
150150
true
151151
gap> DigraphGroup(gr);
152152
Group([ (1,2,3), (1,2) ])
153-
gap> if DIGRAPHS_IsGrapeLoaded then
153+
gap> if DIGRAPHS_IsGrapeLoaded() then
154154
> gr := Digraph(Graph(Group([()]),
155155
> [1, 2, 3],
156156
> OnPoints,
@@ -252,7 +252,7 @@ true
252252
# Graph
253253
gap> gr := Digraph([[2, 2], []]);
254254
<immutable multidigraph with 2 vertices, 2 edges>
255-
gap> if DIGRAPHS_IsGrapeLoaded then
255+
gap> if DIGRAPHS_IsGrapeLoaded() then
256256
> Graph(gr);
257257
> fi;
258258

tst/standard/oper.tst

+30
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,36 @@ infinity
14431443
gap> DigraphLongestDistanceFromVertex(gr, 16);
14441444
Error, the 2nd argument <v> must be a vertex of the 1st argument <D>,
14451445

1446+
# DigraphRandomWalk
1447+
gap> gr := CompleteDigraph(5);
1448+
<immutable complete digraph with 5 vertices>
1449+
gap> path := DigraphRandomWalk(gr, 1, 100);;
1450+
gap> Length(path[1]);
1451+
101
1452+
gap> ForAll(path[1], i -> i in [1 .. 5]);
1453+
true
1454+
gap> Length(path[2]);
1455+
100
1456+
gap> ForAll(path[2], i -> i in [1 .. 4]);
1457+
true
1458+
gap> gr := ChainDigraph(5);
1459+
<immutable chain digraph with 5 vertices>
1460+
gap> DigraphRandomWalk(gr, 2, 100);
1461+
[ [ 2, 3, 4, 5 ], [ 1, 1, 1 ] ]
1462+
gap> DigraphRandomWalk(gr, 2, 2);
1463+
[ [ 2, 3, 4 ], [ 1, 1 ] ]
1464+
gap> DigraphRandomWalk(gr, 5, 100);
1465+
[ [ 5 ], [ ] ]
1466+
gap> gr := CompleteBipartiteDigraph(10, 8);;
1467+
gap> DigraphRandomWalk(gr, 3, 0);
1468+
[ [ 3 ], [ ] ]
1469+
gap> DigraphRandomWalk(gr, 19, 5);
1470+
Error, the 2nd argument <v> must be a vertex of the 1st argument <D>,
1471+
gap> DigraphRandomWalk(gr, 123, 5);
1472+
Error, the 2nd argument <v> must be a vertex of the 1st argument <D>,
1473+
gap> DigraphRandomWalk(gr, 3, -1);
1474+
Error, the 3rd argument <t> must be a non-negative int,
1475+
14461476
# DigraphLayers
14471477
gap> gr := CompleteDigraph(4);
14481478
<immutable complete digraph with 4 vertices>

tst/testinstall.tst

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ gap> OutNeighbours(gr);
2323
[ [ 8 ], [ 4, 5, 6, 8, 9 ], [ 2, 4, 5, 7, 10 ], [ 9 ], [ 1, 4, 6, 7, 9 ],
2424
[ 2, 3, 6, 7, 10 ], [ 3, 4, 5, 8, 9 ], [ 3, 4, 9, 10 ],
2525
[ 1, 2, 3, 5, 6, 9, 10 ], [ 2, 4, 5, 6, 9 ] ]
26-
gap> not DIGRAPHS_IsGrapeLoaded
27-
> or (DIGRAPHS_IsGrapeLoaded and Digraph(Graph(gr)) = gr);
26+
gap> not DIGRAPHS_IsGrapeLoaded()
27+
> or (DIGRAPHS_IsGrapeLoaded() and Digraph(Graph(gr)) = gr);
2828
true
29-
gap> not DIGRAPHS_IsGrapeLoaded
30-
> or (DIGRAPHS_IsGrapeLoaded and Graph(Digraph(Graph(gr))).adjacencies =
29+
gap> not DIGRAPHS_IsGrapeLoaded()
30+
> or (DIGRAPHS_IsGrapeLoaded() and Graph(Digraph(Graph(gr))).adjacencies =
3131
> Graph(gr).adjacencies);
3232
true
3333
gap> adj := [
@@ -38,8 +38,8 @@ gap> adj := [
3838
> [1, 6, 8, 9, 11, 12, 13, 14], [2, 4, 7, 9, 10, 11, 13, 15, 16]];;
3939
gap> func := function(x, y) return y in adj[x]; end;
4040
function( x, y ) ... end
41-
gap> not DIGRAPHS_IsGrapeLoaded or
42-
> (DIGRAPHS_IsGrapeLoaded and
41+
gap> not DIGRAPHS_IsGrapeLoaded() or
42+
> (DIGRAPHS_IsGrapeLoaded() and
4343
> Digraph(Graph(Group(()), [1 .. 20], OnPoints, func, true)) = Digraph(adj));
4444
true
4545

0 commit comments

Comments
 (0)