任何GraphAttributes函数调用

时间:2017-05-12 22:51:05

标签: c++ graph ogdf

我刚刚开始使用OGDF并尝试通过运行How-Tos下的OGDF网页上的一些示例来解决它。 我的代码编译,但是当我尝试在节点上调用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只需要完成代码并理解它。 (至少对我来说)

非常感谢你!

2 个答案:

答案 0 :(得分:1)

不幸的是,你的问题不容易重现。

我的直觉是在从文件加载Graph之后初始化GraphAttributes。

ogdf::Graph G;
if (!ogdf::GraphIO::readGML(G, "sierpinski_04.gml") ) {
    std::cerr << "Could not load sierpinski_04.gml" << std::endl;
    return 1;
}
ogdf::GraphAttributes GA(G, ogdf::GraphAttributes::nodeGraphics |
                         ogdf::GraphAttributes::nodeStyle |
                         ogdf::GraphAttributes::edgeGraphics );

或者在加载图表后调用initAttributes。

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;
}

GA.initAttributes(ogdf::GraphAttributes::nodeGraphics |
                  ogdf::GraphAttributes::nodeStyle |
                  ogdf::GraphAttributes::edgeGraphics);

希望,这有帮助。

答案 1 :(得分:0)

对我来说,在没有-DOGDF_DEBUG 的情况下构建是可行的。

断言(偶然失败)仅在调试模式下检查。

Graph_d.h:168中:

#ifdef OGDF_DEBUG
    // we store the graph containing this node for debugging purposes
    const Graph *m_pGraph; //!< The graph containg this node (**debug only**).
#endif