Boost logo

Boost Users :

From: Camille Lemen (lemen_at_[hidden])
Date: 2006-03-09 08:08:42


Hi all!
I'm new at using boost and my request certainly is obvious but I can't manage
to get the error...
I am trying to set std::vector's type vertex properties in a graph. But it
does not want te set a property to more than one edge.
The program is the following:
/****************************************code*****************************/
#include <vector>
#include <iostream>

#include <list>
#include <map>

//boost includes
#include <boost/property_map.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/properties.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/adjacency_matrix.hpp>

using namespace std;

enum edge_intersec_t { edge_intersec };
enum edge_dist_t { edge_dist };
enum vertex_param_t { vertex_param};
namespace boost {
   BOOST_INSTALL_PROPERTY(edge, intersec);
   BOOST_INSTALL_PROPERTY(edge, dist);
   BOOST_INSTALL_PROPERTY(vertex, param);
}
using namespace boost;

typedef property<edge_intersec_t, unsigned int, property<edge_dist_t,float> >
EdgeProp;
typedef property<vertex_param_t,std::vector<float> > VertexProp;

typedef adjacency_list<setS,vecS, bidirectionalS,VertexProp,EdgeProp> Graph;

typedef graph_traits<Graph>::edge_descriptor edge_descriptor;

int main(int argc, char** argv)
{
int NbRegions = 9;
   Graph g(NbRegions);
 
    edge_descriptor e;
 bool inserted;
   
   tie(e,inserted) = add_edge(vertex(0,g),vertex(1,g),EdgeProp(0,20),g);
   tie(e,inserted) = add_edge(vertex(0,g),vertex(2,g),0,g);
   tie(e,inserted) = add_edge(vertex(1,g),vertex(2,g),0,g);
   tie(e,inserted) = add_edge(vertex(3,g),vertex(4,g),0,g);
   tie(e,inserted) = add_edge(vertex(3,g),vertex(5,g),0,g);
   tie(e,inserted) = add_edge(vertex(3,g),vertex(7,g),0,g);
   tie(e,inserted) = add_edge(vertex(4,g),vertex(5,g),0,g);
   tie(e,inserted) = add_edge(vertex(5,g),vertex(6,g),0,g);
   tie(e,inserted) = add_edge(vertex(1,g),vertex(4,g),50,g);
   tie(e,inserted) = add_edge(vertex(1,g),vertex(3,g),100,g);
   tie(e,inserted) = add_edge(vertex(0,g),vertex(4,g),200,g);
   tie(e,inserted) = add_edge(vertex(2,g),vertex(5,g),500,g);
   tie(e,inserted) = add_edge(vertex(2,g),vertex(6,g),20,g);
   tie(e,inserted) = add_edge(vertex(2,g),vertex(4,g),50,g);
   tie(e,inserted) = add_edge(vertex(0,g),vertex(3,g),50,g);
   

std::vector<float> param(2);
std::vector<float> propriete(2);
  
   param[0] = 800;
   std::cerr<<"param[0] = "<<param[0]<<std::endl;
   param[1] = 20;
    std::cerr<<"param[1] = "<<param[1]<<std::endl;

   put(vertex_param,g,vertex(0,g),param);
   propriete = get(vertex_param,g,vertex(0,g));
 std::cout<<"propriete[0]: "<<propriete[0]<<", propriete[1]:
"<<propriete[1]<<std::endl;

   param.clear();
   param[0] = 2;
   std::cerr<<"param[0] = "<<param[0]<<std::endl;
   param[1] = 50;
    std::cerr<<"param[1] = "<<param[1]<<std::endl;

   put(vertex_param,g,vertex(1,g),param);
  propriete = get(vertex_param,g,vertex(1,g));
 std::cout<<"propriete[0]: "<<propriete[0]<<", propriete[1]:
"<<propriete[1]<<std::endl;
return 0;
}
/************************************************************************/
it compiles and executes, but the property of the second vertex has not been
asigned. Here is the result it gives:
/***************command window*************************************/
param[0] = 800
param[1] = 20
propriete[0]: 800, propriete[1]: 20
param[0] = 2
param[1] = 50
propriete[0]: 800, propriete[1]: 20
/**************************************************************************/
I tried without using "propriete" but directly"get(vertex_param,g,vertex(1,g))
[0]", and it gives a segmentation fault during the execution which confirms
that the vertex property has not been asigned to the second vertex.
Thanks!
Camille.


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