Beispiel #1
0
def go(num_pages_to_crawl, course_map_filename, index_filename):
    '''
    Crawl the college catalog and generate a CSV file with an index.

    Inputs:
        num_pages_to_crawl: the number of pages to process during the crawl
        course_map_filename: the name of a JSON file that contains the mapping of
          course codes to course identifiers
        index_filename: the name for the CSV of the index.

    Outputs:

    \

        CSV file of the index
    '''

    starting_url = ("http://www.classes.cs.uchicago.edu/archive/2015/winter"
                    "/12200-1/new.collegecatalog.uchicago.edu/index.html")
    limiting_domain = "classes.cs.uchicago.edu"

    queue = Queue()
    course_dict = {}
    analyze_page(starting_url, queue, limiting_domain, course_dict)

    counter = 1
    while not queue.isEmpty() and counter <= num_pages_to_crawl:
        counter += 1
        page = queue.dequeue()
        analyze_page(page, queue, limiting_domain, course_dict)

    convert_to_csv(course_dict)
Beispiel #2
0
 def breadth_first(self):
     queue = Queue.Queue(self)
     
     while queue.isEmpty() == False:
         node=queue.dequeue()
         print(str(node.key))
         if node.has_lchild():
             queue.enqueue(node.lchild)
         if node.has_rchild():
             queue.enqueue(node.rchild)
Beispiel #3
0
def findRouteBFS(root, node):
    queue = Queue()
    root.visited = True
    queue.enqueue(root)
    while not queue.isEmpty():
        r = queue.dequeue()
        if r == node:
            return True
        for x in r.children:
            if x.visited != True:
                x.visited = True
                queue.enqueue(x)
    return False
Beispiel #4
0
 def levelByLevel(self, aFile):
     ''' Print the nodes of the BTree level-by-level on aFile. )
     '''
     aFile.write("A level-by-level listing of the nodes:\n")
     queue = MyQueue()
     queue.enqueue(self.rootNode)
     while not queue.isEmpty():
         currentNode = queue.dequeue()
         aFile.write(str(currentNode))
         for i in range(currentNode.getNumberOfKeys() + 1):
             child = self.readFrom(currentNode.child[i])
             if child != None:
                 queue.enqueue(child)
Beispiel #5
0
 def minMutation(self, start, end, bank):
     """
     :type start: str
     :type end: str
     :type bank: List[str]
     :rtype: int
     """
     if start==end: return 0
     
     charSet=['A', 'C', 'G', 'T']
     level=0
     visitedw=[]
     q=queue.Queue()
     q.put(start)
     visited.put(start)
     
     while not q.empty(): 
         size=q.qsize()
         while size>0: 
             
             curr=q[0]
             if curr==end: return level
             
             curr=
     
     
     while(!queue.isEmpty()) {
         int size = queue.size();
         while(size-- > 0) {
             String curr = queue.poll();
             if(curr.equals(end)) return level;
             
             char[] currArray = curr.toCharArray();
             for(int i = 0; i < currArray.length; i++) {
                 char old = currArray[i];
                 for(char c: charSet) {
                     currArray[i] = c;
                     String next = new String(currArray);
                     if(!visited.contains(next) && bankSet.contains(next)) {
                         visited.add(next);
                         queue.offer(next);
                     }
                 }
                 currArray[i] = old;
             }
         }
         level++;
     }
def scheduling(listTask, time):
    print(f"waktu proses cpu = {time}")
    print(f"antrian proses : {listTask.values()}")
    counter = 1
    totalTime = 0
    listName = qq.createQueue()
    for i in listTask:
        qq.enqueue(listName, i)
    #print(listName)
    #print(listTask)
    #print(' ')

    while not qq.isEmpty(listName):
        print(f"iterasi ke - {counter}")
        counter += 1

        name = qq.dequeue(listName)
        value = listTask[name][1]
        print(
            f"proses {name} sedang dikerjakan, sisa waktu proses {name} = {value}"
        )

        if value > time:
            totalTime += time

            value = value - time
            listTask[name][1] = value

            qq.enqueue(listName, name)
            print(f"antrian data tersisa : {listName}")
            print(f"sisa task {listTask}")

        elif value <= time:
            totalTime += value

            listTask[name][1] = 0
            listTask[name][2] = totalTime

            print(f"proses {name} selesai")
            print(f"antrian data tersisa : {listName}")
            print(f"sisa task {listTask}")

    return listTask
Beispiel #7
0
def bfs(maze, queue):
    length = len(maze)
    start = maze[0][0]
    goal = (9, 9)
    queue.enqueue(start)

    while queue.isEmpty() == False:
        node = queue.dequeue()
        node.searched = True
        for x, y in (node.x + 1, node.y), (node.x - 1,
                                           node.y), (node.x,
                                                     node.y - 1), (node.x,
                                                                   node.y + 1):
            if (0 <= x < length and 0 <= y < length) and (
                    maze[x][y].wall == False) and (maze[x][y].searched
                                                   == False):
                if (x, y) == goal:
                    return True
                else:
                    maze[x][y].parent = node
                    queue.enqueue(maze[x][y])
    return False
Beispiel #8
0
def BFTravel2list(rootNode):
    queue = Queue()
    queue.push(rootNode)

    lsBlock = []
    while queue.isEmpty() == False:
        node = queue.pop()
        if node.userData == None:
            info = DiffInfo()
            node.userData = info
        node.userData.fingerPrint = buildFingerPrint(node)
        lsBlock.append(node)

        # print ("%x : %s") % (node.name, node.userData.fingerPrint)
        for childOffset in node.children:
            childNode = node.children[childOffset]
            if childNode.userData == None:
                info = DiffInfo()
                info.parent = node
                childNode.userData = info
                queue.push(childNode)

    return lsBlock