
I have a directed graph that ends at point "L". When I sum all the incoming degrees at point "L", I got the value: 13. But I want to modify the graph based on the given plot (see the figure). In the graph, the incoming degree will be distributed in the following nodes. For instance, the incoming degree of point "F" is 2 therefore the value for "F" is 2. But in the case of point "K" and "G", the value will be 0.5 and 0.5, because the value of "H" is distributed into two parts. The value of point "J" will be the sum of the incoming values from the upper nodes (i.e., G, E, F).
A solution in R or python is desired.
This is the sample code that I used...
library(igraph)
library(dplyr)
g1<- graph (edges = c("A","E", "E","I", "I","L", "E","J", "J","L",
"B","F", "C","F", "F","J", "D","H", "H","K", "H","G", "G","J", "K","L"),
directed = T)
cum_deg <- data.frame(name=names(V(g1))) %>%
mutate(deg_1=degree(g1, mode="in")) %>%
mutate(cum_degree = rowSums
((!is.infinite(distances(g1,mode="in"))) %*% diag (deg_1)))
> cum_deg
name deg_1 cum_degree
A 0 0
B 0 0
C 0 0
D 0 0
E 1 1
F 2 2
G 1 2
H 1 1
I 1 2
J 3 8
K 1 2
L 3 13