在OGDF中使用GraphCopy :: initByCC维护GraphAttribute
问题描述:
我正尝试使用OGDF对从GML文件加载的图进行一些处理。这些图仅在维护节点标签时才有意义。不幸的是,OGDF并不容易保留像标签这样的节点属性,因为它们被保存在一个名为GraphAttributes
的独立数据结构中。我的问题是,GraphAttributes
将节点标签与节点索引相关联,这些不是由我需要使用的某些图形转换维护的。在OGDF中使用GraphCopy :: initByCC维护GraphAttribute
我需要在图上执行的转换之一是将每个连接的子图分割成一个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());
This works,and copy
只包含连接子图的节点和边。但是,副本中节点的索引与原始图中节点的索引不同。这意味着将标签映射到attributes
对象中的节点不适用于copy
中的节点。
有没有办法在attributes
对象上执行相同的转换,以便我可以获取复制连接子图中节点的正确标签?
答
事实证明,这并不像我想象的那么困难。我缺少的关键是您可以使用GraphCopy::original
方法从原始图中获取具有索引的节点,然后使用该节点获取标签。
// get the correct label for the first node of the GraphCopy object copy
attributes.label(copy.original(copy.firstNode()));
[tag:gml]标签用于游戏制造商语言,而不是地理标记语言。 – PGmath