Skip to content

Commit

Permalink
ViewString: special case for trees and forests
Browse files Browse the repository at this point in the history
  • Loading branch information
wilfwilson committed Mar 17, 2021
1 parent 00ad997 commit 33828b3
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions doc/attr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2144,7 +2144,7 @@ gap> D := Digraph([[1, 2, 1, 3], [1], [4], [3, 4, 3]]);
gap> UndirectedSpanningTree(D);
fail
gap> forest := UndirectedSpanningForest(D);
<immutable symmetric digraph with 4 vertices, 4 edges>
<immutable undirected forest digraph with 4 vertices, 4 edges>
gap> OutNeighbours(forest);
[ [ 2 ], [ 1 ], [ 4 ], [ 3 ] ]
gap> IsUndirectedSpanningForest(D, forest);
Expand All @@ -2159,7 +2159,7 @@ true
gap> D := CompleteDigraph(4);
<immutable complete digraph with 4 vertices>
gap> tree := UndirectedSpanningTree(D);
<immutable symmetric digraph with 4 vertices, 6 edges>
<immutable undirected tree digraph with 4 vertices>
gap> IsUndirectedSpanningTree(D, tree);
true
gap> tree = UndirectedSpanningForest(D);
Expand Down
2 changes: 1 addition & 1 deletion doc/oper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ false
gap> DigraphShortestPathSpanningTree(D, 1);
fail
gap> tree := DigraphShortestPathSpanningTree(D, 5);
<immutable digraph with 5 vertices, 4 edges>
<immutable directed tree digraph with 5 vertices>
gap> OutNeighbours(tree);
[ [ ], [ 3 ], [ ], [ 1 ], [ 2, 4 ] ]
gap> ForAll(DigraphVertices(D), v ->
Expand Down
5 changes: 4 additions & 1 deletion gap/attr.gi
Original file line number Diff line number Diff line change
Expand Up @@ -2093,6 +2093,7 @@ InstallMethod(UndirectedSpanningTree, "for an immutable digraph",
InstallMethod(UndirectedSpanningTreeAttr, "for an immutable digraph",
[IsImmutableDigraph],
function(D)
local out;
if DigraphNrVertices(D) = 0
or not IsStronglyConnectedDigraph(D)
or (HasMaximalSymmetricSubdigraphAttr(D)
Expand All @@ -2101,7 +2102,9 @@ function(D)
<> 2 * (DigraphNrVertices(D) - 1)) then
return fail;
fi;
return UndirectedSpanningForest(D);
out := UndirectedSpanningForest(D);
SetIsUndirectedTree(out, true);
return out;
end);

InstallMethod(DigraphMycielskian, "for a digraph",
Expand Down
8 changes: 8 additions & 0 deletions gap/digraph.gi
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,14 @@ function(D)
Append(str, "join semilattice ");
elif HasIsMeetSemilatticeDigraph(D) and IsMeetSemilatticeDigraph(D) then
Append(str, "meet semilattice ");
elif HasIsUndirectedTree(D) and IsUndirectedTree(D) then
Append(str, "undirected tree ");
display_nredges := false;
elif HasIsUndirectedForest(D) and IsUndirectedForest(D) then
Append(str, "undirected forest ");
elif HasIsDirectedTree(D) and IsDirectedTree(D) then
Append(str, "directed tree ");
display_nredges := false;
else
if HasIsEulerianDigraph(D) and IsEulerianDigraph(D) then
Append(str, "Eulerian ");
Expand Down
1 change: 1 addition & 0 deletions gap/prop.gd
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ InstallTrueMethod(IsAcyclicDigraph, IsTournament and IsTransitiveDigraph);
InstallTrueMethod(IsAntisymmetricDigraph, IsAcyclicDigraph);
InstallTrueMethod(IsAntisymmetricDigraph, IsTournament);
InstallTrueMethod(IsBipartiteDigraph, IsCompleteBipartiteDigraph);
InstallTrueMethod(IsBipartiteDigraph, IsUndirectedForest);
InstallTrueMethod(IsCompleteMultipartiteDigraph, IsCompleteBipartiteDigraph);
InstallTrueMethod(IsConnectedDigraph, IsBiconnectedDigraph);
InstallTrueMethod(IsConnectedDigraph, IsStronglyConnectedDigraph);
Expand Down
2 changes: 1 addition & 1 deletion tst/standard/attr.tst
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,7 @@ true
gap> D := DigraphFromDigraph6String("&I~~~~^Znn~|~~x^|v{");
<immutable digraph with 10 vertices, 89 edges>
gap> tree := UndirectedSpanningTree(D);
<immutable symmetric digraph with 10 vertices, 18 edges>
<immutable undirected tree digraph with 10 vertices>
gap> IsUndirectedSpanningTree(D, tree);
true
gap> tree := UndirectedSpanningTree(DigraphMutableCopy(D));
Expand Down

0 comments on commit 33828b3

Please sign in to comment.