{"id":19159495,"url":"https://github.com/creisle/pq-trees","last_synced_at":"2026-07-21T16:05:27.884Z","repository":{"id":17456527,"uuid":"20230486","full_name":"creisle/pq-trees","owner":"creisle","description":null,"archived":false,"fork":false,"pushed_at":"2015-12-27T19:36:59.000Z","size":318,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-03T21:13:53.637Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/creisle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-27T18:24:10.000Z","updated_at":"2023-10-11T05:56:25.000Z","dependencies_parsed_at":"2022-09-18T06:54:06.532Z","dependency_job_id":null,"html_url":"https://github.com/creisle/pq-trees","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creisle%2Fpq-trees","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creisle%2Fpq-trees/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creisle%2Fpq-trees/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creisle%2Fpq-trees/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/creisle","download_url":"https://codeload.github.com/creisle/pq-trees/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240245029,"owners_count":19770907,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T08:49:22.125Z","updated_at":"2025-09-19T05:07:31.919Z","avatar_url":"https://github.com/creisle.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"#PQ-Trees\n\nThis is an implementation of Booth and Leuker's (1) PQTree datastructure as described by Young (2). It should be noted that while the rules outlined for the PQTree trees were followed a large degree of creativity was used in implementing them\n\n##What is a PQ Tree?\n\nA PQ-Tree is a datastructure used in representing all permutations allowed on a given base set, U. The members of the base set are the leaves in the tree and the q-nodes and p-nodes are used in representing the different constraints we wish to apply. children of a p-node must be grouped under that node but their child elements may be permuted randomly with respect to one another. The q-node is more restrictive. Child elements of a q-node may only be reversed.\n\nPQTRee Expressions:\n\n    pnode   - { }\n    qnode   - [ ]\n    leaf    - any integer\n\n![Alt text](tree_example.jpg \"PQTree example\")\n\n**Figure 1. Example PQTree. Can be represented by the expression: { 5 1 3 [ 3 {2 4 } [ { 4 5 } 6 2 ] ] }**\n    \n###PQTree class\n\n####PQTree()\n\n    default constructor\n    \n####PQTree(string const)\n\n    non-default constructor. Initializes the PQTree from a valid PQTree expression\n\n####PQTree(vector\\\u003cint\u003e)\n\n    non-default constructor. Initializes the PQTree with a universal tree based on the \n    set of values in the input vector\n####string print_expression(bool)\n\n    return an expression string corresponding to the current tree structure\n####list\u003cint\u003e reduce\\_and_replace(int, vector\\\u003cint\u003e)\n\n    performs reductions on the tree based on the input vector. after reduction. replaces \n    the full leaves with the new universal tree that was built from the input vector. \n    returns an empty list if the tree is irreducible. Otherwise, the list returned is the \n    list of sources for the replaced full nodes which will be useful in producing the \n    embedding after testing planarity\n####bool set\\_consecutive(vector\\\u003cint\u003e)\n\n    Performs reductions on the tree based on the input vector. does not add or remove any \n    leaves from the tree\n    returns false if the tree is irreducible\n####bool equivalent(PQTree\u0026)\n\n    Compares two trees to see if they are equivalent. Trees are equivalent if they impose \n    the same set of restaints. returns true if the trees are equivalent, false otherwise\n\n##How to use this implementation?\n####Example: Testing Planarity of an st-numbered input graph from the adjacnecy list\n\n![Alt text](st_graph_ex.jpg \"st_graph\")\n\n    //adjacency matrix of an st-numbered input graph\n    std::vector\u003c std::vector\u003cint\u003e \u003e adj2 =\n    {\n        {2, 3, 10}, //1\n        {3, 6, 8},  //2\n        {4, 10},    //3\n        {5, 6, 10}, //4\n        {6, 9},     //5\n        {7, 9},     //6\n        {8, 9},     //7\n        {9},        //8\n        {10},       //9\n    };\n        \n    PQTree tree2(adj2[0], 1);\n        \n    for(size_t i=1; i\u003cadj2.size(); i++)\n    {\n        int curr = (int)(i+1);\n        std::vector\u003cint\u003e v = adj2[i];\n        std::list\u003cint\u003e srcs = tree2.reduce_and_replace(curr, v); //this is the lists we will use to produce the embedding\n        \n        if(srcs.empty())\n        {\n            fprintf(stderr, \"error in building the and reducing the tree\\n\");\n            return false;\n        }\n    }\n    return true;\n        \n####Example: Testing Consecutive ones \n\n    std::vector\u003c std::vector\u003cint\u003e \u003e mat =\n    {\n        {2, 3, 4}, //values that are one in our matrix\n        {1, 2, 3},\n        {4, 5},\n        {2, 3},\n        {3, 4},\n        {1},\n        {5}\n    };\n    PQTree tree(\"{1, 2, 3, 4, 5}\");\n        \n    for(size_t i=0; i\u003cmat.size(); ++i)\n    {\n        if(!tree.set_consecutive(mat[i]))\n        {\n            return false;\n        }\n    }\n    return true;\n\n##File structure and class dependency\n![Alt text](dependencies.jpg \"class dependency\")\n\n**Figure 2. Parent Node class of Leaf and PQnode is abstract, a namespace custom is declared within the PQnode file which contains mainly testing and utility functions or custom string comparision functions. The testing file PQTree tests is dependant on the externally linked library CppUnit ( http://cppunit.sourceforge.net/doc/lastest/index.html )**\n\nTo use the PQTree implementation you only need to #include the PQTree.h header file\n\n##References:\n\n1. Booth, K.S., Lueker, G.S.: Testing for the consecutive ones property, interval graphs, and graph planarity using PQ-tree algorithms. J. Comput. Syst. Sci. 13, 335–379 (1976).\n2. Young, S.M.: Implementation of PQ-tree algorithms, (1977).\n\n##Notes:\n\n1. This software is distributed without any warranty or guarantee and is currently in development. If you come across any bugs or errors be sure to let me know :)\n2. The provided makefile is for unix/linux and compiles with the testing script and you must have cppunit installed for this to work. \n3. This uses C++11. So be sure to use the approriate flags when compiling with your own project\n4. There are some GCC warnings turned off with pre-processor statments in the header files ( i.e. for padding structures and c++11 specific features). Just delete the #pragma lines to turn these back on\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreisle%2Fpq-trees","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcreisle%2Fpq-trees","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreisle%2Fpq-trees/lists"}