如何复制Erlang有向图?在文档中似乎没有复制功能。我是否必须手动构建副本?
我在Elixir编码。
答案 0 :(得分:4)
我可以看到复制整个有向图的最佳方法是将digraph_utils:subgraph/2
与Vertices = digraph:vertices(Digraph)
一起使用。
<强>测试强>
在Digraph
中创建A-&gt; B图表,将其复制到Digraph2
并通过仅将"C"
顶点添加到Digraph2
来检查它是不同的图表。
1> Digraph = digraph:new().
{digraph,16400,20497,24594,true}
2> digraph:add_vertex(Digraph,"A").
"A"
3> digraph:add_vertex(Digraph,"B").
"B"
4> digraph:add_edge(Digraph,"A","B").
['$e'|0]
5> Digraph2 = digraph_utils:subgraph(Digraph, digraph:vertices(Digraph)).
{digraph,28691,32788,36885,true}
6> digraph:add_vertex(Digraph2, "C").
"C"
7> digraph:vertices(Digraph).
["B","A"]
8> digraph:vertices(Digraph2).
["C","B","A"]