2012-07-06 11 views
5

मेरा प्रश्न पर ही आधारित होता:कई गुणों के साथ Graphviz में एक ग्राफ मुद्रित करने के लिए किस प्रकार प्रदर्शित किया

typedef struct vert{ 
    std::string name; 
}; 

typedef struct edge{ 
    int capacity; 
    int weight; 
}; 

typedef adjacency_list<listS, vecS, undirectedS, vert, edge> Graph; 
Graph g; 
vector<int,int> ele; 

मैं एक पाश में कहा जाता है निम्नलिखित है कि चाहिए: How to print a graph with a single property displayed

मैं बंडल गुण का उपयोग कर रहा हूँ किनारों बनाने के लिए:

edge prop; 
    prop.weight = 5; 
    prop.capacity = 4; 
    add_edge(ele.first,ele.second, prop, g); 

इस खंड क्या ग्राफ प्रिंट प्रारूप डॉट है।

ofstream dot("graph.dot"); 
write_graphviz(dot, g, 
    boost::make_label_writer(boost::get(&vert::name, g)), 
    boost::make_label_writer(boost::get(&edge::weight, g)), 
    boost::make_label_writer(boost::get(&edge::capacity, g))); 

त्रुटि है:

/usr/include/boost/graph/graphviz.hpp: In function ‘void boost::write_graphviz(std::ostream&, const Graph&, VertexPropertiesWriter, EdgePropertiesWriter, GraphPropertiesWriter, VertexID) [with Graph = boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, vert, edge, boost::no_property, boost::listS>, VertexPropertiesWriter = boost::label_writer<boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, vert, edge, boost::no_property, boost::listS>, long unsigned int, vert, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, EdgePropertiesWriter = boost::label_writer<boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, vert, edge, boost::no_property, boost::listS>, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, edge, int> >, GraphPropertiesWriter = boost::label_writer<boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, vert, edge, boost::no_property, boost::listS>, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, edge, int> >, VertexID = boost::vec_adj_list_vertex_id_map<boost::property<boost::vertex_bundle_t, vert, boost::no_property>, long unsigned int>]’: 
/usr/include/boost/graph/graphviz.hpp:260: instantiated from ‘void boost::write_graphviz(std::ostream&, const Graph&, VertexPropertiesWriter, EdgePropertiesWriter, GraphPropertiesWriter) [with Graph = Graph, VertexPropertiesWriter = boost::label_writer<boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, vert, edge, boost::no_property, boost::listS>, long unsigned int, vert, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, EdgePropertiesWriter = boost::label_writer<boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, vert, edge, boost::no_property, boost::listS>, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, edge, int> >, GraphPropertiesWriter = boost::label_writer<boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, vert, edge, boost::no_property, boost::listS>, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, edge, int> >]’ 
file_format.cc:194: instantiated from here 
/usr/include/boost/graph/graphviz.hpp:236: error: no match for call to ‘(boost::label_writer<boost::bundle_property_map<boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, vert, edge, boost::no_property, boost::listS>, boost::detail::edge_desc_impl<boost::undirected_tag, long unsigned int>, edge, int> >) (std::basic_ostream<char, std::char_traits<char> >&)’ 

यह मेरे लिए अजीब है क्योंकि इस काम करता है:

write_graphviz(dot, g, 
    boost::make_label_writer(boost::get(&vert_info::name, g))); 

और आउटपुट निम्नलिखित:

graph G { 
0[label="0"]; 
1[label="1"]; 
2[label="2"]; 
3[label="3"]; 
4[label="4"]; 
5[label="5"]; 
6[label="6"]; 
7[label="7"]; 
8[label="8"]; 
9[label=""]; // this is another problem that I will have to fix but beside the point 
0--9 ; 
0--5 ; 
0--2 ; 
0--1 ; 
... 
... 
} 

मेरा लक्ष्य है प्रत्येक नोड लेबल, और प्रत्येक किनारे प्रयोगशाला है इसकी क्षमता और वजन के साथ चिल्लाया।

उत्तर

11

के लिए सभी ओवरलोड की सूची आप here पा सकते हैं। आपकी पहली त्रुटि का कारण यह है कि आपके द्वारा उपयोग किए जाने वाले अधिभार को ग्राफ़ प्रॉपर्टी लेखक को अपने पांचवें तर्क में उम्मीद है।

सहायक समारोह make_label_writer बस एक संपत्ति लेखक है कि या तो एक शीर्ष या एक Graphviz शिखर या किनारे विशेषता label नामित करने के लिए अपने ग्राफ के एक किनारे से केवल एक प्रॉपर्टी प्रदान करती है बनाता है।

जो आप चाहते हैं उसे प्राप्त करने के लिए आपको एक कस्टम property writer बनाने की आवश्यकता है जिसमें आप अपनी प्रत्येक किनारों को graphviz attributes पर निर्दिष्ट करते हैं। मैं व्यक्तिगत रूप से weight ->label और capacity ->taillabel या headlabel का उपयोग करता हूं।

template <class WeightMap,class CapacityMap> 
class edge_writer { 
public: 
    edge_writer(WeightMap w, CapacityMap c) : wm(w),cm(c) {} 
    template <class Edge> 
    void operator()(ostream &out, const Edge& e) const { 
    out << "[label=\"" << wm[e] << "\", taillabel=\"" << cm[e] << "\"]"; 
    } 
private: 
    WeightMap wm; 
    CapacityMap cm; 
}; 

template <class WeightMap, class CapacityMap> 
inline edge_writer<WeightMap,CapacityMap> 
make_edge_writer(WeightMap w,CapacityMap c) { 
    return edge_writer<WeightMap,CapacityMap>(w,c); 
} 

और अंत में अपने write_graphviz मंगलाचरण बस होगा:

ofstream dot("graph.dot"); 
write_graphviz(dot, g, 
    boost::make_label_writer(boost::get(&vert::name, g)), 
    make_edge_writer(boost::get(&edge::weight,g),boost::get(&edge::capacity,g))); 
+0

धन्यवाद, कि एक आकर्षण की तरह काम किया। – Jim

संबंधित मुद्दे

 संबंधित मुद्दे