1
への外部プロパティマップを添付:私は同じことを行うと「外部のプロパティ」を使用して証明したい場合は内部プロパティとしてグラフに辺の重みを追加するためにまっすぐ進むグラフ
今void InternalProperties()
{
std::cout << "InternalProperties()" << std::endl;
// Graph with internal edge weights
using EdgeWeightProperty = boost::property<boost::edge_weight_t, double>; // <tag, type>
using GraphWithInternalEdgeWeightsType = boost::adjacency_list<boost::setS, // out edge container
boost::vecS, // vertex container
boost::undirectedS, // directed or undirected
boost::no_property, // vertex properites
EdgeWeightProperty> // edge properties
;
// Create a graph object
GraphWithInternalEdgeWeightsType g(3);
// add two edges with edge weights
EdgeWeightProperty e1 = 5;
add_edge(0, 1, e1, g);
EdgeWeightProperty e2 = 3;
add_edge(1, 2, e2, g);
boost::property_map<GraphWithInternalEdgeWeightsType, boost::edge_weight_t>::type edgeWeightMap = get(boost::edge_weight_t(), g);
using edge_iter = boost::graph_traits<GraphWithInternalEdgeWeightsType>::edge_iterator;
std::pair<edge_iter, edge_iter> edgePair;
for(edgePair = edges(g); edgePair.first != edgePair.second; ++edgePair.first) {
std::cout << edgeWeightMap[*edgePair.first] << " ";
}
}
、このマップを返す
void ExternalProperties()
{
std::cout << std::endl << "ExternalProperties()" << std::endl;
// Graph with external edge weights
using GraphWithExternalEdgeWeightsType = boost::adjacency_list<boost::setS, // out edge container
boost::vecS, // vertex container
boost::undirectedS> // directed or undirected
;
// Create a graph object
GraphWithExternalEdgeWeightsType g(3);
// add edges (without edge weights)
add_edge(0, 1, g);
add_edge(1, 2, g);
// create a map from edge_descriptors to weights and populate it
std::map<GraphWithExternalEdgeWeightsType::edge_descriptor, double> edgeWeightMap;
edgeWeightMap[boost::edge(0,1,g).first] = 5;
edgeWeightMap[boost::edge(1,2,g).first] = 3;
using edge_iter = boost::graph_traits<GraphWithExternalEdgeWeightsType>::edge_iterator;
std::pair<edge_iter, edge_iter> edgePair;
for(edgePair = edges(g); edgePair.first != edgePair.second; ++edgePair.first) {
std::cout << edgeWeightMap[*edgePair.first] << " ";
}
}
(内部の例から)get(boost::edge_weight_t(), g);
のようなものを作るためにどのような方法があります:私はこれを思い付いたが、まったくリンクは、元のグラフには本当にありませんか?この外部の例ではg.setPropertyMap(boost::edge_weight_t, edgeWeightMap)
と言っていますか?
だから、これは私が求めていたように振る舞う独自のグラフのようなコンテナを作るのではなく、実際の 'adjacency_list'はそのように振る舞う作るの一種です。だから、実際の 'adjacency_list'に' boost :: edge_weight_t'を作成する方法が本当に外部のプロパティマップだと思っているのではないことを確認していると思います。だから、BGLのアルゴリズムは、直接必要とするフィールドの 'std :: map'のようなものを受け入れるべきであり、私が求めていることをする必要はありません。 –
あなたはそれがどのように機能すると思いますか?グラフのプロパティを使用して状態を保存することはできますが、タイプにランタイム状態をエンコードすることはできません。それは物理学の法則です。 – sehe
「edge_weight_t」のエッジウェイトを返すBoostグラフクラスの関数は、タグディスパッチのようなことが起こっていることを想像すると、エッジ重みコンテナを持つファンクタが必要になり、それを返すことができます。私はここでベースオフですか? –