private async void CanvasAnimatedControl_Draw(Microsoft.Graphics.Canvas.UI.Xaml.ICanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedDrawEventArgs args)
        {
            if (SharedMethods.isRunnnig)
            {
                var curDistance = SharedMethods.RoundTripDistance(tourLocations, tourOrder);

                if (curDistance < bestTourDistance)
                {
                    bestTourDistance = curDistance;
                    tourOrder.CopyTo(bestTourOrder, 0);
                }

                currentIteration++;

                UpdateUI();

                tourOrder = LexicographicOrder.Lexicography(tourOrder);


                if (currentIteration >= totalIterations)
                {
                    SharedMethods.isRunnnig = false;
                }
                else
                {
                    SharedMethods.DrawPath(args.DrawingSession, tourLocations, tourOrder, Color.FromArgb(85, 255, 255, 255), 2f);
                    SharedMethods.DrawPath(args.DrawingSession, tourLocations, bestTourOrder, Color.FromArgb(85, 255, 255, 255), 4f);
                }
            }
            else
            {
                if (currentIteration > 0)
                {
                    SharedMethods.DrawPath(args.DrawingSession, tourLocations, bestTourOrder, Color.FromArgb(85, 255, 255, 255), 4f);
                }
                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    startBtn.Visibility = Visibility.Visible;
                    stopBtn.Visibility  = Visibility.Collapsed;
                });

                sender.Paused = true;
            }
        }
        public static int[] PerformSimulatedAnnealing(int[] x, double Temp, Random random)
        {
            var newOrder = AnnealingSwap(x, random);

            var d1 = SharedMethods.RoundTripDistance(SharedMethods.Locations, x);
            var d2 = SharedMethods.RoundTripDistance(SharedMethods.Locations, newOrder);

            var prob = probability(d1, d2, Temp);
            var rand = random.NextDouble();

            if (rand < prob)
            {
                x = newOrder;
            }

            //Temp = Temp * 0.999f;

            return(x);
        }
Beispiel #3
0
        void InitializeValues()
        {
            totalCities = SharedMethods.TotalCities;

            tourOrder     = new int[totalCities];
            tourLocations = new Vector2[totalCities];
            bestTourOrder = new int[totalCities];

            (tourLocations, tourOrder) = SharedMethods.InitializeLocations(totalCities, random);

            SharedMethods.Order.CopyTo(tourOrder, 0);
            SharedMethods.Locations.CopyTo(tourLocations, 0);

            SharedMethods.DrawPoints(pointsGrid);

            initialDistance = SharedMethods.RoundTripDistance(tourLocations, tourOrder);

            bestTourDistance = float.PositiveInfinity;
            swaps            = 0;
        }
        void InitializeValues()
        {
            totalCities = SharedMethods.TotalCities;

            tourOrder     = new int[totalCities];
            tourLocations = new Vector2[totalCities];
            bestTourOrder = new int[totalCities];

            (tourLocations, tourOrder) = SharedMethods.InitializeLocations(totalCities, random);

            SharedMethods.Order.CopyTo(tourOrder, 0);
            SharedMethods.Locations.CopyTo(tourLocations, 0);

            SharedMethods.DrawPoints(pointsGrid);

            initialDistance = SharedMethods.RoundTripDistance(tourLocations, tourOrder);
            totalIterations = SharedMethods.Factorial(totalCities);

            currentIteration = 0;
            bestTourDistance = double.PositiveInfinity;
        }
Beispiel #5
0
        void InitializeValues()
        {
            totalCities = SharedMethods.TotalCities;

            tourOrder     = new int[totalCities];
            tourLocations = new Vector2[totalCities];

            (tourLocations, tourOrder) = SharedMethods.InitializeLocations(totalCities, random);

            SharedMethods.Order.CopyTo(tourOrder, 0);
            SharedMethods.Locations.CopyTo(tourLocations, 0);

            SharedMethods.DrawPoints(pointsGrid);

            initialDistance = SharedMethods.RoundTripDistance(tourLocations, tourOrder);

            Temperature     = SharedMethods.Temperature;
            TemperatureRate = SharedMethods.TemperatureRate;

            count = 0;
        }