比较差异有向无环图差异、无环图

2023-09-11 03:49:52 作者:╭瑾色流年〃

我在寻找一种算法,可以差异双向无环图(DAG)的。也就是说,我想它产生的第一个DAG缺失和插入序列产生第二DAG的算法。

I'm looking for an algorithm which can diff two Directed Acyclic Graphs(DAGs). That is, I'd like an algorithm which produces a sequence of deletions and insertions on the first DAG to produce the second DAG.

我不是百分百肯定,但我认为一个最长公共子可以应用到使用DAG。我不太关心所产生的编辑序列的长度(只要它足够短),并更关注的是算法的运行时间。

I'm not a hundred percent sure, but I think a longest common subsequence can be applied to the DAGs. I'm less concerned about the length of the resulting edit sequence (as long as it's short enough) and more concerned about the running time of the algorithm.

一个复杂因素是没有我的顶点被标记,除了一个根节点。根节点也有入边零的唯一节点。图形的边被标记,并在图中的数据是psented通过的路径从根到叶重$ P $。这类似于一个线索但与向图而不是树。其实我的图是非常相似的向非循环词图数据结构。

One complication is that none of my vertices are labelled except for a single root node. The root node is also the only node with zero in-edges. The graph's edges are labelled, and the 'data' in the graph is represented by the paths from the root to the leaves. This is similar to a trie but with a directed graph instead of a tree. Actually my graphs are quite similar to the directed acyclic word graph data structure.

下面是一个例子。

DAG1

DAG2

要获得DAG 2,您只需从根本上增加一个顶点到另一个顶点与标签B。从该顶点有一个边缘到最终的交流顶点在DAG 1和一个边缘至一个新顶点的标签是D。从最终的顶点还有另一个边缘的'交流'的顶点在DAG 1.我会发布一个链接到DAG形式的差异,但我不能发布超过两个环节。

To get DAG 2, you simply add a vertex from the root to another vertex with label 'b'. From that vertex there is an edge to the final 'ac' vertex in DAG 1 and an edge to a new vertex whose label is 'd'. From that final vertex there is another edge to the 'ac' vertex in DAG 1. I'd post a link to the diff in DAG form, but I can't post more than two links.

感谢,并希望这是不够清晰。

Thanks and hope this is legible enough.

推荐答案

这可能是有点晚了,但只是为了好玩: 无论您的DAG的可pssed为基质的前$ P $,与排索引,表示从的顶点,并表示到顶点列索引,并标有边缘ID对应的单元格。你可以给顶点独特的和随机的ID。

This might be a bit too late but just for fun: Both of your DAGs can be expressed as matrices, with row index indicating the "from" vertex, and the column index indicating the "to" vertex, and the corresponding cell labeled with edge id. You can give vertex unique and random ids.

接下来的部分是有点棘手,因为只有你的边缘有一个从DAG1映射到DAG2有意义的标签。假设你有一组边E *,可从DAG1和DAG2标记边缘相交,则需要进行一系列的行移位(向上或向下移动)或列偏移(向左或向右移动),因此所有的位置在E *边缘DAG1和DAG2映射到彼此。请注意,对于psented在矩阵DAG中重新$ P $,移动整行或整列的位置仍使重presentation等同。

The next part is a bit tricky, because only your edges have meaningful label that maps from DAG1 to DAG2. Suppose you have a set of edges E* that are the intersect of labeled edges from DAG1 and DAG2, you will need to perform a series of row shift (move up or down) or column shift (move left or right) so position of all edges in E* in DAG1 and DAG2 maps to each other. Note that for a DAG represented in Matrix, shifting position of entire row or entire column still makes the representation equivalent.

其余的操作是根据所映射的矩阵来重命名顶点,比较两个矩阵,并确定该可除去所需要的新的边缘和新顶点(和边和顶点

The remaining operation would be to rename the vertex according to the mapped matrices, compare the two matrices, and identify the new edges and new vertex required (and edges and vertices that can be removed.