Find the first approver within the reporting line which is a minimum of 2 grades higher. Eg grade 0 is two grades higher than grade 2.
I'm trying to create a new node attribute Approver which should populate for Employees H,E,F,G which should all identify the approver as Employee A.
I've been trying to figure this out all day but don't really get how how to do a one hop traversal let alone several. My understanding is that a breath first search BFS will start from the leaf nodes and then work it's way up the tree. I'm getting really stuck on how to access different parts of the tree.
Any help much appreciated.
library(tidygraph)
library(visNetwork)
# sample graph
g <- tidygraph::create_tree(8,2) %>%
activate(nodes) %>%
mutate(Employee = LETTERS[1:8],
Grade = c(0,1,1,1,2,2,2,2),
label = paste("Emp",Employee,"Grade",Grade)
)
visIgraph(g,layout="layout_as_tree", flip.y=F,idToLabel = F)
g %>% activate(nodes) %>%
mutate(Approver = map_bfs_back(node_is_root(),.f = function(node,path,...){
#If starting node grade - node grade >= 2 then Approver Employee ID
}))