master > master: code py - refactored code mit Endpunkten
This commit is contained in:
@@ -11,51 +11,29 @@ import sys
|
||||
os.chdir(os.path.join(os.path.dirname(__file__)));
|
||||
sys.path.insert(0, os.getcwd());
|
||||
|
||||
from src.thirdparty.maths import *;
|
||||
|
||||
from models.generated.config import *;
|
||||
from models.generated.commands import *;
|
||||
from src.core.log import *;
|
||||
from src.setup.config import *;
|
||||
from src.models.graphs import *;
|
||||
from src.algorithms.tarjan import *;
|
||||
from src.algorithms.tsp import *;
|
||||
from src.algorithms.hirschberg import *;
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# GLOBAL CONSTANTS/VARIABLES
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
#
|
||||
from src.models.config import *;
|
||||
from src.core import log;
|
||||
from src.setup import config;
|
||||
from src import api;
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# MAIN METHOD
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
def enter():
|
||||
for command in COMMANDS:
|
||||
if isinstance(command, CommandTarjan):
|
||||
tarjan_algorithm(
|
||||
G = Graph(
|
||||
nodes=command.nodes,
|
||||
edges=list(map(tuple, command.edges)),
|
||||
),
|
||||
verbose = OPTIONS.tarjan.verbose
|
||||
);
|
||||
if isinstance(command, CommandTsp):
|
||||
tsp_algorithm(
|
||||
dist = np.asarray(command.dist, dtype=float),
|
||||
optimise = min if command.optimise == EnumTSPOptimise.min else max,
|
||||
verbose = OPTIONS.tsp.verbose,
|
||||
);
|
||||
elif isinstance(command, CommandHirschberg):
|
||||
hirschberg_algorithm(
|
||||
X = command.word1,
|
||||
Y = command.word2,
|
||||
once = command.once,
|
||||
verbose = OPTIONS.hirschberg.verbose,
|
||||
show = OPTIONS.hirschberg.show,
|
||||
);
|
||||
def enter(*args: str):
|
||||
# set logging level:
|
||||
log.configure_logging(config.LOG_LEVEL);
|
||||
|
||||
# process inputs:
|
||||
if len(args) == 0:
|
||||
# Führe befehle in Assets aus:
|
||||
for command in config.COMMANDS:
|
||||
result = api.run_command(command);
|
||||
log.log_result(result, debug=True); # ignored if log-level >> DEBUG
|
||||
else:
|
||||
# Führe CLI-Befehl aus:
|
||||
result = api.run_command_from_json(args[0]);
|
||||
log.log_result(result, debug=True); # ignored if log-level >> DEBUG
|
||||
return;
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
@@ -63,4 +41,5 @@ def enter():
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
if __name__ == '__main__':
|
||||
enter();
|
||||
sys.tracebacklimit = 0;
|
||||
enter(*sys.argv[1:]);
|
||||
|
||||
Reference in New Issue
Block a user