Boost logo

Boost :

From: Petr Ovchenkov (night-crow_at_[hidden])
Date: 2003-09-04 11:38:58


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?

Thanks in advance,

   - 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