【发布时间】:2014-05-14 09:34:55
【问题描述】:
问题
帖子底部的代码打印出来:
Vertices in g = [ 0 1 2 3 4 ]
Vertices in g' = [ 0 1 ]
我预计输出是:
Vertices in g = [ 0 1 2 3 4 ]
Vertices in g' = [ 3 4 ]
这是 boost::subgraph 中的错误还是我对库的理解中的错误?
有问题的代码
#include <sstream>
#include <iostream>
#include <boost/graph/subgraph.hpp>
#include <boost/graph/adjacency_list.hpp>
using namespace std;
using namespace boost;
// Underlying graph representation and implementation
typedef adjacency_list_traits<vecS, vecS, directedS> Traits;
// Graph representation
typedef subgraph< adjacency_list<vecS, vecS, directedS,
property<vertex_color_t, int>, property<edge_index_t, int> > > Graph;
// Iterating over vertices and edges
typedef graph_traits<Graph>::vertex_iterator vertex_iter;
typedef graph_traits<Graph>::edge_iterator edge_iter;
int main(void)
{
Graph g;
add_edge(0,1, g);
add_edge(1,2, g);
add_edge(3,4, g);
Graph sub = g.create_subgraph();
add_vertex(3, sub);
add_vertex(4, sub);
pair<vertex_iter, vertex_iter> vip;
cout << "Vertices in g = [ ";
vip = vertices(g);
for(vertex_iter vi = vip.first; vi != vip.second; ++vi) {
cout << *vi << " ";
}
cout << "]" << endl;
cout << "Vertices in g' = [ ";
vip = vertices(sub);
for(vertex_iter vi = vip.first; vi != vip.second; ++vi) {
cout << *vi << " ";
}
cout << "]" << endl;
return 0;
}
【问题讨论】:
标签: c++ boost boost-graph