//---------------------------------------------------------------------------- // void HypGraph::newGraph(istream & g) //............................................................................ // //---------------------------------------------------------------------------- void HypGraph::newGraph(istream & g) { // toss old data int i; if (nodetable.size() > 0) nodetable.erase(nodetable.begin(),nodetable.end()); if (linktable.size() > 0) linktable.erase(linktable.begin(),linktable.end()); for ( i = 0; i < nodes.size(); i++) { delete nodes[i]; } for ( i = 0; i < links.size(); i++) { delete links[i]; } nodes.erase(nodes.begin(),nodes.end()); links.erase(links.begin(),links.end()); initPos.identity(); hd->centerindex = -1; loadSpanGraph(g); treeroot = nodes[0]; HypNode *treestart = nodes[hd->centerindex]; if (!treestart) treestart = treeroot; doLayout(treestart); if (debug) { string savestr = saveTree(); FILE *f = fopen("/tmp/hypview", "w"); if (f) { fprintf(f, "%s", (char*)savestr.c_str()); fclose(f); } } return; }
static int findTreeInList (bestlist *bt, tree *tr) { topol *tpl; tpl = bt->byScore[0]; saveTree(tr, tpl); return findInList((void *) tpl, (void **) (& (bt->byTopol[1])), bt->nvalid, cmpTopol); }
static int findTreeInList (bestlist *bt, pllInstance *tr, int numBranches) { topol *tpl; tpl = bt->byScore[0]; saveTree(tr, tpl, numBranches); return findInList((void *) tpl, (void **) (& (bt->byTopol[1])), bt->nvalid, cmpTopol); }
void HypGraph::newGraph(string & rootId, int rootPriority, string & rootGroup) { // toss old data int i; if (nodetable.size() > 0) nodetable.erase(nodetable.begin(),nodetable.end()); if (linktable.size() > 0) linktable.erase(linktable.begin(),linktable.end()); for ( i = 0; i < nodes.size(); i++) { delete nodes[i]; } for ( i = 0; i < links.size(); i++) { delete links[i]; } nodes.erase(nodes.begin(),nodes.end()); links.erase(links.begin(),links.end()); initPos.identity(); hd->centerindex = -1; HypNode *newnode = doAddNode((HypNode *)0,rootId,0,rootPriority); if (newnode) { newnode->setGroup(0,rootGroup); hd->centerindex = 0; } int linkparentindex, linkchildindex; for (i = 0; i < links.size(); i++) { // fprintf(stderr, "link %s\n", (char*)links[i]->getId().c_str()); HypLink *link = links[i]; string par = link->getParentId(); linkparentindex = findUrl(par); if (linkparentindex >= 0) link->setParent(nodes[linkparentindex]); string child = link->getChildId(); linkchildindex = findUrl(child); link->setChild(nodes[linkchildindex]); } for (i = 0; i < nodes.size(); i++) markEnable(nodes[i]); treeroot = nodes[0]; doLayout(treeroot); if (debug) { string savestr = saveTree(); FILE *f = fopen("/tmp/hypview", "w"); if (f) { fprintf(f, "%s", (char*)savestr.c_str()); fclose(f); } } return; }
void saveTree(node * tree, char * Filename) { if (tree == NULL) return; FILE * fptr = fopen(Filename, "a"); if(fptr == NULL) { printf("File loading failed: File does not exist or is empty.\n"); return; } saveTree(TLEFT, Filename); saveTree(TRIGHT, Filename); if (tree->split=='-') fprintf(fptr, "%le %le %le %le\n",tree->width, tree->height, tree->xcoord, tree->ycoord); fclose(fptr); }
void XmlTreeSerializer::saveTreeAsFile(const TreeIterator& treeIterator, const String& fileName, bool unicode, const NumberFormat* numberFormat) { LocalFile::removeIfExists(fileName); BinaryFileBuffer fileBuffer(fileName, false, true); BinaryOutputStream outputStream(fileBuffer); if (unicode == true) { outputStream.setStringEncoding(BinaryStreamEncoding::CHAR16); outputStream << "<?xml version='1.0' encoding='UTF-16' ?>" << newLine; } else { outputStream.setStringEncoding(BinaryStreamEncoding::CHAR8); outputStream << "<?xml version='1.0' encoding='UTF-8' ?>" << newLine; } saveTree(treeIterator, outputStream, 0, numberFormat); fileBuffer.close(); }
bool App::saveFile() { if (noFileOpened) return true; if (currentFile == "" && !noFileOpened) { FileName fn(this, 0, true); if (!fn.exec()) return false; currentFile = fn.FileNameI->text(); } if (!saveTree()) return false; // setCaption("IQNotes :: " + currentFile); setModified(false); return true; }
int main(int argc, char * * argv) { if (argc != 3) { printf("usage: ./proj4 input output\n"); return EXIT_FAILURE; } int index = 0; double x = 0, y=0; // Build binary tree stack * root = loadFile(argv[1], &index); node * head = nodeCreate(root->stackNode->width, root->stackNode->height, root->stackNode->split, root->stackNode->index-1); //= buildTree(root); root = StackPop(root); buildTree(root, head, &head, index); node * tree = NULL; tree = nodeArrange(tree, &head); // Packing clock_t timeStart = clock(); assignCutline(tree); setCoord(tree); clock_t timeEnd = clock(); double packTime = (double) (timeEnd - timeStart) / CLOCKS_PER_SEC; searchNode(tree, &x, &y, 1); //printPostorderFull(tree); //Reset output file and save output FILE * fptr = fopen(argv[2], "w"); saveTree(tree, argv[2]); // Screen dump printf("Preorder: "); printPreorder(tree); printf("\n\nInorder: "); printInorder(tree); printf("\n\nPostorder: "); printPostorder(tree); printf("\n\nWidth: %le", tree->width); printf("\nHeight: %le", tree->height); printf("\n\nX-coordinate: %le", x); printf("\nY-coordinate: %le", y); printf("\n"); // Rerooting box * minBox = malloc(sizeof(box)); minBox->width = tree->width; minBox->height = tree->height; timeStart = clock(); // ------------------------------------ to run cases without rerooting, comment out the following lines while (tree->right->split!='-') { tree = reroot(tree, minBox); decideMin(minBox, tree); //printPostorderFull(tree); } // ------------------------------------ timeEnd = clock(); double rootTime = (double) (timeEnd - timeStart) / CLOCKS_PER_SEC; printf("\nElapsed Time: %le", packTime); printf("\n\nBest width: %le", minBox->width); printf("\nBest height: %le\n", minBox->height); printf("\nElapsed Time for re-routing: %le\n", rootTime); // Free stack while(root!=NULL){ root = StackPop(root); } // Memory management free(root); free(minBox); deleteTree(head); deleteTree(tree); fclose(fptr); return EXIT_SUCCESS; }
void XmlTreeSerializer::saveTree(const TreeIterator& treeIterator, const OutputStream& outputStream, int indent, const NumberFormat* numberFormat) { TreeIterator iterator = treeIterator; if (iterator.hasMetaTag(NON_SERIALIZEABLE) == false) { if (iterator.isAttribute() == true) { iterator.moveToParent(); } indentLine(outputStream, indent); String nodeName = iterator.getName(); if (nodeName.findFirst("::") != String::END) { nodeName.searchAndReplace("::", ":"); } outputStream << '<' << nodeName; bool hasData = false; const int attributeCount = iterator.getAttributeCount(); for (int i = 0; i < attributeCount; ++i) { iterator.moveToAttribute(i); if (iterator.hasMetaTag(NON_SERIALIZEABLE) == false && iterator.isDefaultValue() == false) { if (iterator.getName() == "data") { hasData = true; } else { const String value = iterator.getValue(); const char8 quote = value.findFirst('\'') == String::END ? '\'' : '"'; outputStream << ' ' << iterator.getName() << '=' << quote << value << quote; } } iterator.moveToParent(); } const int childCount = iterator.getChildNodeCount(); if (childCount == 0 && hasData == false) { outputStream << " />" << newLine; } else { outputStream << '>' << newLine; if (hasData == true) { outputStream << iterator.getValueOfAttribute("data"); } for (int i = 0; i < childCount; ++i) { iterator.moveToChildNode(i); saveTree(iterator, outputStream, indent+1, numberFormat); iterator.moveToParent(); } indentLine(outputStream, indent); outputStream << "</" << nodeName << '>' << newLine; } } }