read_graphviz with a simple graph

If I have a graph with no vertex properties or edge properties: adjacency_list<vecS, vecS, undirectedS> can I read a .dot file into it with read_graphviz? I tried: dynamic_properties dp; Graph g; read_graphviz(fileinput, g, dp); but it throws an exception "Property not found: node_id". I tried to add property_map<Graph, vertex_name_t>::type name = get(vertex_name, g); dp.property("node_id",name); but I get a compiler error "No match for operator<<" Any suggestions? Thanks, David

On Wed, 22 Jun 2011, David Doria wrote:
If I have a graph with no vertex properties or edge properties:
adjacency_list<vecS, vecS, undirectedS>
can I read a .dot file into it with read_graphviz?
I tried:
dynamic_properties dp; Graph g; read_graphviz(fileinput, g, dp);
but it throws an exception "Property not found: node_id".
I tried to add
property_map<Graph, vertex_name_t>::type name = get(vertex_name, g); dp.property("node_id",name);
but I get a compiler error "No match for operator<<"
I think you will need some kind of property to store the vertex names from Graphviz; you might be able to use null_property_map for that (from <boost/graph/property_maps/null_property_map.hpp>) though. -- Jeremiah Willcock

I think you will need some kind of property to store the vertex names from Graphviz; you might be able to use null_property_map for that (from <boost/graph/property_maps/null_property_map.hpp>) though.
-- Jeremiah Willcock
The following works, but it seems very confusing. I tried the two commented lines separately but they don't compile. Is this the recommended method? typedef boost::property < boost::vertex_name_t, std::string> VertexProperty; typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::directedS, VertexProperty> graph_t; //typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::directedS, boost::no_property> graph_t; //typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::directedS, boost::null_property_map> graph_t; graph_t graph; boost::dynamic_properties dp; boost::property_map<graph_t, boost::vertex_name_t>::type name = get(boost::vertex_name, graph); dp.property("node_id",name); bool status = boost::read_graphviz(stream,graph,dp,"node_id"); David

On Wed, 22 Jun 2011, David Doria wrote:
I think you will need some kind of property to store the vertex names from Graphviz; you might be able to use null_property_map for that (from <boost/graph/property_maps/null_property_map.hpp>) though.
-- Jeremiah Willcock
The following works, but it seems very confusing. I tried the two commented lines separately but they don't compile. Is this the recommended method?
You don't need to modify the graph definition at all. I think this will work: graph_t graph; boost::dynamic_properties dp; dp.property("node_id", boost::make_null_property<vertex_descriptor, string>); bool status = boost::read_graphviz(stream,graph,dp,"node_id"); -- Jeremiah Willcock

On Thu, 23 Jun 2011, Jeremiah Willcock wrote:
On Wed, 22 Jun 2011, David Doria wrote:
I think you will need some kind of property to store the vertex names from Graphviz; you might be able to use null_property_map for that (from <boost/graph/property_maps/null_property_map.hpp>) though.
-- Jeremiah Willcock
The following works, but it seems very confusing. I tried the two commented lines separately but they don't compile. Is this the recommended method?
You don't need to modify the graph definition at all. I think this will work:
graph_t graph;
boost::dynamic_properties dp; dp.property("node_id", boost::make_null_property<vertex_descriptor, string>);
Sorry -- that needs to be make_null_property<...>().
bool status = boost::read_graphviz(stream,graph,dp,"node_id");
-- Jeremiah Willcock

On Thu, Jun 23, 2011 at 4:06 PM, Jeremiah Willcock <jewillco@osl.iu.edu> wrote:
On Thu, 23 Jun 2011, Jeremiah Willcock wrote:
On Wed, 22 Jun 2011, David Doria wrote:
I think you will need some kind of property to store the vertex names from Graphviz; you might be able to use null_property_map for that (from <boost/graph/property_maps/null_property_map.hpp>) though.
-- Jeremiah Willcock
Hm, I tried: #include <boost/graph/property_maps/null_property_map.hpp> ... typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::directedS, VertexProperty> Graph; boost::dynamic_properties dp; dp.property("node_id", boost::make_null_property<Graph::vertex_descriptor, std::string>() ); but I get a compiler error on that last line (i.e. if I comment it the error goes away) that says: "error: no matching function for call to 'get(boost::null_property_map<unsigned int, std::basic_string<char> > &, unsigned int)" I don't know what that means ? David

On Thu, 23 Jun 2011, David Doria wrote:
On Thu, Jun 23, 2011 at 4:06 PM, Jeremiah Willcock <jewillco@osl.iu.edu> wrote:
On Thu, 23 Jun 2011, Jeremiah Willcock wrote:
On Wed, 22 Jun 2011, David Doria wrote:
I think you will need some kind of property to store the vertex names from Graphviz; you might be able to use null_property_map for that (from <boost/graph/property_maps/null_property_map.hpp>) though.
-- Jeremiah Willcock
Hm, I tried:
#include <boost/graph/property_maps/null_property_map.hpp> ...
typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::directedS, VertexProperty> Graph; boost::dynamic_properties dp; dp.property("node_id", boost::make_null_property<Graph::vertex_descriptor, std::string>() );
but I get a compiler error on that last line (i.e. if I comment it the error goes away) that says:
"error: no matching function for call to 'get(boost::null_property_map<unsigned int, std::basic_string<char> > &, unsigned int)"
I don't know what that means ?
Apparently null_property_map is write-only, so it doesn't have a get() function; I hadn't realized that. Please try dummy_property_map (from boost/property_map/property_map.hpp) instead, or if that doesn't work, static_property_map or ref_property_map from the same file. -- Jeremiah Willcock

Apparently null_property_map is write-only, so it doesn't have a get() function; I hadn't realized that. Please try dummy_property_map (from boost/property_map/property_map.hpp) instead, or if that doesn't work, static_property_map or ref_property_map from the same file.
-- Jeremiah Willcock
With dp.property("node_id", boost::dummy_property_map()); I get: "error: invalid use of void expression". with dp.property("node_id", boost::static_property_map<Graph::vertex_descriptor>()); I get: "error: no matching function call to boost::static_property_map<unsigned int>::static_property_map()" with dp.property("node_id", boost::ref_property_map<Graph::vertex_descriptor, std::string>()); I get: "error: no matching function call to boost::ref_property_map<unsigned int, std::basic_string<char>
::ref_property_map()"
Round 3 :) ? David

On Thu, 23 Jun 2011, David Doria wrote:
Apparently null_property_map is write-only, so it doesn't have a get() function; I hadn't realized that. Please try dummy_property_map (from boost/property_map/property_map.hpp) instead, or if that doesn't work, static_property_map or ref_property_map from the same file.
-- Jeremiah Willcock
With
dp.property("node_id", boost::dummy_property_map());
I get: "error: invalid use of void expression".
with
dp.property("node_id", boost::static_property_map<Graph::vertex_descriptor>());
Try: std::string s; ... boost::static_property_map<std::string>(s) ... -- Jeremiah Willcock

Try:
std::string s; ... boost::static_property_map<std::string>(s) ...
-- Jeremiah Willcock
std::string s; dp.property("node_id", boost::static_property_map<std::string>(s)); produces: invalid use of void expression. Before I was just whining that I had to change the adjacency_list template parameters, but now it seems like the vertices that are raed in using the first method (the one that was working) does not keep the correct numbers/ids associated with the vertices. I have an example of that behavior, but I feel like it might be fixed when we get this way working. David

On Thu, 23 Jun 2011, David Doria wrote:
Try:
std::string s; ... boost::static_property_map<std::string>(s) ...
-- Jeremiah Willcock
std::string s; dp.property("node_id", boost::static_property_map<std::string>(s));
produces:
invalid use of void expression.
Before I was just whining that I had to change the adjacency_list template parameters, but now it seems like the vertices that are raed in using the first method (the one that was working) does not keep the correct numbers/ids associated with the vertices. I have an example of that behavior, but I feel like it might be fixed when we get this way working.
Did you need the vertex IDs from the Graphviz file? If so, you will need a "real" property map as node_id (either internal to the graph or an external one). -- Jeremiah Willcock

Did you need the vertex IDs from the Graphviz file? If so, you will need a "real" property map as node_id (either internal to the graph or an external one).
Hm, but then I won't be able to access the vertices like "normal" (with graph[my_vertex_descriptor]) with the vertex_descriptor corresponding to the vertex ID (in the vecS case), right? That would be pretty awkward - to have to use one method to access nodes if the graph was constructed programmatically, and another if it was read from a file. David

On Fri, 24 Jun 2011, David Doria wrote:
Did you need the vertex IDs from the Graphviz file? If so, you will need a "real" property map as node_id (either internal to the graph or an external one).
Hm, but then I won't be able to access the vertices like "normal" (with graph[my_vertex_descriptor]) with the vertex_descriptor corresponding to the vertex ID (in the vecS case), right? That would be pretty awkward - to have to use one method to access nodes if the graph was constructed programmatically, and another if it was read from a file.
Since the vecS vertex descriptors must be contiguous integers, you probably can't use the IDs from the graph directly. You would need a custom graph type for that, or (if you allow messier syntax) an std::map or similar as a lookup table mapping IDs to descriptors. -- Jeremiah Willcock

On Fri, Jun 24, 2011 at 2:50 PM, Jeremiah Willcock <jewillco@osl.iu.edu> wrote:
On Fri, 24 Jun 2011, David Doria wrote:
Did you need the vertex IDs from the Graphviz file? If so, you will need a "real" property map as node_id (either internal to the graph or an external one).
I think I figured out how this must be done. I read the graph, then construct a new graph using the vertex names/ids that were in the file to create edges on a sequentially labeled vertex set (a simple adjacency_list(19) type of thing with vecS vertices). I then convert the string properties to unsigned ints and use those as the new vertex ids: http://programmingexamples.net/index.php?title=CPP/Boost/BGL/RelabelInputVer... Does this look reasonable? Thanks, David

On Sun, 26 Jun 2011, David Doria wrote:
On Fri, Jun 24, 2011 at 2:50 PM, Jeremiah Willcock <jewillco@osl.iu.edu> wrote:
On Fri, 24 Jun 2011, David Doria wrote:
Did you need the vertex IDs from the Graphviz file? If so, you will need a "real" property map as node_id (either internal to the graph or an external one).
I think I figured out how this must be done. I read the graph, then construct a new graph using the vertex names/ids that were in the file to create edges on a sequentially labeled vertex set (a simple adjacency_list(19) type of thing with vecS vertices). I then convert the string properties to unsigned ints and use those as the new vertex ids:
http://programmingexamples.net/index.php?title=CPP/Boost/BGL/RelabelInputVer...
Does this look reasonable?
I think (but am not sure) that backslash-newlines inside strings are not portable. You might want to put it onto one line, or use a separate string constant for each line (which will be joined automatically). You might also want to use boost::lexical_cast for the various string conversions you do in the code. -- Jeremiah Willcock
participants (2)
-
David Doria
-
Jeremiah Willcock