Пример #1
0
def part_2(num_files):
	# Compare run times for each maze using the two tie-break methods

	out_file = open('data/part_2_data.csv','w')
	writer = csv.writer(out_file)

	# Header
	writer.writerow(('maze_num','smaller_exec_time','larger_exec_time','smaller_expanded_states','larger_expanded_states'))

	for i in range(0,num_files):
		maze_file = "mazes/maze_{0}.csv".format(i)
		grid, size = env.read_grid(maze_file)
		start = Cell(0,0,size)
		goal = Cell(100,100,size)

		smaller_expanded_states = 0
		larger_expanded_states = 0

		print "start smaller"
		smaller_break_start = datetime.datetime.now()
		path, smaller_expanded_states = algo.repeated_forward_a_star(start,goal,grid,1,smaller_expanded_states)
		smaller_break_end = datetime.datetime.now()

		print "reset grid"
		# RE-INITIALIZE GRID
		new_grid, size = env.read_grid(maze_file)

		print "start larger"
		larger_break_start = datetime.datetime.now()
		path, larger_expanded_states = algo.repeated_forward_a_star(start,goal,new_grid,0,larger_expanded_states)
		larger_break_end = datetime.datetime.now()

		smaller_exec_time = (smaller_break_end - smaller_break_start).total_seconds()
		larger_exec_time = (larger_break_end - larger_break_start).total_seconds()

		print "{0},{1},{2},{3},{4}".format(i,smaller_exec_time,larger_exec_time,smaller_expanded_states,larger_expanded_states)
		writer.writerow((i,smaller_exec_time,larger_exec_time,smaller_expanded_states,larger_expanded_states))

	out_file.close()
Пример #2
0
def part_4(num_files):
	out_file = open('data/part_4_data.csv','w')
	writer = csv.writer(out_file)

	# Header
	writer.writerow(('maze_num','forward_exec_time','adaptive_exec_time','forward_expanded_states','adaptive_expanded_states'))

	for i in range(0,num_files):
		maze_file = "mazes/maze_{0}.csv".format(i)
		grid, size = env.read_grid(maze_file)
		start = Cell(0,0,size)
		goal = Cell(100,100,size)

		forward_expanded_states = 0
		adaptive_expanded_states = 0

		print "forward"
		forward_start = datetime.datetime.now()
		path, forward_expanded_states = algo.repeated_forward_a_star(start,goal,grid,0,forward_expanded_states)
		forward_end = datetime.datetime.now()

		print "reset grid"
		# RE-INITIALIZE GRID
		new_grid, size = env.read_grid(maze_file)

		print "adaptive"
		adaptive_start = datetime.datetime.now()
		path, adaptive_expanded_states = algo.adaptive_a_star(start,goal,new_grid,0,adaptive_expanded_states)
		adaptive_end = datetime.datetime.now()

		forward_exec_time = forward_end - forward_start
		adaptive_exec_time = adaptive_end - adaptive_start

		forward_exec_time = forward_exec_time.total_seconds()
		adaptive_exec_time = adaptive_exec_time.total_seconds()

		print "{0},{1},{2},{3},{4}".format(i,forward_exec_time,adaptive_exec_time,forward_expanded_states,adaptive_expanded_states) 
		writer.writerow((i,forward_exec_time,adaptive_exec_time,forward_expanded_states,adaptive_expanded_states))

	out_file.close()