Skip to content

Commit 7f64286

Browse files
committed
Result normalization added.
1 parent f24f480 commit 7f64286

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

cfpq_add_context/add_contexts.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@ def add_context(file_path):
127127
decomposition_end = time.perf_counter()
128128
print("Graph decomposition competed in ", decomposition_end - intersection_end)
129129

130-
return decomposed_result
130+
return (decomposed_result, graph.ncols)
131+
132+
def normalize(solver_result, initial_graph_nvertices):
133+
134+
normalization_start = time.perf_counter()
135+
136+
c = solver_result.ncols // initial_graph_nvertices
137+
start_vertices = set([i * c for i in range(0,initial_graph_nvertices)])
138+
edges = solver_result.to_edgelist()
139+
edges = zip(edges[0], edges[1])
140+
new_edges = set([(_edg[0] // c, _edg[1] // c) for (_edg, _lbl) in edges if _edg[0] in start_vertices])
141+
result = Matrix.from_edgelist(new_edges, values=True, dtype=BOOL, nrows = initial_graph_nvertices,
142+
ncols=initial_graph_nvertices, name = "normalized_solver_result")
143+
normalization_end = time.perf_counter()
144+
print("Normalization of solver result done in ", normalization_end - normalization_start)
145+
146+
return result
131147

132148

cfpq_cli/run_all_pairs_cflr.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from cfpq_cli.time_limit import time_limit, TimeoutException
1414
from cfpq_model.cnf_grammar_template import CnfGrammarTemplate
1515
from cfpq_model.label_decomposed_graph import LabelDecomposedGraph
16-
from cfpq_add_context.add_contexts import add_context
16+
from cfpq_add_context.add_contexts import add_context, normalize
1717

1818

1919
def run_all_pairs_cflr(
@@ -27,16 +27,20 @@ def run_all_pairs_cflr(
2727
):
2828
algo = get_all_pairs_cfl_reachability_algo(algo_name)
2929
if add_contexts:
30-
graph = add_context(graph_path)
30+
graph,initial_graph_nvertices = add_context(graph_path)
3131
else:
3232
graph = LabelDecomposedGraph.read_from_pocr_graph_file(graph_path)
33+
print ("graph = ", graph)
3334
grammar = CnfGrammarTemplate.read_from_pocr_cnf_file(grammar_path)
3435
graph, grammar = preprocess_graph_and_grammar(graph, grammar, settings)
3536
try:
3637
with time_limit(time_limit_sec):
3738
start = time()
3839
res = algo.solve(graph=graph, grammar=grammar, settings=settings)
40+
if add_contexts:
41+
res = normalize(res, initial_graph_nvertices)
3942
finish = time()
43+
print("result: ", res)
4044
print(f"AnalysisTime\t{finish - start}")
4145
print(f"#SEdges\t{res.nvals}")
4246
if out_path is not None:

0 commit comments

Comments
 (0)