Skip to content

Commit

Permalink
Implement standartization
Browse files Browse the repository at this point in the history
  • Loading branch information
reiniscirpons committed Nov 22, 2023
1 parent 18c91c5 commit 0fe68c2
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions tests/gap.g
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
LoadPackage("Digraphs");
LoadPackage("Semigroups");

AsWordGraph := function(C)
local lookup, S, A, out, next, pos, class, a;

Expand All @@ -19,33 +22,42 @@ AsWordGraph := function(C)
return Digraph(out);
end;

StandardizeWordGraph := function(D)
local s, t, N, n, result, x, r;
StandardizeWordGraph := function(D, root)
local i, alph, letter, que, seen, node, child, next_node, perm;

# TODO arg checks
if IsNullDigraph(D) then
return D;
fi;
s := 0;
t := 0;
N := OutNeighbours(D);
n := Length(N[1]);
result := DigraphMutableCopy(D);

while s <= t do
for x in [1 .. n] do
r := N[s + 1][x];
if r > t then
t := t + 1;
if r > t then
OnDigraphs(result, (t + 1, r));
N := OutNeighbours(result);
fi;
i := 1;
que := [root];
seen := BlistList([1 .. DigraphNrVertices(D)], [root]);
next_node := OutNeighbours(D);
alph := Length(next_node[root]);

while i <= Length(que) do
node := que[i];
for letter in [1 .. alph] do
child := next_node[node][letter];
if not seen[child] then
Append(que, child);
seen[child] := true;
fi;
od;
s := s + 1;
i := i + 1;
od;
return result;

if Length(que) <> DigraphNrVertices(D) then
# Not all nodes reachable from root!
return fail;
fi;

perm := List([1 .. Length(que)], x -> 0);
for i in [1 .. Length(que)] do
perm[que[i]] := i;
od;
return OnDigraphs(D, perm);
end;

ToWordGraphs := function(Cs)
Expand Down

0 comments on commit 0fe68c2

Please sign in to comment.