Skip to content

Commit 4a9486b

Browse files
committed
Add --prototype in cfpq_decomposer_cli
1 parent 5df9420 commit 4a9486b

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

cfpq_decomposer_cli/decompose_cflr_matrix.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
LazyAddMatrixSetting
1515
from cfpq_cli.time_limit import time_limit, TimeoutException
1616
from cfpq_decomposer.high_performance_decomposer import HighPerformanceDecomposer
17+
from cfpq_decomposer.prototype_decomposer import PrototypeDecomposer
1718
from cfpq_model.cnf_grammar_template import CnfGrammarTemplate
1819
from cfpq_model.label_decomposed_graph import LabelDecomposedGraph
1920

@@ -23,9 +24,10 @@
2324
OptimizeFormatMatrixSetting()
2425
]
2526

26-
def decompose_all_pairs_cflr(solution: Matrix):
27+
def decompose_all_pairs_cflr(solution: Matrix, use_prototype: bool):
2728
start = time()
28-
left, right = HighPerformanceDecomposer().decompose(solution)
29+
decomposer = PrototypeDecomposer() if use_prototype else HighPerformanceDecomposer()
30+
left, right = decomposer.decompose(solution)
2931
finish = time()
3032
print(f"Decomposition time\t{finish - start}")
3133
left_right = left.mxm(right, op=graphblas.semiring.any_pair)
@@ -40,7 +42,8 @@ def run_and_decompose_all_pairs_cflr(
4042
graph_path: str,
4143
grammar_path: str,
4244
out_path: Optional[str],
43-
time_limit_sec: int
45+
time_limit_sec: int,
46+
use_prototype: bool,
4447
):
4548
algo = IncrementalAllPairsCFLReachabilityMatrixAlgo()
4649
graph = LabelDecomposedGraph.read_from_pocr_graph_file(graph_path)
@@ -56,7 +59,7 @@ def run_and_decompose_all_pairs_cflr(
5659
finish = time()
5760
print(f"AnalysisTime\t{finish - start}")
5861
print(f"#SEdges\t{res.nvals}")
59-
decompose_all_pairs_cflr(res)
62+
decompose_all_pairs_cflr(res, use_prototype)
6063
if out_path is not None:
6164
out_dir = os.path.dirname(out_path)
6265
if out_dir != "" and not os.path.exists(out_dir):
@@ -101,12 +104,17 @@ def main(raw_args: List[str]):
101104
'to [END_VERTEX], labels along which spell a word from '
102105
'the specified Context-Free Language (CFL).'
103106
)
107+
parser.add_argument('--prototype',
108+
action='store_true',
109+
dest='prototype',
110+
help='Use PrototypeDecomposer instead of HighPerformanceDecomposer.')
104111
args = parser.parse_args(raw_args)
105112
run_and_decompose_all_pairs_cflr(
106113
graph_path=args.graph,
107114
grammar_path=args.grammar,
108115
time_limit_sec=args.time_limit,
109116
out_path=args.out,
117+
use_prototype=args.prototype,
110118
)
111119

112120

0 commit comments

Comments
 (0)