Skip to content

Commit 61f9de8

Browse files
committed
Optional results validation.
1 parent 78a1638 commit 61f9de8

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

cfpq_add_context/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,12 @@ def print_matrix_to_dot(matrix, file):
1010
for (_edg, _lbl) in edges:
1111
print (str (_edg[0]) + " -> " + str(_edg[1]) + "[label=" + str(_lbl) +"]", file = f)
1212
print("}", file = f)
13+
14+
def verify(result, expected_path):
15+
with open(expected_path, 'r') as file:
16+
expected = set([(int(line[0]),int(line[2])) for line in [line.strip().split(" ") for line in file]])
17+
res = expected.issubset(result)
18+
if not res:
19+
for i in expected.difference(result):
20+
print("Missed: ", i)
21+
return res

cfpq_cli/run_all_pairs_cflr.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from cfpq_model.cnf_grammar_template import CnfGrammarTemplate
1515
from cfpq_model.label_decomposed_graph import LabelDecomposedGraph
1616
from cfpq_add_context.add_contexts import add_context, normalize
17+
from cfpq_add_context.utils import verify
1718

1819

1920
def run_all_pairs_cflr(
@@ -24,13 +25,13 @@ def run_all_pairs_cflr(
2425
out_path: Optional[str],
2526
settings: List[AlgoSetting],
2627
add_contexts: bool = False,
28+
expected_path: str = "",
2729
):
2830
algo = get_all_pairs_cfl_reachability_algo(algo_name)
2931
if add_contexts:
3032
graph,initial_graph_nvertices = add_context(graph_path)
3133
else:
3234
graph = LabelDecomposedGraph.read_from_pocr_graph_file(graph_path)
33-
print ("graph = ", graph)
3435
grammar = CnfGrammarTemplate.read_from_pocr_cnf_file(grammar_path)
3536
graph, grammar = preprocess_graph_and_grammar(graph, grammar, settings)
3637
try:
@@ -39,6 +40,8 @@ def run_all_pairs_cflr(
3940
res = algo.solve(graph=graph, grammar=grammar, settings=settings)
4041
if add_contexts:
4142
res = normalize(res, initial_graph_nvertices)
43+
if not ((len(expected_path) > 0) and (verify(res, expected_path))):
44+
print("Incorrect result !!!")
4245
finish = time()
4346
print("result: ", res)
4447
print(f"AnalysisTime\t{finish - start}")
@@ -90,6 +93,9 @@ def main(raw_args: List[str]):
9093
parser.add_argument('--add_contexts', dest='add_contexts', default=False,
9194
help='Specifies whether approximation of context sensitivity should be added.'
9295
)
96+
parser.add_argument('--expected_path', dest='expected_path', default="",
97+
help='If specified, it will be checked wether solver\'s result is overapproximation of represented in the file.'
98+
)
9399
settings_manager = AlgoSettingsManager()
94100
settings_manager.add_args(parser)
95101
args = parser.parse_args(raw_args)
@@ -98,6 +104,7 @@ def main(raw_args: List[str]):
98104
graph_path=args.graph,
99105
grammar_path=args.grammar,
100106
add_contexts=args.add_contexts,
107+
expected_path=args.expected_path,
101108
time_limit_sec=args.time_limit,
102109
out_path=args.out,
103110
settings=settings_manager.read_args(args)

0 commit comments

Comments
 (0)