Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Erlang中是否有任何模块可用于查找无向图的所有圈?_Erlang_Cycle_Distributed System_Undirected Graph_Digraphs - Fatal编程技术网

Erlang中是否有任何模块可用于查找无向图的所有圈?

Erlang中是否有任何模块可用于查找无向图的所有圈?,erlang,cycle,distributed-system,undirected-graph,digraphs,Erlang,Cycle,Distributed System,Undirected Graph,Digraphs,对于有向图,我们有以下模块: 有向图:循环强分量(G) Erlang中的无向图有类似的功能吗?我想找到一个无向图中的所有圈 有没有一种方法可以代替无向图使用有向图实用程序?直接使用这些模块将非常方便和容易 我尝试了以下方法: 我尝试了相同的有向图模块,添加了双向边,因此图现在是无向的。然后我添加了一个案例,其中循环的长度大于3,然后打印这样一个循环。对于我使用代码的图形,它工作得很好。代码如下:(将我的代码添加到此答案的代码中:) 这是正确的方法,还是有任何图表不适用?我是说,有漏洞吗 -mo

对于有向图,我们有以下模块:

有向图:循环强分量(G)

Erlang中的无向图有类似的功能吗?我想找到一个无向图中的所有圈

有没有一种方法可以代替无向图使用有向图实用程序?直接使用这些模块将非常方便和容易

我尝试了以下方法:

我尝试了相同的有向图模块,添加了双向边,因此图现在是无向的。然后我添加了一个案例,其中循环的长度大于3,然后打印这样一个循环。对于我使用代码的图形,它工作得很好。代码如下:(将我的代码添加到此答案的代码中:)

这是正确的方法,还是有任何图表不适用?我是说,有漏洞吗


-module(test1).
-export([get_cycles/0,pri/2,get_more_cycles/3]).

pri(L,0) ->
    io:fwrite("~n");

pri(L,V) ->
    List = lists:nth(V,L),
    case (length(List) > 3) of
        true -> io:fwrite("Cycle is ~w ~n",[List]);
        false -> io:fwrite("~n")
    end,
    pri(L,V-1).

get_cycles() ->
    G = digraph:new(),
    Vertices = [1,2,3,4,5,6,7,8,9,10,11,12,13],
    lists:foreach(fun(V) -> digraph:add_vertex(G, V) end, Vertices),
    Edges = [{12,13},{13,12},{11,12},{12,11},{11,13},{13,11},{10,11},{11,10},{9,5},{5,9},{10,6},{6,10},{8,7},{7,8},{4,7},{7,4},{1,2},{2,1},{2,3},{3,2},{3,4},{4,3},{4,6},{6,4},{6,5},{5,6},{3,5},{5,3}],
    lists:foreach(fun({V1,V2}) -> digraph:add_edge(G, V1, V2) end, Edges),
    Components = digraph_utils:cyclic_strong_components(G),
    List = lists:foldl(fun(Comp, Acc) -> get_more_cycles(G,Comp,[]) ++ Acc end, [], Components),
    pri(List,length(List)).

get_more_cycles(_G, [], Acc) ->
    Acc;
get_more_cycles(G, [H|T], Acc) ->
    Cycle = digraph:get_cycle(G,H),
    get_more_cycles(G, T -- Cycle, [Cycle|Acc]).