#!/bin/bash

# iedera number of trials
r=1000;

# number of process on the computer for the program to sleep
# (this script is run on student computers, so it must stop when someone logs in)
p=130;

# read length
l=34;

# number of runs
for run in $(seq 1 1000)
do

    # 0) number of hits
    for y in 2
    do

        # A) number of seeds
        for n in 1 2 3 4
        do

            # B) seed weight
            for w in 10 11 12 13 14
            do

                # set seed span
                s=$((${w}+12-${n}));
                mx=$((${l}-${w}));

                # a) non symetric seed
                echo "$HOSTNAME: lossy n:${n} w:${w} y:${y}";
                filename="results_lossy_n${n}_w${w}_y${y}.txt";
                nice -n +10 ./iedera_lossy -A 3 -B 2 -M \{\{0,1,1\},\{0,0,1\}\} -b 0,0.7,0.3 -BSymbols '-#' -l ${l} -n ${n} -w ${w},${w} -s ${w},${s} -r ${r} -k -fF autogen_lossy.txt -e ${filename} -e backup/${filename} -o ${filename} -y ${y} 2> /dev/null

                # b) symetric seed
                echo "$HOSTNAME: lossy ${model} n:${n} w:${w} y:${y} sym";
                filename="results_lossy_n${n}_w${w}_y${y}_sym.txt";
                nice -n +10 ./iedera_lossy -A 3 -B 2 -M \{\{0,1,1\},\{0,0,1\}\} -b 0,0.7,0.3 -BSymbols '-#' -x -l ${l} -n ${n} -w ${w},${w} -s ${w},${s} -r ${r} -k -fF autogen_lossy.txt -e ${filename} -e backup/${filename} -o ${filename} -y ${y} 2> /dev/null

                # c) non symetric position restricted seed
                filename="results_lossy_n${n}_w${w}_y${y}.txt";
                # position restricted lengths
                for q in 64 40 32 24 16 12 10 8 7 6 5 4
                do
                    # q_s "mixer"
                    q_r=${q};q_s="";
                    for i in $(seq 2 ${n})
                    do
                        rx=$(($RANDOM % ${q_r}));
                        while [ ${rx} -gt ${mx} ]; do
                            rx=$(($RANDOM % ${q_r}));
                        done
                        q_s="${q_s},${rx}";
                        q_r=$((${q_r}-${rx}));
                    done;
                    q_s="${q_r}${q_s}";

                    if [ ${q_r} -gt ${mx} ]; then
                        echo "$HOSTNAME: lossy ${model} n:${n} w:${w} y:${y} q:${q} = ${q_s} : ABORD";
                    else
                        echo "$HOSTNAME: lossy ${model} n:${n} w:${w} y:${y} q:${q} = ${q_s} : CONTINUE";
                        # non symetric seed
                        filename="results_lossy_n${n}_w${w}_y${y}_q${q}.txt";
                        nice -n +10 ./iedera_lossy -A 3 -B 2 -M \{\{0,1,1\},\{0,0,1\}\} -b 0,0.7,0.3 -BSymbols '-#' -l ${l} -n ${n} -w ${w},${w} -s ${w},${s} -c ${l} -q ${q_s} -r ${r} -k -fF autogen_lossy.txt -e ${filename} -e backup/${filename} -o ${filename} -y ${y} 2> /dev/null;
                    fi;
                done

                # d) symetric position restricted seed
                filename="results_lossy_n${n}_w${w}_y${y}_sym.txt";
                # position restrited lengths
                for q in 64 40 32 24 16 12 10 8 7 6 5 4
                do
                    # q_s "mixer"
                    q_r=$q;q_s="";
                    for i in $(seq 2 ${n})
                    do
                        rx=$(($RANDOM % ${q_r}));
                        while [ ${rx} -gt ${mx} ]; do
                            rx=$(($rx - $mx));
                        done
                        q_s="${q_s},${rx}";
                        q_r=$((${q_r}-${rx}));
                    done;
                    q_s="${q_r}${q_s}"

                    if [ ${q_r} -gt ${mx} ]; then
                        echo "$HOSTNAME: lossy ${model} n:${n} w:${w} y:${y} q:${q} = ${q_s} sym : ABORD";
                    else
                        echo "$HOSTNAME: lossy ${model} n:${n} w:${w} y:${y} q:${q} = ${q_s} sym : CONTINUE";
                        # symetric seed
                        filename="results_lossy_n${n}_w${w}_y${y}_q${q}_sym.txt";
                        nice -n +10 ./iedera_lossy -A 3 -B 2 -M \{\{0,1,1\},\{0,0,1\}\} -b 0,0.7,0.3 -BSymbols '-#' -x -l ${l} -n ${n} -w ${w},${w} -s ${w},${s} -c ${l} -q ${q_s} -r ${r} -k -fF autogen_lossy.txt -e ${filename} -e backup/${filename} -o ${filename} -y ${y} 2> /dev/null;
                    fi;
                done
            done
        done
    done
done
