-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_sudoku_easy_tests
43 lines (43 loc) · 1.59 KB
/
run_sudoku_easy_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
#!/usr/bin/bash
#check for n_sudokus argument
if [[ $# -lt 1 || $# -gt 1 ]] ; then
echo 'Wrong arguments provided'
exit 1
fi
declare -a easy_sudoku_puzzles
input="./ressources/easy.txt"
n_sudokus=$1
n=0
#some easy puzzles (n_sudokus) to test from the file
while IFS= read -r line
do
hash=$(echo "$line" | awk '{print $1}')
easy_sudoku_puzzles[${#easy_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/easy/stats-$$.txt"
#try the easy puzzles
for i in "${easy_sudoku_puzzles[@]}"
do
result=$(./bin/main "easy.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}')
tries=$(echo "$result" | grep ">> Numbers of tries taken : " | awk 'NF>1{print $NF}')
echo "$exec_time $end_cost $tries" >> "$stats_file"
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 "1" "$stats_file" #"$m" "$b"
#rm -r "fit.log"