Beispiel #1
0
        private void Enter_Query_Click(object sender, RoutedEventArgs e)
        // Memulai proses untuk query dari pengguna
        {
            try
            {
                if (B1)
                {
                    Result.Content = "";
                    B1             = false;
                }

                resetGraph();
                quest          = new Query(Query_Text.Text);
                Next.IsEnabled = false;

                if (quest.getMove() == 0)
                {
                    bool       found2 = false;
                    List <int> res    = new List <int>();
                    String     ans    = quest.getMove() + " " + quest.getTo() + " " + quest.getFrom();
                    Result.Content += ans;
                    recurseSolve(1, quest.getFrom(), ref found2, map, ref res);
                    solution = null;
                    solution = new List <int>(res);

                    if (!res.Contains(quest.getTo()))
                    {
                        AutoClosingMessageBox.Show("Solution Not Found", "Result", 1500);
                        ans             = "   TIDAK\n";
                        Result.Content += ans;
                        resetGraph();
                        this.gViewer.Graph = graph;
                    }
                    else
                    {
                        AutoClosingMessageBox.Show("Solution Found", "Result", 1500);
                        ans             = "   YA\n";
                        Result.Content += ans;
                    }
                }
                else if (quest.getMove() == 1)
                {
                    bool       found3 = false;
                    List <int> res    = new List <int>();
                    String     ans    = quest.getMove() + " " + quest.getTo() + " " + quest.getFrom();
                    Result.Content += ans;
                    recurseSolve(quest.getFrom(), quest.getTo(), ref found3, map, ref res);
                    solution = null;
                    solution = new List <int>(res);

                    if (found3)
                    {
                        AutoClosingMessageBox.Show("Solution Found", "Result", 1500);
                        ans             = "   YA\n";
                        Result.Content += ans;
                    }
                    else
                    {
                        AutoClosingMessageBox.Show("Solution Not Found", "Result", 1500);
                        ans             = "   TIDAK\n";
                        Result.Content += ans;
                        resetGraph();
                        this.gViewer.Graph = graph;
                    }
                }
            }
            catch
            {
                MessageBox.Show("      Error Code 0x14031999\n                Input Error", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Beispiel #2
0
        public void recurseSolve(int curr, int target, ref bool found, Graf path, ref List <int> result)
        // Algoritma pencarian menggunakan DFS
        {
            List <int> neighbor = path.getPath(curr);

            if (curr == target)
            {
                found   = true;
                now     = target;
                checker = 0;
                _timer.Start();
                result.Add(target);

                if (result.Count() != 0)
                {
                    nowpath = result[0].ToString();
                }
                else
                {
                    nowpath = "";
                }

                for (int j = 1; j < result.Count(); j++)
                {
                    nowpath += " -> " + result[j];
                }

                AutoClosingMessageBox.Show(nowpath, "Path", 1000);
            }
            else if (neighbor == null)
            {
                found   = false;
                prev    = curr;
                checker = 0;
                _timer2.Start();
                result.Remove(curr);

                if (result.Count() != 0)
                {
                    prevpath = result[0].ToString();
                }
                else
                {
                    prevpath = "";
                }

                for (int j = 1; j < result.Count(); j++)
                {
                    prevpath += " -> " + result[j];
                }

                AutoClosingMessageBox.Show(prevpath, "Path", 1000);
            }
            else
            {
                now     = curr;
                checker = 0;
                _timer.Start();
                result.Add(curr);

                if (result.Count() != 0)
                {
                    nowpath = result[0].ToString();
                }
                else
                {
                    nowpath = "";
                }

                for (int j = 1; j < result.Count(); j++)
                {
                    nowpath += " -> " + result[j];
                }

                AutoClosingMessageBox.Show(nowpath, "Path", 1000);
                int i = 0;

                while ((i < neighbor.Count) && (!found))
                {
                    recurseSolve(neighbor[i], target, ref found, path, ref result);
                    i++;
                }
                if (!found)
                {
                    prev    = curr;
                    checker = 0;
                    _timer2.Start();
                    result.Remove(curr);

                    if (result.Count() != 0)
                    {
                        prevpath = result[0].ToString();
                    }
                    else
                    {
                        prevpath = "";
                    }

                    for (int j = 1; j < result.Count(); j++)
                    {
                        prevpath += " -> " + result[j];
                    }

                    AutoClosingMessageBox.Show(prevpath, "Path", 1000);
                }
            }
        }
Beispiel #3
0
        private void Next_Click(object sender, RoutedEventArgs e)
        // Memulai proses untuk query selanjutnya
        {
            resetGraph();

            if (quests.getMove(counter) == 0)
            {
                bool       found2 = false;
                List <int> res    = new List <int>();
                String     ans    = quests.getMove(counter) + " " + quests.getTo(counter) + " " + quests.getFrom(counter);
                Result.Content += ans;
                recurseSolve(1, quests.getFrom(counter), ref found2, map, ref res);
                solution = null;
                solution = new List <int>(res);

                if (!res.Contains(quests.getTo(counter)))
                {
                    AutoClosingMessageBox.Show("Solution Not Found", "Result", 1500);
                    ans             = "   TIDAK\n";
                    Result.Content += ans;
                    resetGraph();
                    this.gViewer.Graph = graph;
                }
                else
                {
                    AutoClosingMessageBox.Show("Solution Found", "Result", 1500);
                    ans             = "   YA\n";
                    Result.Content += ans;
                }
            }
            else if (quests.getMove(counter) == 1)
            {
                bool       found3 = false;
                List <int> res    = new List <int>();
                String     ans    = quests.getMove(counter) + " " + quests.getTo(counter) + " " + quests.getFrom(counter);
                Result.Content += ans;
                recurseSolve(quests.getFrom(counter), quests.getTo(counter), ref found3, map, ref res);
                solution = null;
                solution = new List <int>(res);

                if (found3)
                {
                    AutoClosingMessageBox.Show("Solution Found", "Result", 1500);
                    ans             = "   YA\n";
                    Result.Content += ans;
                }
                else
                {
                    AutoClosingMessageBox.Show("Solution Not Found", "Result", 1500);
                    ans             = "   TIDAK\n";
                    Result.Content += ans;
                    resetGraph();
                    this.gViewer.Graph = graph;
                }
            }

            counter++;

            if (counter == quests.getNum())
            {
                Next.IsEnabled = false;
            }
        }