【发布时间】:2014-08-08 04:34:22
【问题描述】:
我有一个这样定义的图表:
struct EdgeInfoProperty{
int score;
//is the trans from v to u, where u<v
Trans trans;
};
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS, boost::no_property, EdgeInfoProperty > Graph;
typedef Graph::edge_descriptor Edge;
typedef Graph::vertex_descriptor Vertex;
我使用write_graphviz 将边 + 分数写入文件(我正在单独编写 Trans,所以我只想在读取点文件时读取分数)。我是这样写的:
auto w_map = boost::get(&EdgeInfoProperty::score, G); // <=== THIS IS THE TRICK!!!
boost::write_graphviz(myfile, G, boost::default_writer(), make_edge_writer(w_map));
我的点文件看起来像:
graph G {
0;
1;
2;
3;
4;
5;
6;
7;
8;
9;
10;
11;
12;
0--1 [label="-3"];
0--5 [label="-2"];
2--3 [label="-8"];
3--8 [label="-4"];
4--5 [label="-1"];
4--6 [label="-6"];
4--7 [label="-5"];
4--8 [label="-10"];
8--9 [label="-9"];
}
所以,我基本上想加载 G,以便在 0--1 等与G[edge].score = -3 等和G[edge].trans = //some default value or whatever 之间有一个边。
我现在拥有的东西给了我大量的编译错误,我正在认真考虑只制作我的图表的纯文本副本,而不是尝试读取点文件然后从那里重新创建图表...
这是我所拥有的:
std::string gn = loc + "MST.dot";
Graph G(0);
boost::dynamic_properties dp;
boost::property_map<Graph, boost::vertex_name_t>::type name = boost::get(boost::vertex_name, G);
dp.property("node_id",name);
auto score = boost::get(&EdgeInfoProperty::score, G);
dp.property("score",score);
std::filebuf fb;
fb.open (gn, std::ios::in);
std::istream isg(&fb);
bool status = boost::read_graphviz(isg,G,dp,"node_id");
我很确定只有分数是个问题,但我尝试获取 EdgeInfoProperty 地图,只是我尝试的所有操作都出错了...
【问题讨论】:
-
我最终制作了一个文本文件并阅读了该文件并使用该信息制作了我的文件,所以我已经解决了我的问题。