2021-10-22 15:29:01 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# IMPORTS
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
import os;
|
2021-10-24 19:33:08 +02:00
|
|
|
import sys;
|
2021-10-22 15:29:01 +02:00
|
|
|
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
|
|
|
|
|
2021-10-23 13:20:37 +02:00
|
|
|
from code.core.log import *;
|
|
|
|
from code.core.config import *;
|
2021-10-24 16:35:29 +02:00
|
|
|
from code.setup.display import *;
|
|
|
|
from code.setup.cli import *;
|
2021-10-23 13:20:37 +02:00
|
|
|
from code.algorithms.exports import *;
|
2021-10-22 15:29:01 +02:00
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# GLOBAL VARIABLES/CONSTANTS
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-10-23 13:20:37 +02:00
|
|
|
PATH_TO_CONFIG: str = 'code/config.yml';
|
2021-10-22 15:29:01 +02:00
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# MAIN PROCESS
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-10-24 13:46:57 +02:00
|
|
|
def enter(quiet: bool, debug: bool, mode: str, path: Any, **_):
|
2021-10-23 13:23:07 +02:00
|
|
|
SetQuietMode(quiet);
|
|
|
|
SetDebugMode(debug);
|
2021-10-24 13:22:55 +02:00
|
|
|
configpath = path if isinstance(path, str) else PATH_TO_CONFIG;
|
2021-10-24 13:46:57 +02:00
|
|
|
if mode == 'all':
|
2021-10-23 13:20:37 +02:00
|
|
|
LoopThroughCases(path=configpath);
|
2021-10-23 11:29:30 +02:00
|
|
|
else:
|
2021-10-24 16:35:29 +02:00
|
|
|
DisplayHelpMessage();
|
2021-10-22 15:29:01 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# SECONDARY PROCESSES
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-10-23 13:20:37 +02:00
|
|
|
def LoopThroughCases(path: str):
|
|
|
|
'''
|
|
|
|
Durchlauf aller Testfälle.
|
|
|
|
'''
|
|
|
|
config = ReadConfigFile(path);
|
|
|
|
cases = GetAttribute(config, 'parts', 'cases', expectedtype=list, default=[]);
|
|
|
|
for caseindex, case in enumerate(cases):
|
|
|
|
command = GetAttribute(case, 'command', expectedtype=str, default='');
|
2021-10-24 23:34:07 +02:00
|
|
|
descr = GetAttribute(case, 'description', expectedtype=str, default='');
|
2021-10-23 13:20:37 +02:00
|
|
|
inputs = GetAttribute(case, 'inputs', expectedtype=dict, default={});
|
|
|
|
|
2021-10-24 23:34:07 +02:00
|
|
|
DisplayStartOfCase(caseindex, descr);
|
|
|
|
|
2021-10-24 12:28:37 +02:00
|
|
|
try:
|
2021-10-24 19:33:08 +02:00
|
|
|
if command == 'algorithm-sum-maxsub':
|
|
|
|
MaxSubSum(L=inputs['L']);
|
|
|
|
elif command == 'algorithm-sum-maxsub-dc':
|
|
|
|
MaxSubSumDC(L=inputs['L']);
|
|
|
|
elif command == 'algorithm-search-sequential':
|
2021-10-24 12:28:37 +02:00
|
|
|
SequentialSearch(L=inputs['L'], x=inputs['x']);
|
|
|
|
elif command == 'algorithm-search-binary':
|
|
|
|
BinarySearch(L=inputs['L'], x=inputs['x']);
|
|
|
|
elif command == 'algorithm-search-interpolation':
|
|
|
|
InterpolationSearch(L=inputs['L'], x=inputs['x'], u=0, v=len(inputs['L'])-1);
|
|
|
|
elif command == 'algorithm-search-jump':
|
|
|
|
JumpSearchLinear(L=inputs['L'], x=inputs['x'], m=inputs['m']);
|
2021-10-24 23:34:07 +02:00
|
|
|
elif command == 'algorithm-search-jump-exp':
|
|
|
|
JumpSearchExponentiell(L=inputs['L'], x=inputs['x']);
|
2021-10-24 20:12:05 +02:00
|
|
|
elif command == 'algorithm-search-ith-element':
|
|
|
|
FindIthSmallest(L=inputs['L'], i=inputs['i']);
|
|
|
|
elif command == 'algorithm-search-ith-element-dc':
|
|
|
|
FindIthSmallestDC(L=inputs['L'], i=inputs['i']);
|
2021-10-26 13:39:58 +02:00
|
|
|
elif command == 'algorithm-search-poison':
|
|
|
|
FindPoison(L=inputs['L']);
|
|
|
|
elif command == 'algorithm-search-poison-fast':
|
|
|
|
FindPoisonFast(L=inputs['L']);
|
2021-10-24 12:28:37 +02:00
|
|
|
else:
|
|
|
|
raise ValueError('Command \033[1m{}\033[0m nicht erkannt'.format(command));
|
|
|
|
except Exception as e:
|
|
|
|
logError(e);
|
2021-10-24 12:40:09 +02:00
|
|
|
DisplayEndOfCase();
|
2021-10-22 15:29:01 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# EXECUTE CODE
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2021-10-23 13:20:37 +02:00
|
|
|
sys.tracebacklimit = 0;
|
2021-10-24 13:46:57 +02:00
|
|
|
try:
|
2021-10-24 16:35:29 +02:00
|
|
|
args = GetArgumentsFromCli(sys.argv[1:]);
|
2021-10-24 13:46:57 +02:00
|
|
|
except:
|
|
|
|
exit(1);
|
|
|
|
enter(quiet=args.quiet, debug=args.debug, mode=args.mode[0], path=args.path);
|