示例#1
0
文件: Tree.cs 项目: ciavy/ProjectONE
        private void edgesToXML(XmlWriter writer, Vertex curvertex)
        {
            if (curvertex == null)
                return;

            if (curvertex.OutgoingEdges == null || curvertex.OutgoingEdges.Count == 0)
                return;

            foreach (Edge e in curvertex.OutgoingEdges)
            {
                writer.WriteStartElement("Edge");
                writer.WriteElementString("Name", e.Name.ToString());
                writer.WriteStartElement("Attributes");
                foreach (Attribute a in e.Attributes)
                {
                    writer.WriteElementString(a.Name,
                        a.type == Attribute.AttributeType.STRING ?
                        a.value_string : a.value_int.ToString());
                }
                writer.WriteEndElement(); //Attributes
                this.vertexToXML(writer, e.Bottom);
                writer.WriteEndElement(); //Vertex
                writer.WriteEndElement(); //Edge
            }
        }
示例#2
0
文件: Tree.cs 项目: ciavy/ProjectONE
 /// <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 || stack.Count != 0; l++)
     {
         if (stack.Count != 0 && 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;
 }
示例#3
0
文件: Tree.cs 项目: ciavy/ProjectONE
        /// <summary>
        /// Prints the cur vertex to XML
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="cur">node to be printed</param>
        private void vertexToXML(XmlWriter writer, Vertex cur)
        {
            if (this.root == null)
                return;

            writer.WriteStartElement("Vertex");
            writer.WriteElementString("Name", cur.Name.ToString());
            writer.WriteElementString("Depth", cur.Level.ToString());
            writer.WriteStartElement("Attributes");
            foreach (Attribute a in cur.Attributes)
            {
                writer.WriteElementString(a.Name,
                    a.type == Attribute.AttributeType.STRING ?
                    a.value_string : a.value_int.ToString());
            }
            writer.WriteEndElement(); //Attributes
        }
示例#4
0
文件: Edge.cs 项目: ciavy/ProjectONE
 public Edge(int name, Vertex top, Vertex btm, Attribute attr) : this(name, top, btm)
 {
     Attributes = new LinkedList<Attribute>();
     Attributes.AddLast(attr);
 }
示例#5
0
文件: Edge.cs 项目: ciavy/ProjectONE
 public Edge(int name, Vertex top, Vertex btm, LinkedList<Attribute> attr) : this(name, top, btm)
 {
     this.Attributes = attr;
 }
示例#6
0
文件: Edge.cs 项目: ciavy/ProjectONE
 public Edge(int name, Vertex top, Vertex bottom)
 {
     this.Name = "edge" + name;
     this.Top = top;
     this.Bottom = bottom;
 }