diff --git a/code/python/src/algorithms/euklid/__init__.py b/code/python/src/algorithms/euklid/__init__.py new file mode 100644 index 0000000..dca246d --- /dev/null +++ b/code/python/src/algorithms/euklid/__init__.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# IMPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +from src.algorithms.euklid.algorithms import *; + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# EXPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +__all__ = [ + 'euklidean_algorithm', +]; diff --git a/code/python/src/algorithms/euklid/algorithms.py b/code/python/src/algorithms/euklid/algorithms.py new file mode 100644 index 0000000..bf3e1cc --- /dev/null +++ b/code/python/src/algorithms/euklid/algorithms.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# IMPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +from src.thirdparty.types import *; +from src.thirdparty.maths import *; + +from models.generated.config import *; +from src.core.utils import *; +# from src.models.euklid import *; +from src.algorithms.euklid.display import *; + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# EXPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +__all__ = [ + 'euklidean_algorithm', +]; + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# METHOD euklidean algorithm +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +def euklidean_algorithm( + a: int, + b: int, + verbose: bool = False, +): + return; diff --git a/code/python/src/algorithms/euklid/display.py b/code/python/src/algorithms/euklid/display.py new file mode 100644 index 0000000..e69de29 diff --git a/code/python/src/algorithms/hirschberg/__init__.py b/code/python/src/algorithms/hirschberg/__init__.py index 997e89c..0837c21 100644 --- a/code/python/src/algorithms/hirschberg/__init__.py +++ b/code/python/src/algorithms/hirschberg/__init__.py @@ -6,7 +6,6 @@ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ from src.algorithms.hirschberg.algorithms import *; -from src.models.hirschberg.penalties import *; from src.algorithms.hirschberg.display import *; # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/code/python/src/algorithms/pollard_rho/__init__.py b/code/python/src/algorithms/pollard_rho/__init__.py new file mode 100644 index 0000000..b072b7e --- /dev/null +++ b/code/python/src/algorithms/pollard_rho/__init__.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# IMPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +from src.algorithms.pollard_rho.algorithms import *; + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# EXPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +__all__ = [ + 'pollard_rho_algorithm', +]; diff --git a/code/python/src/algorithms/pollard_rho/algorithms.py b/code/python/src/algorithms/pollard_rho/algorithms.py new file mode 100644 index 0000000..4b1f56a --- /dev/null +++ b/code/python/src/algorithms/pollard_rho/algorithms.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# IMPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +from src.thirdparty.types import *; +from src.thirdparty.maths import *; + +from models.generated.config import *; +from src.core.utils import *; +# from src.models.pollard_rho import *; +from src.algorithms.euklid.display import *; + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# EXPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +__all__ = [ + 'pollard_rho_algorithm', +]; + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# METHOD pollard's rho algorithm +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +def pollard_rho_algorithm( + n: int, + verbose: bool = False, +): + return; diff --git a/code/python/src/algorithms/pollard_rho/display.py b/code/python/src/algorithms/pollard_rho/display.py new file mode 100644 index 0000000..e69de29 diff --git a/code/python/src/api.py b/code/python/src/api.py index 28ad4e2..6d3239c 100644 --- a/code/python/src/api.py +++ b/code/python/src/api.py @@ -40,4 +40,8 @@ def run_command(command: Command) -> Result[CallResult, CallError]: return endpoint_hirschberg(command); elif isinstance(command, CommandRucksack): return endpoint_rucksack(command); + elif isinstance(command, CommandEuklid): + return endpoint_euklid(command); + elif isinstance(command, CommandPollard): + return endpoint_pollard_rho(command); raise Exception(f'No endpoint set for `{command.name.value}`-command type.'); diff --git a/code/python/src/endpoints/__init__.py b/code/python/src/endpoints/__init__.py index 4ca27f3..cfb4e27 100644 --- a/code/python/src/endpoints/__init__.py +++ b/code/python/src/endpoints/__init__.py @@ -9,6 +9,8 @@ from src.endpoints.ep_algorithm_hirschberg import *; from src.endpoints.ep_algorithm_tarjan import *; from src.endpoints.ep_algorithm_tsp import *; from src.endpoints.ep_algorithm_rucksack import *; +from src.endpoints.ep_algorithm_euklid import *; +from src.endpoints.ep_algorithm_pollard_rho import *; # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # EXPORTS @@ -19,4 +21,6 @@ __all__ = [ 'endpoint_tarjan', 'endpoint_tsp', 'endpoint_rucksack', + 'endpoint_euklid', + 'endpoint_pollard_rho', ]; diff --git a/code/python/src/endpoints/ep_algorithm_euklid.py b/code/python/src/endpoints/ep_algorithm_euklid.py new file mode 100644 index 0000000..7b19904 --- /dev/null +++ b/code/python/src/endpoints/ep_algorithm_euklid.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# IMPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +from src.thirdparty.code import *; + +from models.generated.commands import *; +from src.core.calls import *; +from src.setup import config; +from src.algorithms.euklid import *; + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# EXPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +__all__ = [ + 'endpoint_euklid', +]; + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# ENDPOINT +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +@run_safely() +def endpoint_euklid(command: CommandEuklid) -> Result[CallResult, CallError]: + result = euklidean_algorithm( + a = command.numbers[0], + b = command.numbers[1], + verbose = config.OPTIONS.tsp.verbose, + ); + return Ok(CallResult(action_taken=True, message=result)); diff --git a/code/python/src/endpoints/ep_algorithm_pollard_rho.py b/code/python/src/endpoints/ep_algorithm_pollard_rho.py new file mode 100644 index 0000000..eba2cc4 --- /dev/null +++ b/code/python/src/endpoints/ep_algorithm_pollard_rho.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# IMPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +from src.thirdparty.code import *; + +from models.generated.commands import *; +from src.core.calls import *; +from src.setup import config; +from src.algorithms.pollard_rho import *; + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# EXPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +__all__ = [ + 'endpoint_pollard_rho', +]; + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# ENDPOINT +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +@run_safely() +def endpoint_pollard_rho(command: CommandPollard) -> Result[CallResult, CallError]: + result = pollard_rho_algorithm( + n = command.number, + verbose = config.OPTIONS.tsp.verbose, + ); + return Ok(CallResult(action_taken=True, message=result)); diff --git a/code/python/src/models/config/commands.py b/code/python/src/models/config/commands.py index f5d6aef..39e0b4a 100644 --- a/code/python/src/models/config/commands.py +++ b/code/python/src/models/config/commands.py @@ -44,4 +44,8 @@ def interpret_command(command: Command) -> Command: return CommandHirschberg(**command.dict()); case EnumAlgorithmNames.rucksack: return CommandRucksack(**command.dict()); - raise command; + case EnumAlgorithmNames.euklid: + return CommandEuklid(**command.dict()); + case EnumAlgorithmNames.pollard_rho: + return CommandPollard(**command.dict()); + raise Exception(f'Command type `{command.name.value}` not recognised!'); diff --git a/code/python/src/models/euklid.py/__init__.py b/code/python/src/models/euklid.py/__init__.py new file mode 100644 index 0000000..cee1f46 --- /dev/null +++ b/code/python/src/models/euklid.py/__init__.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# IMPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# from src.models.euklid. import *; + +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# EXPORTS +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +__all__ = [ +];