Пример #1
0
class BadLinks:
    def __init__(self, rsrc):
        self.__rsrc = rsrc.encode('utf-8')
        self.__queue = MyQueue()
        self.__queue.push(Link(self.__rsrc))
        self._handleResource()

    def _handleResource(self):
        while (not (self.__queue.isEnd())):
            currentURL = self.__queue.pop()
            if (self.__rsrc in currentURL.getByteRef()):
                links = currentURL.getAllLinks()
            for i in links:
                self.__queue.push(Link(i))

    def __getRefWithStatus(self, link):
        s = str(link.getUtfRef()) + ' - status: '
        s = s + str(link.getStatusCode()) + '\n'
        return s

    def printLinks(self):
        goodLinks = open('good_links.txt', 'w')
        badLinks = open('bad_links.txt', 'w')

        self.__queue.reset()
        while (not (self.__queue.isEnd())):
            currentURL = self.__queue.pop()
            if (currentURL.isWorking()):
                goodLinks.write(self.__getRefWithStatus(currentURL))
            else:
                badLinks.write(self.__getRefWithStatus(currentURL))

        badLinks.close()
        goodLinks.close()
Пример #2
0
def search(board):
    start = time()
    nodes_generated = 0
    nodes_repeated = 0
    if board.is_win():
        end = time()
        print_results(board, 1, 0, 0, 1, end - start)
        return board
    node = deepcopy(board)
    nodes_generated += 1
    frontier = MyQueue()
    frontier.push(node)
    explored = set()
    keepLooking = True
    while keepLooking:
        if frontier.isEmpty():
            print "Solution not found"
            return
        else:
            currNode = frontier.pop()
            moves = currNode.moves_available()
            currNode.fboxes = frozenset(currNode.boxes)
            explored.add(currNode)
            for m in moves:
                child = deepcopy(currNode)
                nodes_generated += 1
                child.move(m)
                if child not in explored:
                    if child.is_win():
                        end = time()
                        print_results(child, nodes_generated, nodes_repeated,
                                      len(frontier), len(explored),
                                      end - start)
                        return child
                    frontier.push(child)
                else:
                    nodes_repeated += 1