diff --git a/model.py b/model.py index ffebfb1..429a26e 100644 --- a/model.py +++ b/model.py @@ -360,7 +360,7 @@ def model_closure(initial_set: Set[ModelValue], mfunctions: Set[ModelFunction], return closure_set -def model_equivalence(model1: Model, model2: Model) -> bool: +def model_equivalence(model1: Model, model2: Model, ignore_constants: bool = False) -> bool: """ Takes two models and determines if they are equivalent. Assumes for the model to be equilvalent that their @@ -373,8 +373,17 @@ def model_equivalence(model1: Model, model2: Model) -> bool: if model1.designated_values != model2.designated_values: return False - model1_fn_names = set((fn.operation_name for fn in model1.logical_operations)) - model2_fn_names = set((fn.operation_name for fn in model2.logical_operations)) + model1_fn_names = set() + for fn in model1.logical_operations: + if fn.arity == 0 and ignore_constants: + continue + model1_fn_names.add(fn.operation_name) + + model2_fn_names = set() + for fn in model2.logical_operations: + if fn.arity == 0 and ignore_constants: + continue + model2_fn_names.add(fn.operation_name) if model1_fn_names != model2_fn_names: return False diff --git a/utils/compare_vsp_results.py b/utils/compare_vsp_results.py index daee3c5..82c587d 100644 --- a/utils/compare_vsp_results.py +++ b/utils/compare_vsp_results.py @@ -26,6 +26,7 @@ if __name__ == "__main__": parser = argparse.ArgumentParser(description="Compare models that have VSP in two ugly files") parser.add_argument("ugly1", type=str, help="First ugly data file") parser.add_argument("ugly2", type=str, help="Second ugly data file") + parser.add_argument("--ignore-constants", action='store_true', help="When it comes to model equivalance, ignore constants") args = vars(parser.parse_args()) data_file1 = open(args['ugly1'], "r") @@ -36,6 +37,8 @@ if __name__ == "__main__": solutions2 = parse_matrices(SourceFile(data_file2)) solutions2 = list(restructure_solutions(solutions2, None)) + ignore_constants = args.get("ignore_constants", False) + # Total count of models total_models1 = 0 total_models2 = 0 @@ -62,7 +65,7 @@ if __name__ == "__main__": # Check to see if model exists in file 2 match_found_index = (False, -1) for i in range(len(solutions2) - 1, -1, -1): - if model_equivalence(model, solutions2[i][0]): + if model_equivalence(model, solutions2[i][0], ignore_constants): match_found_index = (True, i) break