本文整理汇总了C++中Vertices::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ Vertices::reserve方法的具体用法?C++ Vertices::reserve怎么用?C++ Vertices::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Vertices
的用法示例。
在下文中一共展示了Vertices::reserve方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runtime_error
void set_candidates_and_demands
(const Graph& g, Vertices& candidates, Vertices& demands,
ExistedCenterMap existed_center_map, CandidateMap candidate_map)
{
using boost::vertices;
const typename boost::graph_traits<Graph>::vertices_size_type
num_v = num_vertices(g);
candidates.reserve(num_v);
demands.reserve(num_v);
typename boost::graph_traits<Graph>::vertex_iterator vi, vi_end;
for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi) {
if (get(candidate_map, *vi) != false &&
get(existed_center_map, *vi) == false) {
candidates.push_back(*vi);
}
demands.push_back(*vi);
}
// TODO copy_if or filter_iterator
//
if (candidates.empty()) {
throw std::runtime_error("The number of candidate vertex is too small");
}
}
示例2: main
//.........这里部分代码省略.........
//typedef boost::graph_traits<Graph>::vertex_iterator VertexIter;
//typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
//typedef boost::property_map<Graph, boost::vertex_index_t>::type IndexMap;
// Fix number of vertices, and add one edge at a time.
int num_vertices = 3;
Graph g(num_vertices);
boost::add_edge(0, 1, g);
boost::add_edge(1, 2, g);
// Fix number of vertices, and add one edge array.
{
int num_vertices = 3;
typedef std::pair<int, int> Edge;
std::vector<Edge> edges{
{0, 1},
{1, 2},
};
Graph g(edges.data(), edges.data() + edges.size(), num_vertices);
}
// It is also possible to add vertices with #add_vertex.
//#vertices
{
// Number of vertices.
boost::graph_traits<Graph>::vertices_size_type num_vertices = boost::num_vertices(g);
assert(num_vertices == 3u);
//#vertices() Returns a begin() end() vertex iterator pair so we know where to stop.
{
typedef std::vector<boost::graph_traits<Graph>::vertex_descriptor> Vertices;
Vertices vertices;
vertices.reserve(num_vertices);
//IndexMap
auto index = boost::get(boost::vertex_index, g);
//std::pair<vertex_iter, vertex_iter> vp
for (auto vp = boost::vertices(g); vp.first != vp.second; ++vp.first) {
// Vertex
auto v = *vp.first;
vertices.push_back(index[v]);
}
assert((vertices == Vertices{0, 1, 2}));
}
// The iterator is a ranom access iterator.
{
auto index = boost::get(boost::vertex_index, g);
auto it = boost::vertices(g).first;
assert(index[it[2]] == 2);
assert(index[it[1]] == 1);
}
}
//#edges
{
// It seems that only AdjencyMatrix has a method to get an edge given two vertices:
//edge(u, v, g)
}
}
//#source is also a global function: <http://stackoverflow.com/questions/16114616/why-is-boost-graph-librarys-source-a-global-function>
//#dijikstra
std::cout << "#dijkstra" << std::endl;
{