本文整理汇总了Python中Node.Node类的典型用法代码示例。如果您正苦于以下问题:Python Node类的具体用法?Python Node怎么用?Python Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initFunction
def initFunction(self, fnNode, functionIndex, statements, functionType):
fnNode.itsFunctionType = functionType
fnNode.addChildToBack(statements)
functionCount = fnNode.getFunctionCount()
if (functionCount != 0):
fnNode.itsNeedsActivation = True
## for-while
i = 0
while (i != functionCount):
fn = fnNode.getFunctionNode(i)
if (fn.getFunctionType() == FunctionNode.FUNCTION_EXPRESSION_STATEMENT):
name = fn.getFunctionName()
if name is not None and (len(name) != 0):
fnNode.removeParamOrVar(name)
i += 1
if (functionType == FunctionNode.FUNCTION_EXPRESSION):
name = fnNode.getFunctionName()
if (name is not None) and \
len(name) != 0 \
and (not fnNode.hasParamOrVar(name)):
if (fnNode.addVar(name) == ScriptOrFnNode.DUPLICATE_CONST):
self.parser.addError("msg.const.redecl", name)
setFn = Node(Token.EXPR_VOID, Node(Token.SETNAME, Node.newString(Token.BINDNAME, name), Node(Token.THISFN)))
statements.addChildrenToFront(setFn)
lastStmt = statements.getLastChild()
if lastStmt is None or (lastStmt.getType() != Token.RETURN):
statements.addChildToBack(Node(Token.RETURN))
result = Node.newString(Token.FUNCTION, fnNode.getFunctionName())
result.putIntProp(Node.FUNCTION_PROP, functionIndex)
return result
示例2: check_availablespace
def check_availablespace(self, maxinputsize, files):
"""
Verify that enough local space is available to stage in and run the job
"""
if not self.shouldVerifyStageIn():
return
totalsize = reduce(lambda x, y: x + y.filesize, files, 0)
# verify total filesize
if maxinputsize and totalsize > maxinputsize:
error = "Too many/too large input files (%s). Total file size=%s B > maxinputsize=%s B" % (len(files), totalsize, maxinputsize)
raise PilotException(error, code=PilotErrors.ERR_SIZETOOLARGE)
self.log("Total input file size=%s B within allowed limit=%s B (zero value means unlimited)" % (totalsize, maxinputsize))
# get available space
wn = Node()
wn.collectWNInfo(self.workDir)
available_space = int(wn.disk)*1024**2 # convert from MB to B
self.log("Locally available space: %d B" % available_space)
# are we wihin the limit?
if totalsize > available_space:
error = "Not enough local space for staging input files and run the job (need %d B, but only have %d B)" % (totalsize, available_space)
raise PilotException(error, code=PilotErrors.ERR_NOLOCALSPACE)
示例3: __init__
def __init__(self, logp, doc, name, parents, cache_depth=2, plot=None, verbose=None, logp_partial_gradients = {}):
self.ParentDict = ParentDict
# This function gets used to evaluate self's value.
self._logp_fun = logp
self._logp_partial_gradients_functions = logp_partial_gradients
self.errmsg = "Potential %s forbids its parents' current values"%name
Node.__init__( self,
doc=doc,
name=name,
parents=parents,
cache_depth = cache_depth,
verbose=verbose)
self._plot = plot
# self._logp.force_compute()
# Check initial value
if not isinstance(self.logp, float):
raise ValueError, "Potential " + self.__name__ + "'s initial log-probability is %s, should be a float." %self.logp.__repr__()
示例4: push
def push(self, value):
"""
Add value to top of Stack
"""
new_node = Node(value)
new_node.next = self.head
self.head = new_node
示例5: __init__
def __init__(self, LexNode):
Node.__init__(self, LexNode)
self.text = self.tokens.get('STRING', "")
self.type = self.tokens.get('TYPE', "boolean")
self.ID = self.tokens.get('ID', uuid.uuid4())
self.function = self.tokens.get('function', None)
示例6: test_delete
def test_delete():
bs_tree = BinarySearchTree()
keys = [5, 2, -4, 3, 12, 9 ,21, 19, 25]
for key in keys:
node = Node()
node.key = key
bs_tree.insert(node)
# delete leaf
bs_tree.delete(bs_tree.search(-4))
assert(bs_tree.search(-4) is None)
assert(bs_tree.search(2).left is None)
# delete node with one child
bs_tree.delete(bs_tree.search(2))
assert(bs_tree.search(2) is None)
assert(bs_tree.root.left.key == 3)
# delete node with two children
bs_tree.delete(bs_tree.search(12))
assert(bs_tree.root.right.key == 19)
assert(bs_tree.search(19).left.key == 9)
assert(bs_tree.search(19).right.key == 21)
# delete root
bs_tree.delete(bs_tree.root)
assert(bs_tree.root.key == 9)
assert(bs_tree.root.left.key == 3)
assert(bs_tree.root.right.key == 19)
开发者ID:prathamtandon,项目名称:python-algorithms-and-data-structures,代码行数:31,代码来源:BinarySearchTree_test.py
示例7: push
def push(self, value):
new_node = Node(value, None, None)
new_node.previous = self.end.previous
new_node.next = self.end
self.end.previous.next = new_node
self.end.previous = new_node
self.size += 1
示例8: WaveletTree
class WaveletTree(object):
def __init__(self, data=None):
if data == None:
print "Please give correct parameters"
return
self.__root = Node(data) #Create the parent node
"""
Query Functions
"""
def rank_query(self,character=None, position=None):
if character==None or position==None or position <= 0:
print "Please give correct parameters"
return -1
return self.__root.get_rank_query(position,character)
def select_query(self,character=None, position=None):
if character==None or position==None or position <= 0:
print "Please give correct parameters"
return -1
return self.__root.get_select_query(position, character)
def track_symbol(self,position=None):
if position==None or position <= 0:
print "Please give correct parameters"
return -1
return self.__root.get_track_symbol(position)
"""
示例9: ID3
def ID3(X, Y, attrs, currentDepth, maxDepth=7):
currentDepth += 1
# If all examples are positive, Return the single-node tree Root, with label = +.
# If all examples are negative, Return the single-node tree Root, with label = -.
if len(set(Y)) == 1:
return Leaf(Y[0])
# If the number of predicting attributes is empty, then return a single node tree with
# Label = most common value of the target attribute in the examples
if len(attrs) == 0 or currentDepth == maxDepth:
return Leaf(majorityElement(Y))
# A = The Attribute that best classifies examples.
A = findBestFeatureIndex(X, Y, attrs)
newAttrs = [attr for attr in attrs if attr != A]
# Decision Tree attribute for Root = A.
root = Node(A)
# For each possible value, vi, of A
for possible_value in [0, 1]:
# Let Examples(vi) be the subset of examples that have the value vi for A
X_s, Y_s = splitData(X, Y, A, possible_value)
if len(X_s) == 0 or len(Y_s) == 0:
# Then below this new branch add a leaf node with label = most common target value in the examples
root.addChild(possible_value, Leaf(majorityElement(Y)))
else:
# Else below this node add a subtree ID3(Examples_vi, TargetAttr, Attrs - {A})
root.addChild(possible_value, ID3(X_s, Y_s, newAttrs, currentDepth, maxDepth))
return root
示例10: main
def main():
#Test case 1
root = Node("Max", 23)
john = root.setLeft(Node("John", 18))
mark = john.setRight(Node("Ann", 22)).setRight(Node("Mark", 2))
rob = john.setLeft(Node("Rob", 12))
rob.setRight(Node("Bob", 4)).setLeft(Node("Mie", 6))
rob.setLeft(Node("Steven", 3)).setRight(Node("Sarah", 2))
annie = mark.setLeft(Node("Annie", 9))
annie.setRight(Node("Barnie", 42))
annie.setLeft(Node("Malcolm", 7)).setRight(Node("Susan", 5)).setRight(Node("Terry", 4))
assert root.left.right.right.left.right.name == "Barnie"
assert root.left.left.left.name == "Steven"
assert root.left.right.name == "Ann"
assert root.left.right.left == None
assert root.left.left.right.left.name == "Mie"
maxRating, invitedPeople = FindMaxRating(root)
assert maxRating == 109
assert [n.name for n in invitedPeople] == ['Steven', 'Sarah', 'Mie', 'John', 'Ann', 'Malcolm', 'Susan', 'Terry', 'Barnie']
print "Max rating for people {" + ", ".join(root.allChildren()) + "}: \n" + str(maxRating)
print "People invited: "
print [n.name for n in invitedPeople]
示例11: __init__
def __init__(self, function_name, given_type):
Node.__init__(self, function_name)
self.number_of_params = 0
self.return_type = None
self.type = given_type
# We only want to allow parameters to be added to each green node one time.
self.param_flag = False
示例12: harvest
def harvest(self, vf):
if not Harvester.harvest(self, vf):
return
mvf = vf.getMeta()
# determine grouping
groupTag = self.opts['group']
if groupTag == None:
# no grouping - stuff into root node
target = self.root
else:
# get the grouping value
if groupTag not in mvf:
grp = OTHER
else:
grp = mvf[groupTag]
if type(grp) is list:
raise ConfigError("Configuration Error - grouping item must not be a list")
if grp in self.nodeMap:
# if we've seen this group, then just reuse the
# same node
target = self.nodeMap[grp]
else:
# Otherwise create a new node and link it in
path=os.path.join(self.hpath, Legalize(grp))
target = Node(grp, self.opts, path=path, title = "%s: %s" %(metaTranslate(groupTag), grp))
self.pathMap[os.path.join(self.name, grp)] = path
self.nodeMap[grp] = target
self.root.addDir(target)
self.gcount += 1
target.addVideo(vf)
self.count += 1
示例13: simulate
def simulate(self):
currentNode = Node(Sudoku(self.m_sudokuProblem, self.m_fixedNodes))
currentNode.m_sudoku.populate()
found = False
while not found:
self.m_temperature = self.scheduleTemp()
if currentNode.getValue() <= 0 and currentNode.m_sudoku.validateSudoku():
found = True
return currentNode
if self.m_temperature < 0.00027:
currentNode = self.reheat()
print "REHEAT"
nextNode = currentNode.getRandomSucessor()
deltaE = currentNode.getValue() - nextNode.getValue()
print nextNode.getValue()
probability = self.getProbability(deltaE)
if random.random() < probability:
currentNode = nextNode
示例14: r
def r():
root = Node("Max", 10000)
john = root.setLeft(Node("John", 1))
annie = john.setLeft(Node("Annie", 1))
jens = annie.setLeft(Node("Jens", 10000))
FindMaxRating(root)
示例15: construct
def construct(self, slice):
Node.construct(self, slice)
self.parent_index=self.parents_1[0]
assert(len(self.parents_0)==0)
assert(len(self.parents_1)==1)
parent_size=self.parents_1_sizes[0]
assert(self.node_size==parent_size)
self.mus_shape=(self.node_size,1)
self.kappas_shape=(self.node_size),
# Check or construct means
rnd_mus, rnd_kappas=self._make_rnd_kms(self.node_size)
# If the user has specified some values these are used
if not self.user_mus is None:
self.mus=self.user_mus
for i in range(0, self.node_size):
# Make sure we have angles in [0,2pi[
self.mus[i]=mod2pi(self.mus[i])
assert(self.mus.shape==self.mus_shape)
del self.user_mus
else:
# Otherwise the means are set to random values
self.mus=rnd_mus
# Check or construct kappa values
if not self.user_kappas is None:
self.kappas=self.user_kappas
assert(self.kappas.shape==self.kappas_shape)
del self.user_kappas
else:
self.kappas=rnd_kappas
self.vm_list, self.samplers=self._make_vm_list(self.mus, self.kappas, self.node_size)