コード例 #1
0
        public void Cat_INIT(double[] solutionSpace, double maxVelocity, Random rnd)
        {
            //Random positions
            for (int i = 0; i < _position.Length; i++)
            {
                _position[i] = CSOAlgorithm.RandomDouble() * (solutionSpace[1] - solutionSpace[0]) + solutionSpace[0];
            }

            //Random velocity
            for (int i = 0; i < _velocities.Length; i++)
            {
                //_velocities[i] = CSOAlgorithm.RandomDouble() * (maxVelocity - 0) + 0;
                _velocities[i] = CSOAlgorithm.RandomDouble() * (maxVelocity - (-maxVelocity)) + (-maxVelocity);
            }
        }
コード例 #2
0
        private void TestCATSParam()
        {
            int dimentionIterator = 2;
            int startDimention    = 16;
            int maxDimention      = 64;
            int iterationsCount   = 100;
            int maxCats           = 80;

            UI_progress.Maximum = (int)(iterationsCount * 3 * 4);
            MultipleSolution solution = new MultipleSolution(CSOAlgorithm.Goal.Minimize, iterationsCount);

            for (int dimentionIteration = startDimention; dimentionIteration < maxDimention + 1; dimentionIteration *= dimentionIterator) //choose dim
            {
                for (int curCats = 10; curCats < maxCats; curCats *= 2)                                                                   //choose SRD
                {
                    CSOAlgorithm algorithm = new CSOAlgorithm
                                             (
                        dimentionIteration,
                        curCats,
                        SMP,
                        1.2,
                        CDC,
                        MR,
                        C,
                        MAX_VELOSITY,
                        SPC,
                        R,
                        SOLUTION_SPACE,
                        CSOAlgorithm.Goal.Minimize
                                             );

                    for (int i = 0; i < iterationsCount; i++)               //Repeat 100tests on dim,SRD
                    {
                        UI_progress.PerformStep();
                        Solution stepSolution = stepSolution = algorithm.RunCSO(ITERATONS, UI_progress, true);

                        //solution.AddFV(dimentionIteration, stepSolution.BestFV);
                        //solution.AddVector(dimentionIteration, stepSolution.BestPosition);
                        solution.AddIterations(dimentionIteration, stepSolution.Iterations);
                        //solution.AddStepFV(dimentionIteration, i, stepSolution.FitnessValues);
                    }
                }

                Logger.LogIt(dimentionIteration + " Finished");
            }
        }
コード例 #3
0
        //Единичный запуск
        private void StartProgram()
        {
            //initiallize solution components
            CSOAlgorithm algorithm = new CSOAlgorithm
                                     (
                DIMENTIONS_NUMBER,
                SWARM_SIZE,
                SMP,
                SRD,
                CDC,
                MR,
                C,
                MAX_VELOSITY,
                SPC,
                R,
                SOLUTION_SPACE,
                CSOAlgorithm.Goal.Minimize
                                     );

            Solution finalSolution = algorithm.RunCSOWrong(ITERATONS, UI_progress);


            //Write all solution data to LOG file
            Logger.LogIt("Solution vector:");
            for (int i = 0; i < DIMENTIONS_NUMBER; i++)
            {
                Logger.LogIt(i + ")" + finalSolution.BestPosition[i]);
            }
            Logger.LogIt("FV=" + finalSolution.FitnessValues[finalSolution.FitnessValues.Count - 1]);

            //Add point to chart
            for (int i = 0; i < finalSolution.FitnessValues.Count; i++)
            {
                //BestFVChart.Series["BestFV"].Points.AddXY(i+1, finalSolution.FitnessValues[i]);
            }
        }
コード例 #4
0
        private void TestSRDParam()
        {
            int    dimentionIterator = 2;
            int    startDimention    = 16;
            int    maxDimention      = 64;
            int    iterationsCount   = 100;
            double minSRD            = 0.2;

            UI_progress.Maximum = (int)(iterationsCount * 3 * 9);
            MultipleSolution solution = new MultipleSolution(CSOAlgorithm.Goal.Minimize, iterationsCount);

            for (int dimentionIteration = startDimention; dimentionIteration < maxDimention + 1; dimentionIteration *= dimentionIterator) //choose dim
            {
                for (double curSRD = minSRD; curSRD < 1.8; curSRD += 0.2)                                                                 //choose SRD
                {
                    CSOAlgorithm algorithm = new CSOAlgorithm
                                             (
                        dimentionIteration,
                        SWARM_SIZE,
                        SMP,
                        curSRD,
                        CDC,
                        MR,
                        C,
                        MAX_VELOSITY,
                        SPC,
                        R,
                        SOLUTION_SPACE,
                        CSOAlgorithm.Goal.Minimize
                                             );

                    for (int i = 0; i < iterationsCount; i++)               //Repeat 100tests on dim,SRD
                    {
                        UI_progress.PerformStep();
                        Solution stepSolution = stepSolution = algorithm.RunCSO(ITERATONS, UI_progress, true);

                        //solution.AddFV(dimentionIteration, stepSolution.BestFV);
                        //solution.AddVector(dimentionIteration, stepSolution.BestPosition);
                        //solution.AddIterations(dimentionIteration, stepSolution.Iterations);
                        //solution.AddStepFV(dimentionIteration, i, stepSolution.FitnessValues);

                        solution.AddSRD_FV(dimentionIteration, curSRD, stepSolution.BestFV);
                        solution.AddSRD_Acc(dimentionIteration, curSRD, stepSolution.functionAccessed);
                    }
                }

                Logger.LogIt(dimentionIteration + " Finished");
            }

            for (int dimentionIteration = startDimention; dimentionIteration < maxDimention + 1; dimentionIteration *= dimentionIterator)
            {
                Logger.LogIt(dimentionIteration.ToString());
                string dimId = "M=" + dimentionIteration;

                for (double curSRD = minSRD; curSRD < 1.8; curSRD += 0.2)
                {
                    Logger.LogIt(curSRD.ToString());
                    Logger.LogIt("Fbest " + solution.GetSRDBestFV(dimentionIteration, curSRD));
                    Logger.LogIt("Pf " + solution.GetSRD_Probability_F(dimentionIteration, curSRD));
                    Logger.LogIt("Lavg " + solution.GetSRDAvgAcc(dimentionIteration, curSRD));

                    SRD_fbest_chart.Series[dimId].Points.AddXY(curSRD, solution.GetSRDBestFV(dimentionIteration, curSRD));
                    SRD_pf_chart.Series[dimId].Points.AddXY(curSRD, solution.GetSRD_Probability_F(dimentionIteration, curSRD));
                    SRD_acc_chart.Series[dimId].Points.AddXY(curSRD, solution.GetSRDAvgAcc(dimentionIteration, curSRD));

                    Logger.LogIt("_______________________________________");
                }
            }

            SRD_pf_chart.ChartAreas[0].AxisY.Maximum = 1;

            SRD_pf_chart.ChartAreas[0].AxisX.Minimum    = 0;
            SRD_acc_chart.ChartAreas[0].AxisX.Minimum   = 0;
            SRD_fbest_chart.ChartAreas[0].AxisX.Minimum = 0;
        }
コード例 #5
0
        private void MultyStartProgramm()
        {
            const int dimentionIteratior = 2;
            const int startDimention     = 2;
            const int maxDimention       = 64;
            const int iterationsCount    = 100;



            UI_progress.Maximum = (int)(iterationsCount * (Math.Sqrt(maxDimention)));
            //Probably new solution class need to be created
            MultipleSolution solution = new MultipleSolution(CSOAlgorithm.Goal.Minimize, iterationsCount);

            for (int dimentionIteration = startDimention; dimentionIteration < maxDimention + 1; dimentionIteration *= dimentionIteratior)
            {
                CSOAlgorithm algorithm = new CSOAlgorithm
                                         (
                    dimentionIteration,
                    SWARM_SIZE,
                    SMP,
                    SRD,
                    CDC,
                    MR,
                    C,
                    MAX_VELOSITY,
                    SPC,
                    R,
                    SOLUTION_SPACE,
                    CSOAlgorithm.Goal.Minimize
                                         );

                for (int i = 0; i < iterationsCount; i++)
                {
                    UI_progress.PerformStep();
                    Solution stepSolution = stepSolution = algorithm.RunCSO(ITERATONS, UI_progress, true);

                    solution.AddFV(dimentionIteration, stepSolution.BestFV);
                    solution.AddVector(dimentionIteration, stepSolution.BestPosition);
                    solution.AddIterations(dimentionIteration, stepSolution.Iterations);
                    solution.AddStepFV(dimentionIteration, i, stepSolution.FitnessValues);
                }
            }
            Logger.LogIt("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
            for (int dimentionIteration = startDimention; dimentionIteration < maxDimention + 1; dimentionIteration *= dimentionIteratior)
            {
                Logger.LogIt("DIMENTIONS: " + dimentionIteration);
                Logger.LogIt("Лучшее достигнутое значение функции: " + Math.Round(solution.GetBestFV(dimentionIteration), 3));
                OutputChart.Series["Best FV"].Points.AddXY(dimentionIteration, solution.GetBestFV(dimentionIteration));

                Logger.LogIt("Среднее значение целевой функции: " + Math.Round(solution.GetMedianFV(dimentionIteration), 3));
                Logger.LogIt("Среднеквадратическое отклониение: " + Math.Round(solution.GetFVMQD(dimentionIteration), 3));
                MedianFVChart.Series["Median FV"].Points.AddXY(dimentionIteration, solution.GetMedianFV(dimentionIteration));
                double centerFV = solution.GetMedianFV(dimentionIteration);
                double err      = solution.GetFVMQD(dimentionIteration);
                MedianFVChart.Series["CKO"].Points.AddXY(dimentionIteration, centerFV, centerFV - err, centerFV + err);
                MedianFVChart.ChartAreas[0].RecalculateAxesScale();

                Logger.LogIt("Лучшая точность локализации: " + Math.Round(solution.GetLocalisationOppraximation(dimentionIteration).Min(), 3));
                LocalizationChart.Series["Localisation"].Points.AddXY(dimentionIteration, solution.GetLocalisationOppraximation(dimentionIteration).Min()); //MAX?

                Logger.LogIt("Средняя точность локализации: " + Math.Round(solution.GetMedian_dX(dimentionIteration), 3));
                Logger.LogIt("Среднеквадратическое отклониение локализации: " + Math.Round(solution.Get_dXMQD(dimentionIteration), 3));
                mediandXchart.Series["Avg. localization"].Points.AddXY(dimentionIteration, solution.GetMedian_dX(dimentionIteration));
                double centerdX = solution.GetMedian_dX(dimentionIteration);
                double errdx    = solution.Get_dXMQD(dimentionIteration);
                mediandXchart.Series["CKO"].Points.AddXY(dimentionIteration, centerdX, centerdX - errdx, centerdX + errdx);
                mediandXchart.ChartAreas[0].RecalculateAxesScale();

                Logger.LogIt("Вероятность локализации по F: " + Math.Round(solution.FProbability(dimentionIteration), 3));
                fProbabilityChart.Series["L.Probability"].Points.AddXY(dimentionIteration, solution.FProbability(dimentionIteration));

                Logger.LogIt("Вероятность локализации по X: " + Math.Round(solution.XProbability(dimentionIteration), 3));
                dXProbabilityChart.Series["X.Probability"].Points.AddXY(dimentionIteration, solution.XProbability(dimentionIteration));

                Logger.LogIt("Максимальное число итераций: " + solution.MaximumIterations(dimentionIteration));
                MaxIterationsChart.Series["Maximum It."].Points.AddXY(dimentionIteration, solution.MaximumIterations(dimentionIteration));

                Logger.LogIt("Среднее число итераций: " + solution.AverageIterationNumber(dimentionIteration));
                Logger.LogIt("Среднеквадратическое отклониение числа итераций: " + Math.Round(solution.GetMMQD(dimentionIteration), 3));
                AverageIterationsChart.Series["Average It."].Points.AddXY(dimentionIteration, solution.AverageIterationNumber(dimentionIteration));
                double centerM = solution.AverageIterationNumber(dimentionIteration);
                double errM    = solution.GetMMQD(dimentionIteration);
                AverageIterationsChart.Series["CKO"].Points.AddXY(dimentionIteration, centerM, centerM - errM, centerM + errM);
                AverageIterationsChart.ChartAreas[0].RecalculateAxesScale();

                int    BestIterationId = solution.BestIterationId(dimentionIteration);
                string chartId         = "M=" + dimentionIteration;

                DecreaseFV2_chart.Series[chartId].IsValueShownAsLabel = false;
                DecreaseFV2_chart.Series[chartId].MarkerStep          = 20;

                for (int i = 0; i < solution.dimention_iteration_fvs[dimentionIteration][BestIterationId].Count; i++)
                {
                    DecreaseFV2_chart.Series[chartId].Points.AddXY(i, solution.dimention_iteration_fvs[dimentionIteration][BestIterationId][i]);
                }

                Logger.LogIt("_______________________________________________________________");
            }


            OutputChart.Series["Best FV"].SmartLabelStyle.Enabled = true;
            OutputChart.ChartAreas[0].AxisX.IsLogarithmic         = true;
            OutputChart.ChartAreas[0].AxisX.LogarithmBase         = 2;
            OutputChart.Series["Best FV"].IsValueShownAsLabel     = false;

            MedianFVChart.ChartAreas[0].AxisX.IsLogarithmic = true;
            MedianFVChart.ChartAreas[0].AxisX.LogarithmBase = 2;
            MedianFVChart.Series["CKO"]["PixelPointWidth"]  = "20";
            MedianFVChart.Series["CKO"].Color = Color.Black;
            MedianFVChart.Series["Median FV"].IsValueShownAsLabel = false;

            LocalizationChart.ChartAreas[0].AxisX.IsLogarithmic          = true;
            LocalizationChart.ChartAreas[0].AxisX.LogarithmBase          = 2;
            LocalizationChart.Series["Localisation"].IsValueShownAsLabel = false;

            mediandXchart.ChartAreas[0].AxisX.IsLogarithmic = true;
            mediandXchart.ChartAreas[0].AxisX.LogarithmBase = 2;
            mediandXchart.Series["CKO"]["PixelPointWidth"]  = "20";
            mediandXchart.Series["CKO"].Color = Color.Black;
            mediandXchart.Series["Avg. localization"].IsValueShownAsLabel = false;

            fProbabilityChart.ChartAreas[0].AxisX.IsLogarithmic          = true;
            fProbabilityChart.Series["L.Probability"]["PixelPointWidth"] = "15";
            fProbabilityChart.ChartAreas[0].AxisX.LogarithmBase          = 2;
            fProbabilityChart.ChartAreas[0].AxisY.Maximum = 1;

            dXProbabilityChart.ChartAreas[0].AxisX.IsLogarithmic = true;
            dXProbabilityChart.ChartAreas[0].AxisX.LogarithmBase = 2;
            dXProbabilityChart.ChartAreas[0].AxisY.Maximum       = 1;

            MaxIterationsChart.ChartAreas[0].AxisX.IsLogarithmic = true;
            MaxIterationsChart.ChartAreas[0].AxisX.LogarithmBase = 2;

            AverageIterationsChart.ChartAreas[0].AxisX.IsLogarithmic = true;
            AverageIterationsChart.ChartAreas[0].AxisX.LogarithmBase = 2;
            AverageIterationsChart.Series["CKO"]["PixelPointWidth"]  = "20";
            AverageIterationsChart.Series["CKO"].Color = Color.Black;

            SRD_acc_chart.ChartAreas[0].AxisY.Maximum = 0.01;
        }
コード例 #6
0
        //Прогонка алгоритма с циклами
        private void StartProgramWithCycles()
        {
            CSOAlgorithm alg = new CSOAlgorithm
                               (
                DIMENTIONS_NUMBER,
                SWARM_SIZE,
                SMP,
                SRD,
                CDC,
                MR,
                C,
                MAX_VELOSITY,
                SPC,
                R,
                SOLUTION_SPACE,
                CSOAlgorithm.Goal.Minimize
                               );

            for (int i = 0; i < CYCLES; i++)
            {
                // cycles.Add(alg.RunCSO());
                UI_progress.PerformStep();
            }

            Solution finalSolution = new Solution(DIMENTIONS_NUMBER);

            for (int i = 0; i < ITERATONS; i++)
            {
                double sum = 0;
                for (int j = 0; j < CYCLES; j++)
                {
                    double cycleResult = cycles[j].FitnessValues[i];

                    if (ROUND_ENABLED)
                    {
                        if (Math.Abs(cycleResult) < ROUND_BOUNDARY)
                        {
                            cycleResult = 0;
                        }
                    }

                    sum += cycleResult;
                }

                finalSolution.FitnessValues.Add(sum /= CYCLES);
            }

            int M = cycles.FirstOrDefault().BestPosition.Length;

            double[] finPos = new double[M];

            foreach (Solution sol in cycles)
            {
                for (int i = 0; i < sol.BestPosition.Length; i++)
                {
                    double solutionResult = sol.BestPosition[i];

                    if (ROUND_ENABLED)
                    {
                        if (Math.Abs(solutionResult) < ROUND_BOUNDARY)
                        {
                            solutionResult = 0;
                        }
                    }

                    finPos[i] += solutionResult;
                }
            }
            Logger.LogIt("Solution vector:");
            for (int i = 0; i < M; i++)
            {
                Logger.LogIt(i + ")" + (finPos[i] /= CYCLES));
            }

            Logger.LogIt("AVG FV=" + finalSolution.FitnessValues[ITERATONS - 1]);

            for (int i = 0; i < finalSolution.FitnessValues.Count; i++)
            {
                OutputChart.Series["Test"].Points.AddXY(i, finalSolution.FitnessValues[i]);
            }
        }