Beispiel #1
0
        public static void RunAlgorithm()
        {
            if (currentIteration >= MAX_ITERATIONS)
            {
                Wykres.NotifyAlgorithmFinished(currentIteration,
                                               currentGens.OrderBy(point => point.GetFunctionValue()).First().GetFunctionValue());
                return;
            }

            List <MyPoint2D> nextGens = new List <MyPoint2D>();

            for (int i = 0; i < LAMBDA; i++)
            {
                MyPoint2D nextGenPoint = GetBestCurrentPointUsingTournament();
                nextGens.Add(MutatePoint(nextGenPoint));
            }

            List <MyPoint2D> muAndLambda = new List <MyPoint2D>(currentGens);

            muAndLambda.AddRange(nextGens);
            currentGens = muAndLambda.OrderByDescending(point => point.GetFunctionValue()).Take(MU).ToList();

            Wykres.NotifyNewDataCalculated(currentIteration + 1,
                                           currentGens.OrderBy(point => point.GetFunctionValue()).First().GetFunctionValue());
            currentIteration++;
        }
Beispiel #2
0
        private static MyPoint2D MutatePoint(MyPoint2D pointToMutate)
        {
            MyPoint2D pointAfterMutate = new MyPoint2D();

            double xAfterMutation = pointToMutate.GetX() + RANDOM.Next(-MUTATION_RANGE, MUTATION_RANGE);
            double yAfterMutation = pointToMutate.GetY() + RANDOM.Next(-MUTATION_RANGE, MUTATION_RANGE);

            pointAfterMutate.SetX(xAfterMutation < 0 ? 0 : xAfterMutation > 100 ? 100 : xAfterMutation);
            pointAfterMutate.SetY(yAfterMutation < 0 ? 0 : yAfterMutation > 100 ? 100 : yAfterMutation);
            pointAfterMutate.SetFunctionValue(SinusFunctionChartLogic.Function(xAfterMutation, yAfterMutation));
            return(pointAfterMutate);
        }
Beispiel #3
0
        private static MyPoint2D GetBestCurrentPointUsingTournament()
        {
            MyPoint2D bestCurrentGenPoint = new MyPoint2D();

            foreach (MyPoint2D point in GetRandomPointsToTournament())
            {
                if (bestCurrentGenPoint.GetFunctionValue() < point.GetFunctionValue())
                {
                    bestCurrentGenPoint = point;
                }
            }

            return(bestCurrentGenPoint);
        }
Beispiel #4
0
        private static List <MyPoint2D> GetRandomPointsToTournament()
        {
            List <MyPoint2D> ossTournament = new List <MyPoint2D>();

            for (int i = 0; i < TOURNAMENT_SIZE; i++)
            {
                MyPoint2D randomPoint = currentGens[RANDOM.Next(currentGens.Count)];
                if (ossTournament.Contains(randomPoint))
                {
                    i--;
                    continue;
                }

                ossTournament.Add(randomPoint);
            }

            return(ossTournament);
        }