def test_two_nonterm(algo): test_data_path = LOCAL_CFPQ_DATA.joinpath('two_nonterm') base_algo: BaseProblem = algo() graph = Graph.from_txt(test_data_path.joinpath('Graphs/graph_1.txt')) grammar = cfg_from_txt(test_data_path.joinpath('Grammars/g.cfg')) base_algo.prepare(graph, grammar) result: ResultAlgo = base_algo.solve() assert result.matrix_S.nvals == 156
def test_case_1_graph_1(): test_case_1_path = LOCAL_CFPQ_DATA.joinpath('test_case_1') path_to_graph = test_case_1_path.joinpath('Matrices/graph_1') path_to_grammar = test_case_1_path.joinpath('Grammars/grammar') algo = MatrixSinglePathAlgo(path_to_graph, path_to_grammar) res_graph = algo.solve() assert res_graph["S"].nvals == 2
def test_case_cycle(): path = LOCAL_CFPQ_DATA.joinpath('tensor/test_cycle') path_to_graph = path.joinpath('graph_cycle') path_to_grammar = path.joinpath('rsa_cycle') algo1 = TensorAlgoSimple(path_to_graph, path_to_grammar) algo2 = TensorAlgoDynamic(path_to_graph, path_to_grammar) res_graph1 = algo1.solve() res_graph2 = algo2.solve() assert res_graph1["S"].nvals == res_graph2["S"].nvals == 9
def test_two_nonterm(algo): test_data_path = LOCAL_CFPQ_DATA.joinpath('two_nonterm') ms_algo: MultipleSourceProblem = algo() graph = Graph.from_txt(test_data_path.joinpath('Graphs/graph_1.txt')) grammar = cfg_from_txt(test_data_path.joinpath('Grammars/g.cfg')) ms_algo.prepare(graph, grammar) result: ResultAlgo result, with_cache = ms_algo.solve([1]) assert result.matrix_S.nvals == 1 and with_cache.nvals == 1
def test_two_nonterm(algo): test_data_path = LOCAL_CFPQ_DATA.joinpath('two_nonterm') singlepath_algo: SinglePathProblem = algo() graph = Graph.from_txt(test_data_path.joinpath('Graphs/graph_1.txt')) grammar = cfg_from_txt(test_data_path.joinpath('Grammars/g.cfg')) singlepath_algo.prepare(graph, grammar) result: ResultAlgo = singlepath_algo.solve() assert result.matrix_S.nvals == 156 paths = singlepath_algo.getPath(1, 1, "S") assert paths == 2
def test_two_nonterm(algo): test_data_path = LOCAL_CFPQ_DATA.joinpath('two_nonterm') allpath_algo: AllPathsProblem = algo() graph = Graph.from_txt(test_data_path.joinpath('Graphs/graph_1.txt')) grammar = cfg_from_txt(test_data_path.joinpath('Grammars/g.cfg')) allpath_algo.prepare(graph, grammar) result: ResultAlgo = allpath_algo.solve() assert result.matrix_S.nvals == 156 allpath_algo.prepare_for_exctract_paths() paths = allpath_algo.getPaths(1, 1, "S", 3) assert len(paths) == 1
def test_case_1_graph_1(algo): # (0)-[a]->(1)-[a]->(2)-[b]->(3)-[b]->(4) # S -> a S b | a b test_case_1_path = LOCAL_CFPQ_DATA.joinpath('test_case_1') graph = LabelGraph.from_txt( test_case_1_path.joinpath('Matrices/graph_1.txt')) grammar = CnfGrammar.from_cnf( test_case_1_path.joinpath('Grammars/grammar.cnf')) single_source: SingleSourceSolver = algo(graph, grammar) m, _ = single_source.solve([1]) assert vecbool_to_list(m[1]) == [3] m, _ = single_source.solve([0]) assert vecbool_to_list(m[0]) == [4]
def test_case_1_graph_2(algo): # (6) # / \ # (2) (5) # / \ / \ # (0) (1) (3) (4) # Upstream edges labeled by "a", downstream by "b" # S -> a S b | a b test_case_1_path = LOCAL_CFPQ_DATA.joinpath('test_case_1') graph = LabelGraph.from_txt( test_case_1_path.joinpath('Matrices/graph_2.txt')) grammar = CnfGrammar.from_cnf( test_case_1_path.joinpath('Grammars/grammar.cnf')) single_source: SingleSourceSolver = algo(graph, grammar) m, _ = single_source.solve([0]) assert vecbool_to_list(m[0]) == [0, 1, 3, 4] m, _ = single_source.solve([2]) assert vecbool_to_list(m[2]) == [2, 5]