def deliver_packages(nodes_set, current_position, d): while (len(nodes_set) != 0): nearest_node = nodes_set[0][0] k = 0 nearest_node_len = len(shortest_path(current_position, nodes_set[0][0])) for i in range(len(nodes_set)): length = len(shortest_path(current_position, nodes_set[i][0])) if length < nearest_node_len: nearest_node_len = length k = i nearest_node = nodes_set[k][0] path = shortest_path(current_position, nearest_node) d = bot_movement(path, d) package_client.Message(nodes_set[k][1]) nodes_set[k:k + 1] = [] current_position = path[len(path) - 1] return current_position, d
def deliver_packages(nodes_set, current_position, d): print 'original', nodes_set while (len(nodes_set) != 0): nearest_node = nodes_set[0][0] k = 0 nearest_node_len = len(shortest_path(current_position, nodes_set[0][0])) for i in range(len(nodes_set)): length = len(shortest_path(current_position, nodes_set[i][0])) if length < nearest_node_len: nearest_node_len = length k = i nearest_node = nodes_set[k][0] path = shortest_path(current_position, nearest_node) print nodes_set[k][1] print 'traversal_path', path d = bot_movement(path, d) package_client.Message(nodes_set[k][1]) nodes_set[k:k + 1] = [] print print 'nodes_set', nodes_set current_position = path[len(path) - 1] return current_position, d
print # ##################################################### # #package collection from the warehouse path = shortest_path((8, 770), input_array[0][0]) d = bot_movement(path, d) next_counter = 1 previous_counter = 0 current_position = input_array[0][0] for i in range(len(input_array)): delivery_nodes = [] package_client.Message(input_array[i][2]) if next_counter == 4 or next_counter == 8 or next_counter == 12 or next_counter == len( input_array): ###################################################################################################### ## Logic for traversal once 4 nodes are collected for j in xrange(previous_counter, next_counter): delivery_nodes.append((input_array[j][1], input_array[j][3])) previous_counter = next_counter current_position, d = deliver_packages(delivery_nodes, current_position, d) ###################################################################################################### ## Going back to the warehouse zone after deliery
d = forward_detect_green() # ##################################################### # #package collection from the warehouse path = shortest_path((8,770),input_array[0][0]) d = bot_movement(path,d) next_counter = 1 previous_counter = 0 current_position = input_array[0][0] for i in range(len(input_array)): delivery_nodes = [] package_client.Message(input_array[i][2]) if next_counter == 4 or next_counter == 8 or next_counter == 12 or next_counter == len(input_array): ###################################################################################################### ## Logic for traversal once 4 nodes are collected for j in xrange(previous_counter, next_counter): delivery_nodes.append((input_array[j][1], input_array[j][3])) previous_counter = next_counter current_position,d = deliver_packages(delivery_nodes,current_position,d) ###################################################################################################### ## Going back to the warehouse zone after deliery if i < len(input_array)-1: path = shortest_path(current_position, input_array[i][0])
d = forward_detect_green() # ##################################################### # #package collection from the warehouse path = shortest_path((8,770),input_array[0][0]) display_label(path) d = bot_movement(path,d) next_counter = 1 previous_counter = 0 current_position = input_array[0][0] for i in range(len(input_array)): delivery_nodes = [] package_client.Message(input_array[i][2]) if next_counter == 4 or next_counter == 8 or next_counter == 12 or next_counter == len(input_array): ###################################################################################################### ## Logic for traversal once 4 nodes are collected for j in xrange(previous_counter, next_counter): delivery_nodes.append((input_array[j][1], input_array[j][3])) previous_counter = next_counter current_position,d = deliver_packages(delivery_nodes,current_position,d) ###################################################################################################### ## Going back to the warehouse zone after deliery if i < len(input_array)-1: path = shortest_path(current_position, input_array[i][0])
def direction(a): # i: the index of the array a # status: the current direction of the robot is stored in this variable i=0 status='up' while i<len(a)-1: j=i+1 if type(a[j])==str: package_client.Message(a[j]) if type(a[j])==int and type(a[i])==str: if type(a[i-1])==int: a[i]=a[i-1] else: a[i]=a[i-2] if type(a[j])==int and type(a[i])==int: p=a[j]-a[i] if status=='right': if p==1: path_following() status='right' elif p==7: turn(3) path_following() status='down' elif p==-7: turn(4) path_following() status='up' elif p==-1: turn(3) turn(3) path_following() status='left' elif status=='left': if p==-1: path_following() status='left' elif p==7: turn(4) path_following() status='down' elif p==-7: turn(3) path_following() status='up' elif p==1: turn(3) turn(3) path_following() status='right' elif status=='up': if p==1: turn(3) path_following() status='right' elif p==7: turn(3) turn(3) path_following() status='down' elif p==-7: path_following() status='up' elif p==-1: turn(4) path_following() status='left' elif status=='down': if p==1: turn(4) path_following() status='right' elif p==-7: turn(3) turn(3) path_following() status='up' elif p==7: path_following() status='down' elif p==-1: turn(3) path_following() status='left' i=j