OGDF pqtree:如何添加叶子

OGDF PQTree: How to add leaves?

本文关键字:添加 叶子 何添加 pqtree OGDF      更新时间:2023-10-16

使用我创建并初始化了pqtree的ogdf。初始化是用3个边缘完成的,其中节点A为根,B,C和D是A的叶子。现在,计算后,我需要将叶子E,d和f添加到B中。但是问题是,b是一片叶子,因此既不接受孩子,也不接受叶子。代码在这里。当std :: cout时,我已经添加了它们,但是如果我使用trientgml将其写入GML文件,则在添加节点之前和之后没有区别,它们不在树上。我认为,这是因为pqleafkey,对于非叶边/节点,应该是pqnodekey。根据文档,Ablk-> nodepointer()应返回pqleaf,该PQLEAF从PQNode派生,并且与PQInternElnode不兼容,该PQinternElNode也会派生PQNode。但是我不知道,如何以不同的方式添加。代码:

G = new Graph();
GA = new GraphAttributes(*G, GraphAttributes::nodeGraphics |
                         GraphAttributes::edgeGraphics |
                         GraphAttributes::nodeStyle |
                         GraphAttributes::nodeId |
                         GraphAttributes::edgeType |
                         GraphAttributes::edgeArrow |
                         GraphAttributes::edgeStyle);
node a = G->newNode();
node b = G->newNode();
node c = G->newNode();
node d = G->newNode();
edge ab = G->newEdge(a, b);
edge ac = G->newEdge(a, c);
edge ad = G->newEdge(a, d);
PQLeafKey<edge, IndInfo *, bool> *ablk = new PQLeafKey<edge, IndInfo *, bool>(ab);
PQLeafKey<edge, IndInfo *, bool> *aclk = new PQLeafKey<edge, IndInfo *, bool>(ac);
PQLeafKey<edge, IndInfo *, bool> *adlk = new PQLeafKey<edge, IndInfo *, bool>(ad);
SListPure<PQLeafKey<edge, IndInfo *, bool> *> *lkl = new SListPure<PQLeafKey<edge, IndInfo *, bool> *>();
lkl->pushBack(ablk);
lkl->pushBack(aclk);
lkl->pushBack(adlk);
pqtree = new PQTree<edge, IndInfo *, bool>();
pqtree->Initialize(*lkl);
pqtree->writeGML("/home/LPT/graph_qtree_MOC_after_initialization.gml");
node e = G->newNode();
node f = G->newNode();
node g = G->newNode();
edge be = G->newEdge(b, e);
edge bf = G->newEdge(b, f);
edge bg = G->newEdge(b, g);
PQLeafKey<edge, IndInfo *, bool> *belk = new PQLeafKey<edge, IndInfo *, bool>(be);
PQLeafKey<edge, IndInfo *, bool> *bflk = new PQLeafKey<edge, IndInfo *, bool>(bf);
PQLeafKey<edge, IndInfo *, bool> *bglk = new PQLeafKey<edge, IndInfo *, bool>(bg);
SListPure<PQLeafKey<edge, IndInfo *, bool> *> *lkl4 = new SListPure<PQLeafKey<edge, IndInfo *, bool> *>();
lkl4->pushBack(belk);
lkl4->pushBack(bflk);
lkl4->pushBack(bglk);
PQInternalNode<edge, IndInfo *, bool> *father = (PQInternalNode<edge, IndInfo *, bool> *) (ablk->nodePointer());
father->type(PQNodeRoot::PNode);
bool r = pqtree->addNewLeavesToTree(father, *lkl4);
QString res = r ? "done." : "failed.";
std::cout << "Adding leaves to the tree for MOC has " << res.toStdString() << std::endl;
pqtree->writeGML("/home/LPT/graph_qtree_MOC_after_addition_be_bf_bg.gml");

oki,doki,

我做到了,做得很好。抱歉回复晚了。将叶子直接添加到现有的叶子中是无效的。我使用的方法是PQTREE类中的受保护的口气(pqnode *oldnode,pqnode *newnode)。首先,我提取叶子的ID,然后创建一个新的pqinternalnode *newNode,又有其为空的,并且带有提取的ID的p节点。提取和使用相同的ID不是必须的,但是看起来更可读性。将叶子的节点交换到 *newnode会影响叶片中的节点类型,并作弊pqtree以像p节点一样从交换后处理叶子,这又使我可以将新叶子添加到 *newnode中,不再是叶子。