Skip to content

Commit

Permalink
Merge branch 'amalgamDigraphs' of github.com:finnbuck/Digraphs into a…
Browse files Browse the repository at this point in the history
…malgamDigraphs
  • Loading branch information
finnbuck committed May 11, 2022
2 parents 781dcb9 + 53716a0 commit 2528c7b
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.0
1.5.2
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
# CHANGELOG – Digraphs package for GAP
Copyright © 2014-21 by Jan De Beule, Julius Jonušas, James D. Mitchell,
Copyright © 2014-22 by Jan De Beule, Julius Jonušas, James D. Mitchell,
Wilf A. Wilson, Michael Young et al.

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

## Version 1.5.2 (released 30/03/2022)

This is a very minor release containing technical changes for maintaining compatibility with other GAP packages.

## Version 1.5.1 (released 29/03/2022)

This minor release contains several bugfixes and technical changes. This includes:

* 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).
* 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).
* [Wilf A. Wilson][] improved the performance of `DigraphAddEdge` for digraphs without edge labels in [PR #509](https://github.com/digraphs/Digraphs/pull/509).
* [Max Horn][] changed the declaration of the variable `Vertices` to improve compatibility with Grape in [PR #530](https://github.com/digraphs/Digraphs/pull/530).

## Version 1.5.0 (released 27/10/2021)

This is a fairly major release of the Digraphs package, containing some bugfixes and several new features.
Expand Down
12 changes: 6 additions & 6 deletions PackageInfo.g
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#############################################################################
##
## PackageInfo.g
## Copyright (C) 2015-21 James D. Mitchell
## Copyright (C) 2015-22 James D. Mitchell
##
## Licensing information can be found in the README.md file of this package.
##
#############################################################################
##

## <#GAPDoc Label="PKGVERSIONDATA">
## <!ENTITY VERSION "1.5.0">
## <!ENTITY VERSION "1.5.2">
## <!ENTITY GAPVERS "4.10.0">
## <!ENTITY GRAPEVERS "4.8.1">
## <!ENTITY IOVERS "4.5.1">
## <!ENTITY ORBVERS "4.8.2">
## <!ENTITY DATASTRUCTURESVERS "0.2.5">
## <!ENTITY NAUTYTRACESINTERFACEVERS "0.2">
## <!ENTITY ARCHIVENAME "digraphs-1.5.0">
## <!ENTITY COPYRIGHTYEARS "2014-21">
## <!ENTITY ARCHIVENAME "digraphs-1.5.2">
## <!ENTITY COPYRIGHTYEARS "2014-22">
## <#/GAPDoc>

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

Expand Down
4 changes: 3 additions & 1 deletion VERSIONS
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#############################################################################
##
#W VERSIONS
#Y Copyright (C) 2015-21 James D. Mitchell
#Y Copyright (C) 2015-22 James D. Mitchell
##
## Licensing information can be found in the README.md file of this package.
##
#############################################################################
##

release 1.5.2 - 30/03/2022
release 1.5.1 - 29/03/2022
release 1.5.0 - 27/10/2021
release 1.4.1 - 14/05/2021
release 1.4.0 - 27/01/2021
Expand Down
30 changes: 30 additions & 0 deletions doc/oper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,36 @@ gap> DigraphShortestPath(D, 1, 1);
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="DigraphRandomWalk">
<ManSection>
<Oper Name="DigraphRandomWalk" Arg="digraph, v, t"/>
<Returns>A pair of lists.</Returns>
<Description>
Returns a directed path corresponding to a <E>random walk</E> in the digraph
<A>digraph</A>, starting at vertex <A>v</A> and having length no more than
<A>t</A>.
<P/>

A random walk is defined as follows. The path begins at <A>v</A>, and at
each step it follows a random edge leaving the current vertex. It continues
through the digraph in this way until it has traversed <A>t</A> edges, or
until it reaches a vertex with no out-edges (a <E>sink</E>) and therefore
cannot continue.
<P/>

The output has the same form as that of <Ref Oper="DigraphPath"/>.
<P/>

<Log><![CDATA[
gap> D := Digraph([[1, 2], [3], [2, 4], [1], [2, 4]]);
<immutable digraph with 5 vertices, 8 edges>
gap> DigraphRandomWalk(D, 1, 4);
[ [ 1, 2, 3, 2, 3 ], [ 2, 1, 1, 1 ] ]
]]></Log>
</Description>
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="IteratorOfPaths">
<ManSection>
<Oper Name="IteratorOfPaths" Arg="digraph, u, v"/>
Expand Down
1 change: 1 addition & 0 deletions doc/z-chap4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<#Include Label="VerticesReachableFrom">
<#Include Label="DigraphPath">
<#Include Label="DigraphShortestPath">
<#Include Label="DigraphRandomWalk">
<#Include Label="Dominators">
<#Include Label="DominatorTree">
<#Include Label="IteratorOfPaths">
Expand Down
2 changes: 1 addition & 1 deletion gap/grape.gi
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function(D)
"the Grape graph will have fewer\n#I edges than the original,");
fi;

if not DIGRAPHS_IsGrapeLoaded then
if not DIGRAPHS_IsGrapeLoaded() then
Info(InfoWarning, 1, "Grape is not loaded,");
fi;

Expand Down
11 changes: 6 additions & 5 deletions gap/oper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ DeclareOperation("StrongProduct", [IsDigraph, IsDigraph]);
DeclareOperation("ConormalProduct", [IsDigraph, IsDigraph]);
DeclareOperation("HomomorphicProduct", [IsDigraph, IsDigraph]);
DeclareOperation("LexicographicProduct", [IsDigraph, IsDigraph]);
DeclareOperation("AmalgamDigraphs",
DeclareOperation("AmalgamDigraphs",
[IsDigraph, IsDigraph, IsDigraph,
IsTransformation, IsTransformation]);
DeclareOperation("AmalgamDigraphs",
DeclareOperation("AmalgamDigraphs",
[IsDigraph, IsDigraph, IsDigraph, IsTransformation]);
DeclareOperation("AmalgamDigraphs",
[IsDigraph, IsDigraph, IsDigraph,]);
DeclareOperation("AmalgamDigraphs",
[IsDigraph, IsDigraph, IsDigraph]);

DeclareSynonym("DigraphModularProduct", ModularProduct);
DeclareSynonym("DigraphStrongProduct", StrongProduct);
Expand All @@ -62,7 +62,7 @@ DeclareSynonym("DigraphLexicographicProduct", LexicographicProduct);

DeclareGlobalFunction("DIGRAPHS_CombinationOperProcessArgs");
DeclareOperation("DIGRAPHS_GraphProduct", [IsDigraph, IsDigraph, IsFunction]);
DeclareOperation("NOCHECKS_AmalgamDigraphs",
DeclareOperation("NOCHECKS_AmalgamDigraphs",
[IsDigraph, IsDigraph, IsDigraph,
IsTransformation, IsTransformation]);

Expand Down Expand Up @@ -135,6 +135,7 @@ DeclareOperation("IteratorOfPaths", [IsList, IsPosInt, IsPosInt]);
DeclareOperation("IteratorOfPathsNC", [IsList, IsPosInt, IsPosInt]);
DeclareOperation("IsReachable", [IsDigraph, IsPosInt, IsPosInt]);
DeclareOperation("DigraphLongestDistanceFromVertex", [IsDigraph, IsPosInt]);
DeclareOperation("DigraphRandomWalk", [IsDigraph, IsPosInt, IsInt]);

DeclareOperation("DigraphLayers", [IsDigraph, IsPosInt]);
DeclareAttribute("DIGRAPHS_Layers", IsDigraph, "mutable");
Expand Down
41 changes: 38 additions & 3 deletions gap/oper.gi
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ function(D1, D2, S, map1, map2)

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

# 'map' is an embedding of D2 into the final output graph.
# 'map' is an embedding of D2 into the final output graph.
# The embedding of D1 into the final output graph is the identity mapping.

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

return NOCHECKS_AmalgamDigraphs(D1, D2, S, map1, map2);
Expand Down Expand Up @@ -890,7 +890,7 @@ function(D1, D2, S)
if map2 = fail then
ErrorNoReturn(
"no embeddings could be found from the 3rd argument ",
"(a digraph) to the 2nd argument (a digraph)");
"(a digraph) to the 2nd argument (a digraph)");
fi;

return NOCHECKS_AmalgamDigraphs(D1, D2, S, map1, map2);
Expand Down Expand Up @@ -1891,6 +1891,41 @@ function(D, v)
return dist;
end);

InstallMethod(DigraphRandomWalk,
"for a digraph, a pos int and a non-negative int",
[IsDigraph, IsPosInt, IsInt],
function(D, v, t)
local vertices, edge_indices, i, neighbours, index;

# Check input
if v > DigraphNrVertices(D) then
ErrorNoReturn("the 2nd argument <v> must be ",
"a vertex of the 1st argument <D>,");
elif t < 0 then
ErrorNoReturn("the 3rd argument <t> must be a non-negative int,");
fi;

# Prepare output lists
vertices := [v];
edge_indices := [];

# Iterate to desired length
for i in [1 .. t] do
neighbours := OutNeighboursOfVertex(D, v);
if IsEmpty(neighbours) then
break; # Sink: path ends here
fi;
# Follow a random edge
index := Random(1, Length(neighbours));
v := neighbours[index];
vertices[i + 1] := v;
edge_indices[i] := index;
od;

# Format matches that of DigraphPath
return [vertices, edge_indices];
end);

InstallMethod(DigraphLayers, "for a digraph, and a positive integer",
[IsDigraph, IsPosInt],
function(D, v)
Expand Down
4 changes: 2 additions & 2 deletions init.g
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ if not IsBound(DIGRAPH_OUT_NBS) and
fi;

BindGlobal("DIGRAPHS_IsGrapeLoaded",
IsPackageMarkedForLoading("grape", "4.8.1"));
{} -> IsPackageMarkedForLoading("grape", "4.8.1"));

# To avoid warnings when GRAPE is not loaded
if not IsBound(IsGraph) then
IsGraph := ReturnFalse;
fi;
if not IsBound(Vertices) then
Vertices := IdFunc;
DeclareOperation("Vertices", [IsRecord]);
fi;
if not IsBound(Adjacency) then
Adjacency := IdFunc;
Expand Down
2 changes: 1 addition & 1 deletion read.g
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#############################################################################
##

if not DIGRAPHS_IsGrapeLoaded then
if not DIGRAPHS_IsGrapeLoaded() then
Add(DIGRAPHS_OmitFromTests, "Graph(");
fi;

Expand Down
4 changes: 2 additions & 2 deletions tst/standard/digraph.tst
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ gap> DigraphRange(gr);
[ 2, 3, 2 ]
gap> gr;
<immutable digraph with 3 vertices, 3 edges>
gap> if DIGRAPHS_IsGrapeLoaded then
gap> if DIGRAPHS_IsGrapeLoaded() then
> g := Graph(gr);
> if not Digraph(g) = gr then
> Print("fail");
Expand Down Expand Up @@ -1663,7 +1663,7 @@ gap> MakeImmutable(D);
#
gap> D := NullDigraph(10);
<immutable empty digraph with 10 vertices>
gap> if DIGRAPHS_IsGrapeLoaded then
gap> if DIGRAPHS_IsGrapeLoaded() then
> D := Graph(D);
> if D <> rec(
> adjacencies := [[]],
Expand Down
8 changes: 4 additions & 4 deletions tst/standard/grape.tst
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ rec( adjacencies := [ [ 2, 4 ] ], group := Group([ (1,3), (1,2)(3,4) ]),
schreierVector := [ -1, 2, 1, 2 ] )

# Digraph: copying group from Grape
gap> if DIGRAPHS_IsGrapeLoaded then
gap> if DIGRAPHS_IsGrapeLoaded() then
> gr := Digraph(JohnsonGraph(5, 3));
> else
> gr := JohnsonDigraph(5, 3);
Expand All @@ -140,7 +140,7 @@ gap> HasDigraphGroup(gr);
true
gap> DigraphGroup(gr);
Group([ (1,7,10,6,3)(2,8,4,9,5), (4,7)(5,8)(6,9) ])
gap> if DIGRAPHS_IsGrapeLoaded then
gap> if DIGRAPHS_IsGrapeLoaded() then
> gr := Digraph(CompleteGraph(Group((1, 2, 3), (1, 2))));
> else
> gr := Digraph([[2, 3], [1, 3], [1, 2]]);
Expand All @@ -150,7 +150,7 @@ gap> HasDigraphGroup(gr);
true
gap> DigraphGroup(gr);
Group([ (1,2,3), (1,2) ])
gap> if DIGRAPHS_IsGrapeLoaded then
gap> if DIGRAPHS_IsGrapeLoaded() then
> gr := Digraph(Graph(Group([()]),
> [1, 2, 3],
> OnPoints,
Expand Down Expand Up @@ -252,7 +252,7 @@ true
# Graph
gap> gr := Digraph([[2, 2], []]);
<immutable multidigraph with 2 vertices, 2 edges>
gap> if DIGRAPHS_IsGrapeLoaded then
gap> if DIGRAPHS_IsGrapeLoaded() then
> Graph(gr);
> fi;

Expand Down
30 changes: 30 additions & 0 deletions tst/standard/oper.tst
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,36 @@ infinity
gap> DigraphLongestDistanceFromVertex(gr, 16);
Error, the 2nd argument <v> must be a vertex of the 1st argument <D>,

# DigraphRandomWalk
gap> gr := CompleteDigraph(5);
<immutable complete digraph with 5 vertices>
gap> path := DigraphRandomWalk(gr, 1, 100);;
gap> Length(path[1]);
101
gap> ForAll(path[1], i -> i in [1 .. 5]);
true
gap> Length(path[2]);
100
gap> ForAll(path[2], i -> i in [1 .. 4]);
true
gap> gr := ChainDigraph(5);
<immutable chain digraph with 5 vertices>
gap> DigraphRandomWalk(gr, 2, 100);
[ [ 2, 3, 4, 5 ], [ 1, 1, 1 ] ]
gap> DigraphRandomWalk(gr, 2, 2);
[ [ 2, 3, 4 ], [ 1, 1 ] ]
gap> DigraphRandomWalk(gr, 5, 100);
[ [ 5 ], [ ] ]
gap> gr := CompleteBipartiteDigraph(10, 8);;
gap> DigraphRandomWalk(gr, 3, 0);
[ [ 3 ], [ ] ]
gap> DigraphRandomWalk(gr, 19, 5);
Error, the 2nd argument <v> must be a vertex of the 1st argument <D>,
gap> DigraphRandomWalk(gr, 123, 5);
Error, the 2nd argument <v> must be a vertex of the 1st argument <D>,
gap> DigraphRandomWalk(gr, 3, -1);
Error, the 3rd argument <t> must be a non-negative int,

# DigraphLayers
gap> gr := CompleteDigraph(4);
<immutable complete digraph with 4 vertices>
Expand Down
12 changes: 6 additions & 6 deletions tst/testinstall.tst
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ gap> OutNeighbours(gr);
[ [ 8 ], [ 4, 5, 6, 8, 9 ], [ 2, 4, 5, 7, 10 ], [ 9 ], [ 1, 4, 6, 7, 9 ],
[ 2, 3, 6, 7, 10 ], [ 3, 4, 5, 8, 9 ], [ 3, 4, 9, 10 ],
[ 1, 2, 3, 5, 6, 9, 10 ], [ 2, 4, 5, 6, 9 ] ]
gap> not DIGRAPHS_IsGrapeLoaded
> or (DIGRAPHS_IsGrapeLoaded and Digraph(Graph(gr)) = gr);
gap> not DIGRAPHS_IsGrapeLoaded()
> or (DIGRAPHS_IsGrapeLoaded() and Digraph(Graph(gr)) = gr);
true
gap> not DIGRAPHS_IsGrapeLoaded
> or (DIGRAPHS_IsGrapeLoaded and Graph(Digraph(Graph(gr))).adjacencies =
gap> not DIGRAPHS_IsGrapeLoaded()
> or (DIGRAPHS_IsGrapeLoaded() and Graph(Digraph(Graph(gr))).adjacencies =
> Graph(gr).adjacencies);
true
gap> adj := [
Expand All @@ -38,8 +38,8 @@ gap> adj := [
> [1, 6, 8, 9, 11, 12, 13, 14], [2, 4, 7, 9, 10, 11, 13, 15, 16]];;
gap> func := function(x, y) return y in adj[x]; end;
function( x, y ) ... end
gap> not DIGRAPHS_IsGrapeLoaded or
> (DIGRAPHS_IsGrapeLoaded and
gap> not DIGRAPHS_IsGrapeLoaded() or
> (DIGRAPHS_IsGrapeLoaded() and
> Digraph(Graph(Group(()), [1 .. 20], OnPoints, func, true)) = Digraph(adj));
true

Expand Down

0 comments on commit 2528c7b

Please sign in to comment.