diff --git a/code/python/README.md b/code/python/README.md index 01b7049..86c7ff1 100644 --- a/code/python/README.md +++ b/code/python/README.md @@ -47,5 +47,8 @@ Man kann auch mit einem guten Editor/IDE die Tests einzeln ausführen. ## Testfälle durch Config-Datei ## Statt den Code immer anfassen zu müssen, kann man Fälle für die verschiedenen Algorithmen -in der **[./assets/commands](assets/commands.yaml)** erfassen und (mittels `just run`) +in der **[./assets/commands.yaml](assets/commands.yaml)** erfassen und (mittels `just run`) das Programm ausführen. + +Weitere globale Einstellungen (z. B. über Verbosity, Penalty-Konstanten, usw.) kann man in +**[./assets/config.yaml](assets/config.yaml)** einstellen. diff --git a/code/python/assets/commands.yaml b/code/python/assets/commands.yaml index 1b648c2..95ec3a2 100644 --- a/code/python/assets/commands.yaml +++ b/code/python/assets/commands.yaml @@ -6,28 +6,24 @@ - [2, 5, 0, 5] - [2, 7, 4, 0] optimise: MIN - verbose: true -## Beispiele für Seminarwoche 10 (Blatt 9) -- &command_hirschberg - name: HIRSCHBERG - once: true - verbose: - - COSTS - - MOVES - # show: - # # - ATOMS - # - TREE +# Beispiele für Seminarwoche 10 (Blatt 9) +- name: HIRSCHBERG word1: 'happily ever after' word2: 'apples' -- <<: *command_hirschberg - word1: 'ANSTRENGEN' - word2: 'ANSPANNEN' -- <<: *command_hirschberg - word1: 'ACGAAG' - word2: 'AGAT' -- <<: *command_hirschberg - word1: 'happily ever, lol' - word2: 'apple' -- <<: *command_hirschberg + once: false +- name: HIRSCHBERG word1: 'happily' word2: 'applses' + once: false +- name: HIRSCHBERG + word1: 'happily ever, lol' + word2: 'apple' + once: false +- name: HIRSCHBERG + word1: 'ACGAAG' + word2: 'AGAT' + once: false +- name: HIRSCHBERG + word1: 'ANSTRENGEN' + word2: 'ANSPANNEN' + once: false diff --git a/code/python/assets/config.yaml b/code/python/assets/config.yaml index ca65d67..d0d18b9 100644 --- a/code/python/assets/config.yaml +++ b/code/python/assets/config.yaml @@ -5,4 +5,15 @@ info: Ein Code-Projekt, das Algorithmen und Datenstrukturen aus dem Kurs ADS2 an der Universität Leipzig (Sommersemester 2022) implementiert. -options: {} +options: + tsp: + verbose: true + hirschberg: + penality-missmatch: 1 + penality-gap: 1 + verbose: + - COSTS + - MOVES + # show: + # # - ATOMS + # - TREE diff --git a/code/python/main.py b/code/python/main.py index 8802794..4d85160 100644 --- a/code/python/main.py +++ b/code/python/main.py @@ -22,7 +22,6 @@ from src.graphs.tarjan import *; from src.tsp import *; from src.hirschberg import *; - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # GLOBAL CONSTANTS/VARIABLES # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -39,15 +38,15 @@ def enter(): tsp_algorithm( dist = np.asarray(command.dist, dtype=float), optimise = min if command.optimise == EnumTspOptimise.min else max, - verbose = command.verbose, + verbose = OPTIONS.tsp.verbose, ); elif isinstance(command, CommandHirschberg): hirschberg_algorithm( X = command.word1, Y = command.word2, once = command.once, - verb = command.verbose, - show = command.show, + verb = OPTIONS.hirschberg.verbose, + show = OPTIONS.hirschberg.show, ); return; diff --git a/code/python/models/commands-schema.yaml b/code/python/models/commands-schema.yaml index 32a6a23..6a90a08 100644 --- a/code/python/models/commands-schema.yaml +++ b/code/python/models/commands-schema.yaml @@ -62,9 +62,6 @@ components: type: number optimise: $ref: '#/components/schemas/EnumTSPOptimise' - verbose: - type: boolean - default: false # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Command - Algorithm: Hirschberg # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -87,16 +84,6 @@ components: once: type: boolean default: false - verbose: - type: array - items: - $ref: '#/components/schemas/EnumHirschbergVerbosity' - default: [] - show: - type: array - items: - $ref: '#/components/schemas/EnumHirschbergShow' - default: [] # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Enum Algorithm Names # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -118,23 +105,3 @@ components: enum: - MIN - MAX - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - # Enum Hirschberg - Verbosity options - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - EnumHirschbergVerbosity: - description: |- - Enumeration of verbosity options for Hirschberg - type: string - enum: - - COSTS - - MOVES - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - # Enum Hirschberg - display options - # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - EnumHirschbergShow: - description: |- - Enumeration of verbosity options for Hirschberg - type: string - enum: - - TREE - - ATOMS diff --git a/code/python/models/config-schema.yaml b/code/python/models/config-schema.yaml index 2ac4c5a..85248ed 100644 --- a/code/python/models/config-schema.yaml +++ b/code/python/models/config-schema.yaml @@ -47,3 +47,49 @@ components: description: |- Options pertaining to the rudimentary setup of the app. type: object + properties: + tsp: + type: object + properties: + verbose: + type: boolean + default: false + hirschberg: + type: object + properties: + penality-missmatch: + type: number + default: 1 + penality-gap: + type: number + default: 1 + verbose: + type: array + items: + $ref: '#/components/schemas/EnumHirschbergVerbosity' + default: [] + show: + type: array + items: + $ref: '#/components/schemas/EnumHirschbergShow' + default: [] + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # Enum Hirschberg - Verbosity options + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + EnumHirschbergVerbosity: + description: |- + Enumeration of verbosity options for Hirschberg + type: string + enum: + - COSTS + - MOVES + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + # Enum Hirschberg - display options + # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + EnumHirschbergShow: + description: |- + Enumeration of verbosity options for Hirschberg + type: string + enum: + - TREE + - ATOMS diff --git a/code/python/src/hirschberg/algorithms.py b/code/python/src/hirschberg/algorithms.py index 5eb07e9..ab6103d 100644 --- a/code/python/src/hirschberg/algorithms.py +++ b/code/python/src/hirschberg/algorithms.py @@ -8,7 +8,7 @@ from src.thirdparty.types import *; from src.thirdparty.maths import *; -from models.generated.commands import *; +from models.generated.config import *; from src.hirschberg.constants import *; from src.hirschberg.display import *; from src.hirschberg.matrix import *; diff --git a/code/python/src/hirschberg/constants.py b/code/python/src/hirschberg/constants.py index 2579407..d9be9c3 100644 --- a/code/python/src/hirschberg/constants.py +++ b/code/python/src/hirschberg/constants.py @@ -6,6 +6,7 @@ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ from src.thirdparty.types import *; +from src.setup.config import *; # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # EXPORTS @@ -33,7 +34,7 @@ class Directions(Enum): # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def gap_penalty(x: str): - return 1; + return OPTIONS.hirschberg.penality_gap; def missmatch_penalty(x: str, y: str): - return 0 if x == y else 1; + return 0 if x == y else OPTIONS.hirschberg.penality_missmatch; diff --git a/code/python/src/hirschberg/display.py b/code/python/src/hirschberg/display.py index 02331d5..c9c7c88 100644 --- a/code/python/src/hirschberg/display.py +++ b/code/python/src/hirschberg/display.py @@ -8,7 +8,7 @@ from src.thirdparty.types import *; from src.thirdparty.maths import *; -from models.generated.commands import *; +from models.generated.config import *; from src.hirschberg.constants import *; # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~