在 C# 中生成平面图

发布于 2025-01-10 20:04:50 字数 327 浏览 0 评论 0原文

我正在寻找一种在 C# 中生成随机平面图的方法。我研究了一些算法,如 Voronoi 图、Delaunay 三角剖分和凸包算法。它们非常有用,我设法生成了一个图表,但我面临着一些尚未解决的边缘情况。请记住,我有两个主要约束:最小/最大边长度和最小/最大角度(任意两条边之间),目标顶点/边计数中存在错误是可以的。

我认为有两种方法可以生成该图: 答:有一些来源提供了所有可能的平面图,我需要一个小的平面图,所以这对我有用,但我不知道如何将其绘制在没有交叉点的平面图上。 B. 从几何角度生成它,这是我最理解的。

我发现一些论文旨在非常快速地生成大图,所以这对我来说很复杂。我可以接受经过测试的缓慢算法/库/代码。

I am looking for a way to generate a random planar graph in C#. I've looked into some algorithms like Voronoi Diagram, Delaunay Triangulation and convex hull algorithms. They were quit useful and I managed to generate a graph but I am facing some edge cases that I didn't solve yet. Put in mind that I have 2 main constraints: min/max edge length and min/max angle(between any 2 edges), it is okay to have error in target vertex/edge count.

I think there are 2 ways to generate that graph:
A. There are sources that has all possible planar graphs, I need small one so this works for me, but I don't know how to plot it on a plan without intersections.
B. Generating it geometry-wise, this is what I understand the most.

I found some papers aimed for very fast generation for big graphs so it is complicated for me. I am okay with a tested slow algorithm/library/code.

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

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

发布评论

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

评论(1

鸠书 2025-01-17 20:04:50

您可以通过以下方式创建随机最大平面图:

  1. 从一个由三个顶点和三个边组成的三角形开始,该三角形限制了单个内面。
  2. 将内心的面孔放入清单中。
  3. 从列表中随机选择一个内面,然后:
  • 在面的中心创建一个顶点;
  • 创建将新顶点连接到面周围的三个顶点的边,将原始面三等分成三个新面。
  • 将列表中的原始三等分面替换为新面之一,并将其​​他两个面附加到列表中。
  1. 重复第 3 步,直到生成具有足够顶点的图。

如果您不需要最大平面图而只想要随机图,则从图中删除边。

  • 如果您想要一个随机图,请删除任何边。
  • 如果您想要一个随机连接的图,请删除任何不会断开该图的边(您可以使用深度或广度优先搜索来检查连接性)。
  • 如果您想要一个随机双连通图,则删除任何不留下关节点的边(同样,您可以使用深度或广度优先搜索来检查双连通性)

请记住,我有 2 个主要约束:最小/最大边缘长度和最小/最大角度(任意 2 条边缘之间)

这是将图形嵌入到表面上的问题,而不一定是图形结构的问题。移动顶点并更改角度和边长。您可以尝试使用任何平面图绘制算法来生成嵌入,然后使用弹簧嵌入算法之类的算法来尝试修改嵌入以匹配您的约束。

You can create a random maximal planar graph by:

  1. Start with a triangle composed of three vertices and three edges which bounds a single inner face.
  2. Put that inner face into a list.
  3. Pick a random inner face from the list then:
  • Create a vertex in the centre of the face;
  • Create edges connecting that new vertex to the three vertices around the face an trisect that original face into three new faces.
  • Replace the original trisected face in the list with one of the new faces and append the other two faces to the list.
  1. Repeat from 3. until you have generated a graph with sufficient vertices.

If you do not want a maximal planar graph and just want a random graph then remove edges from the graph.

  • If you want a random graph then remove any edge.
  • If you want a random connected graph then remove any edge that does not disconnect the graph (you can use a depth- or breadth-first search to check for connectivity).
  • If you want a random biconnected graph then remove any edge that does not leave an articulation point (again, you can use a depth- or breadth-first search to check for biconnectivity)

Put in mind that I have 2 main constraints: min/max edge length and min/max angle(between any 2 edges)

This is an issue with the embedding the graph onto a surface and not necessarily with the structure of the graph as you can move a vertex and change the angles and edge lengths. You can try using any planar graph drawing algorithm to generate an embedding and then use something like a spring-embedding algorithm to try to modify the embedding to match your constraints.

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