设置boost:graph中的顶点数 [英] set the number of vertices in boost:graph

查看:73
本文介绍了设置boost:graph中的顶点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个空的boost :: graph g,我想在此图中设置顶点数,然后添加一些边.但是从文档中,我找不到相关的功能.我发现的所有示例都定义了初始化时顶点的大小(例如Graph g(10)定义了具有10个顶点的图).但是我在定义图形时不知道大小.我想先定义一个Graph g,然后再设置大小.

Given an empty boost::graph g, I want to set the number of vertices in this graph and add some edges then. But from the documentation, I cannot find related functions. All examples I found defines the size of vertices in initialization (like Graph g(10) defines a graph with 10 vertices). But I don't know the size when I define the graph. I want to first define a Graph g, and set the size later.

推荐答案

最简单的方法是为所需的每个顶点调用boost :: add_vertex(graph)方法.

The simplest approach is to call the boost::add_vertex( graph ) method for each vertex you want.

这是一个很好的起点使用C ++ Boost的图形库

请注意,您不必一一添加顶点.如果您只关心边缘,那么add_edge()会为您添加丢失的顶点.

Note that you not HAVE to add the vertices one by one. If all you care about are the edges, then add_edge() will add missing vertices for you.

这篇关于设置boost:graph中的顶点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆