-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.py
63 lines (54 loc) · 2.16 KB
/
cli.py
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
import argparse
from comb_spec_searcher import StrategyPack
from tilescopethree import StrategyPacks, TileScopeTHREE
from tilings import Tiling
def list_stratpacks(args):
"""
Prints out every strategy pack available.
"""
for pack in dir(StrategyPacks):
if isinstance(getattr(StrategyPacks, pack), StrategyPack):
print(pack)
return 0
def search_tree(args):
"""
Search for a tree.
"""
print('searching for a tree')
try:
pack_to_run = getattr(StrategyPacks, args.strategy_pack)
except AttributeError as e:
print("Strategy pack '{}' was not found".format(args.strategy_pack))
return 1
start_class = Tiling.from_string(args.basis)
css = TileScopeTHREE(start_class, pack_to_run)
css.auto_search(status_update=30)
return 0
def main():
parser = argparse.ArgumentParser(
description='A command line tool for the Periscope algorithm.'
)
subparsers = parser.add_subparsers(title='subcommands')
# List command
helpstr = 'List all the strategy pack available'
parser_list = subparsers.add_parser('list', help=helpstr,
description=helpstr)
parser_list.set_defaults(func=list_stratpacks)
# Tree command
helpstr = ('Search for a tree with for a given permutation class with a '
'given strategy pack.')
parser_tree = subparsers.add_parser('tree', help=helpstr,
description=helpstr)
parser_tree.add_argument('basis', type=str, help='The basis of the '
'permutation class. The permutation can be 1 or '
'0-based and are separated by an underscore')
parser_tree.add_argument('strategy_pack', type=str, help='The strategy '
'pack to run. The strategy defines the set of '
'strategy that will be used to expand the '
'universe of combinatorial classes.')
parser_tree.set_defaults(func=search_tree)
# Running the parsers
args = parser.parse_args()
return args.func(args)
if __name__ == "__main__":
main()