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

ViewString: special case for trees and forests #440

Merged
merged 1 commit into from
Mar 22, 2021
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
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
8 changes: 4 additions & 4 deletions doc/examples.xml
Original file line number Diff line number Diff line change
Expand Up @@ -654,13 +654,13 @@ ent sizes 5 and 5>
See also <Ref Oper="StarDigraph"/> and <Ref Prop="IsUndirectedTree"/>.
<Example><![CDATA[
gap> D := BananaTree(2, 4);
<immutable connected symmetric digraph with 9 vertices, 16 edges>
<immutable undirected tree digraph with 9 vertices>
gap> D := BananaTree(3, 3);
<immutable connected symmetric digraph with 10 vertices, 18 edges>
<immutable undirected tree digraph with 10 vertices>
gap> D := BananaTree(5, 2);
<immutable connected symmetric digraph with 11 vertices, 20 edges>
<immutable undirected tree digraph with 11 vertices>
gap> D := BananaTree(3, 4);
<immutable connected symmetric digraph with 13 vertices, 24 edges>
<immutable undirected tree digraph with 13 vertices>
]]></Example>
</Description>
</ManSection>
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
8 changes: 4 additions & 4 deletions tst/standard/examples.tst
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,13 @@ true

# BananaTree
gap> D := BananaTree(2, 4);
<immutable connected symmetric digraph with 9 vertices, 16 edges>
<immutable undirected tree digraph with 9 vertices>
gap> D := BananaTree(3, 3);
<immutable connected symmetric digraph with 10 vertices, 18 edges>
<immutable undirected tree digraph with 10 vertices>
gap> D := BananaTree(5, 2);
<immutable connected symmetric digraph with 11 vertices, 20 edges>
<immutable undirected tree digraph with 11 vertices>
gap> D := BananaTree(3, 4);
<immutable connected symmetric digraph with 13 vertices, 24 edges>
<immutable undirected tree digraph with 13 vertices>
gap> D := BananaTree(0, 0);
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
Error, no 1st choice method found for `BananaTree' on 2 arguments
Expand Down