예제 #1
0
        /// <summary>
        /// Returns a List containing the Edges starting at Vertex v
        /// </summary>
        /// <param name="v"></param>
        /// <returns></returns>
        public List <Edge> IncidentEdges(Vertex v)
        {
            List <Edge> incidents = new List <Edge>();

            if (v.GetConnections() == null || v.GetConnections().Count == 0)
            {
                return(incidents);
            }

            incidents.AddRange(_edges.FindAll(x => x.GetVertexA().GetId() == v.GetId()));

            return(incidents);
        }
예제 #2
0
        public void BFS(Vertex v)
        {
            Queue <Vertex> vertexQueue = new Queue <Vertex>();

            vertexQueue.Enqueue(v);
            v.SetLabel("VISITED");

            while (vertexQueue.Count != 0)
            {
                Vertex w = vertexQueue.Dequeue();

                if (w.GetConnections().Count != 0)
                {
                    foreach (Edge e in IncidentEdges(w))
                    {
                        if (e.GetLabel() == "UNEXPLORED")
                        {
                            Vertex u = Opposite(w, e);

                            if (u != null && u.GetLabel() == "UNEXPLORED")
                            {
                                e.SetLabel("DISCOVERY");
                                u.SetLabel("VISITED");
                                vertexQueue.Enqueue(u);
                            }
                            else
                            {
                                e.SetLabel("CROSS");
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
        public bool AreAdjacent(Vertex v, Vertex w)
        {
            if (v == null || w == null)
            {
                return(false);
            }

            foreach (string id in v.GetConnections())
            {
                if (id == w.GetId())
                {
                    return(true);
                }
            }

            foreach (string id in w.GetConnections())
            {
                if (id == v.GetId())
                {
                    return(true);
                }
            }

            return(false);
        }