我刚刚开始使用 OGDF,并尝试通过运行 OGDF 网页上 How-Tos 下的一些示例来掌握它。我的代码可以编译,但是当我尝试在节点上调用 GraphAttributes 函数时会出现段错误。
这是我的代码:
ogdf::Graph G;
ogdf::GraphAttributes GA(G);
if (!ogdf::GraphIO::readGML(G, "sierpinski_04.gml") ) {
std::cerr << "Could not load sierpinski_04.gml" << std::endl;
return 1;
}
ogdf::node v;
GA.setAllHeight(10.0);
GA.setAllWidth(10.0);
ogdf::FMMMLayout fmmm;
fmmm.useHighLevelOptions(true);
fmmm.unitEdgeLength(15.0);
fmmm.newInitialPlacement(true);
//fmmm.qualityVersusSpeed(ogdf::FMMMLayout::qvsGorgeousAndEfficient);
fmmm.call(GA);
ogdf::GraphIO::writeGML(GA, "sierpinski_04-layout.gml");
for(v=G.firstNode(); v; v=v->succ()) {
std::cout << v << std::endl;
//the following line causes the segfault
double xCoord = GA.x(v);
}
如果我注释掉我在评论中提到的导致段错误的行,则程序运行良好而没有段错误。如果我然后查看写出的 .gml 文件,则节点具有 x 和 y 坐标。我收到以下消息:
MT: /home/work/lib/OGDF-snapshot/include/ogdf/basic/NodeArray.h:174: T& ogdf::NodeArray<T>::operator[](ogdf::node) [with T = double; ogdf::node = ogdf::NodeElement*]: Assertion `v->graphOf() == m_pGraph' failed.
当我在 GraphAttributes 上调用不同的函数时也会发生这种情况,例如 .idNode(v)。
有人可以指出我正确的方向,为什么会发生这种情况?我现在完全不明白这是从哪里来的,而且 OGDF 太大了,无法浏览代码并理解它。(至少对我来说)
非常感谢您!