def execute_student_plan(self, warehouse, box_todo, max_distance, max_steering): """Execute student plan and store results in submission. Args: warehouse(list(list)): the warehouse map to test against. box_todo(list): the order of boxes to deliver. max_distance(float): the max distance the robot can travel in a single move. max_steering(float): the max steering angle the robot can turn in a single move. """ self._reset() state = State(warehouse, box_todo, max_distance, max_steering) try: student_planner = partB.DeliveryPlanner(copy.copy(warehouse), copy.copy(box_todo), max_distance, max_steering) action_list = student_planner.plan_delivery() num_delivered = 0 next_box_to_deliver = num_delivered for action in action_list: if VERBOSE_FLAG: state.print_to_console() state.update_according_to(action) # check if new box has been delivered delivered = state.get_boxes_delivered() if len(delivered) > num_delivered: last_box_delivered = int(delivered[-1]) if last_box_delivered == next_box_to_deliver: num_delivered += 1 if num_delivered < len(box_todo): next_box_to_deliver = num_delivered else: # all boxes delivered: end test break else: # wrong box delivered: kill test raise Exception('wrong box delivered: {} instead of {}'.format(last_box_delivered, next_box_to_deliver)) if num_delivered != len(box_todo): raise Exception("Did not deliver all boxes. Only delivered: {}".format(num_delivered)) if VERBOSE_FLAG: # print final state print '\n\n' print 'Final State: ' state.print_to_console() self.submission_score.put(state.get_total_cost()) self.submission_boxes_delivered.put(state.get_boxes_delivered()) except Exception as exp: self.submission_error.put(traceback.format_exc()) self.submission_score.put(float('inf')) self.submission_boxes_delivered.put(state.get_boxes_delivered())
def execute_student_plan(warehouse, todo, max_distance, max_steering): student_planner = partB.DeliveryPlanner(copy.copy(warehouse), copy.copy(todo), max_distance, max_steering) action_list = student_planner.plan_delivery() state = State(warehouse, todo, max_distance, max_steering) num_delivered = 0 next_box_to_deliver = num_delivered for action in action_list: state.print_to_console() state.update_according_to(action) # check if new box has been delivered delivered = state.get_boxes_delivered() if len(delivered) > num_delivered: last_box_delivered = int(delivered[-1]) if last_box_delivered == next_box_to_deliver: num_delivered += 1 if num_delivered < len(todo): next_box_to_deliver = num_delivered else: # all boxes delivered: end test break else: # wrong box delivered: kill test raise Exception('wrong box delivered: {} instead of {}'.format( last_box_delivered, next_box_to_deliver)) if num_delivered != len(todo): raise Exception("Did not deliver all boxes. Only delivered: {}".format( num_delivered)) # print final state print "\n\n" print "Final State: " state.print_to_console() return state.get_total_cost(), state.get_boxes_delivered()
from Queue import Queue from Queue import Empty as QueueEmptyError from threading import Thread from multiprocessing import TimeoutError import unittest import timeit import partB from math import * warehouse = ['@.#...#', '#...#..'] todo = [(6.8, -1.8), (6.0, -1.2), (5.0, -0.8), (4.0, -0.2), (3.8, -1.2), (2.8, -1.2), (1.8, -1.8), (1.2, -1.1), (1.1, -0.1)] student_planner = partB.DeliveryPlanner(copy.copy(warehouse), copy.copy(todo), 0.29, pi / 5.7) # print student_planner.centerof([0,0],3) #pass # print student_planner.centerof([14,14],3) #pass #print student_planner.best_areas((4.5, -.5),first_round=True) # print student_planner.lift_areas([0.5, -1.0]) #print student_planner.best_areas([1.5,-0.5]) # b=student_planner.best_areas([1.5,-0.5]) # while b.size()>0: # a=b.pop() # print a #print student_planner.accessible_neighbors([1, 7]) #pass # cost=student_planner.cost([2,2],[1,0]) #pass # print student_planner.heuristic([0.5, -1.0],student_planner.centerof([2, 0],discretized_by=3)) #pass # print student_planner.threshold_dist(student_planner.centerof([2, 0],student_planner.discretized_by),student_planner.robot_R,[0.5, -1.0],student_planner.box_L)