在OGDF中使用GraphCopy::initByCC维护GraphAttributes
Maintaining GraphAttributes with GraphCopy::initByCC in OGDF
我正在尝试使用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
对象执行相同的转换,这样我就可以为复制的连接子图中的节点获得正确的标签?
事实证明,这并不像我想象的那么困难。我缺少的关键是,您可以使用GraphCopy::original
方法从原始图中获取带有索引的节点,然后使用该节点获取标签。
// get the correct label for the first node of the GraphCopy object copy
attributes.label(copy.original(copy.firstNode()));
相关文章:
- 如何维护资源管理器项目视图中当前可见的项目列表
- 维护unordered_map但同时每一步都需要最低的映射值
- GCC,CMake,预编译标头和维护依赖项
- Q没有管理权限的 exe 无法启动维护工具
- 是否很好地使用状态模式来维护当前选定的对象?
- 如何维护对 std::p riority_queue 容器的引用?
- 维护/维持两个代码集的风险,一个用于 CPU,一个用于 GPU,需要执行非常相似的功能
- 将Qt应用程序维护为模块和库
- 树不维护递归迭代器成员
- 为多个类实例维护共享_ptr的静态列表
- 如何维护V8上下文以备将来使用
- 多线程和单线程代码维护
- 类内非静态字段初始化 + 对象池 - >降低可维护性/可读性
- 维护对元素参考类型
- C 命名区以维护旧代码
- 修改贝尔曼-福特算法以维护基于成本的有序列表
- 以易于维护的方式实现许多类似的(子)类
- 尝试从成员函数推送时不维护元素的成员向量
- C :模拟键,如果在Windows上按下,请将其维护
- 在OGDF中使用GraphCopy::initByCC维护GraphAttributes