简体   繁体   English

在有向无环图的分裂和合并处插入节点

[英]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.我将把图片改写成这样,这样就清楚了哪个MS是相关的。 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: {}}

  1. Take item from stackstack中取出item
  2. Check number of parents with item.parents.length使用item.parents.length检查父母的数量
    • If it is 2, check if item.token exists如果是2,检查item.token是否存在
      • If not, take last item from tokenStack and save it inside item.token如果没有,则从tokenStack中取出最后一项并将其保存在item.token
        • Skip everything else below and continue from 1.跳过下面的所有其他内容并从 1 继续。
      • If there is value existing, it should be same as your last value in tokenStack .如果存在值,它应该与您在tokenStack中的最后一个值相同。 Take that value out of your tokenStack and you can continue with 3.从你的tokenStack中取出那个值,你可以继续 3。
  3. Check number of children with item.childrens.length使用item.childrens.length检查孩子的数量
    • If equal to 1, push that children to stack together with unchanged tokenStack如果等于 1,则将该子项与未更改tokenStack一起推入stack
    • If there are two children, do the split, create token (ie unique string), add this token to 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM