#include #include #include #include #include #include #include #include struct vp { int m_ind; std::string m_n; }; struct ep { int m_ind; double m_w; bool m_exist; ep() : m_ind(0), m_w(0), m_exist(true) {} template double weight(Edge e) const { if (m_exist) { return m_w; } return (std::numeric_limits::max)(); } }; using namespace boost; template struct bundle_property_map1 : put_get_helper > { typedef Descriptor key_type; typedef typename remove_const::type value_type; typedef T& reference; typedef lvalue_property_map_tag category; typedef T (Bundle::*pm_t)(key_type) const; bundle_property_map1() { } bundle_property_map1(TG* g_, pm_t pm_) : g(g_), pm(pm_) {} reference operator[](key_type k) const { const double& r = ((*g)[k].*pm)(k); return const_cast(r); } private: TG* g; pm_t pm; }; typedef adjacency_list graph_t; typedef graph_traits::edge_descriptor edge_t; typedef bundle_property_map1 ewm_t; //dynamic edge weight map int main() { graph_t g; boost::mt19937 rng; generate_random_graph(g, 20, 100, rng, false); graph_traits::edge_iterator ei, ee; int i = 0; for (tie(ei, ee) = edges(g); ei != ee; ++ei) { get(&ep::m_w, g)[*ei] = rand() % 100; get(&ep::m_ind, g)[*ei] = i++; } print_edges2(g, get(vertex_index, g), get(&ep::m_ind, g)); print_edges2(g, get(vertex_index, g), get(&ep::m_w, g)); ewm_t ewm(&g, &ep::weight); print_edges2(g, get(vertex_index, g), ewm); ///Now let us "remove" the half of edges for (tie(ei, ee) = edges(g); ei != ee; ++ei) { if (rand() % 100 > 50) get(&ep::m_exist, g)[*ei] = 0; } print_edges2(g, get(vertex_index, g), ewm); // double tmp = ewm[*edges(g).first]; return EXIT_SUCCESS; }