From 0fe68c28d13f61e7f491033cfb3e7585d1ea5d7c Mon Sep 17 00:00:00 2001 From: Reinis Cirpons Date: Wed, 22 Nov 2023 13:11:12 +0000 Subject: [PATCH] Implement standartization --- tests/gap.g | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/tests/gap.g b/tests/gap.g index 36c3189d0..477cd48c8 100644 --- a/tests/gap.g +++ b/tests/gap.g @@ -1,3 +1,6 @@ +LoadPackage("Digraphs"); +LoadPackage("Semigroups"); + AsWordGraph := function(C) local lookup, S, A, out, next, pos, class, a; @@ -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)