-
Notifications
You must be signed in to change notification settings - Fork 0
/
gap_automorphism_group_finder
66 lines (57 loc) · 1.55 KB
/
gap_automorphism_group_finder
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
[ -f "./gap_config.sh" ] && {
. ./gap_config.sh
}
[ -z "$GAP" ] && {
>&2 echo "error: please, make sure GAP variable is set"
>&2 echo "(you can create gap_config.sh file, it will then be automatically sourced)"
exit 1
}
[ -f "$GAP" ] || {
>&2 echo "error: seems like [GAP=$GAP] does not point to a file"
exit 1
}
gfile=$1;shift
[ -z "$gfile" ] && {
>&2 echo "error: please, specify file for G"
exit 1
}
[ -f "$gfile" ] || {
>&2 echo "error: couldn't find a valid file for G"
exit 1
}
create_adjacency_list() {
file=$1; shift
echo "
from graph_utils import *
import json
if __name__ == '__main__':
g = load_graph('$file')
nodes = list(g.nodes())
edges = list(g.edges())
adj = []
for u in nodes:
row = []
for v in nodes:
e1, e2 = [u, v], [v, u]
if e1 in edges or e2 in edges:
row += [v + 1]
adj += [row]
print(adj)
"
}
gap_script="
LoadPackage(\"Digraphs\");
g := Digraph($(env python3 -c "$(create_adjacency_list "$gfile")"));
a := AutomorphismGroup(g);
Print(\"RESULT\", a, \"_\", Size(a), \"\\n\");
"
start=0
result=$($GAP --quitonbreak <<< "${gap_script}" | while IFS= read -r line; do
[ -z "$(echo "$line" | grep 'RESULT')" ] || start=1
[ $start -eq 1 ] && {
echo "$line" | sed 's/ //g'
}
done | tr '\n' ' ' | sed -e 's/.*RESULT//' -e 's/Group//g')
result=$(env python3 -c "result = '$result'.strip().replace('),(', '), (').split('_');print('size=' + str(result[1]), result[0][1:-1])")
echo "$gfile $result"