Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Nauty digraph6 format #162

Merged
merged 3 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions doc/digraph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ true
old ones, inherit their labels from their parents.

<Example><![CDATA[
gap> gr := DigraphFromDigraph6String("+D[NGc_");
gap> gr := DigraphFromDigraph6String("&DHUEe_");
<digraph with 5 vertices, 11 edges>
gap> DigraphVertexLabels(gr);
[ 1 .. 5 ]
Expand Down Expand Up @@ -234,7 +234,7 @@ gap> DigraphVertexLabels(gr);
old ones, inherit their labels from their parents.

<Example><![CDATA[
gap> gr := DigraphFromDigraph6String("+D[NGc_");
gap> gr := DigraphFromDigraph6String("&DHUEe_");
<digraph with 5 vertices, 11 edges>
gap> DigraphVertexLabel(gr, 3);
3
Expand Down Expand Up @@ -284,7 +284,7 @@ gap> DigraphVertexLabel(gr, 2);
from old ones, inherit their labels from their parents.

<Example><![CDATA[
gap> gr := DigraphFromDigraph6String("+D[NGc_");
gap> gr := DigraphFromDigraph6String("&DHUEe_");
<digraph with 5 vertices, 11 edges>
gap> DigraphEdgeLabels(gr);
[ [ 1 ], [ 1, 1, 1 ], [ 1 ], [ 1, 1, 1 ], [ 1, 1, 1 ] ]
Expand Down Expand Up @@ -322,7 +322,7 @@ gap> OutNeighbours(gr);
See also <Ref Oper="DigraphEdgeLabels"/>.

<Example><![CDATA[
gap> gr := DigraphFromDigraph6String("+D[NGc_");
gap> gr := DigraphFromDigraph6String("&DHUEe_");
<digraph with 5 vertices, 11 edges>
gap> DigraphEdgeLabel(gr, 3, 1);
1
Expand Down Expand Up @@ -350,7 +350,7 @@ gap> gr := Digraph(["a", "b", "c"], ["a", "b", "b"], ["b", "c", "a"]);
<digraph with 3 vertices, 3 edges>
gap> IsMultiDigraph(gr);
false
gap> gr := DigraphFromDigraph6String("+Bug");
gap> gr := DigraphFromDigraph6String("&Bug");
<digraph with 3 vertices, 6 edges>
gap> IsDuplicateFree(DigraphEdges(gr));
true
Expand Down
6 changes: 3 additions & 3 deletions doc/io.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ gap> DigraphFromGraph6String("C]");
<digraph with 4 vertices, 8 edges>
gap> DigraphFromGraph6String("H?AAEM{");
<digraph with 9 vertices, 22 edges>
gap> DigraphFromDigraph6String("+?");
gap> DigraphFromDigraph6String("&?");
<digraph with 0 vertices, 0 edges>
gap> DigraphFromDigraph6String("+CQFG");
gap> DigraphFromDigraph6String("&CQFG");
<digraph with 4 vertices, 6 edges>
gap> DigraphFromDigraph6String("+IM[SrKLc~lhesbU[F_");
gap> DigraphFromDigraph6String("&IM[SrKLc~lhesbU[F_");
<digraph with 10 vertices, 51 edges>
gap> DigraphFromDiSparse6String(".CaWBGA?b");
<multidigraph with 4 vertices, 9 edges>
Expand Down
2 changes: 1 addition & 1 deletion doc/oper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ od;
between the vertices of a digraph is shown below: <P/>

<Example><![CDATA[
gap> gr := DigraphFromDigraph6String("+ECGOElR");
gap> gr := DigraphFromDigraph6String("&EAHQeDB");
<digraph with 6 vertices, 12 edges>
gap> func := function(mat, i, j, k)
> if mat[i][k] <> -1 and mat[k][j] <> -1 then
Expand Down
8 changes: 4 additions & 4 deletions doc/orbits.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ gap> digraph := CayleyDigraph(AlternatingGroup(4));
<digraph with 12 vertices, 24 edges>
gap> DigraphOrbitReps(digraph);
[ 1 ]
gap> digraph := DigraphFromDigraph6String("+I?OGg????A?Ci_o_@?");
gap> digraph := DigraphFromDigraph6String("&IGO??S?`?_@?a?CK?O");
<digraph with 10 vertices, 14 edges>
gap> DigraphOrbitReps(digraph);
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
Expand All @@ -157,7 +157,7 @@ gap> DigraphOrbitReps(digraph);
vertices of <A>digraph</A>.

<Example><![CDATA[
gap> digraph := DigraphFromDigraph6String("+GUIQQWWXHHPg");
gap> digraph := DigraphFromDigraph6String("&GYHPQgWTIIPW");
<digraph with 8 vertices, 24 edges>
gap> DigraphStabilizer(digraph, 8);
Group(())
Expand Down Expand Up @@ -215,12 +215,12 @@ gap> DigraphGroup(digraph);
Group(())
gap> RepresentativeOutNeighbours(digraph);
[ [ 2, 1, 3, 4, 5 ], [ 3, 5 ], [ 2 ], [ 1, 2, 3, 5 ], [ 1, 2, 3, 4 ] ]
gap> digraph := DigraphFromDigraph6String("+GUIQQWWXHHPg");
gap> digraph := DigraphFromDigraph6String("&GYHPQgWTIIPW");
<digraph with 8 vertices, 24 edges>
gap> DigraphGroup(digraph);
Group([ (1,2)(3,4)(5,6)(7,8), (1,3,2,4)(5,7,6,8), (1,5)(2,6)(3,8)
(4,7) ])
gap> RepresentativeOutNeighbours(digraph);
gap> Set(RepresentativeOutNeighbours(digraph), Set);
[ [ 2, 3, 5 ] ]]]></Example>
</Description>
</ManSection>
Expand Down
43 changes: 34 additions & 9 deletions gap/io.gi
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,12 @@ end);
InstallMethod(DigraphFromDigraph6String, "for a string",
[IsString],
function(s)
local list, i, n, start, range, source, pos, len, j, bpos, tabpos;
local legacy, list, n, start, i, range, source, pos, len, j, bpos, tabpos;
# NOTE: this package originally used a version of digraph6 that reads down
# the columns of an adjacency matrix, and appends a '+' to the start. This
# has been replaced by the Nauty standard, which reads across the rows of the
# matrix, and appends a '&' to the start. For backwards compatibility, this
# now accepts both formats, sending an info warning if the old format is used.

s := Chomp(s);
# Check non-emptiness
Expand All @@ -821,8 +826,18 @@ function(s)
"the input string <s> should be non-empty,");
fi;

# Check for the special '+' character
if s[1] <> '+' then
# Check for the special '&' character (or the deprecated '+')
if s[1] = '&' then
legacy := false;
elif s[1] = '+' then
legacy := true;
Info(InfoDigraphs, 1, "Digraph6 strings beginning with '+' use an old");
Info(InfoDigraphs, 1, "specification of the Digraph6 format that is");
Info(InfoDigraphs, 1, "incompatible with the present standard. They can");
Info(InfoDigraphs, 1, "still be read by the Digraphs package, but are");
Info(InfoDigraphs, 1, "unlikely to be recognised by other programs.");
Info(InfoDigraphs, 1, "Please consider re-encoding with the new format.");
else
ErrorNoReturn("Digraphs: DigraphFromDigraph6String: usage,\n",
"the input string <s> is not in valid digraph6 format,");
fi;
Expand Down Expand Up @@ -867,8 +882,8 @@ function(s)
i := i / 2;
else
tabpos := pos + 6 - bpos;
source[len] := (tabpos - 1) mod n + 1;
range[len] := (tabpos - source[len]) / n + 1;
range[len] := (tabpos - 1) mod n + 1;
source[len] := (tabpos - range[len]) / n + 1;
len := len + 1;
i := (i - 1) / 2;
fi;
Expand All @@ -877,6 +892,10 @@ function(s)
pos := pos + 6;
od;

if legacy then # source and range are reversed
return Digraph(rec(nrvertices := n, range := source, source := range));
fi;

return Digraph(rec(nrvertices := n, range := range, source := source));
end);

Expand Down Expand Up @@ -1539,12 +1558,18 @@ InstallMethod(Digraph6String, "for a digraph",
[IsDigraph],
function(digraph)
local list, adj, n, lenlist, tablen, blist, i, j, pos, block;
# NOTE: this package originally used a version of digraph6 that reads down
# the columns of an adjacency matrix, and appends a '+' to the start. This
# has been replaced by the Nauty standard, which reads across the rows of the
# matrix, and appends a '&' to the start. The old '+' format can be read by
# DigraphFromDigraph6String, but can no longer be written by this function.

list := [];
adj := OutNeighbours(digraph);
n := Length(DigraphVertices(digraph));

# First write the special character '+'
Add(list, -20);
# First write the special character '&'
Add(list, -25);

# Now write the number of vertices
lenlist := DIGRAPHS_Graph6Length(n);
Expand All @@ -1555,12 +1580,12 @@ function(digraph)
fi;
Append(list, lenlist);

# Find adjacencies (non-directed)
# Find adjacencies
tablen := n ^ 2;
blist := BlistList([1 .. tablen + 6], []);
for i in DigraphVertices(digraph) do
for j in adj[i] do
blist[i + n * (j - 1)] := true;
blist[j + n * (i - 1)] := true;
od;
od;

Expand Down
4 changes: 2 additions & 2 deletions tst/standard/attr.tst
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ gap> ChromaticNumber(DigraphDisjointUnion(CompleteDigraph(1),
> Digraph([[2], [4], [1, 2], [3], [1, 2, 3]])));
4
gap> gr := DigraphFromDigraph6String(Concatenation(
> "+l??O?C?A_@???CE????GAAG?C??M?????@_?OO??G??@?IC???_C?G?o??C?AO???c_??A?",
> "&l??O?C?A_@???CE????GAAG?C??M?????@_?OO??G??@?IC???_C?G?o??C?AO???c_??A?",
> "A?S???OAA???OG???G_A??C?@?cC????_@G???S??C_?C???[??A?A?OA?O?@?A?@A???GGO",
> "??`?_O??G?@?A??G?@AH????AA?O@??_??b???Cg??C???_??W?G????d?G?C@A?C???GC?W",
> "?????K???__O[??????O?W???O@??_G?@?CG??G?@G?C??@G???_Q?O?O?c???OAO?C??C?G",
Expand Down Expand Up @@ -1425,7 +1425,7 @@ gap> IsUndirectedSpanningForest(gr, forest);
true
gap> gr = forest;
true
gap> gr := DigraphFromDigraph6String("+I?PIMAQc@A?W?ADPP?");
gap> gr := DigraphFromDigraph6String("&IG@qqW?HO?BSQGA?CG");
<digraph with 10 vertices, 23 edges>
gap> IsStronglyConnectedDigraph(gr);
true
Expand Down
4 changes: 2 additions & 2 deletions tst/standard/cliques.tst
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ gap> DigraphMaximalIndependentSets(gr);
gap> gr := CompleteDigraph(2);;
gap> DigraphMaximalIndependentSets(gr);
[ [ 1 ], [ 2 ] ]
gap> gr := DigraphFromDigraph6String("+FWSK?[SK_?");
gap> gr := DigraphFromDigraph6String("&FWsK?WSKC?");
<digraph with 7 vertices, 14 edges>
gap> DigraphMaximalIndependentSetsReps(gr);
[ [ 1, 4 ], [ 1, 5 ], [ 2, 5, 7 ] ]
Expand Down Expand Up @@ -307,7 +307,7 @@ gap> DigraphMaximalCliques(gr);
gap> gr := EmptyDigraph(1);;
gap> DigraphMaximalCliques(gr);
[ [ 1 ] ]
gap> gr := DigraphFromDigraph6String("+D[]]]?");
gap> gr := DigraphFromDigraph6String("&DNNNF?");
<digraph with 5 vertices, 15 edges>
gap> DigraphMaximalCliquesReps(gr);
[ [ 1, 3 ] ]
Expand Down
4 changes: 2 additions & 2 deletions tst/standard/display.tst
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ node [shape=Mrecord, height=0.5, fixedsize=true]ranksep=1;
7 -> 5
8 -> 1
}
gap> gr := Concatenation("+XqD?OG???FbueZpzRKGC@?}]sr]nYXnNl[saOEGOgA@w|he?A?",
> "?}NyxnFlKvbueZpzrLGcHa??A?]NYx_?_GC??AJpzrnw~jm{]srO???_");;
gap> gr := Concatenation("&X_?_A]|^Vr[nHpmVcy~zy[A????_???G??B]nhtmvcwvJq\\^~",
> "|m??_AEx]Rb[nHo??__vJy[??A??O_aV~^Zb]njo???_???GZdxMLy}n_");;
gap> gr := DigraphFromDigraph6String(gr);;
gap> Print(DotPreorderDigraph(gr){[1 .. 94]}, "\n");
//dot
Expand Down
4 changes: 2 additions & 2 deletions tst/standard/grahom.tst
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ IdentityTransformation
gap> gr1 := ChainDigraph(2);;
gap> MonomorphismsDigraphs(gr1, EmptyDigraph(1));
[ ]
gap> gr2 := DigraphFromDigraph6String("+DRZ?L?");;
gap> gr2 := DigraphFromDigraph6String("&DZTAW?");;
gap> monos := MonomorphismsDigraphs(gr1, gr2);
[ IdentityTransformation, Transformation( [ 1, 3, 3 ] ),
Transformation( [ 1, 5, 3, 4, 5 ] ), Transformation( [ 2, 1 ] ),
Expand All @@ -1001,7 +1001,7 @@ gap> gr1 := CompleteDigraph(2);;
gap> gr2 := CompleteDigraph(3);;
gap> EpimorphismsDigraphs(gr1, gr2);
[ ]
gap> gr1 := DigraphFromDigraph6String("+IG????G??I??O?????");;
gap> gr1 := DigraphFromDigraph6String("&I@??HO???????A????");;
gap> DigraphEpimorphism(gr1, gr2);
Transformation( [ 1, 1, 2, 1, 1, 3, 1, 2, 1, 1 ] )
gap> epis := EpimorphismsDigraphsRepresentatives(gr1, gr2);;
Expand Down
6 changes: 4 additions & 2 deletions tst/standard/io.tst
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ gap> DigraphFromSparse6String(str);
gap> gr := Digraph([[5], [1, 2, 5], [1], [2], [4]]);
<digraph with 5 vertices, 7 edges>
gap> str := Digraph6String(gr);
"+DWg?[?"
"&DBeA@?"
gap> gr = DigraphFromDigraph6String("+DWg?[?"); # deprecated format
true
gap> DigraphFromDigraph6String(str);
<digraph with 5 vertices, 7 edges>
gap> gr := Digraph(231, [1 .. 100], [1 .. 100] * 0 + 200);
Expand Down Expand Up @@ -484,7 +486,7 @@ true
gap> DigraphFromGraph6String("~llk");
Error, Digraphs: DigraphFromGraph6String: usage,
the input string <s> is not in valid graph6 format,
gap> DigraphFromDigraph6String("+~llk");
gap> DigraphFromDigraph6String("&~llk");
Error, Digraphs: DigraphFromDigraph6String: usage,
the input string <s> is not in valid digraph6 format,
gap> DigraphFromSparse6String(":~~l");
Expand Down
31 changes: 16 additions & 15 deletions tst/standard/oper.tst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ gap> LoadPackage("digraphs", false);;
gap> DIGRAPHS_StartTest();

# DigraphReverse
gap> gr := DigraphFromDigraph6String("+D[NGc_");
gap> gr := DigraphFromDigraph6String("&DHUEe_");
<digraph with 5 vertices, 11 edges>
gap> rgr := DigraphReverse(gr);
<digraph with 5 vertices, 11 edges>
Expand Down Expand Up @@ -50,11 +50,11 @@ gap> gr = DigraphReverse(gr);
true

# DigraphRemoveLoops
gap> gr := DigraphFromDigraph6String("+EhxPC?@");
gap> gr := DigraphFromDigraph6String("&EhxPC?@");
<digraph with 6 vertices, 11 edges>
gap> DigraphRemoveLoops(gr);
<digraph with 6 vertices, 7 edges>
gap> gr := DigraphFromDigraph6String("+EhxPC?@");
gap> gr := DigraphFromDigraph6String("&EhxPC?@");
<digraph with 6 vertices, 11 edges>
gap> HasDigraphHasLoops(gr);
false
Expand Down Expand Up @@ -99,11 +99,12 @@ gap> last = gr;
true
gap> DigraphRemoveEdges(gr, [[1, 2]]);
<digraph with 2 vertices, 0 edges>
gap> gr := DigraphFromDigraph6String("+Dv?f`_");
gap> gr := DigraphFromDigraph6String("&DtGsw_");
<digraph with 5 vertices, 12 edges>
gap> DigraphEdges(gr);
[ [ 1, 2 ], [ 1, 1 ], [ 1, 4 ], [ 2, 1 ], [ 2, 4 ], [ 3, 4 ], [ 3, 3 ],
[ 4, 1 ], [ 4, 5 ], [ 4, 4 ], [ 5, 1 ], [ 5, 5 ] ]
gap> Set(DigraphEdges(gr)) = Set(
> [[1, 2], [1, 1], [1, 4], [2, 1], [2, 4], [3, 4],
> [3, 3], [4, 1], [4, 5], [4, 4], [5, 1], [5, 5]]);
true
gap> gr1 := DigraphRemoveEdges(gr, [[1, 4], [4, 5], [5, 5]]);
<digraph with 5 vertices, 9 edges>
gap> DigraphEdges(gr1);
Expand Down Expand Up @@ -793,7 +794,7 @@ gap> DigraphVertexLabels(gr2);
[ 1, Sym( [ 1 .. 2 ] ) ]

# DigraphRemoveVertex
gap> gr := DigraphFromDigraph6String("+MW?Gp?GWe?gS?[L?A?f|C@KOCa_gk?F?r_");
gap> gr := DigraphFromDigraph6String("&MU?GAa?SDCFStK`???d?@LWOq[{DECO?U?");
<digraph with 14 vertices, 54 edges>
gap> DigraphRemoveVertex(gr, "a");
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
Expand Down Expand Up @@ -1045,7 +1046,7 @@ gap> func := function(mat, i, j, k)
> fi;
> end;
function( mat, i, j, k ) ... end
gap> gr := DigraphFromDigraph6String("+I???@?A`?G?GCCS@??");
gap> gr := DigraphFromDigraph6String("&I???@?A`?G?GCCS@??");
<digraph with 10 vertices, 11 edges>
gap> tclosure := DigraphFloydWarshall(gr, func, 0, 1);;
gap> grt := DigraphByAdjacencyMatrix(tclosure);
Expand Down Expand Up @@ -1104,7 +1105,7 @@ gap> gr = ChainDigraph(14);
true

# DigraphEdgeUnion
gap> gr1 := DigraphFromDigraph6String("+I????O?GO_?C??_OGG");
gap> gr1 := DigraphFromDigraph6String("&I????@A_?AA???@d??");
<digraph with 10 vertices, 9 edges>
gap> gr2 := DigraphFromDiSparse6String(".H`OS?aEMC?bneOY`l_?QCJ");
<multidigraph with 9 vertices, 20 edges>
Expand Down Expand Up @@ -1594,7 +1595,7 @@ gap> DigraphLayers(gr, 9);
[ [ 9 ], [ 10, 11 ] ]
gap> DigraphLayers(gr, 10);
[ [ 10 ] ]
gap> gr := DigraphFromDigraph6String("+GUIQQWWXHHPg");;
gap> gr := DigraphFromDigraph6String("&GYHPQgWTIIPW");;
gap> DigraphGroup(gr);
Group([ (1,2)(3,4)(5,6)(7,8), (1,3,2,4)(5,7,6,8), (1,5)(2,6)(3,8)(4,7) ])
gap> DigraphOrbitReps(gr);
Expand Down Expand Up @@ -1698,7 +1699,7 @@ the second argument must be a vertex of the digraph,
gap> DigraphDistanceSet(gr, 10, ["string", 1]);
Error, Digraphs: DigraphDistanceSet: usage,
the third argument must be a list of non-negative integers,
gap> gr := DigraphFromDigraph6String("+GUIQQWWXHHPg");;
gap> gr := DigraphFromDigraph6String("&GYHPQgWTIIPW");;
gap> DigraphDistanceSet(gr, 1, [3, 7]);
[ ]
gap> DigraphDistanceSet(gr, 1, [1]);
Expand Down Expand Up @@ -1772,7 +1773,7 @@ gap> IsUndirectedSpanningForest(gr1, gr2);
false
gap> IsUndirectedSpanningForest(gr1, DigraphFromSparse6String(":I`ESyTl^F"));
true
gap> gr := DigraphFromDigraph6String("+I?PIMAQc@A?W?ADPP?");
gap> gr := DigraphFromDigraph6String("&I?PIMAQc@A?W?ADPP?");
<digraph with 10 vertices, 23 edges>
gap> IsUndirectedSpanningForest(gr, DigraphByEdges([[2, 7], [7, 2]], 10));
true
Expand All @@ -1782,7 +1783,7 @@ gap> IsUndirectedSpanningTree(EmptyDigraph(1), EmptyDigraph(1));
true
gap> IsUndirectedSpanningTree(EmptyDigraph(2), EmptyDigraph(2));
false
gap> gr := DigraphFromDigraph6String("+I?PIMAQc@A?W?ADPP?");
gap> gr := DigraphFromDigraph6String("&I?PIMAQc@A?W?ADPP?");
<digraph with 10 vertices, 23 edges>
gap> IsUndirectedSpanningTree(gr, EmptyDigraph(10));
false
Expand Down Expand Up @@ -1995,7 +1996,7 @@ gap> di := Digraph([[1], [1, 2], [1, 3], [1, 2, 3, 4]]);;
gap> S := AsSemigroup(IsPartialPermSemigroup, di);;
gap> IsInverseSemigroup(S) and ForAll(Elements(S), IsIdempotent);
true
gap> temp := "+P~~}~??o??_?@o??_?@_?W}?O_??o??_?@_FGoA?_?Wo?O_Wt_";;
gap> temp := "&P_?@_?B`?FrCK_GXoXo_B?_A@aCA`GDroG`_?`?@e??c?@w??_";;
gap> di := DigraphFromDigraph6String(temp);;
gap> S := AsSemigroup(IsPartialPermSemigroup, di);;
gap> IsInverseSemigroup(S) and ForAll(Elements(S), IsIdempotent);
Expand Down
Loading