使用OGDF我已經創建和初始化一個PQTree。初始化用3條邊完成,其中節點a是根,b,c和d是a的葉。現在,經過計算,我需要將葉子e,d和f添加爲b作爲葉子。但問題是,b是一片葉子,所以既不接受孩子也不接受葉子。代碼在這裏。作爲std :: cout,我已經知道它們是被添加的,但是如果使用writeGML將它寫入GML文件,添加節點之前和之後沒有區別,它們不在樹中。我認爲,這是因爲PQLeafKey,對於非葉邊/節點,它應該是PQNodeKey。根據該文件,ablk-> nodePointer()應返回PQLeaf,它從PQNode衍生和不與PQInternelNode,這也衍生PQNode「兼容」。但我不知道,如何以不同的方式添加。代碼:OGDF PQTree:如何添加葉子?
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");