我试图使用OGDF对从GML文件加载的图形执行一些处理。这些图只有在保持节点标签的情况下才有意义。不幸的是,OGDF无法轻松地保留节点属性(如标签),因为它们是在一个称为GraphAttributes的单独数据结构中维护的。我的问题是,GraphAttributes将节点标签与节点索引关联起来,这些索引不是由我需要使用的一些图转换来维护的。
我需要对图执行的转换之一是将GML文件中的每个连通子图分开。加载图形及其节点标签很简单:
ogdf::Graph graph;
ogdf::GraphAttributes attributes(graph, ogdf::GraphAttributes::nodeLabel);
ogdf::GraphIO::readGML(attributes, graph, FILENAME);
// this gives the correct label of the first node in the graph
attributes.label(graph.firstNode());类似地,OGDF提供CCsInfo类来查找图的连通子图。由于我想独立处理这些子图,所以我使用GraphCopy::initByCC方法来创建单独的Graph实例。
ogdf::CCsInfo info(graph);
ogdf::GraphCopy copy(graph);
ogdf::EdgeArray< ogdf::edge > edgeArray(graph);
// where i (int) is the number of the connected subgraph to copy
copy.initByCC(info, i, edgeArray);
// this now gives the wrong label for the first node in copy
attributes.label(copy.firstNode());这是可行的,而且copy只包含连接子图的节点和边。然而,副本中节点的索引与原始图中节点的索引不同。这意味着标签到attributes对象中的节点的映射不适用于copy中的节点。
是否有方法对attributes对象执行相同的转换,以便为复制的连接子图中的节点获取正确的标签?
发布于 2016-06-09 21:28:12
事实证明,这并不像我想的那么困难。我遗漏的关键部分是,您可以使用GraphCopy::original方法从原始图中获取索引节点,然后使用该节点获取标签。
// get the correct label for the first node of the GraphCopy object copy
attributes.label(copy.original(copy.firstNode()));https://stackoverflow.com/questions/37728544
复制相似问题