【发布时间】:2014-09-23 12:34:36
【问题描述】:
我是新手。我想知道为什么以下代码中的编译失败。我正在创建一组顶点,并尝试分配我自己的顶点索引和顶点名称。 (我在关注这个页面:http://fireflyblue.blogspot.com/2008/01/boost-graph-library.html。)
我知道Boost 中的vertS 顶点列表不需要显式创建顶点ID,我还在Stackoverflow (how provide a vertex_index property for my graph) 中看到了这个非常相关的问题,该问题讨论了如何使用associative_property_map 进行分配顶点索引。以下虽然 - 获取 vertex_index 映射,并分配键值对 - 似乎是一件相当简单的事情,我想了解它为什么会失败。任何帮助是极大的赞赏!
编译错误如下:
error: expression is not assignable
vertIndx[v] = i;
//Define graph
typedef boost::property<boost::vertex_name_t, std::string> sv_namePty;
typedef boost::property<boost::vertex_index_t, int, sv_namePty > sv_indx_n_name_pty;
typedef boost::property<boost::edge_weight_t, int> se_weightPty;
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
sv_indx_n_name_pty, se_weightPty> ScafGraph;
//descriptors
typedef boost::graph_traits<ScafGraph>::vertex_descriptor SV;
typedef boost::graph_traits<ScafGraph>::edge_descriptor SE;
//Graph Object
ScafGraph SG;
//property accessors
boost::property_map<ScafGraph,
boost::vertex_name_t>::type vertName = boost::get(boost::vertex_name, SG);
boost::property_map<ScafGraph,
boost::vertex_index_t>::type vertIndx = boost::get(boost::vertex_index, SG);
boost::property_map<ScafGraph,
boost::edge_weight_t>::type edgeWeight = boost::get(boost::edge_weight, SG);
//Populate Graph
std::vector<SV> svlist;
for(int i=0; i<4; i++) {
SV v = boost::add_vertex(SG);
svlist.push_back(v);
vertName[v] = std::to_string(i);
vertIndx[v] = i;
}
【问题讨论】:
-
物业地图神秘且难以使用。强烈建议您改用捆绑属性 - 它们更容易和直观。 boost.org/doc/libs/1_55_0/libs/graph/doc/bundles.html
-
根据您的评论,我刚刚开始研究它;谢谢!它确实看起来更易于管理!
标签: c++ boost graph boost-graph