[Boost][BGL] Dynamic Property, dynamic_get_failure.
Hi, I'm trying to generate random graphs (with random edge weight) and write them to a dot file, but I get this exception in the write_graphviz_dp() function : "what(): dynamic property get cannot retrieve value for property: weight." The code looks like this : typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, property<edge_index_t, int>, property<edge_weight_t, int> > graph; boost::minstd_rand gen; graph g; boost::generate_random_graph(g, 10, 30, gen, false, false); boost::randomize_property<boost::edge_weight_t>(g, gen); dynamic_properties dp; dp.property("weight", get(edge_weight, g)); boost::write_graphviz_dp(std::cout, g, dp, std::string("weight")); (don't pay attention to the random generator it's just to keep it simple). I've been looking at the examples and at the doc and it doesn't seem to me that I'm doing something wrong... but apparently I am. Thanks in advance!.
On Tue, 26 Apr 2011, Mathieu - wrote:
Hi,
I'm trying to generate random graphs (with random edge weight) and write them to a dot file, but I get this exception in the write_graphviz_dp() function : "what(): dynamic property get cannot retrieve value for property: weight."
The code looks like this :
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, property<edge_index_t, int>, property<edge_weight_t, int> > graph;
boost::minstd_rand gen;
graph g; boost::generate_random_graph(g, 10, 30, gen, false, false); boost::randomize_property<boost::edge_weight_t>(g, gen);
dynamic_properties dp; dp.property("weight", get(edge_weight, g));
boost::write_graphviz_dp(std::cout, g, dp, std::string("weight"));
(don't pay attention to the random generator it's just to keep it simple).
I've been looking at the examples and at the doc and it doesn't seem to me that I'm doing something wrong... but apparently I am.
You are passing "weight" as the node_id parameter to write_graphviz_dp, but what you have defined as "weight" in dp is an edge property, not a vertex property. I think removing the last argument to write_graphviz_dp should fix the problem. Note that your adjacency_list template arguments also put edge_index_t as a vertex property, not an edge property like you probably intended. -- Jeremiah Willcock
On 27 April 2011 00:15, Jeremiah Willcock <jewillco@osl.iu.edu> wrote:
You are passing "weight" as the node_id parameter to write_graphviz_dp, but what you have defined as "weight" in dp is an edge property, not a vertex property.
Ah yes, I didn't pay enough attention I guess!
I think removing the last argument to write_graphviz_dp should fix the problem.
Well, it still throws because it can't retrieve the value for the default value ("node_id") either Thanks for your help. Mathieu Masson
On Wed, 27 Apr 2011, Mathieu - wrote:
On 27 April 2011 00:15, Jeremiah Willcock <jewillco@osl.iu.edu> wrote:
You are passing "weight" as the node_id parameter to write_graphviz_dp, but what you have defined as "weight" in dp is an edge property, not a vertex property.
Ah yes, I didn't pay enough attention I guess!
I think removing the last argument to write_graphviz_dp should fix the problem.
Well, it still throws because it can't retrieve the value for the default value ("node_id") either
You will need something like dp.property("node_id", get(boost::vertex_index, g)) to enable that. -- Jeremiah Willcock
On 27 April 2011 02:12, Jeremiah Willcock <jewillco@osl.iu.edu> wrote:
You will need something like dp.property("node_id", get(boost::vertex_index, g)) to enable that.
Ah yes of course that did it. I though I had tried it before... I guess that's what you get for posting that late in the night. Thanks a lot for your help. Mathieu-
participants (2)
-
Jeremiah Willcock
-
Mathieu -