Пример #1
0
        public void TwoDim_EvaluatesCorrectValues(double[] values)
        {
            var evaluator = new StyblinskiTang(2);
            var ds        = evaluator.GetGlobalOptimum().GetDecisionSpace();
            var result    = evaluator.Evaluate(DecisionVector.CreateFromArray(ds, new[] { values[0], values[1] }));

            Assert.True(Math.Abs(values[2] - result.ElementAt(0)) < 0.001);
        }
Пример #2
0
        public void TwoDim_CorrectlyIdentifiesLegalSolution()
        {
            var evaluator = new StyblinskiTang(2);
            var ds        = evaluator.GetGlobalOptimum().GetDecisionSpace();
            var legal     = evaluator.GetLegality(DecisionVector.CreateFromArray(ds, new[] { 1.0, 1.0 }));

            Assert.True(legal);
        }
Пример #3
0
        public void TwoDim_CorrectlyIdentifiesIllegalSolutions()
        {
            var evaluator = new StyblinskiTang(2);
            var ds        = DecisionSpace.CreateForUniformDoubleArray(2, double.MinValue, double.MaxValue);
            var legal     = evaluator.GetLegality(DecisionVector.CreateFromArray(ds, new[] { -6.0, 2.0 }));

            Assert.False(legal);
            var legal2 = evaluator.GetLegality(DecisionVector.CreateFromArray(ds, new[] { -1.0, 7.0 }));

            Assert.False(legal2);
        }
Пример #4
0
        static void Main(string[] args)
        {
            OptimTests myGoal = new StyblinskiTang(2);// (4, 100);

            double[] lb = new double[] { -100, -100, -100, -100, -100 };
            double[] ub = new double[] { 100, 100, 100, 100, 100 };

            PSOSettings optimSettings = new PSOSettings();
            PSO         myPSO         = new PSO(optimSettings, myGoal.numDims, myGoal.goalFunc, myGoal.lbounds, myGoal.ubounds);
            double      best          = myPSO.Optimize();

            Console.WriteLine("Best: " + best);
            Console.ReadLine();

            for (int i = 0; i < myPSO.gBestHistory.Count; i++)
            {
                Console.WriteLine(i + " " + myPSO.gBestHistory[i]);
            }
            Console.ReadLine();
        }