数据结构的关系 [英] Data structure for relationships

查看:149
本文介绍了数据结构的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我转换VB6 C#和我想让我的数据结构,具有价值和关系更加高效。在VB中我有值的集合,并与​​这些关系优先级的值之间的关系的另一个集合。我也有,当一组值传递给它的加盟,共同返回这些值所需的所有关系的算法。例如,假设值集合包含1-10和关系的集合包含

I am converting a VB6 to C# and I want to make my data structure that holds values and relationships more efficient. In VB I have a collection of values and another collection of relationships between those values with priorities for those relationships. I also have an algorithm that when a set of values is passed to it all relationships required to join those values together is returned. For example, say the values collection contains 1-10 and the relationship collection contains

1,2
3,2
5,2
2,8
8,10
9,10

1,2
3,2
5,2
2,8
8,10
9,10

如果输入的是1,9,10返回的关系是 -

If the input was 1,9,10 the returned relationships would be --

1,2
2,8
8,10
9,10

1,2
2,8
8,10
9,10

由于可能存在最少量的关系将被返回多条路径但存在的关系的优先一个警告。如果一个关系具有较高优先级则该关系将被添加和关系的其余部分将被从那里加入。我想用一个不相交集数据结构,但我不知道。

Since there may be multiple paths the least amount of relationships would be returned but there is a caveat of relationship priorities. If a relationship has a higher priority then that relationship would be added and the rest of the relationships would be added from there. I am thinking of using a Disjoint-set data structure but I am not sure.

任何想法?

感谢

更多信息 -

值的数目通常少于100和关系小于500的集合是静​​态的,该算法将被一次又一次地用于寻找路径。另外,我也没有问这个,但会在算法中不相交集数据结构是最有效的?

The number of values would normally be less than 100 and the relationships less than 500. The collections are static and the algorithm will be used again and again to find paths. Also, I did not ask this but would the algorithm in Disjoint-set data structure be the most efficient?

推荐答案

这听起来像你所拥有的是一个的。这是与节点和边的结构。有<一href="http://www.google.com/search?rlz=1C1GGLS_enUS291US303&aq=f&sourceid=chrome&ie=UTF-8&q=graph+library"相对=nofollow> 和工具,处理图形的许多许多图书馆。 微软的甚至推出了关于如何处理与他们的论文。我认为图是巨大的,在许多情况下非常有用。

It sounds like what you have is a Graph. This is a structure with Nodes and Edges. There are many many libraries and tools that deal with Graphs. Microsoft even put out a paper on how to deal with them. I think graphs are great and extremely useful in many situations.

一大优点是能够优先级分配给各节点之间的边的能力。然后,当你想找到两个节点,繁荣之间的路径,该图可以选择与理想的优先路径。

One big benefit with graphs is the ability to assign priorities to the edges between the nodes. Then when you want to find the path between two nodes, boom, the graph can choose the path with the ideal priority.

在你的情况,你的价值观是节点和你的关系是边缘。

In your situation, your values are the nodes and your relationships are the edges.

这篇关于数据结构的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆