【发布时间】:2018-05-11 13:41:23
【问题描述】:
我正在尝试修改无向图中的特定顶点。本质上,我希望能够从 18 的索引 1 开始,并运行一个算法来从该顶点更改每个节点的字符串。我从点文件中读取图表。我正在查看boost's website 的捆绑属性,它看起来很简单。但是,当我尝试实现这一点时,我得到Attempt to put a value into a const property map: Aborted (core dumped) 错误。所以我找到了this solution,它看起来和我的一模一样。
这是引发错误的一个最小示例:
我从 test.dot 读取的文件:
graph G {
0 [isLeaf=1];
1 [isLeaf=0];
2 [isLeaf=1];
3 [isLeaf=1];
4 [isLeaf=0];
5 [isLeaf=1];
6 [isLeaf=0];
7 [isLeaf=1];
8 [isLeaf=0];
9 [isLeaf=1];
1--3 [time=3.41843];
1--4 [time=1.01826];
4--5 [time=4.2496];
2--6 [time=5.59155];
1--6 [time=9.48199];
6--7 [time=7.72868];
0--8 [time=7.38977];
4--8 [time=6.55225];
8--9 [time=0.0406912];
}
我正在运行的代码:
#include <iostream>
#include <string>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/graphviz.hpp>
#include <boost/property_map/dynamic_property_map.hpp>
#include <boost/graph/graph_utility.hpp>
struct Vertex
{
bool isLeaf;
std::string taxon;
};
typedef boost::property<boost::edge_weight_t, double> Edge;
typedef boost::adjacency_list<boost::vecS,boost::vecS, boost::undirectedS, Vertex, Edge> Graph;
int main()
{
Graph g;
boost::property_map<Graph, boost::edge_weight_t>::type weight = get(boost::edge_weight,g);
boost::dynamic_properties dp;
dp.property("node_id", get(boost::vertex_index, g));
dp.property("isLeaf", get(&Vertex::isLeaf, g));
dp.property("time", weight);
std::string blah = "Hello";
std::ifstream dot("test.dot");
boost::read_graphviz(dot,g,dp);
g[1].taxon = blah;
}
这个错误的原因是什么?
【问题讨论】: