Skip to content

Commit

Permalink
Speed up OnDigraphs for a graph and a permutation
Browse files Browse the repository at this point in the history
* Instead of checking if the permutation fixes the vertices, check
if it is the identity (which is much cheaper, although catches
less cases)

* Do not check explictly if the permutation maps the vertices
  of the graph to itself, do the mapping then check afterwards.
  • Loading branch information
ChrisJefferson authored and wilfwilson committed May 22, 2021
1 parent bc55fe2 commit 2b23a40
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions gap/oper.gi
Original file line number Diff line number Diff line change
Expand Up @@ -665,15 +665,19 @@ end);
InstallMethod(OnDigraphs, "for a mutable digraph by out-neighbours and a perm",
[IsMutableDigraph and IsDigraphByOutNeighboursRep, IsPerm],
function(D, p)
local out;
if ForAll(DigraphVertices(D), i -> i ^ p = i) then
local out, permed;
if p = () then
return D;
elif ForAny(DigraphVertices(D), i -> i ^ p > DigraphNrVertices(D)) then
fi;

out := D!.OutNeighbours;
permed := Permuted(out, p);
if Length(permed) > DigraphNrVertices(D) then
ErrorNoReturn("the 2nd argument <p> must be a permutation that permutes ",
"of the digraph <D> that is the 1st argument,");
fi;
out := D!.OutNeighbours;
out{DigraphVertices(D)} := Permuted(out, p);

out{DigraphVertices(D)} := permed;
Apply(out, x -> OnTuples(x, p));
ClearDigraphEdgeLabels(D);
return D;
Expand All @@ -682,7 +686,7 @@ end);
InstallMethod(OnDigraphs, "for a immutable digraph and a perm",
[IsImmutableDigraph, IsPerm],
function(D, p)
if ForAll(DigraphVertices(D), i -> i ^ p = i) then
if p = () then
return D;
fi;
return MakeImmutable(OnDigraphs(DigraphMutableCopy(D), p));
Expand Down

0 comments on commit 2b23a40

Please sign in to comment.