我的问题如下:考虑一个包含10000个节点和4800个边的非直接图.给定此图并给出该图的节点(例如,节点1),我需要igraph(R)中的命令以获得该节点1与图中最远节点之间的距离.非常感谢你的帮助!:)
亲切的问候,伊格纳西奥.
这本质上是一个探路者/搜索。
假设如果两个节点已连接,则 isConnected(a,b) 返回
(我是用Lua写的代码,应该不难翻译)
function search(list)
local i = 0
while i < 10000 do
i = i + 1
if isConnected(i,list[#list]) then
--This expression refers to the last member
search(list ++ i)
--Although not technically a proper operator, ++ adds the element to the end of the list
end
end
submit_list(list)
end
Run Code Online (Sandbox Code Playgroud)
submit_list是一个接受列表并检查它们的函数。它找到最长且不包含重复项的提交列表。该列表将解决您的问题。
哦,还有一件事;我的代码没有说明什么。如果列表包含重复节点,该函数应该终止,这样它就不会永远递归。