BOOST :: ADGACENCY_LIST<>>和boost ::列表
列表选择STD :: LIST
在示例我正在尝试适应。
在示例中,我看不到边缘和顶点类型的传递以提高:: adjacency_list<>。 毫不奇怪,使用开头对构造图形在边缘容器中构建图并不对我进行编译。
如何告诉图表库有关使用的边缘和顶点的类型?
the documentation says:
listS selects std::list
The same is being used in an example I'm trying to adapt.
I don't see anywhere in the example where the edge and the vertex type are being passed to boost::adjacency_list<>.
And unsurprisingly constructing the graph using a begin-end pair into a container of edges does not compile for me.
How can one tell the graph library about the type of edges and vertices one intends to use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用普通 std::size_t 作为顶点和 std::pair创建了该图的副本对于边缘。
我不清楚为什么我必须这样做,因为图形库是一个模板库。
I created a copy of the graph with plain std::size_t for vertices and std::pair<std::size_t, std::size_t> for edges.
I'm unclear why I have to do this, as the graph library is a template library.
您可以使用模板参数选择图形的所有属性。
前两个选择如何存储边和顶点。对于邻接列表,邻接列表是给定的,但您可以选择边容器选择器(它存储每个源顶点的邻接(出边))和实际的顶点容器选择器(其中存储顶点本身)。
其他模板参数包括顶点/边和图属性。因此,当容器选择器选择如何存储图形实体时,属性描述应该存储什么。
如何存储所有内容最终都是实现细节。
我们对此无话可说,因为我们不知道“边缘容器”是什么意思。您是否已经拥有其他格式的图表?
构建图表不需要构造函数参数。例如:
是创建具有 10 个未连接顶点的图的最简单的程序。也可以打印它: Live
输出显示 10 个没有邻接的顶点:
让我从“使用”开始,然后稍微修改类型:
相反,您可以在构造后添加边/顶点: 实时
输出:
现在,让我们立即展示
setS
作为边缘存储的效果:输出变成 - 因为
setS
不允许重复的出边:现在,让我们还尝试不同的顶点容器选择器?
呃,现在打印图表时遇到问题,因为,正如您可能已经在 链接文档:
如果使用
listS
,则不存在隐式顶点索引。当然,我们可以添加一个索引,但让我们向顶点添加一个名称属性。有很多方法可以添加属性,但让我向您展示更通用/友好的版本:捆绑属性:
现在,我们需要做的就是告诉
print_graph
使用name
属性从束而不是顶点索引(自listS
起不可用于打印):当然,当您实际给出顶点名称时,它会变得更好:
但是当然,名称可以更改:
请参阅全部一起:实时
打印
1 您可能不需要复制任何东西,只需调整/使用现有图表即可)
You choose all the properties of the graph with the template arguments.
The first two choose how edges and vertexes are to be stored. For adjacency-lists, the adjacency-list is a given, but you can choose the edge container selector (which stores the adjacencies (out-edges) per source vertex) and the actual vertex container selector (which stores the vertices themselves).
The other template arguments include the vertex/edge and graph properties. So, where the container selectors choose how to store graph entities, the properties describe what should be stored.
HOW everything is being stored is ultimately an implementation detail.
We can't say anything about that, because we don't know what you mean by "a container of edges". Do you already have your graph in some other format?¹
The constructor arguments are not required to build a graph. E.g.:
Is the simplest possible program that creates a graph with 10, unconnected, vertices. To also print it: Live
Output shows 10 vertices with no adjacencies:
Let me start with the "using", then modify the types a little:
Instead you can add edges/vertices after construction: Live
Output:
Now, let's immediately show the effect of
setS
as edge storage:Output becomes - because the
setS
doesn't admit duplicate out-edges:Now, let's also try a different vertex container selector?
Uhoh, now there is trouble printing the graph, because, as you might have read already in the linked documentation:
If you use
listS
then there is no implicit vertex index. Of course, we can add an index, but let's instead add a name property to our vertex.There are many ways to add properties, but let me show you the more versatile/friendly version: bundled properties:
Now, all we need to do is tell
print_graph
to use thename
property from the bundle instead of the vertex index (which isn't usable for printing sincelistS
):Of course, it becomes nicer when you actually give the vertices names:
But of course, names can be changed:
See it all together: Live
Prints
¹ You may not need to copy anything at all, just adapt/use the existing graph)