diff options
Diffstat (limited to 'plot.py')
-rw-r--r-- | plot.py | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -10,11 +10,13 @@ from algorithms.input_kind import InputKind from algorithms.params import AlgorithmParameters import algorithms.registry as registry + _DEFAULT_ITERATIONS = 100 _DEFAULT_INPUT_KIND = InputKind.AVERAGE _DEFAULT_MIN_LENGTH = 0 _DEFAULT_MAX_LENGTH = 200 + def plot_algorithm(algorithm, input_kind=_DEFAULT_INPUT_KIND, min_len=_DEFAULT_MIN_LENGTH, max_len=_DEFAULT_MAX_LENGTH, @@ -29,6 +31,7 @@ def plot_algorithm(algorithm, input_kind=_DEFAULT_INPUT_KIND, iterations=iterations) params.plot_running_time(output_path) + def _parse_non_negative_integer(s): try: n = int(s) @@ -38,6 +41,7 @@ def _parse_non_negative_integer(s): raise argparse.ArgumentTypeError('must be a non-negative integer') return n + def _parse_positive_integer(s): try: n = int(s) @@ -47,28 +51,34 @@ def _parse_positive_integer(s): raise argparse.ArgumentTypeError('must be a positive integer') return n + def _parse_input_kind(s): try: return InputKind(s) except ValueError: raise argparse.ArgumentTypeError('invalid input kind: ' + str(s)) + def _format_algorithm(codename): return '* {}: {}'.format(codename, registry.get(codename).display_name) + def _format_available_algorithms(): descr = 'available algorithms (in the CODENAME: DISPLAY_NAME format):\n' return descr + '\n'.join(map( _format_algorithm, sorted(registry.get_codenames()))) + def _format_description(): return _format_available_algorithms() + def _create_argument_parser(): return argparse.ArgumentParser( description=_format_description(), formatter_class=argparse.RawDescriptionHelpFormatter) + def _parse_args(args=None): if args is None: args = sys.argv[1:] @@ -98,8 +108,10 @@ def _parse_args(args=None): return parser.parse_args(args) + def main(args=None): plot_algorithm(**vars(_parse_args(args))) + if __name__ == '__main__': main() |