Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/creisle/pq-trees


https://github.com/creisle/pq-trees

Last synced: 7 days ago
JSON representation

Awesome Lists containing this project

README

        

#PQ-Trees

This 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

##What is a PQ Tree?

A 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.

PQTRee Expressions:

pnode - { }
qnode - [ ]
leaf - any integer

![Alt text](tree_example.jpg "PQTree example")

**Figure 1. Example PQTree. Can be represented by the expression: { 5 1 3 [ 3 {2 4 } [ { 4 5 } 6 2 ] ] }**

###PQTree class

####PQTree()

default constructor

####PQTree(string const)

non-default constructor. Initializes the PQTree from a valid PQTree expression

####PQTree(vector\)

non-default constructor. Initializes the PQTree with a universal tree based on the
set of values in the input vector
####string print_expression(bool)

return an expression string corresponding to the current tree structure
####list reduce\_and_replace(int, vector\)

performs reductions on the tree based on the input vector. after reduction. replaces
the full leaves with the new universal tree that was built from the input vector.
returns an empty list if the tree is irreducible. Otherwise, the list returned is the
list of sources for the replaced full nodes which will be useful in producing the
embedding after testing planarity
####bool set\_consecutive(vector\)

Performs reductions on the tree based on the input vector. does not add or remove any
leaves from the tree
returns false if the tree is irreducible
####bool equivalent(PQTree&)

Compares two trees to see if they are equivalent. Trees are equivalent if they impose
the same set of restaints. returns true if the trees are equivalent, false otherwise

##How to use this implementation?
####Example: Testing Planarity of an st-numbered input graph from the adjacnecy list

![Alt text](st_graph_ex.jpg "st_graph")

//adjacency matrix of an st-numbered input graph
std::vector< std::vector > adj2 =
{
{2, 3, 10}, //1
{3, 6, 8}, //2
{4, 10}, //3
{5, 6, 10}, //4
{6, 9}, //5
{7, 9}, //6
{8, 9}, //7
{9}, //8
{10}, //9
};

PQTree tree2(adj2[0], 1);

for(size_t i=1; i v = adj2[i];
std::list srcs = tree2.reduce_and_replace(curr, v); //this is the lists we will use to produce the embedding

if(srcs.empty())
{
fprintf(stderr, "error in building the and reducing the tree\n");
return false;
}
}
return true;

####Example: Testing Consecutive ones

std::vector< std::vector > mat =
{
{2, 3, 4}, //values that are one in our matrix
{1, 2, 3},
{4, 5},
{2, 3},
{3, 4},
{1},
{5}
};
PQTree tree("{1, 2, 3, 4, 5}");

for(size_t i=0; i