コード例 #1
0
def execute_student_plan(warehouse, todo):
    student_planner = partA.DeliveryPlanner(copy.copy(warehouse),
                                            copy.copy(todo))
    action_list = student_planner.plan_delivery()

    state = State(warehouse)
    num_delivered = 0
    next_box_to_deliver = todo[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 = delivered[-1]
            if last_box_delivered == next_box_to_deliver:
                num_delivered += 1
                if num_delivered < len(todo):
                    next_box_to_deliver = todo[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))

    state.print_to_console()

    if num_delivered < len(todo):
        raise Exception('task not accomplished: not all boxes delivered')

    return state.get_total_cost()
コード例 #2
0
    def execute_student_plan(self, warehouse, boxes_todo):
        """Execute student plan and store results in submission.

        Args:
            warehouse(list(list)): the warehouse map to test against.
            boxes_todo(list): the order of boxes to deliver.
        """
        self._reset()

        state = State(warehouse)

        try:
            student_planner = partA.DeliveryPlanner(copy.copy(warehouse),
                                                    copy.copy(boxes_todo))
            action_list = student_planner.plan_delivery()

            num_delivered = 0
            next_box_to_deliver = boxes_todo[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 = delivered[-1]
                    if last_box_delivered == next_box_to_deliver:
                        num_delivered += 1
                        if num_delivered < len(boxes_todo):
                            next_box_to_deliver = boxes_todo[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 VERBOSE_FLAG:
                # print final state
                print('\n\n')
                print('Final State: ')
                state.print_to_console()

            self.submission_score.put(state.get_total_cost())

        except:
            self.submission_error.put(traceback.format_exc())
            self.submission_score.put(float('inf'))
コード例 #3
0
import string
import sys
import copy

from functools import wraps
from Queue import Queue
from Queue import Empty as QueueEmptyError
from threading import Thread
from multiprocessing import TimeoutError

import unittest
import timeit

import partA

warehouse = ['..1.', '..@.', '....', '2...']
todo = ['1', '2']

student_planner = partA.DeliveryPlanner(copy.copy(warehouse), copy.copy(todo))
# accessible_neighbors = student_planner.accessible_neighbors([2,1]) #pass
# cost=student_planner.cost([2,2],[1,0]) #pass
# heuristic=student_planner.heuristic([0,0],[1,1]) #pass
# optimal_path=student_planner.optimal_path([0,0],[2,2])
plan_delivery = student_planner.plan_delivery()
print plan_delivery