1414 LazyAddMatrixSetting
1515from cfpq_cli .time_limit import time_limit , TimeoutException
1616from cfpq_decomposer .high_performance_decomposer import HighPerformanceDecomposer
17+ from cfpq_decomposer .prototype_decomposer import PrototypeDecomposer
1718from cfpq_model .cnf_grammar_template import CnfGrammarTemplate
1819from cfpq_model .label_decomposed_graph import LabelDecomposedGraph
1920
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