简体   繁体   English

查找两个节点之间的隐藏节点-图形-Java

[英]Find the hidden nodes between two nodes - graph - java

My English is not very well, BUT I will try my best to explain my issue here. 我的英语不太好,但是我会尽力在这里解释我的问题。 I am working on an application in which I have to create graph. 我正在开发必须在其中创建图形的应用程序。 For now I am using GraphStream . 现在,我正在使用GraphStream

Requirements for my graph is very complicated, which is : 我的图形要求非常复杂,即:

I have a table named CDR(Call Data Record) in which I have 2 columns ANUMBER and BNUMBER . 我有一个名为CDR(呼叫数据记录)的表 ,其中有2列ANUMBER和BNUMBER The structure of table is very clear that it shows that Anumber called Bnumber and there is another column for DATETIME, which shows the date and time of call. 该表的结构非常清楚,它显示了Anumber称为Bnumber,还有DATETIME的另一列,它显示了调用的日期和时间。 BUT I need here only two columns. 但是我在这里只需要两列。

Lets say we have 4 numbers here : 123, 456 ,789 ,000 and table structure is like this 可以说这里有4个数字:123、456、789、000,表结构是这样的

Anumber    Bnumber
-------    -------
123        456
123        789
456        789
789        000
456        000

My table here clearly shows that 123 didn't call 000 But 123 called 456 and 789 and these two numbers called 000 So I have to show the directed graph between 123 and 000 which probably shows like this 123->456->000 and 132->789->000 我的表格清楚地显示了123并没有调用000,但是123分别调用了456和789,而这两个数字分别称为000,因此我必须显示123和000之间的有向图,它可能显示为123->456->000132->789->000

So the issue is I don't know how to find this path between 123 and 000. There may be more than 2 numbers like 5 or 6 numbers and I have to find the hidden numbers between all the given 5 or 6 numbers AS in the above scenario 456 and 789 are hidden numbers between 132 and 000. 所以问题是我不知道如何找到123和000之间的路径。可能有2个以上的数字(例如5或6个数字),我必须在所有给定的5或6个数字AS之间找到隐藏的数字。场景456和789上方的数字是132和000之间的隐藏数字。

And one thing more my table contains more than 20 million rows and in future obviously the number of rows will grow very fast as user calls each other. 而且我的表还包含超过2000万行,而且将来显然,随着用户彼此调用,行数将非常快地增长。

WHAT I HAVE DONE SO FAR: 我做了这么远的事情:

I have done some R&D on this issue but couldn't found any good library or any solution for this. 我已经在此问题上进行了一些研发,但是找不到任何好的库或解决方案。 So far, I think Dijkstra's Algorithm is best for my scenario as GraphStream luckily provides this algorithm here . 到目前为止,我觉得Dijkstra's Algorithm是最适合我的方案为GraphStream幸运的是,提供了这种算法在这里

What I want from you guys, Give me an idea that Will this algorithm will give me required result OR I have to find any other algo or graph library which will suits best for my problem. 我想从你们这里得到什么,请给我一个想法,该算法将为我提供所需的结果,还是我必须找到其他任何最适合我的问题的算法或图形库。 I am not good at ALGO's thats why I am here for any help or guideline If you guys can gave me. 我不擅长ALGO,那就是我在这里寻求帮助或指导的原因,如果你们能给我的话。 Thanks 谢谢

You don't need Dijkstra's algorithm at all, since you don't have costs on edges. 您根本不需要Dijkstra的算法,因为您没有边缘成本。 You need simple BFS algorithm. 您需要简单的BFS算法。 Here is simple implementation but you should add 'labels' array to mark visited nodes. 这是简单的实现,但是您应该添加“ labels”数组来标记访问的节点。 So after BFS you can restore pass from each node to source node(123 in your case) or say that node cannot be reached from given node(if label for this node remains 0). 因此,在BFS之后,您可以将每个节点的传递恢复到源节点(在您的情况下为123),或者说无法从给定节点访问该节点(如果该节点的标签保持为0)。 You should add label in the following way: 您应通过以下方式添加标签:

all labels equals 0 on start 开始时所有标签等于0

when you visit new node you set it's label as current_node_label+1 当您访问新节点时,将其标签设置为current_node_label + 1

But Dijkstra's can help you if you set cost of each edge as 1. It's just not efficient way to sole you problem. 但是,如果将每个边的成本设置为1,Dijkstra可以为您提供帮助。这并不是解决问题的有效方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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