Ejemplo n.º 1
0
        public void solveProblem()
        {
            timer = new Stopwatch();
            timer.Start();
            counter = 0;
            max     = 0;

            Console.Out.WriteLine();
            initializeSolver();
            stack.Push(new TSPSolution(Cities[0]));

            bool debug = true;

            while (stack.Count != 0 && (timer.Elapsed.TotalSeconds <= 20 || debug))
            {
                counter++;
                if (stack.Count > max)
                {
                    max = stack.Count;
                }
                updateUI();
                TSPSolution parent = stack.Pop();
                if (parent.getBound() >= bssf.costOfRoute())
                {
                    continue;
                }
                //if (parent.isCrossed())
                //    continue;
                List <TSPSolution> children = parent.makeChildren();
                foreach (TSPSolution child in children)
                {
                    if (child.getBound() < bssf.costOfRoute())
                    {
                        if (child.isSolution())
                        {
                            Console.Out.WriteLine("Solution: {0}", child.costOfRoute());
                            bssf = child;
                        }
                        else
                        {
                            stack.Push(child);
                        }
                    }
                    // else discard it (don't explore)
                }
            }

            timer.Stop();
            updateUI();
        }