#!/bin/bash

_NBITERATIONS=$NBITERATIONS

. params.sh

# For dry-run
NBITERATIONS=${_NBITERATIONS:-$NBITERATIONS}

set -u
mkdir -p ${RESDIR}

MAX_PROCESS=10
current_process=0

# run

date > ${RESDIR}/log.txt

for wf in ${WORKFLOWS}
do
for eps in ${EPSILONS}
do
for delta in ${DELTAS}
do
for seed in ${SEEDS}
do
# Skip unnecessarily runs
if [[ $wf = "odonly" && ($delta != "8" || $eps == "1.0") ]]; then
    continue
fi
if [[ $wf = "bronly" && ($eps != "1.0" || $delta == "8") ]]; then
    continue
fi
if [[ $wf != "odonly" && $wf != "bronly" && ($delta == "8" || $eps == "1.0") ]]; then
continue
fi


EXP=${wf}-${eps}-${delta}-${seed}
mkdir -p ${RESDIR}/${EXP}

echo ${EXP}
./${SIMDIR}/soba --seed ${seed} --dir "${RESDIR}/${EXP}" --nbAgent ${NBAGENTS} \
    --tick ${NBITERATIONS} --atoms ${ATOM} \
    --update """`cat ${TEMPLATEDIR}/workflow-${wf}.txt`""" \
    --prehoc "${PREHOC}" \
    --mu "${MU}" --alpha "${ALPHA}" --rewrite ${REWRITE} \
    --pUnfollow "${PREWRITE}" --pActive "${PACTIVE}" --epsilon "${eps}"  \
    --delta ${delta} \
    --values """`cat ${TEMPLATEDIR}/val-${VALUES}.json`""" \
    --topics "${TOPIC}" --reevaluateCatBeforeRewiring &
current_process=$((current_process + 1))

if [[ $current_process = $MAX_PROCESS ]]; then
wait
current_process=0
fi

done
done
done
done


date >> ${RESDIR}/log.txt

# analyse


