通路/道路铺设问题

发布于 2024-10-04 06:46:49 字数 359 浏览 5 评论 0原文

今天我们有一项作业要在实验室完成(两小时内)。问题是:

  • 给你一个 m*n 矩阵。
  • 该矩阵有“h”个宿舍楼和“b”个主楼入口。
  • 这些“h”大厅和“b”入口的位置是已知的(以(x,y)坐标表示)。
  • 您需要铺设通道,使每个宿舍楼至少有一条路可以到达“b”入口之一。
  • 最多可以有“b”条这样的断开路径。
  • 路径的长度必须是最短的。
  • 您只能向上、向下、向左或向右移动。
  • 解决方案不能是暴力尝试。

任务结束了。但我还在想如何解决这个问题。此类问题有标准术语吗?我应该读什么?

人们也在城市中使用这样的算法来铺设道路吗?

Today we got an assignment to complete in lab (in two hours). The question was:

  • You're given an m*n matrix.
  • The matrix has 'h' residential halls and 'b' main building entrances.
  • The location of these 'h' halls and 'b' entrances is known (in terms of (x,y) coordinates).
  • You need to lay pathways such that every residential hall has at least one way to reach one of the 'b' entrances.
  • There can be at most 'b' such disconnected pathways.
  • The length of the pathway must be minimum.
  • You can only move up, down, left or right.
  • The solution must not be a brute force attempt.

The assignment is over. But I'm still thinking how this would be solved. Is there a standard term for such problems? What should I read up?

Do people use such algorithms to laying roads in cities as well?

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

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

发布评论

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

评论(5

清泪尽 2024-10-11 06:46:50

这是一个搜索问题。你应该在 2 小时内完成,对吗?我会DFS修剪。您可以使用启发式更快地找到更好的解决方案。但请记住,启发式方法不能保证最佳解决方案,因此您必须尝试所有可能性。看起来是NP难的。

It is a search problem. You were expected to do it in 2 hours, right? I would DFS and prune. You could use heuristics to get to the better solutions faster. But keep in mind heuristics can not guarantee optimal solutions so you will have to try all possibilities. Seems to be NP-hard.

清君侧 2024-10-11 06:46:49

这是我想出的一个解决方案。它不会生成“b”断开的路径。它生成一条穿过所有宿舍楼和入口的路径。

  • 计算每对节点之间的距离(X坐标差+Y坐标差)。现在你有了一个完整的图表。
  • 找到此完整图的 MST
  • MST 的每个倾斜边缘(非垂直或水平的倾斜边缘)都可以分为两部分 - 水平部分和垂直部分。
  • 每个分割可以通过两种方式进行 - 先水平分割,然后垂直分割,或者反之亦然。
  • 遍历每个这样的排列并计算长度最小的路径。这就是答案。

Here's a solution I came up with. It doesn't generate 'b' disconnected paths. It generates one path that goes through all residential halls and entrances.

  • Calculate the distance between each pair of nodes (difference of X coordinates + difference of Y coordinates). Now you have a complete graph.
  • Find the MST for this complete graph
  • Each inclined edge of the MST (those that are not vertical or horizontal) can be split into two parts - the horizontal and the vertical.
  • Each split can be made in two ways - either horizontal first followed by vertical or vice versa.
  • Go through each such permutation and calculate the path with the least length. This is the answer.
诗笺 2024-10-11 06:46:49

无法告诉您解决方案是什么(猜测是某种最低成本路径分析),但我对道路建模软件有一些经验。

一方面,您拥有使用类似(广义上)方法的战略建模系统。它们可以被认为是一个重力模型 - 它将使用交通产生和需求的估计来对城镇和城市、工业区到住宅区等之间的交通流量进行高级预测。这主要用于查找重大规划开发的宏观影响、人口分布或土地利用区域的变化……诸如此类的事情。

在另一端,你有城市、城镇、立交桥等特定区域的模拟模型。这些数字模型将每辆车视为具有攻击性、道路知识等因素的自主代理。这在很大程度上是一种蛮力式的方法,但它是在具有交通信号灯、公共汽车等功能的复杂网络中提供有关实际流量行为的有用统计数据的唯一方法。例如,流量建模者可以将其插入根据实际的交通控制数据,针对特定的设计方案运行模型一段特定的时间,并设置其运行6或7次。生成的数据可以让您很好地评估特定解决方案相对于另一个解决方案(或现状)的性能。

希望这提供了一些有用的背景。

Couldn't tell you what the solution is (some sort of least cost path analysis, at a guess), but I have some experience with road modelling software.

At one end of the scale you have strategic modelling systems that use a similar (broadly speaking) approach. They can be thought of like a gravity model - it will use estimates of traffic generation and demand to make high level predictions of traffic flows between, for example, towns and cities, or industrial areas to residential, etc. This is mostly useful for looking at the macro effects of major planned developments, changes in population distribution or land-use zones.. that sort of thing.

At the other end you have simulation models of specific areas of a city, town, interchange, etc. These are numeric models that treat each car as an autonomous agent with factors like aggression, road knowledge, and so on. This is very much a brute force style approach, but it is the only way to provide useful statistics on actual traffic behaviour in a complex network with features like traffic lights, buses, etc. A traffic modeller can, for example, plug it into the actual traffic control data, run the model for a specific period for a specific design solutions and set it to run 6 or 7 times. The resulting data gives you a very good assessment of the performance of a particular solution against another (or the status quo).

Hope this provides some useful context.

‖放下 2024-10-11 06:46:49

我不清楚问题描述的一个方面:

  • 当你说“你需要铺设一条路径”时,这是否意味着“只有一条连接的路径?”或者是否可以存在多条不连通的路径? (例如从大厅 H1 到建筑物入口 B1 的路径以及从大厅 H2 到建筑物入口 B2 的单独路径)

但是无论您如何回答我的问题,这是一个非常棘手的问题:它是 NP 困难的,因为它包含 直线斯坦纳树问题作为一种特殊情况(当只有一个主建筑入口时)。

所以没有人知道如何在一般情况下有效地解决它!

There's an aspect of the problem description that isn't clear to me:

  • When you say, "You need to lay a pathway", does that mean "just one connected path?" Or can there be multiple disconnected paths? (e.g. a path from hall H1 to building entrance B1 and a separate path from hall H2 to building entrance B2)

But however you answer my question, this is an extremely tricky problem: it's NP-hard as it includes the rectilinear Steiner tree problem as a special case (when there's just one main building entrance).

So no-one knows how to solve it efficiently in the general case!

仅此而已 2024-10-11 06:46:49

我认为问题更简单,不是斯坦纳树,甚至不是最小生成树。

  1. 将矩阵 M 表示为图 G,其中 V ={Mij | i <=m, j <= n}, E= {(Mi1j1,Mi2j2) : i1,i2 <=m, j1,j2<=n, |i1-i2| = 1-异或 |j1-j2| = 2}

  2. 取入口组 B,大厅组 H

  3. H' = H/B,B' = B/H(标记大厅那些是入口,它们在深度 0 处到达,删除所有这些入口,因为它们是大厅)

  4. 进行广度优先遍历。在每个深度标记从 B 可以到达的大厅,直到标记所有大厅。选择相应的路径。

I think the problem is simpler and not Steiner tree or not even minimum spanning tree .

  1. Represent matrix M as a graph G with V ={Mij | i <=m, j <= n}, E= {(Mi1j1,Mi2j2) : i1,i2 <=m, j1,j2<=n, |i1-i2| = 1-exclusive OR |j1-j2| = 2}

  2. Take set B of entrances, set H of halls

  3. H' = H/B, B' = B/H (mark the halls that are entrances, they are reached at depth 0, remove all these entrances as those are halls)

  4. Do a breadth-first traversal. At each depth mark the halls that can be reached from B until all halls are marked. Pick corresponding pathways.

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