匹配算法

发布于 2024-07-24 13:14:15 字数 673 浏览 8 评论 0原文

这里奇怪的问题不是真正的代码而是逻辑,希望可以将其发布在这里,这是

我有一个可以被认为是图形的数据结构。 每个节点可以支持许多链接,但仅限于每个节点的一个值。 所有链接都是双向的。 并且每个环节都有成本。 成本取决于节点之间的欧氏差(每个节点中两个参数的最小值)。 和一个全局修饰符。

我希望找到该图的最大成本。

想知道是否有一种聪明的方法来找到这样的匹配,而不是用蛮力来完成……这很丑陋……而且我不确定如果不花费 700 万年的时间来运行它,我该如何做到这一点。

澄清一下:

Global variable = T
many nodes N each have E,X,Y,L
L is the max number of links each node can have.
cost of link A,B = Sqrt(  min([a].e | [b].e)  ) x 
     ( 1 + Sqrt( sqrt(sqr([a].x-[b].x)+sqr([a].y-[b].y)))/75 + Sqrt(t)/10 )


total cost =sum all links.....and we wish to maximize this.

节点的平均值是 40-50,范围可以是 (20..600) 平均节点链接因子为 3,范围为 0-10。

Odd question here not really code but logic,hope its ok to post it here,here it is

I have a data structure that can be thought of as a graph.
Each node can support many links but is limited to a value for each node.
All links are bidirectional. and each link has a cost. the cost depends on euclidian difference between the nodes the minimum value of two parameters in each node. and a global modifier.

i wish to find the maximum cost for the graph.

wondering if there was a clever way to find such a matching, rather than going through in brute force ...which is ugly... and i'm not sure how i'd even do that without spending 7 million years running it.

To clarify:

Global variable = T
many nodes N each have E,X,Y,L
L is the max number of links each node can have.
cost of link A,B = Sqrt(  min([a].e | [b].e)  ) x 
     ( 1 + Sqrt( sqrt(sqr([a].x-[b].x)+sqr([a].y-[b].y)))/75 + Sqrt(t)/10 )


total cost =sum all links.....and we wish to maximize this.

average values for nodes is 40-50 can range to (20..600)
average node linking factor is 3 range 0-10.

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

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

发布评论

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

评论(6

苍风燃霜 2024-07-31 13:14:15

为了让其他人看到这篇文章的完整性,我建议重新审视你的图论算法:

  • Dijkstra
  • Astar
  • 贪婪
  • 深度/广度优先
  • 甚至动态规划(在某些情况下)
  • 等。 等等。

那里有解决您问题的正确方法。 我建议先看看 Dijkstra。

我希望这可以帮助别人。

For the sake of completeness for anybody else that looks at this article, i would suggest revisiting your graph theory algorithms:

  • Dijkstra
  • Astar
  • Greedy
  • Depth / Breadth First
  • Even dynamic programming (in some situations)
  • ect. ect.

In there somewhere is the correct solution for your problem. I would suggest looking at Dijkstra first.

I hope this helps someone.

过潦 2024-07-31 13:14:15

如果我正确理解这个问题,很可能没有多项式解。 因此,我将实现以下算法:

  1. 通过 beng 贪婪找到一些解决方案。 为此,您可以按成本对所有边进行排序,然后从最高的边开始遍历它们,尽可能向图中添加一条边,并在节点无法接受更多边时跳过。
  2. 查看您的优势并尝试通过使用启发式来改变它们以实现更高的成本。 我想到的第一个问题是:你循环遍历所有 4 元组节点(A、B、C、D),如果你当前的图有边 AB、CD,但 AC、BD 会更好,那么你就进行更改。
  3. 可选地,与 6 元组或其他遗传算法相同(它们之所以这样称呼,是因为它们通过突变起作用)。

If I understand the problem correctly, there is likely no polynomial solution. Therefore I would implement the following algorithm:

  1. Find some solution by beng greedy. To do that, you sort all edges by cost and then go through them starting with the highest, adding an edge to your graph while possible, and skipping when the node can't accept more edges.
  2. Look at your edges and try to change them to archive higher cost by using a heuristics. The first that comes to my mind: you cycle through all 4-tuples of nodes (A,B,C,D) and if your current graph has edges AB, CD but AC, BD would be better, then you make the change.
  3. Optionally the same thing with 6-tuples, or other genetic algorithms (they are called that way because they work by mutations).
复古式 2024-07-31 13:14:15

这相当于旅行商问题(因此是 NP 完全问题),因为如果您可以有效地解决这个问题,您可以简单地通过用其倒数替换每个成本来解决 TSP。

这意味着你无法准确地解决。 另一方面,这意味着您可以完全按照我所说的那样进行(将每个成本替换为其倒数),然后使用任何已知的 TSP 近似方法来解决此问题。

This is equivalent to the traveling salesman problem (and is therefore NP-Complete) since if you could solve this problem efficiently, you could solve TSP simply by replacing each cost with its reciprocal.

This means you can't solve exactly. On the other hand, it means that you can do exactly as I said (replace each cost with its reciprocal) and then use any of the known TSP approximation methods on this problem.

故人爱我别走 2024-07-31 13:14:15

对我来说似乎是一个最大流量问题

Seems like a max flow problem to me.

未央 2024-07-31 13:14:15

是否有可能通过从任何给定的起点贪婪地选择下一个最昂贵的选项(省略跳转到访问的节点)并在访问所有节点后停止? 如果你走到了死胡同,回溯到之前没有陷入死胡同的位置并贪婪地选择。 这需要一些工作,可能需要一些类似堆栈的东西来保存你的路径。我认为,只要成本排序良好且非负,这将非常有效。

Is it possible that by greedily selecting the next most expensive option from any given start point (omitting jumps to visited nodes) and stopping once all nodes are visited? If you get to a dead end backtrack to the previous spot where you are not at a dead end and greedily select. It would require some work and probably something like a stack to keep your paths in. I think this would work quite effectively provided the costs are well ordered and non negative.

娇纵 2024-07-31 13:14:15

使用遗传算法。 它们旨在解决您提出的问题,快速降低时间复杂度。 检查您选择的语言的 AI 库。

Use Genetic Algorithms. They are designed to solve the problem you state rapidly reducing time complexity. Check for AI library in your language of choice.

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