aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/plot.bat47
-rwxr-xr-xscripts/plot.sh50
-rwxr-xr-xscripts/plot_all.sh46
3 files changed, 143 insertions, 0 deletions
diff --git a/scripts/plot.bat b/scripts/plot.bat
new file mode 100644
index 0000000..c76c43a
--- /dev/null
+++ b/scripts/plot.bat
@@ -0,0 +1,47 @@
+@rem Copyright (c) 2015 Egor Tensin <Egor.Tensin@gmail.com>
+@rem This file is part of the "Sorting algorithms" project.
+@rem For details, see https://github.com/egor-tensin/sorting-algorithms.
+@rem Distributed under the MIT License.
+
+@setlocal enabledelayedexpansion
+@echo off
+
+set default_iterations=100
+set default_min=0
+set default_max=200
+
+if "%~1" == "" goto :exit_with_usage
+set "algorithm=%~1"
+
+if "%~2" == "" (
+ set "iterations=%default_iterations%"
+) else (
+ set "iterations=%~2"
+)
+if "%~3" == "" (
+ set "min=%default_min%"
+) else (
+ set "min=%~3"
+)
+if "%~4" == "" (
+ set "max=%default_max%"
+) else (
+ set "max=%~4"
+)
+
+cd ..
+mkdir /p img
+
+for %%i in (best average worst) do (
+ plot.py "%algorithm%" ^
+ --input "%%i" ^
+ --min "%min%" --max "%max%" ^
+ --iterations "%iterations%" ^
+ --output "img\%algorithm%_%iterations%_%%i_%min%_%max%.png" || exit /b !errorlevel!
+)
+
+exit /b 0
+
+:exit_with_usage:
+echo Usage: %~nx0 ALGORITHM [ITERATIONS [MIN_VALUE [MAX_VALUE]]]
+exit /b 1
diff --git a/scripts/plot.sh b/scripts/plot.sh
new file mode 100755
index 0000000..d310dcd
--- /dev/null
+++ b/scripts/plot.sh
@@ -0,0 +1,50 @@
+#!/usr/bin/env bash
+
+# Copyright (c) 2019 Egor Tensin <Egor.Tensin@gmail.com>
+# This file is part of the "Sorting algorithms" project.
+# For details, see https://github.com/egor-tensin/sorting-algorithms.
+# Distributed under the MIT License.
+
+set -o errexit -o nounset -o pipefail
+shopt -s inherit_errexit lastpipe
+
+script_dir="$( dirname -- "${BASH_SOURCE[0]}" )"
+script_dir="$( cd -- "$script_dir" && pwd )"
+readonly script_dir
+script_name="$( basename -- "${BASH_SOURCE[0]}" )"
+readonly script_name
+
+readonly default_iterations=100
+readonly default_min=0
+readonly default_max=200
+
+main() {
+ if [ "$#" -lt 1 ] || [ "$#" -gt 4 ]; then
+ echo "usage: $script_name ALGORITHM [ITERATIONS [MIN_VALUE [MAX_VALUE]]]" >&2
+ exit 1
+ fi
+
+ local algorithm="$1"
+ local iterations="$default_iterations"
+ [ "$#" -ge 2 ] && iterations="$2"
+ local min="$default_min"
+ [ "$#" -ge 3 ] && min="$3"
+ local max="$default_max"
+ [ "$#" -ge 4 ] && max="$4"
+
+ cd -- "$script_dir/.."
+ mkdir -p -- img
+
+ local input_kind
+ for input_kind in best average worst; do
+ local output_name="${algorithm}_${iterations}_${input_kind}_${min}_${max}.png"
+ python -m algorithms.scripts.plot \
+ "$algorithm" \
+ --input "$input_kind" \
+ --min "$min" --max "$max" \
+ --iterations "$iterations" \
+ --output "img/$output_name"
+ done
+}
+
+main "$@"
diff --git a/scripts/plot_all.sh b/scripts/plot_all.sh
new file mode 100755
index 0000000..1e56f40
--- /dev/null
+++ b/scripts/plot_all.sh
@@ -0,0 +1,46 @@
+#!/usr/bin/env bash
+
+# Copyright (c) 2019 Egor Tensin <Egor.Tensin@gmail.com>
+# This file is part of the "Sorting algorithms" project.
+# For details, see https://github.com/egor-tensin/sorting-algorithms.
+# Distributed under the MIT License.
+
+set -o errexit -o nounset -o pipefail
+shopt -s inherit_errexit lastpipe
+
+script_dir="$( dirname -- "${BASH_SOURCE[0]}" )"
+script_dir="$( cd -- "$script_dir" && pwd )"
+readonly script_dir
+
+declare -a algorithm_list=(
+ bubble_sort
+ bubble_sort_optimized
+ heapsort
+ insertion_sort
+ merge_sort
+ quicksort_first
+ quicksort_last
+ quicksort_middle
+ quicksort_random
+ quicksort_second
+ selection_sort
+)
+
+fix_matplotlib() {
+ # Get rid of:
+ # tkinter.TclError: no display name and no $DISPLAY environment variable
+ mkdir -p -- ~/.config/matplotlib
+ echo 'backend: Agg' > ~/.config/matplotlib/matplotlibrc
+}
+
+main() {
+ fix_matplotlib
+
+ local algorithm
+ for algorithm in ${algorithm_list[@]+"${algorithm_list[@]}"}; do
+ echo "Plotting algorithm $algorithm..."
+ "$script_dir/plot.sh" "$algorithm"
+ done
+}
+
+main "$@"