Skip to content
Open
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
31 changes: 30 additions & 1 deletion doc/oper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2133,9 +2133,38 @@ true
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="IsKParadoxicalTournament">
<ManSection>
<Oper Name="IsKParadoxicalTournament" Arg="digraph, int"/>
<Returns><K>true</K> or <K>false</K>.</Returns>
<Description>
A tournament <A>D</A> is <M>k</M>-<E>paradoxical</E> if for every set
<M>S</M> of <A>k</A> vertices there is a vertex outside <M>S</M> which
is an in-neighbour of every vertex in <M>S</M>, i.e. there is one player
who beats all the players of <M>S</M>. This is a generalisation of
<Ref Oper="IsParadoxicalTournament"/>.
<P/>
If <A>D</A> has no vertices, then the answer is <K>false</K>. If <A>D</A>
has at least one vertex and <A>k</A> is <C>0</C> then the answer is
<K>true</K>.
<P/>
If <A>k</A> is negative or <A>D</A> is not a tournament (see
<Ref Prop="IsTournament"/>), then an error is raised.
<Example><![CDATA[
gap> D := Digraph([[2, 3, 5], [3, 4, 6], [4, 5, 7], [5, 6, 1],
> [6, 7, 2], [7, 1, 3], [1, 2, 4]]);;
gap> IsKParadoxicalTournament(D, 2);
true
gap> IsKParadoxicalTournament(D, 3);
false]]></Example>
</Description>
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="DigraphDijkstra">
<ManSection>
<Oper Name="DigraphDijkstra" Arg="digraph, source, target" Label="for a source and target"/>
<Oper Name="DigraphDijkstra" Arg="digraph, source, target"
Label="for a source and target"/>
<Oper Name="DigraphDijkstra" Arg="digraph, source" Label="for a source"/>
<Returns>Two lists.</Returns>
<Description>
Expand Down
29 changes: 29 additions & 0 deletions doc/prop.xml
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,35 @@ false
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="IsParadoxicalTournament">
<ManSection>
<Prop Name="IsParadoxicalTournament" Arg="digraph"/>
<Returns><K>true</K> or <K>false</K>.</Returns>
<Description>
A tournament <A>D</A> is <E>paradoxical</E> if every vertex has at least
one in-neighbour, i.e. each player loses at least one game. This is the
same as being <M>1</M>-paradoxical; see
<Ref Oper="IsKParadoxicalTournament"/>.
<P/>
If <A>D</A> has no vertices, then the answer is <K>false</K>.
<P/>
If <A>D</A> is not a tournament (see <Ref Prop="IsTournament"/>), then an
error is raised.
<P/>

&MUTABLE_RECOMPUTED_PROP;

<Example><![CDATA[
gap> D := Digraph([[2], [3], [1]]);;
gap> IsParadoxicalTournament(D);
true
gap> D := Digraph([[2, 3], [3], []]);;
gap> IsParadoxicalTournament(D);
false]]></Example>
</Description>
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="IsChainDigraph">
<ManSection>
<Prop Name="IsChainDigraph" Arg="digraph"/>
Expand Down
1 change: 1 addition & 0 deletions doc/z-chap4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<#Include Label="DigraphOutEdges">
<#Include Label="IsDigraphEdge">
<#Include Label="IsMatching">
<#Include Label="IsKParadoxicalTournament">
<#Include Label="DigraphMaximalMatching">
<#Include Label="DigraphMaximumMatching">
</Section>
Expand Down
1 change: 1 addition & 0 deletions doc/z-chap5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<#Include Label="IsReflexiveDigraph">
<#Include Label="IsSymmetricDigraph">
<#Include Label="IsTournament">
<#Include Label="IsParadoxicalTournament">
<#Include Label="IsTransitiveDigraph">
</Section>

Expand Down
1 change: 1 addition & 0 deletions gap/oper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ DeclareOperation("IsPerfectMatching", [IsDigraph, IsHomogeneousList]);
DeclareOperation("IsDigraphPath",
[IsDigraph, IsHomogeneousList, IsHomogeneousList]);
DeclareOperation("IsDigraphPath", [IsDigraph, IsList]);
DeclareOperation("IsKParadoxicalTournament", [IsDigraph, IsInt]);

# 9. Connectivity . . .
DeclareOperation("DigraphIsKing", [IsDigraph, IsPosInt, IsPosInt]);
Expand Down
54 changes: 54 additions & 0 deletions gap/oper.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,60 @@ function(D, edges)
return true;
end);

InstallMethod(IsKParadoxicalTournament, "for a tournament and an integer",
[IsDigraph, IsInt],
function(D, k)
local n, inn_blist, backtrack;

if not IsTournament(D) then
ErrorNoReturn("the 1st argument <D> must be a tournament,");
fi;

if k < 0 then
ErrorNoReturn("the 2nd argument <k> must be non-negative,");
fi;

n := DigraphNrVertices(D);

if n = 0 then
return false;
fi;

if k = 0 then
return true;
fi;

if k = 1 then
return IsParadoxicalTournament(D);
fi;

# this minimum number of vertices needed for k-paradox is given by
# Szekeres, E.; Szekeres, G. (1965), "On a problem of Schütte and Erdős"
if n < (k + 2) * (2 ^ (k - 1)) - 1 then
return false;
fi;

inn_blist := List(InNeighbours(D), inn -> BlistList([1 .. n], inn));

backtrack := function(prev, depth, common)
local vertex, ncommon;
for vertex in [prev + 1 .. n - k + depth + 1] do
ncommon := IntersectionBlist(common, inn_blist[vertex]);
if SizeBlist(ncommon) = 0 then
return false;
fi;
if depth + 1 < k then
if not backtrack(vertex, depth + 1, ncommon) then
return false;
fi;
fi;
od;
return true;
end;

return backtrack(0, 0, BlistList([1 .. n], [1 .. n]));
end);

#############################################################################
# 9. Connectivity
#############################################################################
Expand Down
1 change: 1 addition & 0 deletions gap/prop.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ DeclareProperty("IsCompleteBipartiteDigraph", IsDigraph);
DeclareProperty("IsCompleteMultipartiteDigraph", IsDigraph);
DeclareProperty("IsCompleteDigraph", IsDigraph);
DeclareProperty("IsTournament", IsDigraph);
DeclareProperty("IsParadoxicalTournament", IsDigraph);
DeclareProperty("IsChainDigraph", IsDigraph);
DeclareProperty("IsCycleDigraph", IsDigraph);
DeclareProperty("IsDigraphCore", IsDigraph);
Expand Down
14 changes: 14 additions & 0 deletions gap/prop.gi
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,20 @@ function(D)
return IsAntisymmetricDigraph(D);
end);

InstallMethod(IsParadoxicalTournament, "for a tournament",
[IsDigraph],
function(D)
if not IsTournament(D) then
ErrorNoReturn("the argument <D> must be a tournament,");
fi;

if DigraphNrVertices(D) = 0 then
return false;
else
return not ForAny(InNeighbours(D), IsEmpty);
fi;
end);

InstallMethod(IsEmptyDigraph, "for a digraph with known number of edges",
[IsDigraph and HasDigraphNrEdges],
D -> DigraphNrEdges(D) = 0);
Expand Down
30 changes: 30 additions & 0 deletions tst/standard/oper.tst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,36 @@ gap> gr := Digraph([[], [3, 4], [1, 4], [1]]);
gap> DigraphIsKing(gr, 2, 2);
Error, the 1st argument <D> must be a tournament,

# IsKParadoxicalTournament: for a tournament and a non-negative integer
gap> gr := Digraph([[2], [1]]);;
gap> IsKParadoxicalTournament(gr, 1);
Error, the 1st argument <D> must be a tournament,
gap> gr := EmptyDigraph(0);;
gap> IsKParadoxicalTournament(gr, 0);
false
gap> IsKParadoxicalTournament(gr, 1);
false
gap> gr := Digraph([[]]);;
gap> IsKParadoxicalTournament(gr, 0);
true
gap> IsKParadoxicalTournament(gr, -1);
Error, the 2nd argument <k> must be non-negative,
gap> gr := Digraph([[2], [3], [1]]);;
gap> IsKParadoxicalTournament(gr, 1);
true
gap> gr := Digraph([[2, 4, 7], [4, 5, 7], [1, 2, 4, 6, 7],
> [], [1, 3, 4, 6, 7], [1, 2, 4, 7], [4]]);;
gap> IsKParadoxicalTournament(gr, 2);
false
gap> gr := p -> Digraph(
> List([0 .. p - 1],
> x -> List(Set(List([1 .. (p - 1) / 2], i -> i ^ 2 mod p)),
> s -> (x + s) mod p + 1)));;
gap> IsKParadoxicalTournament(gr(19), 3);
true
gap> IsKParadoxicalTournament(gr(19), 4);
false

# DigraphRemoveLoops
gap> gr := DigraphFromDigraph6String("&EhxPC?@");
<immutable digraph with 6 vertices, 11 edges>
Expand Down
18 changes: 18 additions & 0 deletions tst/standard/prop.tst
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,24 @@ gap> gr := Digraph([[2], [1], [1]]);
gap> IsTournament(gr);
false

# IsParadoxical
gap> gr := Digraph([[2], [1]]);;
gap> IsParadoxicalTournament(gr);
Error, the argument <D> must be a tournament,
gap> gr := EmptyDigraph(0);;
gap> IsParadoxicalTournament(gr);
false
gap> gr := Digraph([[2, 3], [3], []]);;
gap> IsTournament(gr);
true
gap> IsParadoxicalTournament(gr);
false
gap> gr := Digraph([[2], [3], [1]]);;
gap> IsTournament(gr);
true
gap> IsParadoxicalTournament(gr);
true

# IsStronglyConnectedDigraph
gap> gr := Digraph([]);
<immutable empty digraph with 0 vertices>
Expand Down
Loading