x
Yes
No
Do you want to visit DriveHQ English website?
首页
产品服务
价格
免费试用
下载客户端
关于我们
云文件服务
|
云备份服务
|
FTP服务
|
企业邮箱服务
|
网站托管
|
客户端软件
云文件服务
云备份服务
FTP服务
企业级邮箱服务
网站托管
客户端软件
leda_graph.hpp - Hosted on DriveHQ Cloud IT Platform
返回上层目录
上传
下载
共享
发布
新建文件夹
新建文件
复制
剪切
删除
粘贴
评论
升级服务
路径: \\game3dprogramming\materials\GameFactory\GameFactoryDemo\references\boost_1_35_0\boost\graph\leda_graph.hpp
旋转
特效
属性
历史版本
//======================================================================= // Copyright 1997, 1998, 1999, 2000 University of Notre Dame. // Copyright 2004 The Trustees of Indiana University. // Copyright 2007 University of Karlsruhe // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek, Douglas Gregor, // Jens Mueller // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) //======================================================================= #ifndef BOOST_GRAPH_LEDA_HPP #define BOOST_GRAPH_LEDA_HPP #include
#include
#include
#include
#include
#include
#include
// The functions and classes in this file allows the user to // treat a LEDA GRAPH object as a boost graph "as is". No // wrapper is needed for the GRAPH object. // Warning: this implementation relies on partial specialization // for the graph_traits class (so it won't compile with Visual C++) // Warning: this implementation is in alpha and has not been tested #if !defined BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION namespace boost { struct leda_graph_traversal_category : public virtual bidirectional_graph_tag, public virtual adjacency_graph_tag, public virtual vertex_list_graph_tag { }; template
struct graph_traits< leda::GRAPH
> { typedef leda::node vertex_descriptor; typedef leda::edge edge_descriptor; class adjacency_iterator : public iterator_facade
{ public: adjacency_iterator(leda::node node = 0, const leda::GRAPH
* g = 0) : base(node), g(g) {} private: leda::node dereference() const { return leda::target(base); } bool equal(const adjacency_iterator& other) const { return base == other.base; } void increment() { base = g->adj_succ(base); } void decrement() { base = g->adj_pred(base); } leda::edge base; const leda::GRAPH
* g; friend class iterator_core_access; }; class out_edge_iterator : public iterator_facade
{ public: out_edge_iterator(leda::node node = 0, const leda::GRAPH
* g = 0) : base(node), g(g) {} private: const leda::edge& dereference() const { return base; } bool equal(const out_edge_iterator& other) const { return base == other.base; } void increment() { base = g->adj_succ(base); } void decrement() { base = g->adj_pred(base); } leda::edge base; const leda::GRAPH
* g; friend class iterator_core_access; }; class in_edge_iterator : public iterator_facade
{ public: in_edge_iterator(leda::node node = 0, const leda::GRAPH
* g = 0) : base(node), g(g) {} private: const leda::edge& dereference() const { return base; } bool equal(const in_edge_iterator& other) const { return base == other.base; } void increment() { base = g->in_succ(base); } void decrement() { base = g->in_pred(base); } leda::edge base; const leda::GRAPH
* g; friend class iterator_core_access; }; class vertex_iterator : public iterator_facade
{ public: vertex_iterator(leda::node node = 0, const leda::GRAPH
* g = 0) : base(node), g(g) {} private: const leda::node& dereference() const { return base; } bool equal(const vertex_iterator& other) const { return base == other.base; } void increment() { base = g->succ_node(base); } void decrement() { base = g->pred_node(base); } leda::node base; const leda::GRAPH
* g; friend class iterator_core_access; }; class edge_iterator : public iterator_facade
{ public: edge_iterator(leda::edge edge = 0, const leda::GRAPH
* g = 0) : base(edge), g(g) {} private: const leda::edge& dereference() const { return base; } bool equal(const edge_iterator& other) const { return base == other.base; } void increment() { base = g->succ_edge(base); } void decrement() { base = g->pred_edge(base); } leda::node base; const leda::GRAPH
* g; friend class iterator_core_access; }; typedef directed_tag directed_category; typedef allow_parallel_edge_tag edge_parallel_category; // not sure here typedef leda_graph_traversal_category traversal_category; typedef int vertices_size_type; typedef int edges_size_type; typedef int degree_size_type; }; template<> struct graph_traits
{ typedef leda::node vertex_descriptor; typedef leda::edge edge_descriptor; class adjacency_iterator : public iterator_facade
{ public: adjacency_iterator(leda::edge edge = 0, const leda::graph* g = 0) : base(edge), g(g) {} private: leda::node dereference() const { return leda::target(base); } bool equal(const adjacency_iterator& other) const { return base == other.base; } void increment() { base = g->adj_succ(base); } void decrement() { base = g->adj_pred(base); } leda::edge base; const leda::graph* g; friend class iterator_core_access; }; class out_edge_iterator : public iterator_facade
{ public: out_edge_iterator(leda::edge edge = 0, const leda::graph* g = 0) : base(edge), g(g) {} private: const leda::edge& dereference() const { return base; } bool equal(const out_edge_iterator& other) const { return base == other.base; } void increment() { base = g->adj_succ(base); } void decrement() { base = g->adj_pred(base); } leda::edge base; const leda::graph* g; friend class iterator_core_access; }; class in_edge_iterator : public iterator_facade
{ public: in_edge_iterator(leda::edge edge = 0, const leda::graph* g = 0) : base(edge), g(g) {} private: const leda::edge& dereference() const { return base; } bool equal(const in_edge_iterator& other) const { return base == other.base; } void increment() { base = g->in_succ(base); } void decrement() { base = g->in_pred(base); } leda::edge base; const leda::graph* g; friend class iterator_core_access; }; class vertex_iterator : public iterator_facade
{ public: vertex_iterator(leda::node node = 0, const leda::graph* g = 0) : base(node), g(g) {} private: const leda::node& dereference() const { return base; } bool equal(const vertex_iterator& other) const { return base == other.base; } void increment() { base = g->succ_node(base); } void decrement() { base = g->pred_node(base); } leda::node base; const leda::graph* g; friend class iterator_core_access; }; class edge_iterator : public iterator_facade
{ public: edge_iterator(leda::edge edge = 0, const leda::graph* g = 0) : base(edge), g(g) {} private: const leda::edge& dereference() const { return base; } bool equal(const edge_iterator& other) const { return base == other.base; } void increment() { base = g->succ_edge(base); } void decrement() { base = g->pred_edge(base); } leda::edge base; const leda::graph* g; friend class iterator_core_access; }; typedef directed_tag directed_category; typedef allow_parallel_edge_tag edge_parallel_category; // not sure here typedef leda_graph_traversal_category traversal_category; typedef int vertices_size_type; typedef int edges_size_type; typedef int degree_size_type; }; } // namespace boost #endif namespace boost { //=========================================================================== // functions for GRAPH
template
typename graph_traits< leda::GRAPH
>::vertex_descriptor source(typename graph_traits< leda::GRAPH
>::edge_descriptor e, const leda::GRAPH
& g) { return source(e); } template
typename graph_traits< leda::GRAPH
>::vertex_descriptor target(typename graph_traits< leda::GRAPH
>::edge_descriptor e, const leda::GRAPH
& g) { return target(e); } template
inline std::pair< typename graph_traits< leda::GRAPH
>::vertex_iterator, typename graph_traits< leda::GRAPH
>::vertex_iterator > vertices(const leda::GRAPH
& g) { typedef typename graph_traits< leda::GRAPH
>::vertex_iterator Iter; return std::make_pair( Iter(g.first_node(),&g), Iter(0,&g) ); } template
inline std::pair< typename graph_traits< leda::GRAPH
>::edge_iterator, typename graph_traits< leda::GRAPH
>::edge_iterator > edges(const leda::GRAPH
& g) { typedef typename graph_traits< leda::GRAPH
>::edge_iterator Iter; return std::make_pair( Iter(g.first_edge(),&g), Iter(0,&g) ); } template
inline std::pair< typename graph_traits< leda::GRAPH
>::out_edge_iterator, typename graph_traits< leda::GRAPH
>::out_edge_iterator > out_edges( typename graph_traits< leda::GRAPH
>::vertex_descriptor u, const leda::GRAPH
& g) { typedef typename graph_traits< leda::GRAPH
> ::out_edge_iterator Iter; return std::make_pair( Iter(g.first_adj_edge(u,0),&g), Iter(0,&g) ); } template
inline std::pair< typename graph_traits< leda::GRAPH
>::in_edge_iterator, typename graph_traits< leda::GRAPH
>::in_edge_iterator > in_edges( typename graph_traits< leda::GRAPH
>::vertex_descriptor u, const leda::GRAPH
& g) { typedef typename graph_traits< leda::GRAPH
> ::in_edge_iterator Iter; return std::make_pair( Iter(g.first_adj_edge(u,1),&g), Iter(0,&g) ); } template
inline std::pair< typename graph_traits< leda::GRAPH
>::adjacency_iterator, typename graph_traits< leda::GRAPH
>::adjacency_iterator > adjacent_vertices( typename graph_traits< leda::GRAPH
>::vertex_descriptor u, const leda::GRAPH
& g) { typedef typename graph_traits< leda::GRAPH
> ::adjacency_iterator Iter; return std::make_pair( Iter(g.first_adj_edge(u,0),&g), Iter(0,&g) ); } template
typename graph_traits< leda::GRAPH
>::vertices_size_type num_vertices(const leda::GRAPH
& g) { return g.number_of_nodes(); } template
typename graph_traits< leda::GRAPH
>::edges_size_type num_edges(const leda::GRAPH
& g) { return g.number_of_edges(); } template
typename graph_traits< leda::GRAPH
>::degree_size_type out_degree( typename graph_traits< leda::GRAPH
>::vertex_descriptor u, const leda::GRAPH
& g) { return g.outdeg(u); } template
typename graph_traits< leda::GRAPH
>::degree_size_type in_degree( typename graph_traits< leda::GRAPH
>::vertex_descriptor u, const leda::GRAPH
& g) { return g.indeg(u); } template
typename graph_traits< leda::GRAPH
>::degree_size_type degree( typename graph_traits< leda::GRAPH
>::vertex_descriptor u, const leda::GRAPH
& g) { return g.outdeg(u) + g.indeg(u); } template
typename graph_traits< leda::GRAPH
>::vertex_descriptor add_vertex(leda::GRAPH
& g) { return g.new_node(); } template
typename graph_traits< leda::GRAPH
>::vertex_descriptor add_vertex(const vtype& vp, leda::GRAPH
& g) { return g.new_node(vp); } template
void clear_vertex( typename graph_traits< leda::GRAPH
>::vertex_descriptor u, leda::GRAPH
& g) { typename graph_traits< leda::GRAPH
>::out_edge_iterator ei, ei_end; for (tie(ei, ei_end)=out_edges(u,g); ei!=ei_end; ei++) remove_edge(*ei); typename graph_traits< leda::GRAPH
>::in_edge_iterator iei, iei_end; for (tie(iei, iei_end)=in_edges(u,g); iei!=iei_end; iei++) remove_edge(*iei); } template
void remove_vertex( typename graph_traits< leda::GRAPH
>::vertex_descriptor u, leda::GRAPH
& g) { g.del_node(u); } template
std::pair< typename graph_traits< leda::GRAPH
>::edge_descriptor, bool> add_edge( typename graph_traits< leda::GRAPH
>::vertex_descriptor u, typename graph_traits< leda::GRAPH
>::vertex_descriptor v, leda::GRAPH
& g) { return std::make_pair(g.new_edge(u, v), true); } template
std::pair< typename graph_traits< leda::GRAPH
>::edge_descriptor, bool> add_edge( typename graph_traits< leda::GRAPH
>::vertex_descriptor u, typename graph_traits< leda::GRAPH
>::vertex_descriptor v, const etype& et, leda::GRAPH
& g) { return std::make_pair(g.new_edge(u, v, et), true); } template
void remove_edge( typename graph_traits< leda::GRAPH
>::vertex_descriptor u, typename graph_traits< leda::GRAPH
>::vertex_descriptor v, leda::GRAPH
& g) { typename graph_traits< leda::GRAPH
>::out_edge_iterator i,iend; for (boost::tie(i,iend) = out_edges(u,g); i != iend; ++i) if (target(*i,g) == v) g.del_edge(*i); } template
void remove_edge( typename graph_traits< leda::GRAPH
>::edge_descriptor e, leda::GRAPH
& g) { g.del_edge(e); } //=========================================================================== // functions for graph (non-templated version) graph_traits
::vertex_descriptor source(graph_traits
::edge_descriptor e, const leda::graph& g) { return source(e); } graph_traits
::vertex_descriptor target(graph_traits
::edge_descriptor e, const leda::graph& g) { return target(e); } inline std::pair< graph_traits
::vertex_iterator, graph_traits
::vertex_iterator > vertices(const leda::graph& g) { typedef graph_traits
::vertex_iterator Iter; return std::make_pair( Iter(g.first_node(),&g), Iter(0,&g) ); } inline std::pair< graph_traits
::edge_iterator, graph_traits
::edge_iterator > edges(const leda::graph& g) { typedef graph_traits
::edge_iterator Iter; return std::make_pair( Iter(g.first_edge(),&g), Iter(0,&g) ); } inline std::pair< graph_traits
::out_edge_iterator, graph_traits
::out_edge_iterator > out_edges( graph_traits
::vertex_descriptor u, const leda::graph& g) { typedef graph_traits
::out_edge_iterator Iter; return std::make_pair( Iter(g.first_adj_edge(u),&g), Iter(0,&g) ); } inline std::pair< graph_traits
::in_edge_iterator, graph_traits
::in_edge_iterator > in_edges( graph_traits
::vertex_descriptor u, const leda::graph& g) { typedef graph_traits
::in_edge_iterator Iter; return std::make_pair( Iter(g.first_in_edge(u),&g), Iter(0,&g) ); } inline std::pair< graph_traits
::adjacency_iterator, graph_traits
::adjacency_iterator > adjacent_vertices( graph_traits
::vertex_descriptor u, const leda::graph& g) { typedef graph_traits
::adjacency_iterator Iter; return std::make_pair( Iter(g.first_adj_edge(u),&g), Iter(0,&g) ); } graph_traits
::vertices_size_type num_vertices(const leda::graph& g) { return g.number_of_nodes(); } graph_traits
::edges_size_type num_edges(const leda::graph& g) { return g.number_of_edges(); } graph_traits
::degree_size_type out_degree( graph_traits
::vertex_descriptor u, const leda::graph& g) { return g.outdeg(u); } graph_traits
::degree_size_type in_degree( graph_traits
::vertex_descriptor u, const leda::graph& g) { return g.indeg(u); } graph_traits
::degree_size_type degree( graph_traits
::vertex_descriptor u, const leda::graph& g) { return g.outdeg(u) + g.indeg(u); } graph_traits
::vertex_descriptor add_vertex(leda::graph& g) { return g.new_node(); } void remove_edge( graph_traits
::vertex_descriptor u, graph_traits
::vertex_descriptor v, leda::graph& g) { graph_traits
::out_edge_iterator i,iend; for (boost::tie(i,iend) = out_edges(u,g); i != iend; ++i) if (target(*i,g) == v) g.del_edge(*i); } void remove_edge( graph_traits
::edge_descriptor e, leda::graph& g) { g.del_edge(e); } void clear_vertex( graph_traits
::vertex_descriptor u, leda::graph& g) { graph_traits
::out_edge_iterator ei, ei_end; for (tie(ei, ei_end)=out_edges(u,g); ei!=ei_end; ei++) remove_edge(*ei, g); graph_traits
::in_edge_iterator iei, iei_end; for (tie(iei, iei_end)=in_edges(u,g); iei!=iei_end; iei++) remove_edge(*iei, g); } void remove_vertex( graph_traits
::vertex_descriptor u, leda::graph& g) { g.del_node(u); } std::pair< graph_traits
::edge_descriptor, bool> add_edge( graph_traits
::vertex_descriptor u, graph_traits
::vertex_descriptor v, leda::graph& g) { return std::make_pair(g.new_edge(u, v), true); } //=========================================================================== // property maps for GRAPH
class leda_graph_id_map : public put_get_helper
{ public: typedef readable_property_map_tag category; typedef int value_type; typedef int reference; typedef leda::node key_type; leda_graph_id_map() { } template
long operator[](T x) const { return x->id(); } }; template
inline leda_graph_id_map get(vertex_index_t, const leda::GRAPH
& g) { return leda_graph_id_map(); } template
inline leda_graph_id_map get(edge_index_t, const leda::GRAPH
& g) { return leda_graph_id_map(); } template
struct leda_property_map { }; template <> struct leda_property_map
{ template
struct bind_ { typedef leda_graph_id_map type; typedef leda_graph_id_map const_type; }; }; template <> struct leda_property_map
{ template
struct bind_ { typedef leda_graph_id_map type; typedef leda_graph_id_map const_type; }; }; template
class leda_graph_data_map : public put_get_helper
> { public: typedef Data value_type; typedef DataRef reference; typedef void key_type; typedef lvalue_property_map_tag category; leda_graph_data_map(GraphPtr g) : m_g(g) { } template
DataRef operator[](NodeOrEdge x) const { return (*m_g)[x]; } protected: GraphPtr m_g; }; template <> struct leda_property_map
{ template
struct bind_ { typedef leda_graph_data_map
*> type; typedef leda_graph_data_map
*> const_type; }; }; template
inline typename property_map< leda::GRAPH
, vertex_all_t>::type get(vertex_all_t, leda::GRAPH
& g) { typedef typename property_map< leda::GRAPH
, vertex_all_t>::type pmap_type; return pmap_type(&g); } template
inline typename property_map< leda::GRAPH
, vertex_all_t>::const_type get(vertex_all_t, const leda::GRAPH
& g) { typedef typename property_map< leda::GRAPH
, vertex_all_t>::const_type pmap_type; return pmap_type(&g); } template <> struct leda_property_map
{ template
struct bind_ { typedef leda_graph_data_map
*> type; typedef leda_graph_data_map
*> const_type; }; }; template
inline typename property_map< leda::GRAPH
, edge_all_t>::type get(edge_all_t, leda::GRAPH
& g) { typedef typename property_map< leda::GRAPH
, edge_all_t>::type pmap_type; return pmap_type(&g); } template
inline typename property_map< leda::GRAPH
, edge_all_t>::const_type get(edge_all_t, const leda::GRAPH
& g) { typedef typename property_map< leda::GRAPH
, edge_all_t>::const_type pmap_type; return pmap_type(&g); } // property map interface to the LEDA node_array class template
class leda_node_property_map : public put_get_helper
> { public: typedef E value_type; typedef ERef reference; typedef leda::node key_type; typedef lvalue_property_map_tag category; leda_node_property_map(NodeMapPtr a) : m_array(a) { } ERef operator[](leda::node n) const { return (*m_array)[n]; } protected: NodeMapPtr m_array; }; template
leda_node_property_map
*> make_leda_node_property_map(const leda::node_array
& a) { typedef leda_node_property_map
*> pmap_type; return pmap_type(&a); } template
leda_node_property_map
*> make_leda_node_property_map(leda::node_array
& a) { typedef leda_node_property_map
*> pmap_type; return pmap_type(&a); } template
leda_node_property_map
*> make_leda_node_property_map(const leda::node_map
& a) { typedef leda_node_property_map
*> pmap_type; return pmap_type(&a); } template
leda_node_property_map
*> make_leda_node_property_map(leda::node_map
& a) { typedef leda_node_property_map
*> pmap_type; return pmap_type(&a); } // g++ 'enumeral_type' in template unification not implemented workaround template
struct property_map
, Tag> { typedef typename leda_property_map
::template bind_
map_gen; typedef typename map_gen::type type; typedef typename map_gen::const_type const_type; }; template
inline typename boost::property_traits< typename boost::property_map
,PropertyTag>::const_type ::value_type get(PropertyTag p, const leda::GRAPH
& g, const Key& key) { return get(get(p, g), key); } template
inline void put(PropertyTag p, leda::GRAPH
& g, const Key& key, const Value& value) { typedef typename property_map
, PropertyTag>::type Map; Map pmap = get(p, g); put(pmap, key, value); } // property map interface to the LEDA edge_array class template
class leda_edge_property_map : public put_get_helper
> { public: typedef E value_type; typedef ERef reference; typedef leda::edge key_type; typedef lvalue_property_map_tag category; leda_edge_property_map(EdgeMapPtr a) : m_array(a) { } ERef operator[](leda::edge n) const { return (*m_array)[n]; } protected: EdgeMapPtr m_array; }; template
leda_edge_property_map
*> make_leda_node_property_map(const leda::node_array
& a) { typedef leda_edge_property_map
*> pmap_type; return pmap_type(&a); } template
leda_edge_property_map
*> make_leda_edge_property_map(leda::edge_array
& a) { typedef leda_edge_property_map
*> pmap_type; return pmap_type(&a); } template
leda_edge_property_map
*> make_leda_edge_property_map(const leda::edge_map
& a) { typedef leda_edge_property_map
*> pmap_type; return pmap_type(&a); } template
leda_edge_property_map
*> make_leda_edge_property_map(leda::edge_map
& a) { typedef leda_edge_property_map
*> pmap_type; return pmap_type(&a); } } // namespace boost #endif // BOOST_GRAPH_LEDA_HPP
leda_graph.hpp
网页地址
文件地址
上一页
55/95
下一页
下载
( 29 KB )
Comments
Total ratings:
0
Average rating:
无评论
of 10
Would you like to comment?
Join now
, or
Logon
if you are already a member.