Loading src/aligater.py +52 −25 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ from time import time_ns ############### Some constants ######################### RABIT_MIN = "mr" DFA_MIN = "md" RABIT_MIN_AFTER = "mra" VALIDATE = "v" F_POWERSET = "f" Loading Loading @@ -58,9 +59,6 @@ def run_gate_complement(ext_nfa: ExtendedNFA, data["type"] = "NONE" data["complement_time_ns"] = "N/A" if rabit: data["gate_size_rabit_min"] = "N/A" data["rabit_min_time_ns"] = "N/A" return None complement_start_time = time_ns() Loading @@ -79,29 +77,22 @@ def run_gate_complement(ext_nfa: ExtendedNFA, data["type"] = gate_pair.type data["complement_time_ns"] = complement_time if rabit: rabit_start_time = time_ns() gate_comp = cmpl.rabit_minimize(gate_comp) rabit_time = time_ns() - rabit_start_time if gate_comp is not None: data["gate_size_rabit_min"] = len(gate_comp.states) data["rabit_min_time_ns"] = rabit_time else: data["gate_size_rabit_min"] = "ERROR" data["rabit_min_time_ns"] = "ERROR" return gate_comp def run_port_complement(ext_nfa: ExtendedNFA, data: dict, minify_rabit: bool = False, minify_dfa: bool = False) \ minify_dfa: bool = False, lookahead: int = cmpl.LOOKAHEAD_DEFAULT) \ -> ExtendedNFA: start_time = time_ns() comp = port_complement(ext_nfa, minify_rabit=minify_rabit, minify_dfa=minify_dfa, data_dict=data) comp = port_complement(ext_nfa, minify_rabit=minify_rabit, minify_dfa=minify_dfa, lookahead=lookahead, data_dict=data) comp_time = time_ns() - start_time data["port_comp_size"] = len(comp.states) Loading Loading @@ -178,6 +169,26 @@ def load_from_file(file_path: str) -> None | tuple[ExtendedNFA, str]: return ext_nfa, name def run_rabit_minimize_after(comp: ExtendedNFA | None, data: dict, lookahead: int = cmpl.LOOKAHEAD_DEFAULT): if comp is not None: rabit_start_time = time_ns() min_comp = cmpl.rabit_minimize(comp, lookahead=lookahead) rabit_time = time_ns() - rabit_start_time if min_comp is not None: data["gate_size_rabit_min"] = len(min_comp.states) data["rabit_min_time_ns"] = rabit_time else: data["gate_size_rabit_min"] = "ERROR" data["rabit_min_time_ns"] = "ERROR" else: data["gate_size_rabit_min"] = "N/A" data["rabit_min_time_ns"] = "N/A" def complement_from_file(file_path: str, mode: str, options: list[str], Loading @@ -185,7 +196,8 @@ def complement_from_file(file_path: str, xml_path: Optional[str], save_path: Optional[str], pic_path: Optional[str], verbose: bool): verbose: bool, lookahead: int = cmpl.LOOKAHEAD_DEFAULT): """ Complement an automaton in given file by given mode, perform output actions. """ Loading @@ -201,7 +213,9 @@ def complement_from_file(file_path: str, try: validate = VALIDATE in options rabit_min = RABIT_MIN in options dfa_min = DFA_MIN in options rabit_min_during = RABIT_MIN in options rabit_min_after = RABIT_MIN_AFTER in options if mode in [F_GATE, R_GATE]: reverse = mode == R_GATE Loading @@ -209,10 +223,13 @@ def complement_from_file(file_path: str, comp = run_gate_complement(ext_nfa, data, gate_symbols=gate_symbols, reverse=reverse, rabit=rabit_min) rabit=rabit_min_during) elif mode == PORT: comp = run_port_complement(ext_nfa, data, minify_rabit=rabit_min, minify_dfa=False) comp = run_port_complement(ext_nfa, data, minify_rabit=rabit_min_during, minify_dfa=dfa_min, lookahead=lookahead) elif mode == F_POWERSET: comp = run_forward_powerset_complement(ext_nfa, data) Loading @@ -220,6 +237,9 @@ def complement_from_file(file_path: str, elif mode == R_POWERSET: comp = run_reverse_powerset_complement(ext_nfa, data) if rabit_min_after: run_rabit_minimize_after(comp, data) if validate: if comp is None: data["correct"] = "N/A" Loading Loading @@ -346,13 +366,14 @@ f"""complementation algorithm to be used: {PORT} port complement """) parser.add_argument('-O', '--options', choices=[VALIDATE, DFA_MIN, RABIT_MIN], choices=[VALIDATE, DFA_MIN, RABIT_MIN, RABIT_MIN_AFTER], nargs='+', default=[], help= f"""options: {VALIDATE} validate (check produced complement for correctness) {DFA_MIN} minimize with DFA minimization {RABIT_MIN} minimize with RABIT""") {RABIT_MIN} minimize with RABIT periodically {RABIT_MIN_AFTER} minimize with rabit after computation""") parser.add_argument('-o', '--outputpath', help='path to the output file, export in .dot') parser.add_argument('-v', '--verbose', Loading @@ -370,6 +391,10 @@ f"""options: parser.add_argument('--compliment', action='store_true', help='be uplifted by a compliment from AliGater.') parser.add_argument('-l', '--lookahead', type=int, default=10, help='lookahead parameter for RABIT') return parser.parse_args() Loading @@ -386,6 +411,7 @@ def main(): mode = args.mode verbose = args.verbose options = args.options lookahead = args.lookahead if args.compliment: print(compliment()) Loading @@ -408,7 +434,8 @@ def main(): xml_path=xml_path, save_path=save_path, pic_path=pic_path, verbose=verbose) verbose=verbose, lookahead=lookahead) if __name__ == "__main__": main() Loading Loading
src/aligater.py +52 −25 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ from time import time_ns ############### Some constants ######################### RABIT_MIN = "mr" DFA_MIN = "md" RABIT_MIN_AFTER = "mra" VALIDATE = "v" F_POWERSET = "f" Loading Loading @@ -58,9 +59,6 @@ def run_gate_complement(ext_nfa: ExtendedNFA, data["type"] = "NONE" data["complement_time_ns"] = "N/A" if rabit: data["gate_size_rabit_min"] = "N/A" data["rabit_min_time_ns"] = "N/A" return None complement_start_time = time_ns() Loading @@ -79,29 +77,22 @@ def run_gate_complement(ext_nfa: ExtendedNFA, data["type"] = gate_pair.type data["complement_time_ns"] = complement_time if rabit: rabit_start_time = time_ns() gate_comp = cmpl.rabit_minimize(gate_comp) rabit_time = time_ns() - rabit_start_time if gate_comp is not None: data["gate_size_rabit_min"] = len(gate_comp.states) data["rabit_min_time_ns"] = rabit_time else: data["gate_size_rabit_min"] = "ERROR" data["rabit_min_time_ns"] = "ERROR" return gate_comp def run_port_complement(ext_nfa: ExtendedNFA, data: dict, minify_rabit: bool = False, minify_dfa: bool = False) \ minify_dfa: bool = False, lookahead: int = cmpl.LOOKAHEAD_DEFAULT) \ -> ExtendedNFA: start_time = time_ns() comp = port_complement(ext_nfa, minify_rabit=minify_rabit, minify_dfa=minify_dfa, data_dict=data) comp = port_complement(ext_nfa, minify_rabit=minify_rabit, minify_dfa=minify_dfa, lookahead=lookahead, data_dict=data) comp_time = time_ns() - start_time data["port_comp_size"] = len(comp.states) Loading Loading @@ -178,6 +169,26 @@ def load_from_file(file_path: str) -> None | tuple[ExtendedNFA, str]: return ext_nfa, name def run_rabit_minimize_after(comp: ExtendedNFA | None, data: dict, lookahead: int = cmpl.LOOKAHEAD_DEFAULT): if comp is not None: rabit_start_time = time_ns() min_comp = cmpl.rabit_minimize(comp, lookahead=lookahead) rabit_time = time_ns() - rabit_start_time if min_comp is not None: data["gate_size_rabit_min"] = len(min_comp.states) data["rabit_min_time_ns"] = rabit_time else: data["gate_size_rabit_min"] = "ERROR" data["rabit_min_time_ns"] = "ERROR" else: data["gate_size_rabit_min"] = "N/A" data["rabit_min_time_ns"] = "N/A" def complement_from_file(file_path: str, mode: str, options: list[str], Loading @@ -185,7 +196,8 @@ def complement_from_file(file_path: str, xml_path: Optional[str], save_path: Optional[str], pic_path: Optional[str], verbose: bool): verbose: bool, lookahead: int = cmpl.LOOKAHEAD_DEFAULT): """ Complement an automaton in given file by given mode, perform output actions. """ Loading @@ -201,7 +213,9 @@ def complement_from_file(file_path: str, try: validate = VALIDATE in options rabit_min = RABIT_MIN in options dfa_min = DFA_MIN in options rabit_min_during = RABIT_MIN in options rabit_min_after = RABIT_MIN_AFTER in options if mode in [F_GATE, R_GATE]: reverse = mode == R_GATE Loading @@ -209,10 +223,13 @@ def complement_from_file(file_path: str, comp = run_gate_complement(ext_nfa, data, gate_symbols=gate_symbols, reverse=reverse, rabit=rabit_min) rabit=rabit_min_during) elif mode == PORT: comp = run_port_complement(ext_nfa, data, minify_rabit=rabit_min, minify_dfa=False) comp = run_port_complement(ext_nfa, data, minify_rabit=rabit_min_during, minify_dfa=dfa_min, lookahead=lookahead) elif mode == F_POWERSET: comp = run_forward_powerset_complement(ext_nfa, data) Loading @@ -220,6 +237,9 @@ def complement_from_file(file_path: str, elif mode == R_POWERSET: comp = run_reverse_powerset_complement(ext_nfa, data) if rabit_min_after: run_rabit_minimize_after(comp, data) if validate: if comp is None: data["correct"] = "N/A" Loading Loading @@ -346,13 +366,14 @@ f"""complementation algorithm to be used: {PORT} port complement """) parser.add_argument('-O', '--options', choices=[VALIDATE, DFA_MIN, RABIT_MIN], choices=[VALIDATE, DFA_MIN, RABIT_MIN, RABIT_MIN_AFTER], nargs='+', default=[], help= f"""options: {VALIDATE} validate (check produced complement for correctness) {DFA_MIN} minimize with DFA minimization {RABIT_MIN} minimize with RABIT""") {RABIT_MIN} minimize with RABIT periodically {RABIT_MIN_AFTER} minimize with rabit after computation""") parser.add_argument('-o', '--outputpath', help='path to the output file, export in .dot') parser.add_argument('-v', '--verbose', Loading @@ -370,6 +391,10 @@ f"""options: parser.add_argument('--compliment', action='store_true', help='be uplifted by a compliment from AliGater.') parser.add_argument('-l', '--lookahead', type=int, default=10, help='lookahead parameter for RABIT') return parser.parse_args() Loading @@ -386,6 +411,7 @@ def main(): mode = args.mode verbose = args.verbose options = args.options lookahead = args.lookahead if args.compliment: print(compliment()) Loading @@ -408,7 +434,8 @@ def main(): xml_path=xml_path, save_path=save_path, pic_path=pic_path, verbose=verbose) verbose=verbose, lookahead=lookahead) if __name__ == "__main__": main() Loading