2
グラフのエッジを反復してエッジウェイトを出力しようとしています。私は混乱している。私は "エッジ"を出力する方法を知っていますが、これは実際にはエッジを定義する単なる(頂点、頂点)です。では、* edgePair.firstをEdgeWeightMapに挿入して、頂点* edgePair.firstから始まるエッジの重みを取得しますか?これはコンパイルされません: "no operator for operator < <"。出力BGLエッジウェイト
#include <iostream>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
typedef boost::property<boost::edge_weight_t, double> EdgeWeightProperty;
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, EdgeWeightProperty> Graph;
int main(int,char*[])
{
// Create a graph object
Graph g(2);
EdgeWeightProperty e = 5;
add_edge(0, 1, e, g);
boost::property_map<Graph, boost::edge_weight_t>::type EdgeWeightMap = get(boost::edge_weight_t(), g);
typedef boost::graph_traits<Graph>::edge_iterator edge_iter;
std::pair<edge_iter, edge_iter> edgePair;
for(edgePair = edges(g); edgePair.first != edgePair.second; ++edgePair.first)
{
std::cout << EdgeWeightMap[*edgePair.first] << " ";
}
return 0;
}
どのような考えですか?
おかげで、このコードで
デビッド
参照してください:http://programmingexamples.net/index.php?title=Boost簡単な例については、 –