2011-04-12 65 views
0

运行Boost.Graph实施例4对于QT给出流错误:Boost.Graph实施例4周的dynamic_properties错误

敌不过调用“(升压:: dynamic_properties的)(标准:: bacic_ostream> &,无符号整型) “graphvic.hpp

在以下行graphvic.hpp发生错误:

for(boost::tie(i,end) = vertices(g); i != end; ++i) { 
     out << escape_dot_string(get(vertex_id, *i)); 
     vpw(out, *i); //print vertex attributes 
     out << ";" << std::endl; 
} 

我无法找出错误的原因。以下是Boost.Graph示例4代码。请帮帮我。

typedef boost::adjacency_list 
    < 
    boost::vecS, 
    boost::vecS, 
    boost::undirectedS, 
    boost::property<boost::vertex_name_t,std::string>, 
    boost::property<boost::edge_weight_t,double>, 
    boost::property<boost::graph_name_t,std::string> 
    > Graph; 

    Graph g; 

    std::vector<std::string> names; 
    names.push_back("Mr_A"); 
    names.push_back("Mrs_B"); 
    names.push_back("Dr_C"); 
    names.push_back("Prof_D"); 

    const Graph::vertex_descriptor v0 = boost::add_vertex(names[0],g); 
    const Graph::vertex_descriptor v1 = boost::add_vertex(names[1],g); 
    const Graph::vertex_descriptor v2 = boost::add_vertex(names[2],g); 
    const Graph::vertex_descriptor v3 = boost::add_vertex(names[3],g); 

    std::vector<double> frequencies; 
    frequencies.push_back(0.9); 
    frequencies.push_back(0.5); 
    frequencies.push_back(0.6); 
    frequencies.push_back(0.1); 

    boost::add_edge(v0,v1,frequencies[0],g); 
    boost::add_edge(v1,v2,frequencies[1],g); 
    boost::add_edge(v2,v3,frequencies[2],g); 
    boost::add_edge(v0,v3,frequencies[3],g); 

    //Writing graph to file 
    { 
    std::ofstream f("test.dot"); 

    boost::dynamic_properties p; 
    p.property("label", boost::get(boost::edge_weight, g)); 
    p.property("weight", boost::get(boost::edge_weight, g)); 
    p.property("node_id", boost::get(boost::vertex_name, g)); 
    boost::write_graphviz(f,g,p); 
    f.close(); 
    } 

感谢, 普拉卡什

回答

0

有非法呼叫的功能get()。第二个参数应该是一个图,而不是一个顶点描述符。另外,你没有指定它是什么vertex_id。可能你的意思是vertext_name_t

+0

感谢您的回复。 基于write_graphviz调用write_graphviz的文档是正确的。 Docs说: write_graphviz(std :: ostream&out,const VertexAndEdgeListGraph&g, VertexPropertyWriter vpw); \t \t \t 所以调用write_graphviz(f,g,p)是正确的。 \t 关于vertex_id,它已经在graphvic.hpp中。我没有触及那部分,我在运行示例代码时发现了错误 ,并且在graphvic.hpp中出现了错误代码。 – 2011-04-12 11:41:24

1

您可以将write_graphviz更改为write_graphviz_dp并再试一次,它应该可以工作,但是,我不知道底下的故事。有人可以提供一些解释吗?