Using metric_tsp_approx with bundled properties
Hi, I am trying to use metric_tsp_approx on a graph defined as : typedef adjacency_list<vecS, vecS, undirectedS, City, Road> Graph; City contains the vertex id and Road the edge weight. After reading the documentation, I arrived to : metric_tsp_approx(g_init, weight_map(get(&Road::length, g_init)). vertex_index_map(get(&City::id, g_init)), make_tsp_tour_visitor(back_inserter(c))); I have compilation errors however. The relevant part seems to be : /usr/include/boost/property_map/property_map.hpp:382:58: error: no type named ‘key_type’ in ‘struct boost::property_traits<boost::bgl_named_params<boost::bundle_property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, City, Road>, long unsigned int, City, int>, boost::vertex_index_t, boost::no_property> >’ Any help appreciated, thanks. -- Alexis Praga, PhD Student (CERFACS) GPG key : AD4A AF6D BB5C 042F 9422 1223 06E1 C1BF E287 65D0
On 13/04/14 22:02, Alexis Praga wrote:
Hi,
I am trying to use metric_tsp_approx on a graph defined as :
typedef adjacency_list<vecS, vecS, undirectedS, City, Road> Graph;
City contains the vertex id and Road the edge weight. After reading the documentation, I arrived to :
metric_tsp_approx(g_init, weight_map(get(&Road::length, g_init)). vertex_index_map(get(&City::id, g_init)), make_tsp_tour_visitor(back_inserter(c)));
I have compilation errors however. The relevant part seems to be :
/usr/include/boost/property_map/property_map.hpp:382:58: error: no type named ‘key_type’ in ‘struct boost::property_traits<boost::bgl_named_params<boost::bundle_property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, City, Road>, long unsigned int, City, int>, boost::vertex_index_t, boost::no_property> >’
Any help appreciated, thanks.
Are City and Road really properties? get() looks up properties by tag. Supply your adjacency list properties rather than the classes themselves. For instance: typedef property<vertex_index_t, City> CityProperty; typedef property<edge_index_t, Road> RoadProperty; typedef adjacency_list<vecS, vecS, undirectedS, CityProperty, RoadProperty> Graph; Then you can use get(vertex_index_t(), g_init) and get(edge_index_t(), g_init). These are predefined tags - for more and how to define your own: http://www.boost.org/doc/libs/1_55_0/libs/graph/doc/using_adjacency_list.htm... Albert
On Mon, Apr 14, 2014 at 10:50:52AM +0100, Albert Yiamakis wrote:
On 13/04/14 22:02, Alexis Praga wrote:
Hi,
I am trying to use metric_tsp_approx on a graph defined as :
typedef adjacency_list<vecS, vecS, undirectedS, City, Road> Graph;
City contains the vertex id and Road the edge weight. After reading the documentation, I arrived to :
metric_tsp_approx(g_init, weight_map(get(&Road::length, g_init)). vertex_index_map(get(&City::id, g_init)), make_tsp_tour_visitor(back_inserter(c)));
I have compilation errors however. The relevant part seems to be :
/usr/include/boost/property_map/property_map.hpp:382:58: error: no type named ‘key_type’ in ‘struct boost::property_traits<boost::bgl_named_params<boost::bundle_property_map<boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, City, Road>, long unsigned int, City, int>, boost::vertex_index_t, boost::no_property> >’
Any help appreciated, thanks.
Are City and Road really properties? get() looks up properties by tag. Supply your adjacency list properties rather than the classes themselves. For instance:
typedef property<vertex_index_t, City> CityProperty; typedef property<edge_index_t, Road> RoadProperty;
typedef adjacency_list<vecS, vecS, undirectedS, CityProperty, RoadProperty> Graph;
Then you can use get(vertex_index_t(), g_init) and get(edge_index_t(), g_init). These are predefined tags - for more and how to define your own:
http://www.boost.org/doc/libs/1_55_0/libs/graph/doc/using_adjacency_list.htm...
Albert
Thanks for the answer. I am a bit confused about properties. From the documentation, I understood you could use any class to create the graph, as long as you use bundled property and as long as you create the property map when needed. I thought it would suffice to create a property map for vertices index and for the edge index. In my case : vertex_index_map(get(&City::id, g_init)), and weight_map(get(&Road::length, g_init)), From your answer, I think you want me to use internal properties, instead of bundled properties. Am I missing something ? -- Alexis Praga, PhD Student (CERFACS) GPG key : AD4A AF6D BB5C 042F 9422 1223 06E1 C1BF E287 65D0
On 14/04/14 13:58, Alexis Praga wrote:
From your answer, I think you want me to use internal properties, instead of bundled properties.
Correct - apologies for the confusion. Clearly not familiar enough with bundled properties; might be of more help if you could post a complete and minimal example. Albert
From: Alexis Praga <alexispraga@mailoo.org> To: boost-users@lists.boost.org Sent: Sunday, April 13, 2014 3:02 PM Subject: [Boost-users] Using metric_tsp_approx with bundled properties
Hi,
I am trying to use metric_tsp_approx on a graph defined as :
typedef adjacency_list<vecS, vecS, undirectedS, City, Road> Graph;
City contains the vertex id and Road the edge weight. After reading the documentation, I arrived to :
metric_tsp_approx(g_init, weight_map(get(&Road::length, g_init)). vertex_index_map(get(&City::id, g_init)), make_tsp_tour_visitor(back_inserter(c)));
After your first named argument, you need to use named arguments for the rest of the argument list: metric_tsp_approx(g_init, weight_map(...).vertex_index_map(...).visitor(...)); Fixing that might fix your compilation errors. -- Jeremiah Willcock
After your first named argument, you need to use named arguments for the rest of the argument list:
metric_tsp_approx(g_init, weight_map(...).vertex_index_map(...).visitor(...));
Fixing that might fix your compilation errors.
-- Jeremiah Willcock
Jeremiah : could you explain why you need named arguments ? I find that very confusing ! Also, I'm having trouble creating a visitor. I tried : metric_tsp_approx(g_init, weight_map(get(&Road::length, g_init)).vertex_index_map(get(&City::id, g_init)) .make_tsp_tour_visitor(back_inserter(c))); But compiling raises the error : has no member named ‘make_tsp_tour_visitor’ Should I create a class for the visitor ? Albert : I have included a small example as an attached file. -- Alexis Praga, PhD Student (CERFACS) GPG key : AD4A AF6D BB5C 042F 9422 1223 06E1 C1BF E287 65D0
After your first named argument, you need to use named arguments for the rest of the argument list:
metric_tsp_approx(g_init, weight_map(...).vertex_index_map(...).visitor(...));
Fixing that might fix your compilation errors.
-- Jeremiah Willcock
Interestingly, I don't see a named parameter overload in metric_tsp_approx.hpp.
Also, I'm having trouble creating a visitor. I tried :
metric_tsp_approx(g_init, weight_map(get(&Road::length, g_init)).vertex_index_map(get(&City::id, g_init)) .make_tsp_tour_visitor(back_inserter(c)));
But compiling raises the error : has no member named ‘make_tsp_tour_visitor’
Should I create a class for the visitor ?
No, the call should be metric_tsp_approx(g_init, weight_map(get(&Road::length, g_init)).vertex_index_map(get(&City::id, g_init)) .visitor(make_tsp_tour_visitor(back_inserter(c)))); However that doesn't compile either; I suspect because there is no named parameter overload and it tries to call metric_tsp_approx(VertexListGraph& g, TSPVertexVisitor vis) instead. Albert
On Thu, Apr 17, 2014 at 10:26:31AM +0100, Albert Yiamakis wrote:
No, the call should be
metric_tsp_approx(g_init, weight_map(get(&Road::length, g_init)).vertex_index_map(get(&City::id, g_init)) .visitor(make_tsp_tour_visitor(back_inserter(c))));
However that doesn't compile either; I suspect because there is no named parameter overload and it tries to call
metric_tsp_approx(VertexListGraph& g, TSPVertexVisitor vis)
What should I do then to call metric_tsp_approx properly then ? Cheers, -- Alexis Praga, PhD Student (CERFACS) GPG key : AD4A AF6D BB5C 042F 9422 1223 06E1 C1BF E287 65D0
participants (3)
-
Albert Yiamakis
-
Alexis Praga
-
Jeremiah Willcock