Boost logo

Boost :

From: JOAQUIN LOPEZ MU?Z (joaquin_at_[hidden])
Date: 2005-01-30 08:34:49


Hi Alexander,

----- Mensaje original -----
De: Me here <rhjrjlbk2002_at_[hidden]>
Fecha: Viernes, Enero 28, 2005 5:21 pm
Asunto: [boost] Help needed with BGL & multi_index_container

> Hi there,
>
> I need an advanced container which allows me to access
> my data over number of different indices. That is
> exactly what for boost::multi_index_container was
> made. But, my data items also have relationships with
> other data in the same container, which could be
> represented as directed graph.
>
> So, I have made a custom container, which aggregates
> multi_index_container (MIC) to store data items and a
> graph (BGL) to store relationships. To allow switching
> from MIC to walk over relationships, as an additional
> field of my item in MIC I store BGL vertex; as vertex
> property in graph I store the key of unique index in
> MIC. So, MIC and BGL refer to each other. But, it is
> difficult to have those two containers in sync.
>
> So, I made another attempt to have MIC as customized
> vertex storage. I succeed two write the code for it
> (see it below). It also compiles and links :-).
> Unfortunately, I can not add neither vertices not
> edges. If I try to add vertex as in commeted code
> below, an error errors that there is no convertion
> from vertex property to vertex descriptor (error
> message is below).
>
> What's wrong?

Well, I'm no BGL expert, so take this with a grain of salt,
but I think adjacency_list does not work the way you're
assuming: it is adjacency_list that internally defines its
vertex_descriptor type, and uses the container supplied to
store them: so, you just cannot select what vertices actually
are (like it seems you're trying with ItemHolder.) In fact,
the primary API for adding vertices is

  add_vertex(g);

which does not specify the vertex being added (it is
created internally by adjacency_list). The syntax

  add_vertex(p,g);

is shorthand for adding a vertex and attaching it
a property.

I'd say that, in order to blend BGL with
multi_index_container, you have three options:

1. Maintain the two structures in sync, like you've done
in your first approach.
2. Use multi_index_container as a property map attached
to a graph. I don't know if this would work, since I'm
not a BGL conoisseur.
3. Create your own data structure modeling mutable graph
which internally uses multi_index_container. Besides
the multi-index container, you'll need another one for
storing edges, if you are to follow the way adjacency_list
works.

Good luck with your project,

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo

>
> My another question is: how can I get access to my
> MIC stored in graph? I would like to use its indices.
>
> Best wishes,
> Alexander
>
> --------- sample code -----------
> #include <iostream>
>
> #include <boost/multi_index_container.hpp>
> #include <boost/multi_index/ordered_index.hpp>
>
> #include <boost/graph/adjacency_list.hpp>
>
> using namespace boost;
> using namespace boost::multi_index;
>
> using namespace std;
>
>
> struct MICSelector {};
>
> struct Item
> {
> Item(int _a=0, int _b=0, int _c=0)
> : a(_a), b(_b), c(_c) {}
>
> int a,b,c;
> };
>
> struct ItemHolder
> {
> ItemHolder(int id=0, const Item item=Item())
> : m_ID(id), m_item(item) {}
>
> int m_ID;
> Item m_item;
> };
>
> struct ItemHolderKey
> {
> typedef int result_type;
> int operator()(const ItemHolder& v) const
> { return v.m_ID; }
> };
>
> template<class ValueType>
> struct MICWrapper
> {
> typedef multi_index_container
> <
> ValueType,
> indexed_by
> <
> ordered_unique< ItemHolderKey >
> >
> > type;
> };
>
> namespace boost
> {
> // the specialization for your selector
> template<class ValueType>
> struct container_gen<MICSelector, ValueType>
> {
> typedef typename MICWrapper<ValueType>::type type;
> };
>
> template <>
> struct parallel_edge_traits<MICSelector> {
> typedef allow_parallel_edge_tag type;
> };
> };
>
> typedef adjacency_list
> < listS, MICSelector,
> bidirectionalS, ItemHolder
> > MG;
>
> int tmain(int argc, char* argv[])
> {
>
> MG mg;
>
> /*
> ItemHolder IH( 1, Item(1) );
>
> add_vertex( &IH, mg );
>
> // add_edge(
> // ItemHolder( 1, Item(1) ),
> // ItemHolder( 2, Item(2) ),
> // mg );
> */
>
> cout << typeid(
> boost::graph_traits<MG>::vertex_descriptor ).name();
>
> return 0;
> }
> --------- sample code -----------
>
> ----------- error message -------------
> Compiling...
> MIC_BGL.cpp
> c:\test\MIC_BGL.cpp(87) : error C2664:
> 'boost::add_vertex' : cannot convert parameter 1 from
> 'ItemHolder *__w64 ' to 'const
>
boost::detail::adj_list_gen<Graph,VertexListS,OutEdgeListS,DirectedS,Ver
texProperty,EdgeProperty,GraphProperty,EdgeListS>::config::vertex_proper
ty_type
> &'
> with
> [
>
>
Graph=boost::adjacency_list<boost::listS,MICSelector,boost::bidirectiona
lS,ItemHolder>,
> VertexListS=MICSelector,
> OutEdgeListS=boost::listS,
> DirectedS=boost::bidirectionalS,
>
>
VertexProperty=boost::detail::retag_property_list<boost::vertex_bundle_t
,ItemHolder>::type,
>
>
EdgeProperty=boost::detail::retag_property_list<boost::edge_bundle_t,boo
st::no_property>::type,
> GraphProperty=boost::no_property,
> EdgeListS=boost::listS
> ]
> Reason: cannot convert from 'ItemHolder *__w64 ' to
> 'const
>
boost::detail::adj_list_gen<Graph,VertexListS,OutEdgeListS,DirectedS,Ver
texProperty,EdgeProperty,GraphProperty,EdgeListS>::config::vertex_proper
ty_type'
> with
> [
>
>
Graph=boost::adjacency_list<boost::listS,MICSelector,boost::bidirectiona
lS,ItemHolder>,
> VertexListS=MICSelector,
> OutEdgeListS=boost::listS,
> DirectedS=boost::bidirectionalS,
>
>
VertexProperty=boost::detail::retag_property_list<boost::vertex_bundle_t
,ItemHolder>::type,
>
>
EdgeProperty=boost::detail::retag_property_list<boost::edge_bundle_t,boo
st::no_property>::type,
> GraphProperty=boost::no_property,
> EdgeListS=boost::listS
> ]
> No constructor could take the source type, or
> constructor overload resolution was ambiguous
> ----------- error message -------------
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail - Find what you need with new enhanced search.
> http://info.mail.yahoo.com/mail_250
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost


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