图中最长的圆

发布于 2024-08-11 08:20:06 字数 341 浏览 2 评论 0原文

我想解决以下问题:

我有一个 DAG,其中包含城市以及它们之间需要完成的工作。这些工作针对的是可以装载规定限制的卡车。卡车装载的越多,旅行就越好。有些作业用于加载某些内容,有些作业用于加载定义的内容。你总是可以开车从a城市到b城市,即使它们之间没有工作要做。 最后一个限制是我总是需要从a城市出发并返回a,因为那里是卡车的家:)

我首先想到了Dijkstra的最短路径算法。我可以轻松地将其转化为最长路径计算。我现在想到的问题是,所有这些算法都是为了计算从顶点 a 到 b 的最短或最长路径,但我需要它从 a 返回到 a - 在一个圆圈中。

有人能给我一些启发吗?

感谢您的反馈!

马可

I want to solve the following problem:

I have a DAG which contains cities and jobs between them that needs to be done. The jobs are for trucks which can load a definied limit. The more the truck is loaded the better is the tour. Some jobs are for loading something in and some are for loading defined things out. You can always drive from city a to b even if there is no job to be done between them.
The last restriction is that I always need to start in city a and return to a because there is the home of the trucks :)

I first thought of Dijkstra's shortest path algorithm. I could easly turn that into longest path calculation. My problem in mind is now that all these algorithms are for calculating a shortest or longest path from vertex a to b, but I need it from a returning to a - in a circle.

Has some one some kicks for my mind?

Thanks for your feedback!

Marco

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

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

发布评论

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

评论(4

八巷 2024-08-18 08:20:06

背包和旅行推销员的疯狂组合肯定是NP-hard

几乎在任何地方,当您想要为代理加载最佳作业计划时,或者当您想要构建穿过图中所有顶点的路线时,或者当您觉得需要寻找“最长路径*",您很可能会遇到 NP-completeNP-难题。

这意味着,没有已知的快速且精确的问题解决方案,即在多项式时间内运行的解决方案。

因此,您必须根据您的特定条件创建近似值并实现非最佳算法。什么时间损失是可以接受的?卡车还可以行驶其他模式吗?您对图表了解更多吗(例如,该区域是否分为遥远的密集区域)?回答这些问题,您将找到令您的客户满意的非严格启发式方法。


*是的,搜索最长路径并不像您想象的那么容易。最长路径问题是 NP 完全问题,因为您的图不是是无环的。

This crazy combination of knapsack and travelling salesman is surely NP-hard.

Virtually everywhere, when you want to load your agent with optimal job schedule, or when you want to build a route through all vertexes in the graph, or when you feel that you need to look for a "longest path*", you most likely run into an NP-complete or an NP-hard problem.

That means, that there is no known fast and exact solution to the problem, i.e. the one that runs in a polynomial time.

So you have to create approximations and implement non-optimal algorithms based on your particular conditions. What time loss is acceptable? Are there additional patterns the trucks can drive? Do you know more about the graph (e.g. is the area divided into distant dense regions)? Answer these questions and you'll find a non-strict heuristics that satisfies your customers.


*yes, searching for longest paths is not as easy as you think. Longest path problem is NP-complete, given that your graph is not acyclic.

咿呀咿呀哟 2024-08-18 08:20:06

您正在尝试找到尽可能最小的方法来完成所有事情吗?这让我想起了最大流/最小割问题。您可以通过以下方式近似获得最佳答案:

  • 将所有终端节点连接到最终 end 节点。
  • 运行各种最大流量算法之一来查找a和<代码>结束。
  • 返回城市a。更新图表以反映您刚刚所做的事情。重复此操作直至完成所有作业。

我们的想法是让您在每次旅行中都能获得最大的收获。第一次之后的每次旅行效率都会越来越低,但这是可以预料的。

注意:这仅在您有 DAG 时才有效。旅行推销员在 DAG 上也不是 NP 完全的,而且甚至可能不可能到达图表上的所有节点。重新阅读你的问题,似乎你没有 DAG,因为你可以返回城市 a - 这是真的吗?

You're trying to find the smallest possible way to get everything done? This reminds me of a max-flow/min-cut problem. You might be able to approximate the best answer by:

  • Connect all terminal nodes to a final end node.
  • Run one of the various maximum flow algorithms to find the max flow between a and end.
  • Return to city a. Update the graph to reflect what you just did. Repeat until all jobs are done.

The idea is that you get the most bang for every trip. Each trip after the 1st will be less efficient and less efficient, but that's to be expected.

Note: This only works because you have a DAG. Travelling salesman wouldn't be NP-Complete on a DAG, either, and it will likely be impossible to even hit all nodes on the graph. Re-reading your problem, it seems like you don't have a DAG, since you can return to city a - is that true?

风月客 2024-08-18 08:20:06

您可以调整旅行商问题动态规划算法来完成您想要的操作。

经典的方法是,您希望最大限度地发挥所有城市的最佳功能,但您可以在每一步中都考虑到回家的可能性。

正如 Pavel 提到的,这个问题绝对是 NP 困难的。对于城市数量或卡车上可以装载的最大物体数量,您是否有一些上限?

PS:您想要最好的解决方案(最大利润 - 就处理时间而言可能不现实)还是接受一些近似值?

You can adjust the traveling sales man problem dynamic programming algorithm to do what you want.

The classic approach says that you want to maximize the optimum function from all cities but you can take in consideration, at each step also the possibility of returning home.

And like Pavel mentioned, this problem is definitively NP-hard. Do you have some upper bounds for the number of cities or maximum number of objects that can be loaded in a truck?

PS: Do you want the BEST solution (maximum profit - might not be realistic in terms of processing time) or you accept some approximation?

疑心病 2024-08-18 08:20:06

这不是交通问题吗?

根据卡车数量和起点,您可以添加虚假运输或增加成本以满足您的限制。

我还想问一下卡车限制:

  • 它们都在同一个城市吗?
  • 你有固定的数量吗?
  • 如果你使用更少的话你会赢得什么
    你有吗?
  • 有周期时间限制吗?

Isn't this a Transportation problem?

Depending on the trucks number and starting points, you could add a fake transporations or add costs in order to satisfy your restrictions.

I'd also ask about truck restrictions:

  • are they all based in the same city?
  • do you have a fixed number of them?
  • and what you win if you use less then
    you have?
  • is there a cycle time restriction?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文