-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun_me.py
executable file
·65 lines (54 loc) · 2.09 KB
/
run_me.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
64
65
#!/usr/bin/env python
"""
Sample executor showing the result of the stitching & validation methods.
"""
import argparse
import json
import sys
import logging
from networkx.readwrite import json_graph
from stitcher import bidding
from stitcher import evolutionary
from stitcher import iterative_repair
from stitcher import stitch
from stitcher import validators
from stitcher import vis
FORMAT = "%(asctime)s - %(filename)s - %(lineno)s - " \
"%(levelname)s - %(message)s"
logging.basicConfig(format=FORMAT, level=logging.DEBUG)
def main(algo):
"""
main routine.
"""
container_tmp = json.load(open('data/container.json'))
container = json_graph.node_link_graph(container_tmp, directed=True)
request_tmp = json.load(open('data/request.json'))
request = json_graph.node_link_graph(request_tmp, directed=True)
rels = json.load(open('data/stitch.json'))
conditions = {}
if algo == 'evolutionary':
# to show the true power of this :-)
conditions = {'compositions': [('diff', ('k', 'l'))]}
stitcher = evolutionary.EvolutionarySticher(rels)
elif algo == 'bidding':
# to show the true power of this :-)
conditions = {'attributes': [('lt', ('l', ('rank', 9)))]}
stitcher = bidding.BiddingStitcher(rels)
elif algo == 'repair':
# to show the true power of this :-)
conditions = {'attributes': [('eq', ('k', ('rank', 5)))]}
stitcher = iterative_repair.IterativeRepairStitcher(rels)
else:
stitcher = stitch.GlobalStitcher(rels)
graphs = stitcher.stitch(container, request, conditions=conditions)
if graphs:
results = validators.validate_incoming_edges(graphs, {'b': 5})
# XXX: disable this if you do not want to see the results.
vis.show(graphs, request, results)
if __name__ == '__main__':
OPT = ['global', 'evolutionary', 'bidding', 'repair']
PARSER = argparse.ArgumentParser()
PARSER.add_argument('-a', choices=OPT, default='global',
help='Select the stitching algorithm.')
ALGO = PARSER.parse_args(sys.argv[1:]).a
main(ALGO)