예제 #1
0
        /// <summary>
        /// Copies this instance.
        /// </summary>
        /// <returns>JGGraph.</returns>
        public JGGraph Copy()
        {
            var graph = new JGGraph();

            foreach (JGVertex item in this.Vertices)
            {
                graph.AddVertex(item);
            }
            return(graph);
        }
예제 #2
0
        /// <summary>
        /// Converts the graph to a list of edges.
        /// </summary>
        /// <returns>List&lt;JGEdge&gt;.</returns>
        public List <JGEdge> ToEdges()
        {
            List <JGEdge> edges = new List <JGEdge>();
            JGGraph       g     = this.Copy();

            while (g.Vertices.Count != 0)
            {
                JGVertex v = g.Vertices.FirstOrDefault <JGVertex>();
                foreach (JGVertex item in v.Connections)
                {
                    if (g.Vertices.Contains(item))
                    {
                        edges.Add(new JGEdge(item.Point, v.Point));
                    }
                }
                g.Vertices.Remove(v);
            }
            g = null;

            return(edges);
        }
예제 #3
0
        /// <summary>
        /// Creates a deep copy of this instance.
        /// </summary>
        /// <returns>JGGraph.</returns>
        public JGGraph DeepCopy()
        {
            JGGraph copied = new JGGraph();

            //copying vertices
            foreach (JGVertex item in this.Vertices)
            {
                JGVertex newJGV = new JGVertex(item.Point.Copy());
                copied.AddVertex(newJGV);
            }
            //copying connections
            foreach (JGVertex item in this.Vertices)
            {
                JGVertex current = copied.Find(item.Point);
                foreach (JGVertex connection in item.Connections)
                {
                    JGVertex next = copied.Find(connection.Point);
                    current.AddToConnections(next);
                    next.AddToConnections(current);
                }
            }
            return(copied);
        }