def visualize_animate(i):
	global visualization_UAV, visualization_nodes_text, visualization_path, path_x, path_y
	global UAV_energy_efficient_bar
	global UAV, nodes, round_num

	# visualize the field
	visualization_UAV.set_data(UAV['current_x'], UAV['current_y'])
	if path_x[-1] != UAV['current_x'] or path_y[-1] !=  UAV['current_y']:
		path_x.append(UAV['current_x'])
		path_y.append(UAV['current_y'])
	visualization_path.set_data(path_x, path_y)
	for node_index in range(len(visualization_nodes_text)):
		visualization_nodes_text[node_index].set_text('%d:' % node_index + '(%.2lf)' % nodes[node_index]['power'])

	# make it easier to make videos
	# if i == 0:
	# 	time.sleep(10)

	# visualize the UAV
	for rect in UAV_energy_bar:
		rect.set_height(UAV['power'])

	# visualize the sensor nodes
	for bars, node in zip(nodes_energy_bar_list, nodes):
		for rect in bars:
			rect.set_height(node['power'])

	left = param_animation_frame_skip_num + 1
	while left > 0 and is_valid_node_network(nodes) and is_valid_UAV(UAV):
		nodes_next_second(nodes)
		UAV_AI.next_second(UAV, nodes, charge_mode, path_mode, 1.0, params)
		round_num += 1
		left -= 1
													for path_mode in param_path_mode:
														# filter invalid combination
														if is_valid_combination(charge_mode, path_mode) == False:
															continue
														UAV_mode = path_mode + '_' + charge_mode
														print 'UAV Mode: ' + UAV_mode
														UAV = copy.deepcopy(UAV_new)
														nodes = copy.deepcopy(nodes_new)
														# a hack for combination experiment
														# for node in nodes:
														# 	node['capacity'] = 100000000000 
														params = {}
														round_num = 0
														while is_valid_node_network(nodes) and is_valid_UAV(UAV) and round_num < param_time_limit:
															nodes_next_second(nodes)
															UAV_AI.next_second(UAV, nodes, charge_mode, path_mode, task_threshold, params)
															round_num += 1
														round_num += int(min(node['power'] for node in nodes) / nodes[0]['rate'])
														print 'The system is dead at round: ' + str(round_num)
														res_file.write(network_type_str + ',' + UAV_mode + ',' + str(round_num) + '\n')
											# multi flight
											else:
												for charge_mode in param_charge_mode:
													for path_mode in param_path_mode:
														# filter invalid combination
														if is_valid_combination(charge_mode, path_mode) == False:
															continue
														UAV_mode = path_mode + '_' + charge_mode
														print 'UAV Mode: ' + UAV_mode
														UAV = copy.deepcopy(UAV_new)
														nodes = copy.deepcopy(nodes_new)