示例#1
0
        private void RunAlgorithm(string _algoName, Graph _graph)
        {
            // Variables
            DateTime  beginning;
            DateTime  end;
            TimeSpan  duration;
            Algorithm algo = null;

            // Création de l’algorithme
            switch (_algoName)
            {
            case "Depth-First":
                algo = new DepthFirst(_graph, this);
                break;

            case "Breadth-First":
                algo = new BreadthFirst(_graph, this);
                break;

            case "Bellman-Ford":
                algo = new BellmanFord(_graph, this);
                break;

            case "Dijkstra":
                algo = new Dijkstra(_graph, this);
                break;

            case "A*":
                algo = new AStar(_graph, this);
                break;
            }
            // Résolution
            Console.Out.WriteLine("Algorithme : " + _algoName);
            beginning = DateTime.Now;
            algo.Solve();
            end      = DateTime.Now;
            duration = end - beginning;
            Console.Out.WriteLine("Durée (ms) : " +
                                  duration.TotalMilliseconds.ToString() + "\n");
        }
示例#2
0
        private void startButton_Click_1(object sender, EventArgs e)//开始搜索
        {
            myDraw.Change(CurrentLaby);
            myDraw.DrawLaby();
            MethodNum = 0;
            IsChosen  = new bool[6] {
                false, false, false, false, false, false
            };

            if (breadthBox.Checked)//使用宽度优先搜索
            {
                breadthSearch = new BreadthFirst(myDraw.Laby);
                MethodNum++;
                IsChosen[0] = true;
            }

            if (depthBox.Checked)//使用深度优先搜索
            {
                depthSearch = new DepthFirst(myDraw.Laby);
                MethodNum++;
                IsChosen[1] = true;
            }
            if (bestBox.Checked)//使用最佳优先搜索
            {
                bestSearch = new BestFirst(myDraw.Laby);
                MethodNum++;
                IsChosen[2] = true;
            }

            if (dijkstraBox.Checked)//使用一致代价搜索
            {
                dijkstraSearch = new Dijkstra(myDraw.Laby);
                MethodNum++;
                IsChosen[3] = true;
            }

            if (AstarBox.Checked)//使用A*搜索
            {
                astarSearch = new AStar(myDraw.Laby);
                MethodNum++;
                IsChosen[4] = true;
            }

            if (bibreadthBox.Checked)//使用双向宽度优先搜索
            {
                bibreadthSearch = new BiBreadthFirst(myDraw.Laby);
                MethodNum++;
                IsChosen[5] = true;
            }

            if (MethodNum == 0)
            {
                MessageBox.Show("请选择搜索算法以开始游戏!", "未选择");
                return;
            }
            labyPicture.Enabled         = false;
            generateButton.Enabled      = false;
            startButton.Enabled         = false;
            SaveButton.Enabled          = false;
            materialTab.SelectedTab     = showPage;
            materialTabSelector.Enabled = false;

            minPathLength = int.MaxValue;
            minPathCost   = int.MaxValue;

            initLabels();
            initTable();
            CurrentLine   = 0;
            CurrentMethod = 0;
            addLine();
            refreshTimer.Enabled = true;
            labelcost.Visible    = false;
            ResetButton.Enabled  = false;
        }