创建一个数据结构来相互比较 300 个元素

发布于 2024-09-28 16:06:11 字数 271 浏览 1 评论 0原文

首先,我正在研究大约 300 个元素之间的相互作用。每个元素都会与所有其他元素及其自身相互作用。在少数情况下,会发生反应,我会标记该反应。

由于这基本上是一个包含大约 90,000 个可能的交互的矩阵,因此我想用代码管理这些数据,以便我可以轻松地测试交互,直到我将它们全部测试为止。由于我显然不会一次性完成所有这些工作,因此数据必须以某种方式存储在磁盘上。

这是我的问题:理想的数据结构设计是什么?我通常使用关系数据库进行数据存储,而这个特殊问题似乎与 RDB 不太吻合。如果我不清楚,请告诉我。

First of all, I'm looking at the interactions between around 300 elements. Each element will interact with all others and itself. In a minority of these cases, a reaction will occur, and I will mark that reaction.

Since this is basically a matrix with around 90,000 possible interactions, I want to manage this data with code so I can easily test the interactions however I would like to until I have them all tested. Since I obviously won't do all of them in one sitting, the data would have to be stored on disk somehow.

Here's my question: What would be the ideal data structure design for this? I generally use relational databases for data storage, and this particular problem doesn't seem to mesh very well with an RDB. Please let me know if I'm not being clear.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

∞琼窗梦回ˉ 2024-10-05 16:06:11

RDBMS 在这里并没有什么问题:重要的不是获取数据,而是事后报告它,并且人们无法从您的描述中得知您的需求是什么。

至于存储 300x300 结果:您只需要记录反应,而不是每次测试。那,以及你在测试中通过矩阵的程度。

请注意,90k 条记录实际上并不是很多数据,因此您可以根据需要保留全部数据。

编辑:您所需要的只是几个表:

Elements
--------
ItemID
... -- whatever identifying info you need

Crossref
--------
ItemX int
ItemY int
Results -- whatever data you need

就其价值而言:如果元组 {ItemX, ItemY} 等于 {ItemY, ItemX},那么您就不会进行 300x300 的比较,而是正在做 (300 + 299 + 298 + ... + 1) = 45150。

Nothing wrong with an RDBMS here: the important thing isn't getting the data in, but reporting on it afterwards, and one can't tell from your description what your needs will be.

As far as storing 300x300 results: you only need to record the reactions, not every test. That, and how far through the matrix you've gotten in your testing.

Note that 90k records isn't really very much data, so you could keep it all if you wanted.

Edit: all you need is a couple of tables:

Elements
--------
ItemID
... -- whatever identifying info you need

Crossref
--------
ItemX int
ItemY int
Results -- whatever data you need

For what it's worth: if the tuple {ItemX, ItemY} is equivalent to {ItemY, ItemX}, then you're not doing 300x300 comparisons, you're doing (300 + 299 + 298 + ... + 1) = 45150.

治碍 2024-10-05 16:06:11

我认为就数据结构而言,您已经在帖子中回答了您的问题。我相信,矩阵将是解决此问题的最简单方法。就存储而言,正如egrunin所说,90k条记录并不算多。您可以将其存储在数据库或平面文件中的某个位置。只需存储已经通过测试的对,即(A1,A2),(A1,A3),...

I think in terms of data structures, you've answered your question in your post. A matrix, I believe, would be the easiest way to go about this. In terms of storing it, as egrunin said, 90k records is not a lot. You can store this in a DB or a flat file somewhere. Simply store the pairs that have already gone through your testing, ie, (A1,A2),(A1,A3),...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文