当前位置: 首页>>代码示例>>Python>>正文


Python node.node函数代码示例

本文整理汇总了Python中node.node函数的典型用法代码示例。如果您正苦于以下问题:Python node函数的具体用法?Python node怎么用?Python node使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了node函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: bfstree

def bfstree(s0):
    # s0 = initial state

    # create the initial node
    n0 = node(s0, None, None, 0, 0) 

    # initizlize #visited nodes
    nvisited = 0
    
    # initialize the frontier list
    frontier = deque([n0])

    while True:
        # the search fails when the frontier is empty
        if not frontier:
            return (None, nvisited)
        else:
            # get one node from the frontier
            n = frontier.popleft()
            # count the number of visited nodes
            nvisited+=1
            # check if the state in n is a goal
            if n.state.isgoal():
                return (n, nvisited)
            else:
                # generate successor states
                S = n.state.successors()
                # create new nodes and add to the frontier
                for (s, a, c) in S:
                    p = node(s, n, a, n.cost+c, n.depth+1)
                    frontier.append(p)
开发者ID:Blazework,项目名称:its336f15,代码行数:31,代码来源:bfstree.py

示例2: gen

def gen():
    '''
    The nodeList of type 'node' will be created, including numNode sensors
    the root node is located at the center of the area
    :return:
    '''
    nodeList = []
    root = node.node(0, 0)
    nodeList.append(root)
    for i in range(1, numNode):
        while True:
            #generata new pair of (x,y) until it's not same with any added node
            newPos = (random.randint(0, xRange), random.randint(0, yRange))
            if not checkPosDup(newPos, nodeList):
                break
        newNode = node.node(*newPos)
        nodeList.append(newNode)

    # open file for outputing the topology information
    topoFile = open('topo.txt', 'w')
    for i in range(0, numNode-1):
        for j in range(i+1, numNode):
            if distance(nodeList[i], nodeList[j]) == 0:
                # should remove one of the two, but becareful with the 'out of range' loop
                print "Oh, there are two nodes with same location..."
                print nodeList[i].x, nodeList[i].y, "|||", nodeList[j].x, nodeList[j].y
            else:
                # write to file: [node1 , node2, link quality, node1.x, node1.y, node2.x, node2.y]
                topoFile.write("%u, %u, %f, %u, %u, %u, %u\n" % (
                i, j, quality(nodeList[i], nodeList[j]), nodeList[i].x, nodeList[i].y, nodeList[j].x, nodeList[j].y))
开发者ID:dzungntp,项目名称:pEOT,代码行数:30,代码来源:gentopo.py

示例3: prepend

 def prepend(self, num):
     if self.head == None:
         self.head = node.node(num)
     else:
         temp = node.node(num)
         temp.set_next(self.head)
         self.head = temp
开发者ID:paolo215,项目名称:DataStructures,代码行数:7,代码来源:List.py

示例4: sum_by_bit

def sum_by_bit(e,t):
    mod = 0
    i = 1
    while e != None or t != None:
       if e != None:
           e_data = e.data
       else: e_data = 0
       if t != None:
           t_data = t.data
       else: t_data = 0
       (mod,remain) = divmod(e_data+t_data+mod,10)
       if i == 1:
           head = node(remain)
           tail = head
       else:
           tail.next_element = node(remain)
           tail = tail.next_element
       if e != None:
        e = e.next_element
       if t != None:
        t = t.next_element
       i = i+1
    if mod != 0:
        tail.next_element = node(mod)
    return head
开发者ID:superplayer2004,项目名称:CTCI,代码行数:25,代码来源:sum.py

示例5: get_map

    def get_map(self, n, set_x, set_y, exclude):

        # print(n,set_x,set_y)
        children = []
        next_exclude = exclude
        if n == 1:
            for x in set_x:
                for y in set_y:
                    print("exclude: {}".format(exclude))
                    if self.Point_valid((x,y), exclude):
                        node_child = node((x,y))
                        children.append(node_child)
            return children
        else:
            for x in set_x:
                for y in set_y:
                    s_x = set([x])
                    s_y = set([y])
                    # print("gaaga")
                    # print(set_x,set_y,s_x,s_y)
                    if self.Point_valid((x,y),exclude):
                        if exclude:
                            print("get exclude")
                            print(exclude)
                            next_exclude.append((x,y))
                            print("next exclude: {}".format(next_exclude))
                        else:
                            next_exclude = [(x,y)]
                        print("next exclude: {}".format(next_exclude))
                        node_child = node((x, y))
                        if n-1 >0:
                            node_child.add_child(*self.get_map(n-1, set_x - s_x, set_y - s_y, next_exclude))
                        children.append(node_child)
            return children
开发者ID:xiaoqiangzhao,项目名称:algorithm,代码行数:34,代码来源:my_queen.py

示例6: append

 def append(self, num):
     if self.head == None:
         self.head = node.node(num)
     else:
         current = self.head
         while(current.get_next() != None):
             current = current.get_next()
         temp = node.node(num)
         current.set_next(temp)
         temp.set_next(None)
开发者ID:paolo215,项目名称:DataStructures,代码行数:10,代码来源:List.py

示例7: sum

def sum(e, t):
    e_sum = assemble(e)
    t_sum = assemble(t)
    sum =  e_sum + t_sum
    head = node(str(sum)[-1])
    tail = head
    for i in str(sum)[-2::-1]:
        temp = node(i)
        tail.next_element = temp
        tail = temp
    return head
开发者ID:superplayer2004,项目名称:CTCI,代码行数:11,代码来源:sum.py

示例8: jump_step

 def jump_step(self, n):
     children = []
     if n == 1 :
         node_child = node(1)
         children.append(node_child)
         return children
     if n >=2 :
         for i in [1,2]:
             node_child = node(i)
             if self.jump_step(n-i):
                 node_child.add_child(*self.jump_step(n-i))
             children.append(node_child)
         return children
开发者ID:xiaoqiangzhao,项目名称:algorithm,代码行数:13,代码来源:jump.py

示例9: f

def f(s1, s2):
    if not s1:
        return s2
    if not s2:
        return s1

    it1 = s1
    it2 = s2

    res = None
    carry = 0

    while it1 and it2:
        curr = it1.value + it2.value + carry
        carry = curr / 10
        value = curr % 10
        if not res:
            res = node(value)
            prev = res
        else:
            prev.next = node(value)
            prev = prev.next
        it1 = it1.next
        it2 = it2.next

    while it1:
        curr = it1.value + carry
        carry = curr / 10
        value = curr % 10
        prev.next = node(value)
        prev = prev.next
        it1 = it1.next

    while it2:
        curr = it2.value + carry
        carry = curr / 10
        value = curr % 10
        prev.next = node(value)
        prev = prev.next
        it2 = it2.next

    if carry:
        prev.next = node(carry)

    it = res
    while it:
        print it.value
        it = it.next
    return res
开发者ID:jinghanx,项目名称:chea,代码行数:49,代码来源:add_two_numbers.py

示例10: get_node_peb

def get_node_peb():
    name = pal_get_platform_name()
    info = {
            "Description": name + " PCIe Expansion Board",
    }

    return node(info)
开发者ID:theopolis,项目名称:openbmc,代码行数:7,代码来源:node_peb.py

示例11: copynode

 def copynode( self, parent, nod ):
     thisnode = node( self, parent, leaf=nod.isLeaf, op=nod.operator, copy=True )
     parent.children.append( thisnode )
     
     if not thisnode.isLeaf:
         self.copynode( thisnode, nod.children[0] )
         self.copynode( thisnode, nod.children[1] )
开发者ID:brhoades,项目名称:irps,代码行数:7,代码来源:tree.py

示例12: test_hasNeighbor

	def test_hasNeighbor(self):
		neighbors = []
		n = node("0xfaca", "00:00:00:00:00:00:00:00", "0xffff")
		
		nei_nwk = ["0x0001", "0x0002", "0x0003"]
		nei_in = [7, 5, 3]
		nei_out = [7, 5, 3]

		for i in range(0,3):
			neighbors.append({"nwkAdr" : nei_nwk[i], "in_cost" : int(nei_in[i]), "out_cost" : int(nei_out[i])})
	
		nei_nwk = ["0x0001", "0x0002", "0x0003", "0x0004"]
		nei_in = [1, 3, 5, 1]
		nei_out = [1, 3, 5, 3]

		for i in range(0,4):
			neighbors.append({"nwkAdr" : nei_nwk[i], "in_cost" : int(nei_in[i]), "out_cost" : int(nei_out[i])})
	
		n.setCurNeighbors(neighbors)
		n.addNpPreNeighbors()
		n.processPreNeighbors()

		assert n.hasNeighbor("0x0001", n.getHistoricalNeighbors()) == True
		assert n.hasNeighbor("0x0002", n.getHistoricalNeighbors()) == True
		assert n.hasNeighbor("0x0003", n.getHistoricalNeighbors()) == True
		assert n.hasNeighbor("0x0004", n.getHistoricalNeighbors()) == True
		assert n.hasNeighbor("0x0005", n.getHistoricalNeighbors()) == False
		assert n.hasNeighbor("0x0000", n.getHistoricalNeighbors()) == False
		assert n.hasNeighbor("0xFFFF", n.getHistoricalNeighbors()) == False
开发者ID:Caipers,项目名称:TCC,代码行数:29,代码来源:test_module.py

示例13: extract_title

def extract_title(url):
    page = urllib2.urlopen(url)
    if not page:
     print "Error down page" + url
    else:
        soup = BeautifulSoup(page, 'lxml')

        # get head title, this title is noisy
        head_title = soup.find('title').string

        # append h1 ~ h6 p a
        node_list = []
        for tag in tags:
            all_content = soup.find_all(tag)
            for content in all_content:
                if type(content) == None:
                    continue
                tmp = content.string
                if tmp == None:
                    continue
                else:
                    nod = node.node(tmp.rstrip('\n').lstrip('\n').rstrip(' ').lstrip(' '))
                    node_list.append(nod)

        for nod in node_list:
            nod.calculate_LCS(head_title)
            nod.calculate_pureness(head_title)
            nod.calculate_prefix_ratio()
        node_list.sort(key=lambda x: x.lcs_length, reverse=True)

        nod = node_list[0]
        if float(nod.pureness) > 0.5 and float(nod.prefix_ratio) == 0:
            return nod.lcs
        else:
            return head_title
开发者ID:icylord,项目名称:TitleExtractor,代码行数:35,代码来源:TitleExtractor.py

示例14: rootify

    def rootify(self,center_branch):

	# remember the old branch:
	self.root_branch = center_branch

	# create a new node
	center_name = center_branch.ends[0].name
	center_name += "-" + center_branch.ends[1].name
	center_node = node.node(center_name,self)
	self.root = center_node
	
	# give it children branches
	child1 = branch.branch(center_branch.length/2)
	child1.addNode(center_node)
	child1.addNode(center_branch.ends[0])
	child2 = branch.branch(center_branch.length/2)
	child2.addNode(center_node)
	child2.addNode(center_branch.ends[1])
	center_node.child_branches.append(child1)
	center_node.child_branches.append(child2)

	# erase the original branch from the child nodes branch_list
	for kids in center_branch.ends:
	    kids.branch_list.remove(center_branch)

	# impose a hierarchy from the root
	center_node.imposeHierarchy()
        self.labelSubtrees()
        self.Get_Subnodes()
        self.root.Fill_Node_Dict()
开发者ID:almlab,项目名称:adaptml-angst-server,代码行数:30,代码来源:multitree.py

示例15: generate_children

  def generate_children(self, current):
    """ Generate the child nodes of the current node. This will
        apply the transformations listed above to the blank
        tile in the order specified in self.moves. The
        legal ones will be kept and states that have not
        been explored will be returned.
    """

    children = []
    blank_tile_index = None

    # Find the blank tile we will use to create new states
    for index in range(len(current.state)):
      if current.state[index] == "0":
        blank_tile_index = index
    
    # Get legal operations -
    operations = [blank_tile_index + move for move in self.moves if
                  self.test_operator(blank_tile_index, move)]
      
    # Create the new states
    for transformation in operations:

      child_state = copy.deepcopy(current.state)
      child_state[transformation] = "0"
      child_state[blank_tile_index] = current.state[transformation]

      # If these have not been explored, create the node
      if tuple(child_state) not in self._explored:
        child = node(child_state)
        child.parent = current
        child.operator = transformation - blank_tile_index
        children.append(child)
 
    return children
开发者ID:christianwhite93,项目名称:ai-eight_tile_problem,代码行数:35,代码来源:search.py


注:本文中的node.node函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。