[Boost-users] How to access a GRAPH property? - simple

65 views
Skip to first unread message

Mike Douglass

unread,
Aug 13, 2010, 8:59:23 PM8/13/10
to boost...@lists.boost.org
I have

struct vertex_properties
{
    blah blah
}

struct edge_properties
{
    blah blah
}

struct graph_properties
{

  int bobo;

}


typedef adjacency_list < vecS, vecS, bidirectionalS,
        property< vertex_predecessor_t, vertex_t, vertex_properties >,
        property< edge_reverse_t, edge_t, edge_properties >,
        graph_properties
                > graph_t;

graph_t g;

But how can I access bobo?

g.bobo; does not compile (otherwise compiles OK).

thanks

Cedric Laczny

unread,
Aug 14, 2010, 4:49:02 AM8/14/10
to boost...@lists.boost.org
Hi Mike,

please see Table 1 the last part on PropertyGraph on
http://www.boost.org/doc/libs/1_43_0/libs/graph/doc/graph_concepts.html

You need first to get the property_map, which is the central concept to
graph-/vertex-/edge-properties.

You might try something like:
(get(graph_properties, g))[g].bobo

Hope that helps.

Best,

Cedric

_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Jeremiah Willcock

unread,
Aug 14, 2010, 3:05:25 PM8/14/10
to boost...@lists.boost.org
On Fri, 13 Aug 2010, Mike Douglass wrote:

> I have
>
> struct vertex_properties
> {
> ᅵᅵᅵ blah blah
> }
>
> struct edge_properties
> {
> ᅵᅵᅵ blah blah
> }
>
> struct graph_properties
> {
>
> ᅵ int bobo;


>
> }
>
>
> typedef adjacency_list < vecS, vecS, bidirectionalS,

> ᅵᅵᅵᅵᅵᅵᅵ property< vertex_predecessor_t, vertex_t, vertex_properties >,
> ᅵᅵᅵᅵᅵᅵᅵ property< edge_reverse_t, edge_t, edge_properties >,
> ᅵᅵᅵᅵᅵᅵᅵ graph_properties
> ᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵᅵ > graph_t;


>
> graph_t g;
>
> But how can I access bobo?
>
> g.bobo; does not compile (otherwise compiles OK).

To get the graph property, you can use the get_property() function,
documented at
<URL:http://www.boost.org/doc/libs/1_43_0/libs/graph/doc/adjacency_list.html>
(near the bottom). Bundled graph properties are new (just added to the
trunk in the past few weeks); I believe the syntax for those is
"g[graph_bundle].bobo".

-- Jeremiah Willcock

Caligula

unread,
Aug 15, 2010, 3:07:17 AM8/15/10
to boost...@lists.boost.org
Thanks Cedric & Jeremiah,

I tried a bunch of stuff

  template < typename Graph >
    void test_graph_property( Graph & g )
  {


        //get_property(graph_properties, bobo);
        //g[graph_properties].bobo;
        //g[graph_bundle].bobo;
        //g[bobo];
 
        //get(bobo,g);
        //get(g, graph_properties);
        //cout << g[g].bobo << endl;
 
        //get_property(g.graph_properties, bobo);
        get_property(g, bobo);

  }

But nothing works.
For "get_property(g, bobo);"  I get
 
In function ‘void test_graph_property(Graph&)’:
error: ‘bobo’ was not declared in this scope


The doc pages you refered me to only mention property_maps, as far as I can tell.
Maybe I need to declare a property_map such as

       property_map < graph_t, int >::type
          capacity = get(bobo, g);

I would hope that I could avoid this using bundled properties.


Thanks

From: Jeremiah Willcock <jewi...@osl.iu.edu>
To: boost...@lists.boost.org
Sent: Sat, August 14, 2010 12:05:25 PM
Subject: Re: [Boost-users] How to access a GRAPH property? - simple

On Fri, 13 Aug 2010, Mike Douglass wrote:

> I have
>
> struct vertex_properties
> {
>     blah blah
> }
>
> struct edge_properties
> {
>     blah blah
> }
>
> struct graph_properties
> {
>
>   int bobo;
>
> }
>
>
> typedef adjacency_list < vecS, vecS, bidirectionalS,
>         property< vertex_predecessor_t, vertex_t, vertex_properties >,
>         property< edge_reverse_t, edge_t, edge_properties >,
>         graph_properties

>                 > graph_t;
>
> graph_t g;
>
> But how can I access bobo?
>
> g.bobo; does not compile (otherwise compiles OK).

To get the graph property, you can use the get_property() function, documented at http://www.boost.org/doc/libs/1_43_0/libs/graph/doc/adjacency_list.html> (near the bottom).  Bundled graph properties are new (just added to the trunk in the past few weeks); I believe the syntax for those is "g[graph_bundle].bobo".

-- Jeremiah Willcock

Mike Douglass

unread,
Aug 15, 2010, 3:39:25 AM8/15/10
to boost...@lists.boost.org
Thanks Cedric & Jeremiah,

I tried a bunch of things
On Fri, 13 Aug 2010, Mike Douglass wrote:

> I have
>
> struct vertex_properties
> {
>     blah blah
> }
>
> struct edge_properties
> {
>     blah blah
> }
>
> struct graph_properties
> {
>
>   int bobo;
>
> }
>
>
> typedef adjacency_list < vecS, vecS, bidirectionalS,
>         property< vertex_predecessor_t, vertex_t, vertex_properties >,
>         property< edge_reverse_t, edge_t, edge_properties >,
>         graph_properties

>                 > graph_t;
>
> graph_t g;
>
> But how can I access bobo?
>
> g.bobo; does not compile (otherwise compiles OK).

To get the graph property, you can use the get_property() function, documented at http://www.boost.org/doc/libs/1_43_0/libs/graph/doc/adjacency_list.html> (near the bottom).  Bundled graph properties are new (just added to the trunk in the past few weeks); I believe the syntax for those is "g[graph_bundle].bobo".

-- Jeremiah Willcock

Jeremiah Willcock

unread,
Aug 15, 2010, 2:19:02 PM8/15/10
to boost...@lists.boost.org
On Sun, 15 Aug 2010, Caligula wrote:

> Thanks Cedric & Jeremiah,
>
> I tried a bunch of stuff
>
>   template < typename Graph >
>     void test_graph_property( Graph & g )
>   {
>
>
>         //get_property(graph_properties, bobo);
>         //g[graph_properties].bobo;
>         //g[graph_bundle].bobo;
>         //g[bobo];
>  
>         //get(bobo,g);
>         //get(g, graph_properties);
>         //cout << g[g].bobo << endl;
>  
>         //get_property(g.graph_properties, bobo);
>         get_property(g, bobo);
>
>   }
>
> But nothing works.
> For "get_property(g, bobo);"  I get
>  
> In function ‘void test_graph_property(Graph&)’:
> error: ‘bobo’ was not declared in this scope
>
>
> The doc pages you refered me to only mention property_maps, as far as I can tell.
> Maybe I need to declare a property_map such as
>
>        property_map < graph_t, int >::type
>           capacity = get(bobo, g);
>
> I would hope that I could avoid this using bundled properties.

You probably can, but bundled graph properties have only been in the Boost
trunk for about a week and are not the 1.43 or 1.44 releases. Otherwise,
you will need to use old-style properties (you can define a single
property that contains your struct of properties, though).

-- Jeremiah Willcock

Mike Douglass

unread,
Aug 16, 2010, 2:13:54 AM8/16/10
to boost...@lists.boost.org
Downloaded the trunk and used  g[graph_bundle].bobo;
It works.

Thanks


From: Jeremiah Willcock <jewi...@osl.iu.edu>
To: boost...@lists.boost.org
Sent: Sun, August 15, 2010 11:19:02 AM

Subject: Re: [Boost-users] How to access a GRAPH property? - simple
Reply all
Reply to author
Forward
0 new messages