-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.sh
executable file
·363 lines (294 loc) · 9.24 KB
/
script.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#!/bin/bash
if ! type g++ &> /dev/null; then
echo "No tienes instalado g++"
echo "Instálalo usando el comando 'sudo apt-get install g++'"
exit 1
fi
if ! type gnuplot &> /dev/null; then
echo "No tienes instalado gnuplot"
echo "Instálalo usando el comando 'sudo apt-get install gnuplot'"
exit 1
fi
compiler="g++ -std=c++11"
flags="-g -O2"
plotter="gnuplot"
gnu_dir="binaries/gnuplot"
temp="temporal.gp"
really_slow=("slowsort")
slow=("insertion" "selection" "bubblesort")
fast=("quicksort" "radixsortlsd" "radixsortmsd" "mergesort" "heapsort" "bitonicsort" "countingsort")
_compile(){
echo "--------------------------------------"
echo " ***** Compilación de programas *****"
echo "--------------------------------------"
rm -rf binaries
mkdir -p binaries/{gnuplot,print} 2> /dev/null
for SRC in `ls src/`; do
print_bin=$(echo $SRC | cut -d"." -f1)
gnuplot_bin="$print_bin-gnuplot"
macro=$(echo $print_bin | tr '[:lower:]' '[:upper:]')
printf "Compilando %s..." "$SRC"
$compiler $flags -D PRINT -D $macro main.cpp -o binaries/print/$print_bin
$compiler $flags -D $macro main.cpp -o $gnu_dir/$gnuplot_bin
printf " [OK]\n"
done
}
_data(){
rm -rf data
if [ ! -d binaries ]; then
_compile
fi
echo "---------------------------------"
echo " ***** Generación de datos *****"
echo "---------------------------------"
echo "Nota: Se recomienda no tener muchas cosas ejecutando para obtener resultados más limpios"
mkdir data 2> /dev/null
for BIN in "${really_slow[@]}"; do
printf "Ejecutando %s... (Puede tardar un rato)" "$BIN"
for NUM in `seq 10 10 300`; do
./$gnu_dir/$BIN-gnuplot $NUM >> data/$BIN.dat
done
printf " [OK]\n"
done
for BIN in "${slow[@]}"; do
printf "Ejecutando %s... (Puede tardar un rato)" "$BIN"
for NUM in `seq 1000 1000 50000`; do
./$gnu_dir/$BIN-gnuplot $NUM >> data/$BIN.dat
done
printf " [OK]\n"
done
for BIN in "${fast[@]}"; do
printf "Ejecutando %s... (Puede tardar un rato)" "$BIN"
for NUM in `seq 100000 100000 5000000`; do
./$gnu_dir/$BIN-gnuplot $NUM >> data/$BIN.dat
done
printf " [OK]\n"
done
}
_init_gnuplot(){
echo "set terminal jpeg size 800,600" > $temp
echo "set xlabel \"Size\"" >> $temp
echo "set ylabel \"Time (s)\"" >> $temp
echo "set key tmargin" >> $temp
}
_graphs(){
rm -rf graphs/separate
if [ ! -d data ]; then
_data
fi
echo "--------------------------------------------"
echo " ***** Creación de gráficas separadas *****"
echo "--------------------------------------------"
mkdir -p graphs/separate 2> /dev/null
for DATA in `ls data/`; do
label=$(echo $DATA | cut -d"." -f1)
printf "Creando gráfica de %s..." "$label"
_init_gnuplot
echo "set output \"graphs/separate/$label.jpeg\"" >> $temp
echo "plot \"data/$DATA\" with linespoints title \"$label\"" >> $temp
$plotter $temp
printf " [OK]\n"
done
rm $temp
}
_incremental_graphs(){
if [ ! -d data ]; then
_data
fi
echo "------------------------------------------------"
echo " ***** Creación de gráficas incrementales *****"
echo "------------------------------------------------"
mkdir -p graphs/comparative 2> /dev/null
_init_gnuplot
echo "set output \"graphs/comparative/really_slow-slow.jpeg\"" >> $temp
printf "plot" >> $temp
printf "Creando gráfica muy lentos-lentos..."
for DATA in "${really_slow[@]}"; do
printf ", \"data/$DATA.dat\" with linespoints title \"$DATA\"" >> $temp
done
for DATA in "${slow[@]}"; do
printf ", \"data/$DATA.dat\" with linespoints title \"$DATA\"" >> $temp
done
printf " [OK]\n"
printf "\n" >> $temp
echo "set output \"graphs/comparative/slow-fast.jpeg\"" >> $temp
printf "plot" >> $temp
printf "Creando gráfica lentos-rápidos..."
for DATA in "${slow[@]}"; do
printf ", \"data/$DATA.dat\" with linespoints title \"$DATA\"" >> $temp
done
for DATA in "${fast[@]}"; do
printf ", \"data/$DATA.dat\" with linespoints title \"$DATA\"" >> $temp
done
printf " [OK]\n"
sed -i 's/plot,/plot/g' $temp
$plotter $temp
rm $temp
}
_comparative_graphs(){
if [ ! -d data ]; then
_data
fi
echo "-----------------------------------------------"
echo " ***** Creación de gráficas comparativas *****"
echo "-----------------------------------------------"
mkdir -p graphs/comparative 2> /dev/null
_init_gnuplot
echo "set output \"graphs/comparative/really_slow.jpeg\"" >> $temp
printf "plot" >> $temp
printf "Creando gráfica muy lentos..."
for DATA in "${really_slow[@]}"; do
printf ", \"data/$DATA.dat\" with linespoints title \"$DATA\"" >> $temp
done
printf " [OK]\n"
printf "\n" >> $temp
echo "set output \"graphs/comparative/slow.jpeg\"" >> $temp
printf "plot" >> $temp
printf "Creando gráfica lentos..."
for DATA in "${slow[@]}"; do
printf ", \"data/$DATA.dat\" with linespoints title \"$DATA\"" >> $temp
done
printf " [OK]\n"
printf "\n" >> $temp
echo "set output \"graphs/comparative/fast.jpeg\"" >> $temp
printf "plot" >> $temp
printf "Creando gráfica rápidos..."
for DATA in "${fast[@]}"; do
printf ", \"data/$DATA.dat\" with linespoints title \"$DATA\"" >> $temp
done
printf " [OK]\n"
sed -i 's/plot,/plot/g' $temp
$plotter $temp
rm $temp
}
_full_graph(){
if [ ! -d data ]; then
_data
fi
echo "-------------------------------------"
echo " ***** Creación de gráfica total *****"
echo "-------------------------------------"
mkdir -p graphs/comparative 2> /dev/null
count=0
printf "Creando gráfica total..."
for FILE in `ls data/`; do
array[count]=$FILE
let count=count+1
done
_init_gnuplot
echo "set output \"graphs/comparative/comparativa.jpeg\"" >> $temp
printf "plot" >> $temp
for DATA in `ls data/`; do
label=$(echo $DATA | cut -d"." -f1)
printf ", \"data/$DATA\" with lines title \"$label\"" >> $temp
done
sed -i 's/plot,/plot/' $temp
$plotter $temp
rm $temp
printf " [OK]\n"
}
_compare(){
if [ ! -d data ]; then
_data
fi
mkdir -p graphs/vs/ 2> /dev/null
expresion="("
for DATA in `ls data/`; do
label=$(echo $DATA | cut -d"." -f1)
expresion="$expresion$label|"
done
expresion=${expresion:0:-1}
expresion="$expresion)"
num_algs=$(ls data/ | wc -l)
while
printf "Introduce el número de algoritmos que quieres comparar (mínimo 2, máximo $num_algs) --> "
read NUM
[ $NUM -lt 2 ] || [ $NUM -gt $num_algs ]
do
:
done
echo "Elige $NUM entre estos:"
for DATA in `ls data/`; do
echo "*) $(echo $DATA | cut -d"." -f1)"
done
printf "\n"
for i in `seq 1 1 $NUM`; do
while
printf "Introduzca el nombre de un algoritmo válido ($(($NUM-$i+1)) restantes)--> "
read ALG
[[ ! $ALG.dat =~ $expresion\.dat ]]
do
:
done
let num=$i-1
array[$num]=$ALG
done
printf "Creando gráfica..."
_init_gnuplot
printf "set output \"graphs/vs/" >> $temp
for ALG in "${array[@]}"; do
label=${ALG:0:4}
printf "$label-" >> $temp
done
printf "comp.jpeg\"\n" >> $temp
printf "plot" >> $temp
for DATA in "${array[@]}"; do
printf ", \"data/$DATA.dat\" with linespoints title \"$DATA\"" >> $temp
done
sed -i 's/plot,/plot/' $temp
$plotter $temp
rm $temp
printf " [OK]\n"
}
_help(){
echo "Uso: ./script.sh <option>"
echo " --all: Genera todos los archivos (hace --mrproper, --compile, --data, --graphs y --comparative)"
echo " --clean: Borra los binarios que generan los datos y las gráficas que comparan dos algoritmos"
echo " --mrproper: Borra los datos de gnuplot, todos los binarios y todas las gráficas"
echo " --compile: Compila los programas"
echo " --data: Genera los datos (se compilarán los programas si estos no existen)"
echo " --graphs: Genera las gráficas de cada algoritmo a partir de los datos (se generan los datos si estos no existen)"
echo " --comparative: Genera las gráficas de las comparativas (tanto la total como la separada según velocidad como la incremental; generan datos si no existen)"
echo " --compare: Genera una gráfica comparativa de dos algoritmos (se pedirán los nombres por consola; se generan datos si estos no existen)"
echo " --help: Muestra esta ayuda"
echo " Si no hay argumentos o más de uno, devolverá un error, mostrará esta ayuda y acabará"
echo " Ejecutar el script en el directorio donde está, sino dará error"
}
if [ $# -eq 1 ]; then
if [ "$1" == "--clean" ]; then
find . -regex ".*~" -exec rm {} \;
rm -rf binaries/gnuplot graphs/vs
elif [ "$1" == "--mrproper" ]; then
find . -regex ".*~" -exec rm {} \;
rm -rf data graphs binaries
elif [ "$1" == "--compile" ]; then
_compile
elif [ "$1" == "--data" ]; then
_data
elif [ "$1" == "--graphs" ]; then
_graphs
elif [ "$1" == "--comparative" ]; then
_incremental_graphs
_comparative_graphs
_full_graph
elif [ "$1" == "--compare" ]; then
_compare
elif [ "$1" == "--help" ]; then
_help
elif [ "$1" == "--all" ]; then
find . -regex ".*~" -exec rm {} \;
rm -rf data binaries graphs
_compile
_data
_graphs
_incremental_graphs
_comparative_graphs
_full_graph
else
echo "Error: Argumento incorrecto"
_help
fi
else
echo "Error: Número de argumentos incorrecto"
_help
fi