Created
November 8, 2017 19:57
-
-
Save aldantas/fafb9b975de932a750efb924a7e1094e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# last_script_pid=$1 | |
algorithm=$1 | |
numbers_of_tests=30 | |
underscore="_" | |
done_instances=instances.txt | |
avaiable_cpus=10 | |
wait_queue() { | |
while [ ! `qstat | grep -F "${jobs_id}" | wc -l` -eq 0 ]; do | |
sleep 1 | |
done | |
} | |
wait_last_script() { | |
while [ `ps | grep $last_script_pid | wc -l` -ne 0 ]; do | |
sleep 1 | |
done | |
} | |
wait_free_cpu() { | |
while [ `qstat | grep "add_job.sh" | wc -l` -eq $avaiable_cpus ]; do | |
sleep 1 | |
done | |
} | |
submit_mmas_tests() { | |
echo $1 >> $done_instances | |
job="python3 runner.py ../qap_instances/$1" | |
jobs_id="" | |
for i in $(seq 1 $numbers_of_tests); do | |
jobs_id=$(printf "${jobs_id}\n`qsub -terse add_job.sh "$job $i $algorithm"`") | |
# if [ $(($i % $avaiable_cpus)) -eq 0 ]; then | |
# wait_queue | |
# fi | |
done | |
wait_queue | |
mv_files | |
} | |
submit_ga_tests() { | |
echo $1 >> $done_instances | |
outfile="QAP_"$instance"_test_"$algorithm_name"_tid_" | |
job="./ga -f ../qap_instances/$1 -o $outfile" | |
jobs_id="" | |
for i in $(seq 1 $numbers_of_tests); do | |
seed=$(shuf -i 1-1000 -n 1) | |
jobs_id=$(printf "${jobs_id}\n`qsub -terse add_job.sh "$job$i.dat -s $seed"`") | |
if [ $(($i % $avaiable_cpus)) -eq 0 ]; then | |
wait_queue | |
fi | |
done | |
wait_queue | |
mv_files | |
} | |
run_instances_tests() { | |
if [ ! -f "$done_instances" ]; then | |
>$done_instances | |
fi | |
for file in $(ls ../qap_instances/); do | |
if ! grep -q $file $done_instances; then | |
instance=${file%.*} | |
($runner $file) | |
fi | |
done | |
} | |
mv_files() { | |
root_dir="experiments/$instance/$algorithm_name" | |
dir="$root_dir/single_test_files" | |
mkdir -p "$dir" | |
file_prefix="QAP_$instance"_test_"$algorithm_name" | |
mv $file_prefix*.dat $dir | |
# python3 organize_data.py $root_dir | |
logs_dir="logs/$instance/$algorithm_name" | |
mkdir -p $logs_dir | |
# for job_id in `echo "$jobs_id" | tr '\n' ' '`; do | |
for job_id in $jobs_id; do | |
mv "add_job.sh.o$job_id" $logs_dir | |
done | |
} | |
if [ "$algorithm" = "0" ]; then | |
algorithm_name="maxmin_ant_system" | |
job="python3 runner.py ../qap_instances/$1" | |
runner=submit_mmas_tests | |
elif [ "$algorithm" = "1" ]; then | |
algorithm_name="genetic_algorithm" | |
runner=submit_ga_tests | |
fi | |
run_instances_tests |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment