//TODO: Může tam házet vrcholy se stejnejma referencema předělat a je problém s číslováním
        /// <summary>
        /// Create new node in this graph and raise corresponding event 
        /// </summary>
        /// <returns>Reference to the added node</returns>
        public override Vertex addVertex(Vertex v)
        {
            innerVertices.Add(v);

            foreach (var obs in innerVertObs)
            {
                obs.update(v, ChangeType.Added);
            }

            return v;
        }
        /// <summary>
        /// Returns all edges, where our target node is contained.
        /// </summary>
        /// <param name="v">Target node</param>
        /// <returns>Inciden edges</returns>
        public override List<IEdge> incidentEdges(Vertex v)
        {
            List<IEdge> l = new List<IEdge>();

            if (v == null) { return l; }

            foreach (IEdge e in innerEdges)
            {
                if (e.Vertex_1 == v || e.Vertex_2 == v) { l.Add(e); }
            }

            return l;
        }
        /// <summary>
        /// Create new edge between two nodes. If the same edge is already contained in this graph, new edge isn't created.
        /// </summary>
        /// <param name="v1">Starting node</param>
        /// <param name="v2">Ending node</param>
        /// <returns> Reference to the added (or finded) edge</returns>
        public override IEdge addEdge(Vertex v1, Vertex v2)
        {
            if (v1 == null || v2 == null) { return null; }

            IEdge e = new NonOrientedEdge(v1, v2);
            foreach (IEdge edge in innerEdges)
            {
                if (edge.Equals(e)) { return null; }
            }

            innerEdges.Add(e);

            foreach (var obs in innerEdgeObs)
            {
                obs.update(e, ChangeType.Added);
            }

            return e;
        }
 /// <summary>
 /// List of edges going from this node. In this (nonoriented) graph nextEdges are equal to incidentEdges.
 /// </summary>
 /// <param name="v">Target node</param>
 /// <returns>Incident edges</returns>
 public override List<IEdge> nextEdges(Vertex v)
 {
     return incidentEdges(v);
 }
        /// <summary>
        /// Remove vertex from this graph
        /// </summary>
        /// <param name="v">Target node</param>
        /// <returns>true if vertex was succesfully removed</returns>
        public override bool removeVertex(Vertex v)
        {
            if (v == null || !innerVertices.Contains(v)) { return false; }

            List<IEdge> incidentEdges = new List<IEdge>();

            foreach (IEdge e in innerEdges)
            {
                if (e.Vertex_1 == v || e.Vertex_2 == v) { incidentEdges.Add(e); }
            }

            foreach (IEdge e in incidentEdges)
            {
                this.removeEdge(e);
            }

            innerVertices.Remove(v);

            foreach (var obs in innerVertObs)
            {
                obs.update(v, ChangeType.Removed);
            }

            return true;
        }
 /// <summary>
 /// List of edges going to this node. In this (nonoriented) graph previousEdges are equal to incidentEdges.
 /// </summary>
 /// <param name="v">Target node</param>
 /// <returns>Incident edges</returns>
 public override List<IEdge> previousEdges(Vertex v)
 {
     return incidentEdges(v);
 }
示例#7
0
 /// <summary>
 /// Create nonoriented edge
 /// </summary>
 /// <param name="v1">First node</param>
 /// <param name="v2">Other node</param>
 public NonOrientedEdge(Vertex v1, Vertex v2)
 {
     innerV1 = v1;
     innerV2 = v2;
 }