[英]Inserting nodes at split and merges of directed acyclic graphs
I have the following directed acyclic graph where edge directions are from top to bottom我有以下有向无环图,其中边缘方向从上到下
A
|
B
/ \
C D
/ \ |
E F |
\ / |
G |
\ /
H
and I want to insert special split nodes where the nodes split and merge nodes where they merge again, ie, I want the above graph structure to be transformed into the graph below并且我想插入特殊的拆分节点,节点拆分和合并节点再次合并,即我希望将上面的图形结构转换为下面的图形
A
|
B
|
B-S
/ \
C D
| |
C-S |
/ \ |
E F |
\ / |
C-M |
| |
G |
\ /
B-M
|
H
How can I do the above transformation?如何进行上述转换?
I will rewrite the picture as this, so its clear which M
and S
are related.我将把图片改写成这样,这样就清楚了哪个
M
和S
是相关的。 I am also considering the tree to have maximum of two children, but it can easily be updated to more children in merging part.我也在考虑这棵树最多有两个孩子,但它可以很容易地在合并部分更新为更多的孩子。
A
|
B
|
B-S1
/ \
C D
| |
C-S2 |
/ \ |
E F |
\ / |
C-M2 |
| |
G |
\ /
B-M1
|
H
The main principle is that when you do the split, you have to carry through all the other nodes the information about that until you merge them again.主要原则是,当您进行拆分时,您必须通过所有其他节点传递有关该信息的信息,直到您再次合并它们。
The alghoritm will be as following:算法如下:
Start: Create stack
variable and push A
to it together with empty tokenStack
(it will be like one object {node: A, tokenStack: {}}
开始:创建
stack
变量并将A
与空tokenStack
一起推送到它(它将像一个 object {node: A, tokenStack: {}}
item
from stack
stack
中取出item
item.parents.length
item.parents.length
检查父母的数量
item.token
existsitem.token
是否存在
tokenStack
and save it inside item.token
tokenStack
中取出最后一项并将其保存在item.token
tokenStack
.tokenStack
中的最后一个值相同。 Take that value out of your tokenStack
and you can continue with 3.tokenStack
中取出那个值,你可以继续 3。item.childrens.length
item.childrens.length
检查孩子的数量
stack
together with unchanged tokenStack
tokenStack
一起推入stack
tokenStack
, save it to current item.token
and push both children to stack
together with tokenStack
tokenStack
,将其保存到当前item.token
并将两个孩子与tokenStack
一起推送到stack
Now you did it all and Split and Merge nodes have the same item.token
现在您完成了所有操作,Split 和 Merge 节点具有相同的
item.token
note: You can also save information about all the existing tokens in tokenStack
during the flow if you want later investigate which nodes are in left/right part of which split branches.注意:如果您想稍后调查哪些节点位于哪些拆分分支的左/右部分,您还可以在流程期间将有关所有现有令牌的信息保存在
tokenStack
中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.