filtered_graph<Graph, EdgePredicate, VertexPredicate>
filtered_graph クラス・テンプレートはグラフの濾過された眺めを 作成するアダプタである。述語関数オブジェクトは元のグラフのどの辺と頂点が 濾過グラフ (filtered graph) 中に現れるかを決定する。辺述語が辺のために true を 返すならば、それは濾過グラフ中に現れ、もし述語が false を 返すならば、辺は濾過グラフ中に現れない。頂点も同様である。 filtered_graph クラスは元のグラフのコピーを作成しないが、元のグラフ へのリファレンスを使う。元のグラフの有効期間は濾過グラフの使用後まで 引き延ばさなければならない。濾過グラフは元のグラフの構造を変更しない。 もっとも元のグラフの頂点プロパティと辺プロパティは濾過グラフのプロパティ・ マップを通して変更できるが。濾過グラフの頂点記述子と辺記述子は元のグラフの 頂点記述子及び辺記述子と同じで、かつ交換可能である。
この例中で辺の重みに基づいてグラフの辺を濾過してみよう。正の辺の重みを持つ 全ての辺を保存するつもりである。最初に、述語関数オブジェクトを作成する。
template <typename EdgeWeightMap> struct positive_edge_weight { positive_edge_weight() { } positive_edge_weight(EdgeWeightMap weight) : m_weight(weight) { } template <typename Edge> bool operator()(const Edge& e) const { return 0 < get(m_weight, e); } EdgeWeightMap m_weight; };さてグラフを作成し、濾過グラフをプリント・アウトする。
int main() { using namespace boost; typedef adjacency_list<vecS, vecS, directedS, no_property, property<edge_weight_t, int> > Graph; typedef property_map<Graph, edge_weight_t>::type EdgeWeightMap; enum { A, B, C, D, E, N }; const char* name = "ABCDE"; Graph g(N); add_edge(A, B, 2, g); add_edge(A, C, 0, g); add_edge(C, D, 1, g); add_edge(C, E, 0, g); add_edge(D, B, 3, g); add_edge(E, C, 0, g); positive_edge_weight<EdgeWeightMap> filter(get(edge_weight, g)); filtered_graph<Graph, positive_edge_weight<EdgeWeightMap> > fg(g, filter); std::cout << "filtered edge set: "; print_edges(fg, name); std::cout << "filtered out-edges:" << std::endl; print_graph(fg, name); return 0; }出力は:
filtered edge set: (A,B) (C,D) (D,B) filtered out-edges: A --> B B --> C --> D D --> B E -->
パラメータ | 説明 | デフォルト |
---|---|---|
Graph | 基礎にあるグラフの型。 | |
EdgePredicate | 元のグラフからどの辺が濾過グラフ中に現れるかを選ぶ関数オブジェクト。 関数オブジェクトは Predicate を モデルとしなければならない。関数オブジェクトのための引数型はグラフの 辺記述子でなければならない。さらに、述語は Default Constructible [1] でなければならない。 | |
VertexPredicate | 元のグラフからどの頂点が濾過グラフ中に現れるからを選ぶ関数オブジェクト。 関数オブジェクトは Predicate を モデルとしなければならない。関数オブジェクトのための引数型はグラフの 頂点記述子でなければならない。さらに、述語は Default Constructible [1] でなければならない。 | keep_all |
これは基礎にあるグラフの型によって決まる。もし基礎にある Graph の型 が VertexAndEdgeListGraph と PropertyGraph をモデルとするなら、濾過 グラフもまたそうである。もし基礎にある Graph がこれらよりも小数で 小さなコンセプトをモデルとするなら、濾過グラフも同様にそうである。
boost/graph/filtered_graph.hpp
filtered_graph(Graph& g, EdgePredicate ep, VertexPredicate vp)グラフ g と辺フィルタ ep と頂点フィルタ vp に基づく 濾過グラフを作成する。
filtered_graph(Graph& g, EdgePredicate ep)グラフ g と辺フィルタ ep に基づく濾過グラフを作成する。 元のグラフからの全ての頂点は保持される。
filtered_graph& operator=(const filtered_graph& x)これは x と同じ基礎にあるグラフのための濾過グラフを作成する。 別の言葉では、これは浅いコピーである。
std::pair<vertex_iterator, vertex_iterator> vertices(const filtered_graph& g)グラフ g の頂点集合へのアクセスを提供するイテレータ範囲を返す。
std::pair<edge_iterator, edge_iterator> edges(const filtered_graph& g)グラフ g の辺集合へのアクセスを提供するイテレータ範囲を返す。
std::pair<adjacency_iterator, adjacency_iterator> adjacent_vertices(vertex_descriptor u, const filtered_graph& g)グラフ g 中の頂点 u に隣接する頂点へのアクセスを提供する イテレータ範囲を返す。
std::pair<out_edge_iterator, out_edge_iterator> out_edges(vertex_descriptor u, const filtered_graph& g)グラフ g 中の頂点 u の出辺へのアクセスを提供する イテレータ範囲を返す。もしグラフが無向グラフなら、このイテレータ範囲は 頂点 u の全ての接続辺へのアクセスを提供する。有向グラフと無向グラフ の両方のために、出辺 e にとって、v が u に 隣接する頂点の場合 source(e, g) == u かつ target(e, g) == v である。
std::pair<in_edge_iterator, in_edge_iterator> in_edges(vertex_descriptor v, const filtered_graph& g)グラフ g 中の頂点 v の入辺へのアクセスを提供する イテレータ範囲を返す。入辺 e にとって、 グラフが有向グラフであろうと無向グラフであろうと v に隣接する同じ頂点 u について target(e, g) == v かつ source(e, g) == u である。
vertex_descriptor source(edge_descriptor e, const filtered_graph& g)辺 e の始点を返す。
vertex_descriptor target(edge_descriptor e, const filtered_graph& g)辺 e の終点を返す。
degree_size_type out_degree(vertex_descriptor u, const filtered_graph& g)頂点 u を出て行く辺数を返す。
degree_size_type in_degree(vertex_descriptor u, const filtered_graph& g)頂点 u に入ってくる辺数を返す。
vertices_size_type num_vertices(const filtered_graph& g)基礎にあるグラフ中の頂点数を返す [2]。
edges_size_type num_edges(const filtered_graph& g)グラフ g 中の辺数を返す。
std::pair<edge_descriptor, bool> edge(vertex_descriptor u, vertex_descriptor v, const filtered_graph& g)グラフ g 中の頂点 u から頂点 v へと接続する 辺を返す。
template <typename G, typename EP, typename VP> std::pair<out_edge_iterator, out_edge_iterator> edge_range(vertex_descriptor u, vertex_descriptor v, const filtered_graph& g)辺 u から辺 v への全ての多重辺のための範囲を与える 出辺イテレータのペアを返す。この関数は基礎にあるグラフが edge_range をサポートする場合にのみ動作し、それが出辺を終点に従って並べ替え、かつ 多重辺を許可している事を必要とする。OutEdgeList=multisetS である adjacency_list クラスがそのようなグラフの例である。
template <class PropertyTag> property_map<filtered_graph, PropertyTag>::type get(PropertyTag, filtered_graph& g) template <class PropertyTag> property_map<filtered_graph, Tag>::const_type get(PropertyTag, const filtered_graph& g)PropertyTag によって指定される頂点プロパティのための プロパティ・マップ・オブジェクトを返す。PropertyTag は グラフの VertexProperty テンプレート引数中で指定されるプロパティの 一つに一致しなければならない。
template <class PropertyTag, class X> typename property_traits<property_map<filtered_graph, PropertyTag>::const_type>::value_type get(PropertyTag, const filtered_graph& g, X x)これは x のためのプロパティ値を返し、ここで x は頂点 記述子または辺記述子のどちらか一方である。
template <class PropertyTag, class X, class Value> void put(PropertyTag, const filtered_graph& g, X x, const Value& value)これは x のためのプロパティ値を value にする。x は 頂点記述子または辺記述子のどちらか一方である。Value は typename property_traits<property_map<filtered_graph, PropertyTag>::type>::value_type に変更可能でなければならない。
[1] EdgePredicate と VertexPredicate 型の中で Default Constructible を必要とする理由は、これらの述語はフィルタ・ イテレータ・アダプタ中で値によって (性能の理由のために) 格納され、 イテレータは C++ 標準によってデフォルト・コンストラクタを持っていること (Default Constructible) が要求されるからである。
[2]
フィルタが適用された後に残存している頂点の数を返すことはより適切であろうが、
これは二つの問題を持つ。一番目は計算するのに長い時間がかかるだろうこと、
二番目に基礎にある頂点の添え字マッピングとまずく相互作用するだろうことで
ある。添え字マッピングは多くのアルゴリズム中で仮定されている範囲
[0,num_vertices(g)) にはもはや整列しないだろう。
アルゴリズムからその仮定を除去するような解決に取り組んでいる。
Copyright © 2000-2001 |
Jeremy Siek,
Indiana University (jsiek@osl.iu.edu) Lie-Quan Lee, Indiana University (llee@cs.indiana.edu) Andrew Lumsdaine, Indiana University (lums@osl.iu.edu) |
Japanese Translation Copyright © 2003 Takashi Itou
オリジナルの、及びこの著作権表示が全ての複製の中に現れる限り、この文書の複製、利用、変更、販売そして配布を認める。このドキュメントは「あるがまま」に提供されており、いかなる明示的、暗黙的保証も行わない。また、いかなる目的に対しても、その利用が適していることを関知しない。
このドキュメントの対象: Boost Version 1.29.0
最新版ドキュメント (英語)