#!/bin/bash

### Define the parameter settings to run through
STEPSPERCANDIDATE="313"
INITIALMUTATIONSTEPSIZE="0.2693"
REEVALRATE="0.018"
CROSSOVERRATE="0.061"
MUTATIONRATE="0.1501"

### Run through these settings
echo "" > settings_to_test
LINES=0
for steps in $STEPSPERCANDIDATE
do
	for stepsize in $INITIALMUTATIONSTEPSIZE
	do
		for reeval in $REEVALRATE
		do
			for xover in $CROSSOVERRATE
			do
				for mutation in $MUTATIONRATE
				do
					for i in {1..26}
					do
						let LINES=$LINES+1
						echo ./run_hivemind_p2.sh --robots 400 --stepsPerCandidate $steps --initialMutationStepSize $stepsize --reEvaluationRate $reeval --crossoverRate $xover --mutationRate $mutation --seed $RANDOM >> settings_to_test
					done
				done
			done
		done
	done
done

echo $LINES experiments to run

THREADS=2
function perform_experiments() {
	j=$1
	let real=$j+1
	while [ $j -le $LINES ]
	do
		cmd=`head -n $real settings_to_test | tail -n 1`
		eval $cmd
		let j=$j+$THREADS
		let real=$j+1
	done 
}

i=0
while [ $i -lt $THREADS ]
do
	let i=$i+1
	perform_experiments $i &
done
