1
は以下のtypedefとdefintiontionsをふり:boost :: adjacency_listのノードを置換する方法は?
#include <boost/graph/adjacency_list.hpp>
using namespace boost;
int main()
{
typedef adjacency_list<vecS, vecS, directedS, property<vertex_index_t, int> > GraphTC;
GraphTC g;
typedef typename property_map<GraphTC, vertex_index_t>::const_type VertexIndexMap;
VertexIndexMap index_map = get(vertex_index, g);
typedef typename graph_traits<GraphTC>::vertex_descriptor tc_vertex;
std::vector<tc_vertex> to_tc_vec(num_vertices(g));
iterator_property_map < tc_vertex *, VertexIndexMap, tc_vertex, tc_vertex&>
g_to_tc_map(&to_tc_vec[0], index_map);
}
私はグラムとg_to_tc_map(上記のように)私を出力するアルゴリズムを持っています。今、私はg_to_tc_mapによってノードを並べ替える必要があります(これは整数配列やstd :: mapのようなものです)。
注:boost/graph/detail/permutation.hppがあることがわかりましたが、どのように使用するかわかりません(他のヘッダーと競合するこのファイルのみを含むバグもあります)。
この順列をどのように行うかについてのアイデア/コードをありがとう。
struct permute_edge {
iterator_property_map < tc_vertex *, VertexIndexMap, tc_vertex, tc_vertex&> g_to_tc_map;
const GraphTC& g;
permute_edge(iterator_property_map < tc_vertex *, VertexIndexMap, tc_vertex, tc_vertex&> g_to_tc_map, const GraphTC& g): g_to_tc_map(g_to_tc_map), g(g) {}
std::pair<tc_vertex, tc_vertex> operator()(graph_traits<Graph>::edge_descriptor e) const {
return std::make_pair(get(g_to_tc_map, source(e, g)), get(g_to_tc_map, target(e, g));
}
};
permute_edge perm(g_to_tc_map, g);
typedef graph_traits<GraphTC>::edge_iterator edge_iterator;
std::pair<edge_iterator, edge_iterator> g_edges = edges(g);
GraphTC g_permuted(
make_transform_iterator(g_edges.first, perm),
make_transform_iterator(g_edges.second, perm),
num_vertices(g), num_edges(g));
PS:あなたは、グラフの順列のコピーを作成して暮らすことができる場合は、イテレータの範囲を使用して新しいグラフを作成することができます
コードを私の後ろにコピーしました.2つの小さなバグが修正されました。それでも、make_transform_iteratorは見つかりません。そこで私は '#include'をインクルードしました。しかし、今私は '' make_transform_iterator(.......)への呼び出しに対応する関数がありません。間違ったヘッダですか? –
Johannes
あなたは 'using namespace boost;'をやったことがありますか?そうでなければ、 'make_transform_iterator'への呼び出しを修飾する必要があります。 –
はい、私はそうしました。私はコード全体をアップロードすることができましたが、20行以上が必要です... – Johannes