MutableGraph
ブースト グラフ ライブラリを使用して、グリッドとしての生活を開始するために a を初期化しようとしています。エッジは後で追加および削除されるためadjacency_list<vecS,listS,undirectedS>
、正しい選択だと思います。
BGL について読んだところ、これらのエッジで BGL を初期化する賢明な方法は、すべての初期エッジを無料で作成できるa からコピーすることboost::grid_graph
を利用
することであることがわかりました。のモデルから のモデルへのコピーは、まさに私が持っているものです。boost::copy_graph
boost::grid_graph
copy_graph
VertexListGraph
MutableGraph
私は最初、 の 2 引数バージョンを使用してみcopy_graph
ましたが、残りのデフォルトで何か賢明なことが起こるという漠然とした希望を持っていました。そうではないことが判明しましたgrid_graph
(理由がよくわかりませんでした) には、エッジまたは頂点のいずれかで s を使用する機能がないようPropertyMap
です。プロパティ。vertex_copy
edge_copy
引数が 2 つのバージョンは明らかに適切ではないように思われたので、次に進み、頂点とエッジをコピーするための独自の 2 項演算子を実装しようとしました。'no-op' コピーを使用しても、期待どおりに動作しません (つまり、コンパイルされません)。
問題を説明する最小限の実例をまとめました。
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/grid_graph.hpp>
#include <boost/graph/copy.hpp>
struct Position {
int x, y;
};
struct VertexProperties {
Position pos;
};
typedef boost::adjacency_list<boost::vecS, boost::listS, boost::undirectedS,
VertexProperties> Graph;
struct MyCopy {
template <typename S, typename D>
void operator()(const S& /*src*/, D& /*dest*/) {
// Nothing for now, deduced types to try and just make it compile
// TODO: set values for pos to reflect position on grid.
}
};
int main() {
boost::array<std::size_t, 2> lengths = { { 3, 3 } };
boost::grid_graph<2> grid(lengths);
Graph graph;
MyCopy copier;
// Using 3-Arg version of copy_graph so we can specify a custom way of copying to create the properties
boost::copy_graph(grid,graph,boost::bgl_named_params<MyCopy,boost::vertex_copy_t,
boost::bgl_named_params<MyCopy,boost::edge_copy_t> >(copier));
}
この例はコンパイルされません:
g++ -Wextra -Wall -O2 -g -o copytest.o -c copytest.cc
In file included from /usr/include/boost/graph/grid_graph.hpp:24:0,
from copytest.cc:2:
/usr/include/boost/iterator/transform_iterator.hpp: In constructor ‘boost::transform_iterator<UnaryFunction, Iterator, Reference, Value>::transform_iterator() [with UnaryFunc = boost::detail::grid_graph_vertex_at<boost::grid_graph<2u> >, Iterator = boost::counting_iterator<unsigned int, boost::use_default, boost::use_default>, Reference = boost::use_default, Value = boost::use_default]’:
/usr/include/boost/graph/copy.hpp:115:55: instantiated from ‘static void boost::detail::copy_graph_impl<0>::apply(const Graph&, MutableGraph&, CopyVertex, CopyEdge, Orig2CopyVertexIndexMap, IndexMap) [with Graph = boost::grid_graph<2u>, MutableGraph = boost::adjacency_list<boost::vecS, boost::listS, boost::undirectedS, VertexProperties>, CopyVertex = MyCopy, CopyEdge = MyCopy, IndexMap = boost::grid_graph_index_map<boost::grid_graph<2u>, boost::array<unsigned int, 2u>, unsigned int>, Orig2CopyVertexIndexMap = boost::iterator_property_map<__gnu_cxx::__normal_iterator<void**, std::vector<void*, std::allocator<void*> > >, boost::grid_graph_index_map<boost::grid_graph<2u>, boost::array<unsigned int, 2u>, unsigned int>, void*, void*&>]’
/usr/include/boost/graph/copy.hpp:327:5: instantiated from ‘void boost::copy_graph(const VertexListGraph&, MutableGraph&, const boost::bgl_named_params<P, T, R>&) [with VertexListGraph = boost::grid_graph<2u>, MutableGraph = boost::adjacency_list<boost::vecS, boost::listS, boost::undirectedS, VertexProperties>, P = MyCopy, T = boost::vertex_copy_t, R = boost::bgl_named_params<MyCopy, boost::edge_copy_t>]’
/mnt/home/ajw/code/hpcwales/copytest.cc:31:66: instantiated from here
/usr/include/boost/iterator/transform_iterator.hpp:100:26: error: no matching function for call to ‘boost::detail::grid_graph_vertex_at<boost::grid_graph<2u> >::grid_graph_vertex_at()’
/usr/include/boost/graph/grid_graph.hpp:104:7: note: candidates are: boost::detail::grid_graph_vertex_at<Graph>::grid_graph_vertex_at(const Graph*) [with Graph = boost::grid_graph<2u>]
/usr/include/boost/graph/grid_graph.hpp:100:33: note: boost::detail::grid_graph_vertex_at<boost::grid_graph<2u> >::grid_graph_vertex_at(const boost::detail::grid_graph_vertex_at<boost::grid_graph<2u> >&)
grid_graph
そのエラーの私の分析は、私にはひどく明確ではない何らかの理由で、デフォルトで構築できないの内部の一部をデフォルトで構築しようとしているように見えるということです。(clang は、ここで g++ から見えないことは何も教えてくれません)。
質問:
- これは、可変グラフを初期化して通常のグリッドとして開始する正しい方法ですか? 私は当初、自分で関数を書くよりもはるかに簡単だと思っていましたが、今ではよくわかりません!
orig_to_copy
ここでand/orのデフォルト値がvertex_index
適切でないのはなぜですか? この2つがエラーの原因だと思います。(もしあれば、実際に問題を引き起こしているのはどれですか?現在のエラーの根本的な原因が何であるかを解読することはできません)。- これを修正する「正しい」方法は何ですか?