-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrunParallal.sh
executable file
·170 lines (136 loc) · 3.15 KB
/
runParallal.sh
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#! /bin/bash
clear
usage()
{
echo "USAGE: ./runParallal.sh [OPTIONS] NB_OF_EXP CONFIG_FILE NB_OF_INSTANCE "
echo ""
echo "OPTIONS"
echo " -p, --postExperiemtScript=SCRIPT_AND_PARAMETERS"
echo " Use the SCRIPT_AND_PARAMETERS after an experiment has been completed"
}
oneRun()
{
#init variables
config=$1
mainTimeStamp=$2
postExperimentScript=$3
readSpawn=$4
expNo=$5
echo "LAUNCH COUNT $cnt"
isSuccess=0
timeStamp=`date +%H%M%S%N`
#launch experiment
#expNo=$(cat "complete$mainTimeStamp")
#Read spawn locations from file
if [ "$readSpawn" = "r" ]
then
echo "READING Spawn locations"
config=$(echo $config|sed 's/pheromone.properties/pheromone-read.properties/')
readSpawnLocations $expNo $config
else
echo "Spawn locations Random"
config=$(echo $config|sed 's/pheromone.properties/pheromone-random.properties/')
fi
./roborobo -l $config 2>"temp"$timeStamp"Error" | tee "temp$timeStamp"
#apply post-experiment processing if the last experiment isn't already done
if [ ! -e "./lastRunDone" ]
then
#standard post-experiment processing
if [ "$postExperimentScript" = "" ]
then
#wait until can update the results
while [ -e "take$mainTimeStamp" ]
do
sleep 1
done
#update results
touch "take$mainTimeStamp"
count=$(cat "complete$mainTimeStamp")
count=$((count+1))
echo $count > "complete$mainTimeStamp"
rm "take$mainTimeStamp"
rm "temp$timeStamp"
echo "Done : $count/$nbExp"
#user specified post-experiment processing
else
. $postExperimentScript
fi
else
rm "take$mainTimeStamp"
rm "temp$timeStamp"
fi
}
readSpawnLocations()
{
expNo=$1
conf=$2
export IFS=","
cat output/spawn/"$expNo"spawn | while read n x y o;
do
#echo "$expNo spawn robot: $n x: $x y: $y theta $o";
#echo "using config file $conf"
sed -i "/agent\[$n\]\.x =/s/= .*/= $x/" "$conf";
sed -i "/agent\[$n\]\.y =/s/= .*/= $y/" "$conf";
sed -i "/agent\[$n\]\.orientation =/s/= .*/= $o/" "$conf";
done
}
if [ $# -lt 3 ]
then
usage
else
nbInst=""
nbExp=""
config=""
postExperimentScript=""
rdSpawn=""
while [ "$1" != "" ]; do
case $1 in
-p | --postExperimentScript ) shift
postExperimentScript=$1
;;
-h | --help ) usage
exit
;;
*) break
esac
shift
done
nbExp=$1
config=$2
nbInst=$3
rdSpawn=$4
mainTimeStamp=`date +%H%M%S%N`
completeCnt=0
totCnt=0
lastRunDone=0
launchCnt=0
if [ -e "./lastRunDone" ]
then
rm lastRunDone
fi
echo "0" > "complete$mainTimeStamp"
while [ $completeCnt -lt $nbExp ]
do
while [ `jobs | wc -l` -ge $nbInst ] # check the number of instance currently running
do
jobs >/dev/null
sleep 5
done
while [ -e "take$mainTimeStamp" ]
do
sleep 1
done
touch "take$mainTimeStamp"
completeCnt=$(cat "complete$mainTimeStamp")
rm "take$mainTimeStamp"
if [ $totCnt -lt $nbExp ]
then
oneRun $config $mainTimeStamp "$postExperimentScript" "$rdSpawn" "$launchCnt" &
totCnt=$((totCnt+1))
launchCnt=$((launchCnt+1))
fi
sleep 1
done
touch "./lastRunDone"
killall -9 roborobo
fi