From ebceafeb862e446ee6f113c738cfe0abfdf080c0 Mon Sep 17 00:00:00 2001 From: voic00 <voic00@mi.fu-berlin.de> Date: Sun, 2 Jun 2024 11:58:55 +0200 Subject: [PATCH] hzfg: alle main varianten: Kann nun Ordner oder einzelne Dateien als Argument empfangen --- src/main.py | 30 +++++++++++++++++++++++------- src/main_iterative_opt.py | 31 ++++++++++++++++++++++++------- src/main_zykel.py | 30 +++++++++++++++++++++++------- 3 files changed, 70 insertions(+), 21 deletions(-) diff --git a/src/main.py b/src/main.py index 45c47cb..04708ca 100644 --- a/src/main.py +++ b/src/main.py @@ -6,6 +6,19 @@ from pulp import * # Erstellen eines Graphen zur Bestimmung der Knotenreihenfolge from collections import defaultdict, deque +import argparse +def main(): + parser = argparse.ArgumentParser(description="Given a bi-partite graph this program will return a permutation of the second partition (called B or Y) so that the crossings of the graph are minimized.") + parser.add_argument("-f", "--file", required=True, help="Path to the file or directory that holds the graph(s).") + args = parser.parse_args() + path = args.file + + if os.path.isfile(path): + solve_bipartite_minimization(path) + elif os.path.isdir(path): + process_directory(path) + else: + logging.error(f"The path '{path}' does not exist or is neither a file nor a directory.") # Erstelle einen FileHandler und einen StreamHandler file_handler = logging.FileHandler('logfile.log') @@ -188,11 +201,14 @@ def process_directory(directory_path): solve_bipartite_minimization(file_path) # Rufe die Verarbeitungsfunktion für jede .gr Datei auf logging.info(f"Verarbeitung abgeschlossen für {file_path}") -#directory_path = 'githubtests/tiny_test_set/instances/' -#directory_path = 'mytests/instances/' -#process_directory(directory_path) +# #directory_path = 'githubtests/tiny_test_set/instances/' +# #directory_path = 'mytests/instances/' +# #process_directory(directory_path) + +# #test_file = 'githubtests/tiny_test_set/instances/complete_4_5.gr' +# test_file = 'githubtests/medium_test_set/instances/10.gr' +# #test_file = 'mytests/instances/1.gr' +# solve_bipartite_minimization(test_file) -#test_file = 'githubtests/tiny_test_set/instances/complete_4_5.gr' -test_file = 'githubtests/medium_test_set/instances/10.gr' -#test_file = 'mytests/instances/1.gr' -solve_bipartite_minimization(test_file) +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/src/main_iterative_opt.py b/src/main_iterative_opt.py index 404fee8..607fa90 100644 --- a/src/main_iterative_opt.py +++ b/src/main_iterative_opt.py @@ -5,6 +5,20 @@ from datetime import datetime, timedelta from pulp import * from collections import defaultdict, deque +import argparse +def main(): + parser = argparse.ArgumentParser(description="Given a bi-partite graph this program will return a permutation of the second partition (called B or Y) so that the crossings of the graph are minimized.") + parser.add_argument("-f", "--file", required=True, help="Path to the file or directory that holds the graph(s).") + args = parser.parse_args() + path = args.file + + if os.path.isfile(path): + solve_bipartite_minimization(path) + elif os.path.isdir(path): + process_directory(path) + else: + logging.error(f"The path '{path}' does not exist or is neither a file nor a directory.") + # Erstelle einen FileHandler und einen StreamHandler file_handler = logging.FileHandler('logfile.log') console_handler = logging.StreamHandler() @@ -174,11 +188,14 @@ def process_directory(directory_path): solve_bipartite_minimization(file_path) logging.info(f"Verarbeitung abgeschlossen für {file_path}") -#directory_path = 'githubtests/tiny_test_set/instances/' -#directory_path = 'mytests/instances/' -#process_directory(directory_path) +# #directory_path = 'githubtests/tiny_test_set/instances/' +# #directory_path = 'mytests/instances/' +# #process_directory(directory_path) + +# #test_file = 'githubtests/tiny_test_set/instances/complete_4_5.gr' +# test_file = 'githubtests/medium_test_set/instances/10.gr' +# #test_file = 'mytests/instances/1.gr' +# solve_bipartite_minimization(test_file) -#test_file = 'githubtests/tiny_test_set/instances/complete_4_5.gr' -test_file = 'githubtests/medium_test_set/instances/10.gr' -#test_file = 'mytests/instances/1.gr' -solve_bipartite_minimization(test_file) +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/src/main_zykel.py b/src/main_zykel.py index c189ff4..3af853a 100644 --- a/src/main_zykel.py +++ b/src/main_zykel.py @@ -6,6 +6,19 @@ from pulp import * # Erstellen eines Graphen zur Bestimmung der Knotenreihenfolge from collections import defaultdict, deque +import argparse +def main(): + parser = argparse.ArgumentParser(description="Given a bi-partite graph this program will return a permutation of the second partition (called B or Y) so that the crossings of the graph are minimized.") + parser.add_argument("-f", "--file", required=True, help="Path to the file or directory that holds the graph(s).") + args = parser.parse_args() + path = args.file + + if os.path.isfile(path): + solve_bipartite_minimization(path) + elif os.path.isdir(path): + process_directory(path) + else: + logging.error(f"The path '{path}' does not exist or is neither a file nor a directory.") # Erstelle einen FileHandler und einen StreamHandler file_handler = logging.FileHandler('logfile.log') @@ -213,11 +226,14 @@ def process_directory(directory_path): solve_bipartite_minimization(file_path) # Rufe die Verarbeitungsfunktion für jede .gr Datei auf logging.info(f"Verarbeitung abgeschlossen für {file_path}") -#directory_path = 'githubtests/tiny_test_set/instances/' -#directory_path = 'mytests/instances/' -#process_directory(directory_path) +# #directory_path = 'githubtests/tiny_test_set/instances/' +# #directory_path = 'mytests/instances/' +# #process_directory(directory_path) + +# #test_file = 'githubtests/tiny_test_set/instances/complete_4_5.gr' +# test_file = 'githubtests/medium_test_set/instances/10.gr' +# #test_file = 'mytests/instances/1.gr' +# solve_bipartite_minimization(test_file) -#test_file = 'githubtests/tiny_test_set/instances/complete_4_5.gr' -test_file = 'githubtests/medium_test_set/instances/10.gr' -#test_file = 'mytests/instances/1.gr' -solve_bipartite_minimization(test_file) +if __name__ == "__main__": + main() \ No newline at end of file -- GitLab