Boost logo

Boost :

From: Petr Ovchenkov (night-crow_at_[hidden])
Date: 2003-09-05 03:46:37


Petr Ovchenkov wrote:

> Hi,
>
> I am try to walk through graph with edges that has properties defined as
> 'color' and 'weght' properties combination. But I don't uderstand how
> access 'color' property by correct way? Can anybody help to me?

I am found the solution (changes in code below):

...
  typedef property<edge_weight_t,int,Color> EdgeProperty;
...
  for ( tie(ei,eend) = out_edges(v,g); ei != eend; ++ei ) {
    cout << color[*ei] << ", " << weight[*ei] << " ";
  }
...

(types Weight typdef and color_weight_t not required)

By the way, this issue is explained in the documentation:
http://www.boost.org/libs/graph/doc/using_adjacency_list.html#sec:custom-edge-properties

 - Petr

>
> -----------------------------------------------------------------------
>
> #include <iostream>
> #include <boost/graph/adjacency_list.hpp>
>
> using namespace boost;
> using namespace std;
>
> typedef property<edge_color_t,int> Color;
> typedef property<edge_weight_t,int> Weight;
>
> // struct color_weight_t {
> // enum { num = 30000 };
> // typedef edge_property_tag kind;
> // };
>
> enum edge_cw_t { edge_cw };
>
> namespace boost {
>
> template <>
> struct property_kind<edge_cw_t>
> {
> typedef edge_property_tag type;
> };
> } // namespace boost
>
> int main( int, char * const * )
> {
> typedef property<edge_cw_t,Color,Weight> EdgeProperty;
> typedef adjacency_list<vecS, vecS, directedS, no_property, EdgeProperty
> >
> graph_t;
>
> enum {
> One,
> Two,
> NVertices
> };
>
> graph_t g( NVertices );
>
> add_edge( NotConnected, Connected, EdgeProperty(0,1), g );
> add_edge( Connected, NotConnected, EdgeProperty(0,1), g );
>
> cout << "Walk through graph\n";
>
> typedef graph_traits<graph_t>::vertex_descriptor vertex_t;
>
> vertex_t v = vertex( NotConnected, g );
>
> typedef graph_traits<graph_t>::out_edge_iterator out_edge_iterator_t;
> typedef property_map<graph_t,edge_color_t>::type edge_color_map_t;
> typedef property_map<graph_t,edge_weight_t>::type edge_weight_map_t;
>
> edge_weight_map_t weight = get( edge_weight, g );
> edge_color_map_t color = get( edge_color, g );
>
> out_edge_iterator_t ei;
> out_edge_iterator_t eend;
>
> for ( tie(ei,eend) = out_edges(v,g); ei != eend; ++ei ) {
> cout << /* color[*ei] */ get(edge_cw, g, *ei ).m_value << ", "
> // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> // How I can access color property with correct way?
> << weight[*ei] << " ";
> }
> cout << endl;
>
> return 0;
> }
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk