예제 #1
0
        public void AddEdge(int b, int e)
        {
            GVertex begin      = existingVertices[b - 1];
            GVertex end        = existingVertices[e - 1];
            string  edgeString = string.Format("{0}-{1} Connected", begin.ID, end.ID);

            connections.Add(new GEdge(edgeString, begin, end, "Black"));
        }
예제 #2
0
        public void DeleteEdge(int b)
        {
            GVertex begin = existingVertices[b - 1];
            int     i     = 0;

            while (i < connections.Count)
            {
                if (connections[i].Source == begin)
                {
                    connections.Remove(connections[i]);
                }
                else
                {
                    i++;
                }
            }
        }
예제 #3
0
        bool DFS0(int start, int finish, int goal, bool Found)
        {
            //Variables
            GVertex S = existingVertices[start - 1];

            if (start == finish) // basis 1 : Node sekarang adalah node finish
            {
                S.VertexColor = "Yellow";
                Thread.Sleep(500);
                S.VertexColor = "Black";
                Thread.Sleep(500);
                if (start == goal) // cek apakah node sekarang adalah node yang dicari
                {
                    S.VertexColor = "Green";
                    Thread.Sleep(500);
                    S.VertexColor = "Black";
                    Thread.Sleep(500);
                    return(true);
                }
                else
                {
                    if (Found)
                    {
                        S.VertexColor = "Green";
                        Thread.Sleep(500);
                    }
                    else
                    {
                        S.VertexColor = "Red";
                        Thread.Sleep(500);
                    }
                    S.VertexColor = "Black";
                    return(Found);
                }
            }
            else if (graph.OutDegree(S) == 0) // basis 2 : Node sekarang adalah node daun (Tidak memiliki child node lagi)
            {
                S.VertexColor = "Red";
                Thread.Sleep(1000);
                S.VertexColor = "Black";
                return(false);
            }
            else
            {
                if (start == goal)
                {
                    S.VertexColor = "Green";
                    Found         = true;
                }


                S.VertexColor = "Blue";
                Thread.Sleep(500);
                int  i         = 0;
                int  N         = graph.OutDegree(S);
                bool FoundTemp = false;
                while (i < N && !FoundTemp)
                {
                    graph.OutEdge(S, i).EdgeColor = "Blue";
                    Thread.Sleep(500);
                    FoundTemp = DFS0(Convert.ToInt32(graph.OutEdge(S, i).Target.ID), finish, goal, Found); // rekursi
                    Thread.Sleep(500);
                    graph.OutEdge(S, i).EdgeColor = "Black";
                    Thread.Sleep(500);
                    i++;
                }
                S.VertexColor = "Black";
                return(FoundTemp);
            }
        }