首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在OGDF中用GraphCopy::initByCC维护GraphAttributes

在OGDF中用GraphCopy::initByCC维护GraphAttributes
EN

Stack Overflow用户
提问于 2016-06-09 14:17:31
回答 1查看 212关注 0票数 1

我试图使用OGDF对从GML文件加载的图形执行一些处理。这些图只有在保持节点标签的情况下才有意义。不幸的是,OGDF无法轻松地保留节点属性(如标签),因为它们是在一个称为GraphAttributes的单独数据结构中维护的。我的问题是,GraphAttributes将节点标签与节点索引关联起来,这些索引不是由我需要使用的一些图转换来维护的。

我需要对图执行的转换之一是将GML文件中的每个连通子图分开。加载图形及其节点标签很简单:

代码语言:javascript
复制
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实例。

代码语言:javascript
复制
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对象执行相同的转换,以便为复制的连接子图中的节点获取正确的标签?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-09 21:28:12

事实证明,这并不像我想的那么困难。我遗漏的关键部分是,您可以使用GraphCopy::original方法从原始图中获取索引节点,然后使用该节点获取标签。

代码语言:javascript
复制
// get the correct label for the first node of the GraphCopy object copy
attributes.label(copy.original(copy.firstNode()));
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37728544

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档