Ejemplo n.º 1
0
 /// <summary>
 /// Generates a random tree with a given splitsize, depth and list of attributes for either vertexes and for edges.
 /// </summary>
 /// <param name="EdgeAttributes">List of attributes of each edge in the future tree</param>
 /// <param name="VertexAttributes">List of attributes of each vertex in the future tree</param>
 /// <returns>a random tree</returns>
 public static Tree getRandomTree(int Depth, int SplitSize, LinkedList<Attribute> VertexAttributes, LinkedList<Attribute> EdgeAttributes)
 { //generate per level: each Vertex gets its childs
     //Console.WriteLine("depth: " + Depth + "; splitsize: " + SplitSize);
     Tree tree = new Tree(SplitSize, Depth, VertexAttributes, EdgeAttributes);
     Vertex root = new Vertex(1, GetRandomAttributes(true, VertexAttributes, EdgeAttributes).ToArray());
     tree.root = root;
     Queue<Vertex> stack = new Queue<Vertex>();
     stack.Enqueue(tree.root);
     Vertex curVertex;
     int n = 2;
     for (int l = 1; l < Depth; l++)
     {
         curVertex = stack.Dequeue();
         //Console.WriteLine("curVertex:" + curVertex);
         for (int s = 0; s < SplitSize; s++)
         {
             Vertex childVertex = new Vertex(n++, GetRandomAttributes(true, VertexAttributes, EdgeAttributes).ToArray(), new LinkedList<Edge>(), l);
             if (l != Depth - 1)
             {
                 stack.Enqueue(childVertex);
                 //Console.WriteLine("childVx: " + childVertex.ToString());
             }
             curVertex.append(new Edge(n, curVertex, childVertex, GetRandomAttributes(false, VertexAttributes, EdgeAttributes)));
         }
     }
     return tree;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Counts Vertexs in this tree. For test
        /// </summary>
        /// <returns></returns>
        public int countVertexs()
        {
            int n = 1;
            if (root.OutgoingEdges == null)
                return n;

            foreach (Edge e in root.OutgoingEdges)
            {
                Tree subtree = new Tree(SplitSize, Depth - 1, VertexAttributes, EdgeAttributes);
                subtree.root = e.Bottom;
                n += subtree.countVertexs();
            }
            return n;
        }
Ejemplo n.º 3
0
 private void generateTree(XmlWriter writer)
 {
     Tree subtree = new Tree(SplitSize, Depth, VertexAttributes, EdgeAttributes);
     subtree.root = e.Bottom;
     subtree.generateTree(writer, true);
 }
Ejemplo n.º 4
0
        private void generateTree(XmlWriter writer, bool first)
        {
            if (this.root == null)
                return;

            if (this.root.OutgoingEdges == null)
                return;

            //Prima esecuzione
            if (first)
            {
                this.vertexToXML(writer, this.root);
            }
            else {

                //Seconda esecuzione
                for (int i = 0; i < this.splitsize; i++)
                {
                    for (int j = 0; j < this.depth; j++)
                    {
                        this.edgesToXML(writer, this.root);
                        this.vertexToXML(writer, this.root);
                    }
                }

                for (int i = 0; i < this.splitSize; i++)
                {
                    for (int j = 0; j < this.depth; j++)
                    {
                        writer.WriteEndElement(); //Vertex
                    }
                }
            }

            writer.WriteEndElement(); //Vertex

            foreach (Edge e in this.root.OutgoingEdges)
            {
                Tree subtree = new Tree(SplitSize, Depth - 1, VertexAttributes, EdgeAttributes);
                subtree.root = e.Bottom;
                subtree.generateTree(writer, first);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Writes the xml with vertexes printed in preorder
        /// </summary>
        /// <param name="writer"></param>
        private void preorderXML_vertexes(XmlWriter writer)
        {
            if (this.root == null)
                return;

            if (this.root.OutgoingEdges == null)
                return;

            this.vertexToXML(writer, this.root);
            this.edgesToXML(writer, this.root);
            writer.WriteEndElement(); //Vertex

            foreach (Edge e in this.root.OutgoingEdges)
            {
                Tree subtree = new Tree(SplitSize, Depth - 1, VertexAttributes, EdgeAttributes);
                subtree.root = e.Bottom;
                subtree.preorderXML_vertexes(writer);
            }
        }