2022-03-30 18:00:11 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# IMPORTS
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
import os;
|
2022-06-10 11:50:59 +02:00
|
|
|
import sys
|
2022-03-30 18:00:11 +02:00
|
|
|
|
2022-06-10 11:50:59 +02:00
|
|
|
os.chdir(os.path.join(os.path.dirname(__file__)));
|
2022-03-30 18:00:11 +02:00
|
|
|
sys.path.insert(0, os.getcwd());
|
|
|
|
|
2022-06-09 18:12:24 +02:00
|
|
|
from src.thirdparty.maths import *;
|
2022-06-10 11:50:59 +02:00
|
|
|
|
2022-06-10 12:46:53 +02:00
|
|
|
from models.generated.config import *;
|
2022-06-10 11:50:59 +02:00
|
|
|
from models.generated.commands import *;
|
|
|
|
from src.core.log import *;
|
|
|
|
from src.setup.config import *;
|
2022-06-10 16:05:15 +02:00
|
|
|
from src.models.graphs import *;
|
|
|
|
from src.algorithms.tarjan import *;
|
2022-06-10 12:28:00 +02:00
|
|
|
from src.algorithms.tsp import *;
|
|
|
|
from src.algorithms.hirschberg import *;
|
2022-04-07 16:41:33 +02:00
|
|
|
|
2022-03-30 18:00:11 +02:00
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# GLOBAL CONSTANTS/VARIABLES
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# MAIN METHOD
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
def enter():
|
2022-06-10 11:50:59 +02:00
|
|
|
for command in COMMANDS:
|
2022-06-10 16:05:15 +02:00
|
|
|
if isinstance(command, CommandTarjan):
|
|
|
|
tarjan_algorithm(
|
|
|
|
G = Graph(
|
|
|
|
nodes=command.nodes,
|
|
|
|
edges=list(map(tuple, command.edges)),
|
|
|
|
),
|
|
|
|
verbose = OPTIONS.tarjan.verbose
|
|
|
|
);
|
2022-06-10 11:50:59 +02:00
|
|
|
if isinstance(command, CommandTsp):
|
|
|
|
tsp_algorithm(
|
|
|
|
dist = np.asarray(command.dist, dtype=float),
|
2022-06-10 12:46:53 +02:00
|
|
|
optimise = min if command.optimise == EnumTSPOptimise.min else max,
|
2022-06-10 12:08:31 +02:00
|
|
|
verbose = OPTIONS.tsp.verbose,
|
2022-06-10 11:50:59 +02:00
|
|
|
);
|
|
|
|
elif isinstance(command, CommandHirschberg):
|
|
|
|
hirschberg_algorithm(
|
|
|
|
X = command.word1,
|
|
|
|
Y = command.word2,
|
|
|
|
once = command.once,
|
2022-06-10 16:05:15 +02:00
|
|
|
verbose = OPTIONS.hirschberg.verbose,
|
2022-06-10 12:08:31 +02:00
|
|
|
show = OPTIONS.hirschberg.show,
|
2022-06-10 11:50:59 +02:00
|
|
|
);
|
2022-03-30 18:00:11 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# EXECUTION
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
enter();
|