Compare commits
4 Commits
ab2473af9e
...
965cd48ae6
Author | SHA1 | Date | |
---|---|---|---|
965cd48ae6 | |||
8ddb4fa427 | |||
3f3ccf1059 | |||
60b27c1abe |
@ -80,13 +80,13 @@ def algorithmInfos(
|
|||||||
outputs_ = outputs if isinstance(outputs, tuple) else tuple([outputs]);
|
outputs_ = outputs if isinstance(outputs, tuple) else tuple([outputs]);
|
||||||
outputnames_ = outputnames if isinstance(outputnames, tuple) else tuple([outputnames]);
|
outputnames_ = outputnames if isinstance(outputnames, tuple) else tuple([outputnames]);
|
||||||
outputsNamed = { outputnames_[k]: value for k, value in enumerate(outputs_) };
|
outputsNamed = { outputnames_[k]: value for k, value in enumerate(outputs_) };
|
||||||
# Postchecks
|
|
||||||
if checks and callable(postChecks):
|
|
||||||
postChecks(**inputs, **outputsNamed);
|
|
||||||
# Letzte Messages
|
# Letzte Messages
|
||||||
if metrics:
|
if metrics:
|
||||||
DisplayMetrics();
|
DisplayMetrics();
|
||||||
DisplayEndOfAlgorithm(**outputsNamed);
|
DisplayEndOfAlgorithm(**outputsNamed);
|
||||||
|
# Postchecks
|
||||||
|
if checks and callable(postChecks):
|
||||||
|
postChecks(**inputs, **outputsNamed);
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
nonnestedAlgorithms.state = state1;
|
nonnestedAlgorithms.state = state1;
|
||||||
nonnestedRecursion.state = state2;
|
nonnestedRecursion.state = state2;
|
||||||
|
@ -58,4 +58,6 @@ def BinarySearch(L: List[int], x: int) -> int:
|
|||||||
else: # x > L[m]
|
else: # x > L[m]
|
||||||
logDebug('Suche in L[m+1], L[m+2], ..., L[len(L)-1] fortsetzen, m = {}.'.format(m));
|
logDebug('Suche in L[m+1], L[m+2], ..., L[len(L)-1] fortsetzen, m = {}.'.format(m));
|
||||||
index = BinarySearch(L=L[m+1:], x=x);
|
index = BinarySearch(L=L[m+1:], x=x);
|
||||||
return (m + 1) + index; # NOTE: muss Indexwert kompensieren
|
if index >= 0:
|
||||||
|
index += (m + 1); # NOTE: muss Indexwert kompensieren
|
||||||
|
return index;
|
||||||
|
@ -56,7 +56,9 @@ def JumpSearchLinear(L: List[int], x: int, m: int) -> int:
|
|||||||
if x < elementAfterBlock:
|
if x < elementAfterBlock:
|
||||||
logDebug('Element muss sich im Block [{i0}, {i1}) befinden.'.format(i0 = i*m, i1 = (i+1)*m));
|
logDebug('Element muss sich im Block [{i0}, {i1}) befinden.'.format(i0 = i*m, i1 = (i+1)*m));
|
||||||
index = SequentialSearch(L=block, x=x);
|
index = SequentialSearch(L=block, x=x);
|
||||||
return offset + index; # NOTE: muss wegen Offset kompensieren
|
if index >= 0:
|
||||||
|
index += offset; # NOTE: muss wegen Offset kompensieren
|
||||||
|
return index;
|
||||||
logDebug('Element befindet sich nicht im im Block [{i0}, {i1}) befinden.'.format(i0 = i*m, i1 = (i+1)*m));
|
logDebug('Element befindet sich nicht im im Block [{i0}, {i1}) befinden.'.format(i0 = i*m, i1 = (i+1)*m));
|
||||||
i += 1;
|
i += 1;
|
||||||
return -1;
|
return -1;
|
||||||
@ -85,7 +87,9 @@ def JumpSearchExponentiell(L: List[int], x: int) -> int:
|
|||||||
if x < elementAfterBlock:
|
if x < elementAfterBlock:
|
||||||
logDebug('Element muss sich im Block [{i0}, {i1}) befinden.'.format(i0 = i0, i1 = i1));
|
logDebug('Element muss sich im Block [{i0}, {i1}) befinden.'.format(i0 = i0, i1 = i1));
|
||||||
index = SequentialSearch(L=block, x=x);
|
index = SequentialSearch(L=block, x=x);
|
||||||
return i0 + index; # NOTE: muss wegen Offset kompensieren
|
if index >= 0:
|
||||||
|
index += i0; # NOTE: muss wegen Offset kompensieren
|
||||||
|
return index;
|
||||||
logDebug('Element befindet sich nicht im Block [{i0}, {i1}) befinden.'.format(i0 = i0, i1 = i1));
|
logDebug('Element befindet sich nicht im Block [{i0}, {i1}) befinden.'.format(i0 = i0, i1 = i1));
|
||||||
i0 = i1;
|
i0 = i1;
|
||||||
i1 *= 2;
|
i1 *= 2;
|
||||||
|
@ -37,7 +37,7 @@ parts:
|
|||||||
description: 'Freiwilliges ÜB2, A5a'
|
description: 'Freiwilliges ÜB2, A5a'
|
||||||
inputs: &ref_inputs_ueb2_5
|
inputs: &ref_inputs_ueb2_5
|
||||||
L: [4, 11, 22, 23, 25, 27, 29, 36, 41, 52, 64, 76, 82, 86, 94, 96, 102, 117, 123, 147, 188, 211, 216, 222, 224, 226, 233, 239, 255, 263, 277, 289]
|
L: [4, 11, 22, 23, 25, 27, 29, 36, 41, 52, 64, 76, 82, 86, 94, 96, 102, 117, 123, 147, 188, 211, 216, 222, 224, 226, 233, 239, 255, 263, 277, 289]
|
||||||
x: 117
|
x: 114
|
||||||
- command: 'algorithm-search-jump'
|
- command: 'algorithm-search-jump'
|
||||||
description: 'Freiwilliges ÜB2, A5b'
|
description: 'Freiwilliges ÜB2, A5b'
|
||||||
inputs:
|
inputs:
|
||||||
|
@ -88,6 +88,5 @@ if __name__ == '__main__':
|
|||||||
try:
|
try:
|
||||||
args = GetArgumentsFromCli(sys.argv[1:]);
|
args = GetArgumentsFromCli(sys.argv[1:]);
|
||||||
except:
|
except:
|
||||||
DisplayHelpMessage();
|
|
||||||
exit(1);
|
exit(1);
|
||||||
enter(quiet=args.quiet, debug=args.debug, mode=args.mode[0], path=args.path);
|
enter(quiet=args.quiet, debug=args.debug, mode=args.mode[0], path=args.path);
|
||||||
|
@ -57,17 +57,17 @@ def DisplayStartOfAlgorithm(name: str, *_: Any, **inputs: Any):
|
|||||||
logPlain('Ausführung vom Algorithmus: \033[92;1m{}\033[0m'.format(name));
|
logPlain('Ausführung vom Algorithmus: \033[92;1m{}\033[0m'.format(name));
|
||||||
logPlain('INPUTS');
|
logPlain('INPUTS');
|
||||||
for varname, value in inputs.items():
|
for varname, value in inputs.items():
|
||||||
logPlain(' - {} = {}'.format(varname, RepresentValue(value)))
|
logPlain(' - {} = {}'.format(varname, RepresentValue(value)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
def DisplayEndOfAlgorithm(*_: Any, **outputs: Any):
|
def DisplayEndOfAlgorithm(*_: Any, **outputs: Any):
|
||||||
logPlain('OUTPUTS:')
|
logPlain('OUTPUTS:')
|
||||||
for varname, value in outputs.items():
|
for varname, value in outputs.items():
|
||||||
logPlain(' - {} = {}'.format(varname, RepresentValue(value)))
|
logPlain(' - {} = {}'.format(varname, RepresentValue(value)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
def DisplayMetrics():
|
def DisplayMetrics():
|
||||||
logPlain('Dauer der Ausführung: t = \033[1m{}\033[0m'.format(TimeElapsed()));
|
logPlain('Dauer der Ausführung: t = \033[1m{}\033[0m'.format(TimeElapsed()));
|
||||||
logPlain('Anzahl der Schritte: T(n) = \033[1m{}\033[0m'.format(NumberOfSteps()));
|
logPlain('Anzahl der Schritte: T(n) = \033[1m{}\033[0m'.format(NumberOfSteps()));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user