Boost logo

Boost Users :

From: TC MA (maottawa3_at_[hidden])
Date: 2004-11-24 17:12:51


Thanks for your help.
Now I try to add Vertex and Edge data with bundled
properties.
Source code is:
#include <boost/config.hpp>
#include <iostream>
#include <algorithm>
#include <boost/graph/adjacency_list.hpp>
#include <boost/property_map.hpp>

using namespace std;
using namespace boost;

struct VertexData {
  int x;
  int y;
};

struct EdgeData {
  int weight;
};

template <class EdgeIter, class Graph>
void who_owes_who(EdgeIter first, EdgeIter last, const
Graph& G)
{
  // Access the propety acessor type for this graph
  while (first != last) {
    // fail to compile here!!!
    cout << G[source(*first, G)].x << "," <<
G[source(*first, G)].y << " joins " <<
G[target(*first, G)].x << "," << G[target(*first,
G)].y << " weight " << G[edge(*first)].weight << endl;
    ++first;
  }
}

int
main()
{
  // Create the graph, and specify that we will use
store the data.
  typedef adjacency_list<vecS, vecS, directedS,
VertexData, EdgeData> MyGraphType;
  
  typedef pair<int, int> Pair; // from <utility>
  Pair edge_array[11] = { Pair(0,1), Pair(0,2),
Pair(0,3), Pair(0,4),
                          Pair(2,0), Pair(3,0),
Pair(2,4), Pair(3,1),
                          Pair(3,4), Pair(4,0),
Pair(4,1) };
  
  MyGraphType G(5);
  for (int i=0; i<11; ++i)
    add_edge(edge_array[i].first,
edge_array[i].second, G);

  G[0].x = 0;
  G[0].y = 0;
  G[1].x = 1;
  G[1].y = 1;
  G[2].x = 2;
  G[2].y = 2;
  G[3].x = 3;
  G[3].y = 3;
  G[4].x = 4;
  G[4].y = 4;
  
  // store weights in edges
  graph_traits <MyGraphType>::edge_iterator ei, eend;
  int i = 0;
  for (tie(ei, eend) = edges(G); ei != eend; ++ei) {
    G[*ei].weight = i++;
    cout << "G[e] weight " << G[*ei].weight << endl;
  }

  who_owes_who(edges(G).first, edges(G).second, G);

  cout << endl;

  return 0;
}

Compile error is:
gcc-C++-action
/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.test/gcc/debug/inlining-on/interior_property_map.o
/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp:
In function `void who_owes_who(EdgeIter, EdgeIter,
const Graph&) [with EdgeIter =
boost::detail::adj_list_edge_iterator<boost::counting_iterator<size_t,
boost::use_default, boost::use_default>,
boost::detail::out_edge_iter<__gnu_cxx::__normal_iterator<boost::detail::sep_<size_t,
boost::property<boost::edge_bundle_t, EdgeData,
boost::no_property> >*,
std::vector<boost::detail::sep_<size_t,
boost::property<boost::edge_bundle_t, EdgeData,
boost::no_property> >,
std::allocator<boost::detail::sep_<size_t,
boost::property<boost::edge_bundle_t, EdgeData,
boost::no_property> > > > >, size_t,
boost::detail::edge_desc_impl<boost::directed_tag,
size_t>, ptrdiff_t>,
boost::adjacency_list<boost::vecS, boost::vecS,
boost::directedS, VertexData, EdgeData,
boost::no_property, boost::listS> >, Graph =
main()::MyGraphType]':
/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp:113:
  instantiated from here
/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp:64:
error: no matching function for call to
`edge(boost::detail::edge_desc_impl<boost::directed_tag,
size_t>)'

    set -e
    "g++" -c -Wall -ftemplate-depth-255 -g -O0
-Wno-inline
-I"../../../bin/boost/libs/graph/example" -I
"/home/tcma/cpp/boost_1_32_0" -o
"/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.test/gcc/debug/inlining-on/interior_property_map.o"

"/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp"
    "/usr/bin/objcopy" --set-section-flags
.debug_str=contents,debug
"/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.test/gcc/debug/inlining-on/interior_property_map.o"
...

> On Nov 24, 2004, at 11:21 AM, TC MA wrote:
>
> Still has a compile problem.
> interior_property_map.cpp is now:
>
> struct vertexStruct {
> string name;
> };
>
> template <class EdgeIter, class Graph>
> void who_owes_who(EdgeIter first, EdgeIter last,
const
> Graph& G)
> {
> // Access the propety acessor type for this graph
> typedef typename property_map<Graph,
> &vertexStruct::name>::const_type NamePA;
>
> My mistake, this would have needed to be:
> typedef typename property_map<Graph, string
(vertexStruct::*)>::const_type NamePA;
>
> But, this shows us just how different bundled
properties are from the prior types of properties. The
property_map class becomes harder to use, but in many
cases is not necessary. At the end is my rewrite of
the example, which illustrates how much less baggage
we need to worry about when we go all-out with bundled
parameters.
>
> Doug
>
> template <class EdgeIter, class Graph>
> void who_owes_who(EdgeIter first, EdgeIter last,
const Graph& G)
> {
> while (first != last) {
> cout << G[source(*first, G)].first_name << " owes "
> << G[target(*first, G)].first_name << " some money"
<< endl;
> ++first;
> }
> }
>
> struct VertexData
> {
> string first_name;
> };
>
> int
> main()
> {
> {
> // Create the graph, and specify that we will use
std::string to
> // store the first name's.
> typedef adjacency_list<vecS, vecS, directedS,
VertexData> MyGraphType;
>
> typedef pair<int,int> Pair;
> Pair edge_array[11] = { Pair(0,1), Pair(0,2),
Pair(0,3), Pair(0,4),
> Pair(2,0), Pair(3,0), Pair(2,4), Pair(3,1),
> Pair(3,4), Pair(4,0), Pair(4,1) };
>
> MyGraphType G(5);
> for (int i=0; i<11; ++i)
> add_edge(edge_array[i].first, edge_array[i].second,
G);
>
> G[0].first_name = "Jeremy";
> G[1].first_name = "Rich";
> G[2].first_name = "Andrew";
> G[3].first_name = "Jeff";
> G[4].first_name = "Doug";
>
> who_owes_who(edges(G).first, edges(G).second, G);
> }
>
> cout << endl;
>
> return 0;
> }

=====
TingChong Ma

______________________________________________________________________
Post your free ad now! http://personals.yahoo.ca


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net