-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrickgen.py
More file actions
executable file
·118 lines (97 loc) · 3.83 KB
/
Copy pathbrickgen.py
File metadata and controls
executable file
·118 lines (97 loc) · 3.83 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/home/s4n7h05h/sage/sage
import argparse, sys, subprocess
from itertools import combinations
import NTfamily, operations
DEFAULT_SHORTG_PATH = './shortg'
class Parser(argparse.ArgumentParser):
def error(self, message):
print(f'error!\t{message}')
sys.exit(1)
def _filename(n,m):
return f'{args.path}/bricks-{n}-{m}.g6'
def _is_valid(n,m):
return n >= 4 and 2*m >= 3*n and 2*m <= n*(n-1)
from itertools import combinations
def _apply_operation_on_a_particular_brick(g6_string, index):
H = Graph(g6_string)
degree_at_least_four = [v for v in H.vertices() if H.degree(v) >= 4]
degree_at_least_five = [v for v in H.vertices() if H.degree(v) >= 5]
if index == 0:
yield from operations.index_zero(H)
elif index == 1:
for v in degree_at_least_four:
yield from operations.index_one(H, v)
elif index == 2:
for u, v in combinations(degree_at_least_four, 2):
yield from operations.index_two(H, u, v)
elif index == 3:
for v in degree_at_least_five:
yield from operations.index_three(H, v)
def _apply_operation_on_all_bricks(n,m,index):
if not _is_valid(n,m):
return
with open(_filename(n, m), "r") as input_file:
for smaller_brick in input_file:
for brick in _apply_operation_on_a_particular_brick(smaller_brick,index):
yield brick.graph6_string()
def generate_bricks(n,m):
print(f'Generating simple bricks of order {n} and size {m}')
# generate Norine-Thomas bricks first
# K_4 is hardcoded
if n == 4 and m == 6:
yield 'C~'
return
if n == 10 and m == 15:
yield graphs.PetersenGraph().graph6_string()
if 2*m == 3*n:
prism_or_mobius_ladder = NTfamily.prism if n % 4 == 2 else NTfamily.mobius_ladder
yield prism_or_mobius_ladder(n).graph6_string()
yield NTfamily.staircase(n).graph6_string()
elif m == 2*n-2:
yield NTfamily.wheel(n).graph6_string()
elif m == 2*n-3:
yield NTfamily.truncated_biwheel(n).graph6_string()
# now generate other bricks using the four operations, if possible
yield from _apply_operation_on_all_bricks( n, m-1, 0 )
yield from _apply_operation_on_all_bricks( n-2, m-3, 1 )
yield from _apply_operation_on_all_bricks( n-4, m-5, 2 )
yield from _apply_operation_on_all_bricks( n-4, m-5, 3 )
if __name__ == '__main__':
print('Importing sage...',end='',flush=True)
from sage.all import *
from sage.version import version
print(f'\rRunning SageMath version {version}')
parser = Parser(prog='./brickgen.py', usage='%(prog)s order size',description='Generate (simple) bricks using the Strictly Thin Edge Theorem.')
# parser.add_argument('-n', '--order', metavar='order', type=int, required=True, help='The order of the bricks to be generated.')
# parser.add_argument('-m', '--size', metavar='size', type=int, required=True, help='The size of the bricks to be generated.')
parser.add_argument('n', type=int, nargs='?', help='the order of the bricks to be generated')
parser.add_argument('m', type=int, nargs='?', help='the size of the bricks to be generated')
parser.add_argument(
'-s',
'--shortg-path',
metavar='path_to_shortg',
type=str,
default='./shortg',
help='to remove isomorphic copies using shortg (default: ./shortg)'
)
parser.add_argument(
'-p',
'--path',
metavar='path_to_working_folder',
type=str,
default = './g6files/',
help='path of the working folder that has all the g6 files (default: ./g6files/)'
)
args = parser.parse_args()
if args.n is None or args.m is None:
parser.error('order and size are required\ntry\'./brickgen.py --help\' for more information')
if not (args.n%2==0 and _is_valid(args.n,args.m)):
parser.error(f'there are no simple bricks of order {args.n} and size {args.m}')
with open(_filename(args.n, args.m), "x") as output_file:
for brick in generate_bricks(args.n, args.m):
output_file.write(brick +'\n')
try:
subprocess.run([ args.shortg_path, _filename(args.n, args.m) ])
except:
parser.error('invalid path to shortg')
sys.exit(0)