Commit 03e08974 authored by Julian Rudolf's avatar Julian Rudolf
Browse files

changed how to calculate worst case time

fixed shell script
using wall clock time instead of processor time
parent 795f84eb
......@@ -9,12 +9,14 @@ def calculate_times(filename):
time_sum = 0
time_file = open("../Experiments/" + filename, "r")
times = (time_file.readlines())[:200]
worst_case = -1
for time in times:
time = float(time)
time_sum += time
if time > worst_case:
worst_case = time
mean_time = time_sum / len(times)
worst_case = max(times)
return mean_time, worst_case
......@@ -31,11 +33,11 @@ def run_experiment(max_steps, length, source_filename, target_filename):
reset(True, int(length))
mean, worst_case = calculate_times(source_filename)
string = (str(mean)).ljust(25) + " " + str(worst_case)
string = (str(mean)).ljust(25) + " " + str(worst_case) + "\n"
target_file = open(target_filename, "a")
target_file.write(string)
# run_experiment(10, 10, "test.txt", "test2.txt")
# run_experiment(30, 10, "test.txt", "test2.txt")
if __name__ == '__main__':
globals()[sys.argv[1]](sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5])
......@@ -25,10 +25,10 @@ echo "-------------------------------------------" >> $TARGET_FILE
echo "Starting experiments!"
for i in 10 15 20
do
echo "Snake Length: " $i
echo "Snake Length: " $i >> $TARGET_FILE
for j in {10..30}
do
echo "Snake length: " $i " max_steps: " $j
echo "Snake length: " $i " max_steps: " $j " calculating ..."
python experiment.py run_experiment $j $i $SOURCE_FILE $TARGET_FILE
rm $SOURCE_FILE
done
......
......@@ -432,7 +432,7 @@ class Snake:
except AttributeError:
choice = True
if not choice and False:
if not choice:
if check_if_after_crossing(self.enemy_norm_snake.pos[1] / block_size,
self.enemy_norm_snake.pos[0] / block_size,
self.enemy_norm_snake.direction):
......
......@@ -617,7 +617,7 @@ def remove_files(files, master_filename='master.nm'):
# return:
# crash_prob : probability of a crash for each possible direction
def get_shield(crash_prob_queue, snake_player, snake_enemy, count=0, recalc=False, p_move=0):
shield_start = time.process_time_ns()
shield_start = time.perf_counter()
# master file name
master_filename = 'master_' + str(uuid.uuid4()) + '.nm'
......@@ -667,9 +667,9 @@ def get_shield(crash_prob_queue, snake_player, snake_enemy, count=0, recalc=Fals
# return the crash probabilities (multiprocessing)
crash_prob_queue.put(crash_prob)
shield_end = time.process_time_ns()
shield_end = time.perf_counter()
total_time = shield_end - shield_start
total_time /= 1e+9
#total_time /= 1e+9
if times_filename:
times_file = open("../Experiments/" + times_filename, "a")
times_file.write(str(total_time) + "\n")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment