コード例 #1
0
        private void handleToolStripMenuClick(RunType runType)
        {
            this.reset();

            tbElapsedTime.Text = " Running...";
            tbCostOfTour.Text  = " Running...";
            Refresh();

            Solver solver;

            if (runType == RunType.BRANCH_AND_BOUND)
            {
                BranchAndBoundSolver babs = new BranchAndBoundSolver(CityData);
                CityData = babs.solve();
            }
            else if (runType == RunType.GREEDY)
            {
                CityData = GreedySolver.solve(CityData);
            }
            else if (runType == RunType.FANCY)
            {
                solver   = new FancySolver();
                CityData = solver.solve(CityData);
            }
            else  // runType == RunType.DEFAULT
            {
                solver   = new DefaultSolver();
                CityData = solver.solve(CityData);
            }

            tbCostOfTour.Text   = CityData.bssf.costOfRoute.ToString();
            tbElapsedTime.Text  = CityData.timeElasped.ToString();
            tbNumSolutions.Text = CityData.solutions.ToString();
            Invalidate();                          // force a refresh.
        }
コード例 #2
0
ファイル: OptimalSolver.cs プロジェクト: vvancak/ai
        public TSPSolution solve(TSPInput input)
        {
            GreedySolver s = new GreedySolver();

            best = s.solve(input).computeDistance() + 1;

            bestSolution = new int[input.nodesCount];
            List <int> current = new List <int>();

            current.Add(0);
            List <int> remaining = new List <int>();

            for (int i = 1; i < input.nodesCount; i++)
            {
                remaining.Add(i);
            }
            trySolve(input, current, remaining, 0);
            TSPSolution result = new TSPSolution(input);

            for (int i = 0; i < input.nodesCount - 1; i++)
            {
                result.setSuccessor(bestSolution[i], bestSolution[i + 1]);
            }
            result.setSuccessor(bestSolution[input.nodesCount - 1], 0);
            return(result);
        }
コード例 #3
0
ファイル: HillClimbingSolver.cs プロジェクト: vvancak/ai
        private PermutationStandard initialize2(TSPInput input)
        {
            var solver = new GreedySolver();
            var result = solver.solve(input);

            return(new PermutationStandard(result));
        }
コード例 #4
0
        // finds the best tour possible using the branch and bound method of attack
        // For an example of what to return, see DefaultSolver.solve() method.
        public Problem solve()
        {
            Stopwatch timer = new Stopwatch();

            timer.Start();

            State beginningState = new State(cityData.size);

            SolverHelper.initializeState(beginningState, cityData);
            this.q.Enqueue(beginningState);
            Problem determineBSSFProblem = SolverHelper.clone(cityData);

            this.cityData.bssf = GreedySolver.solve(determineBSSFProblem).bssf;

            while (q.Count > 0)
            {
                recur(q.Dequeue());
                //Clear out any states that have a BSSF less than
                //that of the current
            }

            timer.Stop();
            cityData.timeElasped = timer.Elapsed;

            return(cityData);
        }
コード例 #5
0
        public static void greedyHard()
        {
            Problem cityData = new Problem(1, 20, 60, HardMode.Modes.Hard);

            cityData = GreedySolver.solve(cityData);
            if (cityData.bssf.costOfRoute != 4928)
            {
                throw new SystemException("Incorrect cost");
            }
        }
コード例 #6
0
        public static void greedyEasy()
        {
            Problem cityData = new Problem(1, 5, 60, HardMode.Modes.Easy);

            cityData = GreedySolver.solve(cityData);
            if (cityData.bssf.costOfRoute != 2060)
            {
                throw new SystemException("Incorrect cost");
            }
        }