-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_sudoku_medium_tests
51 lines (51 loc) · 1.81 KB
/
run_sudoku_medium_tests
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
#!/usr/bin/bash
#check for n_sudokus argument
if [[ $# -lt 1 || $# -gt 1 ]] ; then
echo 'Wrong arguments provided'
exit 1
fi
declare -a medium_sudoku_puzzles
input="./ressources/medium.txt"
n_sudokus=$1
n=0
#some medium puzzles (n_sudokus) to test from the file
while IFS= read -r line
do
hash=$(echo "$line" | awk '{print $1}')
medium_sudoku_puzzles[${#medium_sudoku_puzzles[@]}]="$hash"
((n++))
if [[ n -eq n_sudokus ]]; then
break;
fi
done < "$input"
#make compile main sudoku solving C program
make clean && make
#set variables
stats_file="./benchmark/medium/stats-$$.txt"
sum_exec=0.0
sum_cost=0
sum_pow_exec=0.0
sum_exec_cost=0.0
n=0
#try the medium puzzles
for i in "${medium_sudoku_puzzles[@]}"
do
result=$(./bin/main "medium.txt" "$i")
echo -e "$result"
#get the execution time for the x axis and the final cost of the algorithm for the y axis
exec_time=$(echo "$result" | grep ">> CPU Execution time of the sudoku solving simulation :" | awk 'NF>1{print $NF}')
end_cost=$(echo "$result" | grep ">> Best solution (lowest cost) found during the execution of the simulation :" | awk 'NF>1{print $NF}')
echo "$exec_time $end_cost" >> "$stats_file"
#sum_exec=$(echo "$sum_exec + $exec_time" | bc -l)
#sum_cost=$(echo "$sum_cost + $end_cost" | bc -l)
#sum_pow_exec=$(echo "$sum_pow_exec + $exec_time^2" | bc -l)
#sum_exec_cost=$(echo "$sum_exec_cost + $exec_time * $end_cost" | bc -l)
#n+=1
done
#calculate m and b for standard curve
#https://www.statisticshowto.com/probability-and-statistics/regression-analysis/find-a-linear-regression-equation/
#m=$(echo "($n * $sum_exec_cost - $sum_exec * $sum_cost) / ($n * $sum_pow_exec - $sum_exec^2)" | bc -l)
#b=$(echo "($sum_cost - $m * $sum_exec) / $n" | bc -l)
#echo -e " $m $b"
#create benchmark graph
./bin/benchmark "2" "$stats_file" #"$m" "$b"