c++ - boost BGL : Edge property maps?

标签 c++ boost

我试图在给定连接边列表的情况下制作一个图,但我的边同时具有分数(权重)和反式(用户定义的数据类型,基本上是从一个点到另一个点的转换矩阵其他)。我已经尝试了很多方法来做到这一点,但我检查过的每个网站(包括 stackoverflow)都有不同的方法来做到这一点,这并不是 100% 适合我的问题。我已经尝试了所有这些,但现在我已经解决了以下问题:

struct EdgeInfoProperty{
    int score;
    Trans trans;
};

typedef boost::adjacency_list<boost::listS, boost::vecS, boost::directedS, boost::no_property, EdgeInfoProperty > mygraph;
typedef mygraph::edge_descriptor Edge;

mygraph G;

for (i..i++){//some is
    for(j..j++){//some js
        boost::graph_traits<mygraph>::vertex_descriptor u, v;
        u = vertex(i, G);
        v = vertex(j, G);
        EdgeInfoProperty property_uv;
        property_uv.score=s[i]+s[j];//some score
        property_uv.trans = T[i]*T[j];
        boost::add_edge(u,v,property_uv,G);
    }
}

但是据我所知,从大多数网站上可以看出,仅声明一个结构是不够的...

确实,现在当我尝试打印我的图表时:

typedef boost::property_map<mygraph, boost::vertex_index_t>::type IndexMap;
IndexMap index = get(boost::vertex_index, G);

std::cout << "vertices(g) = ";
typedef boost::graph_traits<mygraph>::vertex_iterator vertex_iter;
std::pair<vertex_iter, vertex_iter> vp;
for (vp = boost::vertices(G); vp.first != vp.second; ++vp.first)
    std::cout << index[*vp.first] <<  " ";
std::cout << std::endl;

std::cout << "edges(g) = ";
boost::graph_traits<mygraph>::edge_iterator ei, ei_end;
for (boost::tie(ei, ei_end) = edges(G); ei != ei_end; ++ei)
    //----- how do I get the edge property?
    //EdgeInfoProperty prop = boost::get(EdgeInfoProperty, *ei);
    std::cout << "(" << index[source(*ei, G)]<< "," << index[target(*ei, G)] << ") ";

当我尝试获取 EdgeInfoProperty Prop 以便最终打印出 prop.score 时,我得到了

error C2275: 'ConnGraph::MakeKinectGraph::EdgeInfoProperty' : illegal use of this type as an expression

帮助。这是一个研究项目,如果我不能超越这个,我将无法进入更有趣的部分......

最佳答案

使用这个:

G[*ei].score
G[*ei].trans

关于c++ - boost BGL : Edge property maps?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25111393/

相关文章:

c++ - Boost C++ 库是否支持 Sparc 上的 Solaris?

Python 导入使用 Boost Python 构建的共享对象获得了 SegFault

c++ - DLL 注入(inject) : DrawText and TextOut doesn't return all text

c++ - 我们如何在 C++ 中使用 while 循环添加前 10 个整数

c++ - boost 日志 : Interaction of log settings file and code configuration

c++ - 在 ‘)’ token C++ 之前预期为 ‘&’

c++ - Poco HTTPClientSession 将 header 添加到 HTTPRequest

c++ - 将数组转换为编码字符串

c++ - 将 std::stringstream 数据高效解析为 std::vector<std::vector<double>>

c++ - 如何将websocket客户端连接到服务器?