Пример #1
0
        // Tombol Solve ditekan
        private void Solve(object sender, RoutedEventArgs e)
        {
            Parser p = new Parser();
            List <List <string> > graph   = p.ParseMap(this.MapField.Text);
            List <string>         queries = p.ParseQuery(this.QueryField.Text);

            if (queries == null && graph == null)
            {
                QueryText.Text = "No graph can be shown";
            }
            else
            {
                TopologicalSort T = new TopologicalSort(Map);

                foreach (var q in queries)
                {
                    bool     result = T.CekQuery(q);
                    string[] words  = q.Split(' ');

                    List <string> nodes = new List <string>();
                    bool          found = false;
                    T.CekJalur(Int32.Parse(words[2]), Int32.Parse(words[1]), ref found, Int32.Parse(words[0]), ref nodes);

                    ResultText.Text += "Apakah bisa Ferdiant begerak dari rumah ";
                    ResultText.Text += words[2];
                    ResultText.Text += " ke rumah ";
                    ResultText.Text += words[1];
                    if (words[0] == "1")
                    {
                        ResultText.Text += " menjauhi istana\n";
                    }
                    else
                    {
                        ResultText.Text += " mendekati istana\n";
                    }
                    string str;
                    if (result)
                    {
                        str              = "YA";
                        ResultText.Text += ">> YA\n";
                    }
                    else
                    {
                        str              = "TIDAK";
                        ResultText.Text += ">> TIDAK\n";
                    }

                    GraphAnimation.view(graph, nodes, words[2], words[1], str);
                    Task.Delay(1000).Wait();
                    nodes = new List <string>();
                    T.ResetVisited();
                }
            }
        }
Пример #2
0
        // Tombol insert query ditekan
        private void Insert(object sender, RoutedEventArgs e)
        {
            Parser p = new Parser();
            List <List <string> > graph = p.ParseMap(this.MapField.Text);
            string q = InsertQueryField.Text;

            if (q == "")
            {
                ResultText.Text = "Query Kosong";
            }
            else
            {
                TopologicalSort T = new TopologicalSort(Map);

                bool     result = T.CekQuery(q);
                string[] words  = q.Split(' ');

                List <string> nodes = new List <string>();
                bool          found = false;
                T.CekJalur(Int32.Parse(words[2]), Int32.Parse(words[1]), ref found, Int32.Parse(words[0]), ref nodes);

                ResultText.Text += "Apakah bisa Ferdiant begerak dari rumah ";
                ResultText.Text += words[2];
                ResultText.Text += " ke rumah ";
                ResultText.Text += words[1];
                if (words[0] == "1")
                {
                    ResultText.Text += " menjauhi istana\n";
                }
                else
                {
                    ResultText.Text += " mendekati istana\n";
                }
                string str;
                if (result)
                {
                    str              = "YA";
                    ResultText.Text += ">> YA\n";
                }
                else
                {
                    str              = "TIDAK";
                    ResultText.Text += ">> TIDAK\n";
                }

                GraphAnimation.view(graph, nodes, words[2], words[1], str);
                nodes = new List <string>();
                T.ResetVisited();
            }
        }