Let's define the function that allows to associate randomly a certain
number of leafs for each child under a constraint : the total number of
leafs is 100.
function random_edges(nleafs) #nleafs = 100
x=rand(1:nleafs,(1,10)) # (1,10) to tell that we have 10 childs
while (sum(x) !== nleafs) # the while loop allows to get a tuple of 10
values where each value represents the number of
# of leafs for each child where sum(x)= nleafs
x=rand(1:nleafs,(1,10))
end
return x
end
y=random_edges(100)
1x10 Array{Int64,2}:
3 1 7 5 13 7 30 6 18 10
sum(y)
100
# child 1 has 3 leafs , child 2 has 1 leaf, child 3 has 7 leafs ......
child 10 has ten leafs
# here we need to define the function that allows to link each child to its
leafs and transfer data from each child to its leafs
# some improvement to do !!!!
function add_leafs!(childs,nleafs) # x: the tuple that containts the
values of random edges (random_edges(nleafs))
level = childs.level +1 # since the level of child is 1 then the level of
leafs is 2
for i in 1:nleafs
leaf=MyNode(data,level, MyNode[], 0)
push!(childs.leaf,leaf)
end
end
x=random_edges(100)
function add_leafs!(childs,x) #x : the output of the function
random_edges childs : the output of the function add_children!
data = child data ? # the data of each child
level = childs.level +1 # since the level of child is 1 then the level of
leafs is 2
h = 0
for i in 1:length(x)
while h < x[i] # how to link each child to its
leafs. for example i= 1 x[1]= 3 then we need to have 3 leafs for child 1
and so on ...
leaf=MyNode(data,level, MyNode[], 0)
push!(childs.leaf,leaf)
h += 1
end
end
end
On Friday, July 1, 2016 at 12:41:09 PM UTC+2, Andre Bieler wrote:
>
> Well the child can also have children, just like in your graph you
> attached. This is then one level down in your graph.
>
> Note that the root is of the same type as the children. (MyNode can be
> parent, child, grandchild etc.) The children are just put inside the root.
> Then you can continue and put children into these children. This is how you
> get the tree structure.
>
> I hope this is somehow clear.
>
> Best,
> Andre
>
>