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 23, 2021
1 parent ccae5d3 commit 473853b
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 473853b

Please sign in to comment.