Get a List of Nodes in an Specific Area

Get a list of nodes in an specific area?

You are creating a physical world where there is a specific rectangle that has 'special properties' - this is the rectangle that you use in enumerateBodiesInRect(). Why not create an invisible, inert physical body with the required rectangular dimension and then use SKPhysicsBody to check for collisions and/or contacts? You could then use allContactedBodies() or some delegate callbacks to learn what other bodies are inside your special rectangle.

Think of it like a 'tractor beam' or a 'warp rectangle'.

How do you print all nodes in a specific level?

Your get_level_nodes function has some issues:

  • c never changes value: it always represents self.children, so you are not actually moving down in the tree. You should somewhere iterate over those children and extend your collection of nodes with the children of these children.
  • You start out with self.children, but that list of nodes already represents the second level in the tree. You should foresee that the function can return the top-level of the tree, i.e. a list with just the root node in it.

I'll assume that you use the definition of "level" as specified in Wikipedia, although other definitions exist:

Level

      1 + the number of edges between a node and the root, i.e. (depth + 1)

Solution:

    def get_level_nodes(self, cur_level):
nodes = [self]
for i in range(cur_level-1): # assuming that cur_level is at least 1
children = []
for node in nodes:
children.extend(node.children)
nodes = children
return nodes

How do I print a list of nodes at a specific level of a general tree?

Ok, let's to this step by step (leaving you with some holes for now):

nodes at level 0

as I understand it you are suppost to only return the roots value here (of course in a list)

so what goes in the ... here?

nodesAtLevel 0 (Node a subtrees) = ...

nodes at deeper levels

well the structure is nicely recursive so we probably want to use recursion.

So let's go recursively deeper one level deeper (decreasing the way we have left to go - aka our n)

But there is a slight problem: nodesAtLevel acts on a single node but we only have a list of nodes left (the subtrees) .. so what to do?

Well maybe we should do something for each of the subtrees/subnodes - so we need to find the right function f here (hint you probably want to map and concat the results ...):

nodesAtLevel n (Node a subtrees) = f (nodesAtLevel (n-1)) subtrees

what can that f be? Can you guess it? Maybe you can write it yourself if not?


Additional Hint:

maybe you should first find out what type f has - because then you might be even able to use Hoogle to find a good fit.

If you use a newer GHC version you an let the compiler do the work if you write

nodesAtLevel n (Node _ subtrees) = _f (nodesAtLevel (n-1)) subtrees

where _f is a hole - now if you load this in GHCi it will give you a

Found hole ‘_f’ with type: ....

error with lot's of additional information ;)


so just find ... and f and this should work ;)

BTW you can use the functions you already have instead of pattern matching again as I did, but I feel it's easier to see the result this way - so if you follow this path you don't need to use treeSubtrees or treeRoot


solution

  • ... = [a]
  • f = concatMap

so one possible way to do it is this:

nodesAtLevel :: Int -> Tree a -> [a]
nodesAtLevel 0 (Node a _) = [a]
nodesAtLevel n (Node _ subtrees) = concatMap (nodesAtLevel (n-1)) subtrees

Retrieving a list of nodes and edges from a specific cluster in igraph

Maybe you can try the code below

grps <- split(V(g),eb$membership)
grp <- unlist(subset(grps,mapply(`%in%`,5,grps)))
df <- subset(get.data.frame(g),from %in% grp & to %in% grp)

such that

> df
from to
9 4 6
16 4 10
17 5 10
34 4 19
35 5 19

How to get a list of all Jenkins nodes assigned with label including master node?

This is the way I'm doing it right now. I haven't found anything else:

@NonCPS
def hostNames(label) {
def nodes = []
jenkins.model.Jenkins.get().computers.each { c ->
if (c.node.labelString.contains(label)) {
nodes.add(c.node.selfLabel.name)
}
}
return nodes
}

jenkins.model.Jenkins.get.computers contains the master-node and all the slaves.



Related Topics



Leave a reply



Submit