write_graphviz: write out edges when vertex data is a boost::shared_ptr?
How does one write out the proper edge node names when the vertex data
is a boost::shared_ptr? My graph is defined as:
typedef property< vertex_index_t, uint32_t,
property< vertex_name_t, boost::shared_ptr<Component> > >
VertexProperty;
typedef adjacency_list
I believe you need to use boost::make_label_writer. Here is how I use it to place information from an external property map: ofstream os("workFlow.dot"); write_graphviz(os,workFlowGraph_,make_label_writer(workFlowVertexLabeler(workFlowGraph_))); Where workFlowVertexLabeler is: struct workFlowVertexLabeler { workFlowVertexLabeler(WorkFlowGraph& workFlowGraph) : workFlowGraph_(workFlowGraph) {} std::string operator[](const WorkFlowVertex& v) const { return workFlowGraph_.getWorkFlowData()[v].getLabel(); } private: WorkFlowGraph& workFlowGraph_; Stephen torri wrote:
How does one write out the proper edge node names when the vertex data is a boost::shared_ptr? My graph is defined as:
typedef property< vertex_index_t, uint32_t, property< vertex_name_t, boost::shared_ptr<Component> > > VertexProperty;
typedef adjacency_list
// VertexProperties Graph_Type; The call in graphviz.hpp at line 269 has me confused. I understand that the node ids are printed out by looking for the value stored in the vertex_index_t property, graphviz.hpp at line 263. So if the value stored at the vertex_index_t property was the value '3' the node's name would be '3'. The edges are what have me confused. I would expect that the source id and the target it would be the value of the vertex_index_t property. So if there are two nodes the dot file would be:
0[label="A"]; 1[label="B"]; 0 -> 1;
Yet with a boost::shared_ptr stored in a vertex_name_t property I get:
0[label="A"]; 1[label="B"]; 0x807a108->0x807a128;
Well anything starting with a '0x' is ambigiuos to the dot parser. It breaks the 0x807a108 into two names.
I need to use a boost::shared_ptr for my data. I believe I have not used the right boost::property type. Is that right?
What I expect to see as output for the dot file is:
0[label="A"]; 1[label="B"]; 0->1;
Stephen
On Mon, 2004-11-08 at 15:17, Jeffrey Holle wrote:
I believe you need to use boost::make_label_writer. Here is how I use it to place information from an external property map:
ofstream os("workFlow.dot"); write_graphviz(os,workFlowGraph_,make_label_writer(workFlowVertexLabeler(workFlowGraph_)));
Where workFlowVertexLabeler is:
struct workFlowVertexLabeler { workFlowVertexLabeler(WorkFlowGraph& workFlowGraph) : workFlowGraph_(workFlowGraph) {} std::string operator[](const WorkFlowVertex& v) const { return workFlowGraph_.getWorkFlowData()[v].getLabel(); } private: WorkFlowGraph& workFlowGraph_;
Your solution words when modified for my situation (data structure). The problem with the edge labelling still remains. I see a problem with the loop in graphviz.hpp that prints out the edges: typename graph_traits<Graph>::edge_iterator ei, edge_end; for(tie(ei, edge_end) = edges(g); ei != edge_end; ++ei) { out << source(*ei, g) << Traits::delimiter() << target(*ei, g) << " "; epw(out, *ei); //print edge attributes out << ";" << std::endl; } There is no operator<< function for graph_traits so the memory location of the vertex_descriptor that is returned is printed instead of the vertex_index_t value used to name the nodes above. I don't see why this does not work as the documentation example. Stephen -- Email: storri@torri.org
Stephen torri wrote:
The problem with the edge labelling still remains. I see a problem with the loop in graphviz.hpp that prints out the edges:
typename graph_traits<Graph>::edge_iterator ei, edge_end; for(tie(ei, edge_end) = edges(g); ei != edge_end; ++ei) { out << source(*ei, g) << Traits::delimiter() << target(*ei, g) << " "; epw(out, *ei); //print edge attributes out << ";" << std::endl; }
There is no operator<< function for graph_traits so the memory location of the vertex_descriptor that is returned is printed instead of the vertex_index_t value used to name the nodes above.
I ran into this exact same problem a few days ago, and posted about it (even referring to the same code snippet you did), but received no response. I eventually ended up modifying the loop in graphviz.hpp, replacing out << source(*ei, g) << Traits::delimiter() << target(*ei, g)) << " "; with out << get(vertex_index, source(*ei, g)) << Traits::delimiter() << \ get(vertex_index, target(*ei, g)) << " "; Let's hear it for the BSD license. Cheers, Meredith L. Patterson
On Nov 8, 2004, at 9:28 PM, Meredith L. Patterson wrote:
I ran into this exact same problem a few days ago, and posted about it (even referring to the same code snippet you did), but received no response.
Sorry! I lost the message in the shuffle.
I eventually ended up modifying the loop in graphviz.hpp, replacing
out << source(*ei, g) << Traits::delimiter() << target(*ei, g)) << " ";
with
out << get(vertex_index, source(*ei, g)) << Traits::delimiter() << \ get(vertex_index, target(*ei, g)) << " ";
FWIW, we actually did fix this in CVS back in May and the corrected code will be in 1.32.0. Doug
participants (4)
-
Doug Gregor
-
Jeffrey Holle
-
Meredith L. Patterson
-
Stephen torri