mirror of
https://github.com/Brandon-Rozek/matmod.git
synced 2025-07-29 20:52:01 +00:00
Add flag to ignore constants during model equivalence
This commit is contained in:
parent
7305b358a9
commit
6d7fc9094a
2 changed files with 16 additions and 4 deletions
15
model.py
15
model.py
|
@ -360,7 +360,7 @@ def model_closure(initial_set: Set[ModelValue], mfunctions: Set[ModelFunction],
|
||||||
return closure_set
|
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.
|
Takes two models and determines if they are equivalent.
|
||||||
Assumes for the model to be equilvalent that their
|
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:
|
if model1.designated_values != model2.designated_values:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
model1_fn_names = set((fn.operation_name for fn in model1.logical_operations))
|
model1_fn_names = set()
|
||||||
model2_fn_names = set((fn.operation_name for fn in model2.logical_operations))
|
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:
|
if model1_fn_names != model2_fn_names:
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -26,6 +26,7 @@ if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description="Compare models that have VSP in two ugly files")
|
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("ugly1", type=str, help="First ugly data file")
|
||||||
parser.add_argument("ugly2", type=str, help="Second 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())
|
args = vars(parser.parse_args())
|
||||||
|
|
||||||
data_file1 = open(args['ugly1'], "r")
|
data_file1 = open(args['ugly1'], "r")
|
||||||
|
@ -36,6 +37,8 @@ if __name__ == "__main__":
|
||||||
solutions2 = parse_matrices(SourceFile(data_file2))
|
solutions2 = parse_matrices(SourceFile(data_file2))
|
||||||
solutions2 = list(restructure_solutions(solutions2, None))
|
solutions2 = list(restructure_solutions(solutions2, None))
|
||||||
|
|
||||||
|
ignore_constants = args.get("ignore_constants", False)
|
||||||
|
|
||||||
# Total count of models
|
# Total count of models
|
||||||
total_models1 = 0
|
total_models1 = 0
|
||||||
total_models2 = 0
|
total_models2 = 0
|
||||||
|
@ -62,7 +65,7 @@ if __name__ == "__main__":
|
||||||
# Check to see if model exists in file 2
|
# Check to see if model exists in file 2
|
||||||
match_found_index = (False, -1)
|
match_found_index = (False, -1)
|
||||||
for i in range(len(solutions2) - 1, -1, -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)
|
match_found_index = (True, i)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue