Esempio n. 1
0
        public void UniformIntAndDoubleArrays_WithEqualBounds_AreNotEqual()
        {
            var space1 = DecisionSpace.CreateForUniformIntArray(Dims, MinValueDiscrete, MaxValueDiscrete);
            var space2 = DecisionSpace.CreateForUniformDoubleArray(Dims, MinValueDiscrete, MaxValueDiscrete);

            Assert.NotEqual(space1, space2);
        }
Esempio n. 2
0
        public void GetNearestLegalLocation_WrongLengthVector_Throws()
        {
            var space = DecisionSpace.CreateForUniformDoubleArray(Dims, MinValueContinuous, MaxValueContinuous);

            Assert.Throws <ArgumentOutOfRangeException>(
                () => space.GetNearestLegalLocation(Enumerable.Repeat <object>(-999.0, Dims + 1)));
        }
Esempio n. 3
0
        public void GetNearestLegalLocation_IllegalTypeVector_Throws()
        {
            var space = DecisionSpace.CreateForUniformDoubleArray(Dims, MinValueContinuous, MaxValueContinuous);

            Assert.Throws <FormatException>(
                () => space.GetNearestLegalLocation(Enumerable.Repeat <object>("foo", Dims)));
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a set of Decision Vectors, which are generated evenly across the decision space.
        /// </summary>
        /// <param name="space">The <see cref="DecisionSpace"/> defining what is legal.</param>
        /// <param name="numberToCreate">The number of new Decision Vectors desired.</param>
        /// <returns>A list of evenly-spaced <see cref="DecisionVector"/>s.</returns>
        public static List <DecisionVector> CreateLatinHypercube(DecisionSpace space, int numberToCreate)
        {
            var orderedLocations = space.Select(d => d.GetSpacedArray(numberToCreate));

            // TODO!
            throw new NotImplementedException();
        }
Esempio n. 5
0
        public DecisionVectorTests()
        {
            continuousSpace = DecisionSpace.CreateForUniformDoubleArray(
                Dims, MinValueContinuous, MaxValueContinuous);

            var range = MaxValueContinuous - MinValueContinuous - 1.01;

            exampleContinuousVector = Enumerable.Range(0, Dims)
                                      .Select(i => MinValueContinuous + range / (Dims - 1) * i + 1)
                                      .ToArray();

            exampleDiscreteVector = Enumerable.Range(0, Dims)
                                    .Select(i => (int)Math.Ceiling(MinValueContinuous) + i)
                                    .ToArray();

            var mixedVars = new List <IVariable>();

            mixedVars.AddRange(
                Enumerable.Repeat(
                    new VariableContinuous(MinValueContinuous, MaxValueContinuous),
                    Dims));
            mixedVars.AddRange(
                Enumerable.Repeat(
                    new VariableDiscrete(int.MinValue, int.MaxValue),
                    Dims));

            mixedSpace = new DecisionSpace(mixedVars);
        }
Esempio n. 6
0
        public void ThreeCitiesInATriangle_CorrectlyCalculatesDistances(params double[][] cityLocations)
        {
            var tsp = new TravellingSalesman("Test Triangle", cityLocations,
                                             DecisionVector.CreateFromArray(DecisionSpace.CreateForUniformIntArray(4, 0, 2), new[] { 0, 1, 2, 0 }));

            Assert.Equal(12.0, tsp.Evaluate(tsp.GetGlobalOptimum()).ElementAt(0));
        }
Esempio n. 7
0
        public static OptimiserBuilder GetBuilder(DecisionSpace problemSpace)
        {
            var hyps = EvolutionaryAlgorithmHyperParameters.GetDefaultHyperParameters();

            var population = new Population(
                200);

            hyps.UpdateHyperParameterValue(
                EvolutionaryAlgorithmHyperParameters.Population_Size,
                200);

            IParentSelectionOperator parentSelector = new ParentSelectionTournament(
                20, false);

            IRecombinationOperator recombinationOperator = new CrossoverSimulatedBinary(
                2);;

            hyps.UpdateHyperParameterValue(
                EvolutionaryAlgorithmHyperParameters.Number_Of_Parents, 2);

            IMutationOperator mutationOperator = new MutationAddRandomNumber(
                0.1,
                0.1,
                1);

            IReinsertionOperator reinsertionOperator = new ReinsertionReplaceRandom();

            return(new EvolutionaryAlgorithmBuilderContinuousMO(population, problemSpace, hyps,
                                                                parentSelector, recombinationOperator, mutationOperator, reinsertionOperator));
        }
Esempio n. 8
0
        public static List <Individual> CreateNewIndividualsFromArray(double[][] testValues)
        {
            var ds  = DecisionSpace.CreateForUniformDoubleArray(testValues.ElementAt(0).Length, double.MinValue, double.MaxValue);
            var dvs = testValues.Select(v => DecisionVector.CreateFromArray(ds, v));

            return(dvs.Select(v => new Individual(v)).ToList());
        }
Esempio n. 9
0
        public void TwoUniformDoubleArrays_WithEqualBounds_AreEqual()
        {
            var space1 = DecisionSpace.CreateForUniformDoubleArray(Dims, MinValueContinuous, MaxValueContinuous);
            var space2 = DecisionSpace.CreateForUniformDoubleArray(Dims, MinValueContinuous, MaxValueContinuous);

            Assert.Equal(space1, space2);
        }
Esempio n. 10
0
        public void CreateInitialVertices_WithStepSizeZero_Throws()
        {
            var initialVertex = DecisionVector.CreateFromArray(
                DecisionSpace.CreateForUniformDoubleArray(3, double.MinValue, double.MaxValue),
                Enumerable.Repeat(0.0, 3));

            Assert.Throws <ArgumentOutOfRangeException>(() => Simplex.CreateInitialVertices(initialVertex, 0));
        }
Esempio n. 11
0
        public void TwoDim_CorrectlyIdentifiesIllegalSolution()
        {
            var evaluator = new Ellipsoidal(2);
            var ds        = DecisionSpace.CreateForUniformDoubleArray(2, double.MinValue, double.MaxValue);
            var legal     = evaluator.GetLegality(DecisionVector.CreateFromArray(ds, new[] { 11.0, -12.0 }));

            Assert.False(legal);
        }
Esempio n. 12
0
 /// <summary>
 /// Creates an evaluator for the ZDT3 problem.
 /// N-D Decision space constrained on [0,1]
 /// Two minimisation objectives, with Pareto optimal values at [x1, 1 - sqrt(x1) - x1.sin(10.pi.x1)]
 /// </summary>
 /// <param name="numberOfDimensions">The number of input dimensions (default is 30)</param>
 public Zdt3(int numberOfDimensions = 30) : base(
         "ZDT3",
         DecisionSpace.CreateForUniformDoubleArray(30, 0, 1, 0, 1),
         ContinuousProblemPropertyNames.TheLocation,
         ContinuousProblemPropertyNames.Result + "1", ContinuousProblemPropertyNames.Result + "2")
 {
     this.numberOfDimensions = numberOfDimensions;
 }
Esempio n. 13
0
 public MutationRandomSwapTests()
 {
     testDv = DecisionVector.CreateFromArray(
         DecisionSpace.CreateForUniformDoubleArray(8, double.MinValue, double.MaxValue),
         new double[8] {
         7, 6, 5, 4, 3, 2, 1, 0
     });
 }
Esempio n. 14
0
 protected ProblemMultipleObjective(string name, DecisionSpace decisionSpace,
                                    string definitionKey, params string[] solutionKeys)
     : base(definitionKey, solutionKeys)
 {
     this.name          = name;
     numberOfObjectives = solutionKeys.Length;
     this.decisionSpace = decisionSpace;
 }
 public MutationReplaceWithRandomNumberTests()
 {
     testDv = DecisionVector.CreateFromArray(
         DecisionSpace.CreateForUniformDoubleArray(8, 0, 10),
         new double[8] {
         7, 6, 5, 4, 3, 2, 1, 0
     });
 }
Esempio n. 16
0
 /// <summary>
 /// Creates an evaluator for the Styblinski-Tang Function.
 /// Constrained on [-5, 5]
 /// Global optimum is at [-2.903534, -2.903534, -2.903534,...]
 /// </summary>
 /// <param name="numDims">Number of input dimensions</param>
 public StyblinskiTang(int numDims) : base(
         "Styblinski-Tang Function",
         DecisionVector.CreateFromArray(
             DecisionSpace.CreateForUniformDoubleArray(numDims,
                                                       -5, 5,
                                                       -4.5, 2.5),
             Enumerable.Repeat(-2.903534, numDims).ToArray()))
 {
 }
Esempio n. 17
0
 /// <summary>
 /// Creates an evaluator for the Ellipsoidal Function.
 /// Constrained on [-10, 10]
 /// Global optimum is at [0,0,0,...]
 /// </summary>
 /// <param name="numDims">Number of input dimensions</param>
 public Ellipsoidal(int numDims) : base(
         "Ellipsoidal Function",
         DecisionVector.CreateFromArray(
             DecisionSpace.CreateForUniformDoubleArray(numDims,
                                                       -10, 10,
                                                       -5, 5),
             new double[numDims]))
 {
 }
Esempio n. 18
0
        public void GetNearestLegalLocation_AllContinuous_OneValueIsTooHigh_CorrectsIt()
        {
            var space          = DecisionSpace.CreateForUniformIntArray(Dims, MinValueDiscrete, MaxValueDiscrete);
            var expectedResult = Enumerable.Repeat <object>(MaxValueDiscrete, Dims);
            var testVector     = expectedResult.ToArray();

            testVector[Dims - 1] = MaxValueDiscrete + 1;
            Assert.Equal(expectedResult.ToArray(), space.GetNearestLegalLocation(testVector));
        }
Esempio n. 19
0
 /// <summary>
 /// Creates an evaluator for Salomon's Function.
 /// Assumes unconstrained, even though normally checked on a +/-100 basis
 /// Global optimum is at [0,0,0,...]
 /// </summary>
 /// <param name="numDims">Number of input dimensions</param>
 public Salomon(int numDims) : base(
         "Salomon's Function",
         DecisionVector.CreateFromArray(
             DecisionSpace.CreateForUniformDoubleArray(numDims,
                                                       double.MinValue, double.MaxValue,
                                                       -100, 100),
             new double[numDims]))
 {
 }
Esempio n. 20
0
 /// <summary>
 /// Creates an evaluator for the Schwefel Function.
 /// Constrained on [-500, 500]
 /// Global optimum is at [420.9687, 420.9687, 420.9687,...]
 /// </summary>
 /// <param name="numDims">Number of input dimensions</param>
 public Schwefel(int numDims) : base(
         "Schwefel Function",
         DecisionVector.CreateFromArray(
             DecisionSpace.CreateForUniformDoubleArray(numDims,
                                                       -500.0, 500.0,
                                                       -250, 475),
             Enumerable.Repeat(420.9687, numDims).ToArray()))
 {
 }
Esempio n. 21
0
        public void CorrectlyIdentifiesIllegalSolution()
        {
            var evaluator = new Zdt3();
            var ds        = DecisionSpace.CreateForUniformDoubleArray(30, -2, -1, -2, -1);
            var legal     = evaluator.GetLegality(DecisionVector.CreateFromArray(ds,
                                                                                 ds.Select(d => d.GetNextRandom(new SystemRandomSource()))));

            Assert.False(legal);
        }
Esempio n. 22
0
 /// <summary>
 /// Creates an evaluator for the Generalised Rastrigin Function.
 /// Assumes unconstrained, even though normally checked on a +/-5.12 basis
 /// Global optimum is at [0,0,0,...]
 /// </summary>
 /// <param name="numDims">Number of input dimensions</param>
 public Rastrigin(int numDims) : base(
         "Generalised Rastrigin Function",
         DecisionVector.CreateFromArray(
             DecisionSpace.CreateForUniformDoubleArray(numDims,
                                                       double.MinValue, double.MaxValue,
                                                       -5.12, 5.12),
             new double[numDims]))
 {
 }
Esempio n. 23
0
 /// <summary>
 /// Creates an evaluator for the Rosenbrock Function.
 /// Assumes unconstrained, even though normally checked on a [-5, 10] basis.
 /// Global optimum is at [1,1,1,...]
 /// </summary>
 /// <param name="numDims">Number of input dimensions</param>
 public Rosenbrock(int numDims) : base(
         "Rosenbrock Function",
         DecisionVector.CreateFromArray(
             DecisionSpace.CreateForUniformDoubleArray(numDims,
                                                       double.MinValue, double.MaxValue,
                                                       -5.0, 10.0),
             Enumerable.Repeat(1.0, numDims).ToArray()))
 {
 }
Esempio n. 24
0
        public void CreatedWithUniformIntArray_ConstructsOk()
        {
            var space = DecisionSpace.CreateForUniformIntArray(Dims, MinValueDiscrete, MaxValueDiscrete);

            Assert.Equal(Dims, space.Count);
            Assert.True(space.First().IsInBounds(MinValueDiscrete));
            Assert.True(space.First().IsInBounds(MaxValueDiscrete));
            Assert.False(space.First().IsInBounds(MinValueDiscrete - 1));
            Assert.False(space.First().IsInBounds(MaxValueDiscrete + 1));
        }
Esempio n. 25
0
        public RandomNumberManagerTests()
        {
            testDv = DecisionVector.CreateFromArray(
                DecisionSpace.CreateForUniformIntArray(8, 0, 7),
                new int[8] {
                7, 6, 5, 4, 3, 2, 1, 0
            });

            rngManager = new RandomNumberManager(new MersenneTwister(123456789));
        }
Esempio n. 26
0
        public CrossoverSimulatedBinaryTests()
        {
            var decisionSpaceUniform = DecisionSpace.CreateForUniformDoubleArray(
                4, double.MinValue, double.MaxValue);

            parent1 = DecisionVector.CreateFromArray(
                decisionSpaceUniform, new[] { 0.5, 1.5, 2.5, 3.5 });
            parent2 = DecisionVector.CreateFromArray(
                decisionSpaceUniform, new[] { 4.5, 3.5, 2.5, 1.5 });
        }
Esempio n. 27
0
        public void CreatedWithUniformDoubleArray_ConstructsOk()
        {
            var space = DecisionSpace.CreateForUniformDoubleArray(Dims, MinValueContinuous, MaxValueContinuous);

            var range = MaxValueContinuous - MinValueContinuous;

            Assert.Equal(Dims, space.Count);
            Assert.True(space.First().IsInBounds(MinValueContinuous + range / 2));
            Assert.False(space.First().IsInBounds(MinValueContinuous - range / 2));
            Assert.False(space.First().IsInBounds(MaxValueContinuous + range / 2));
        }
Esempio n. 28
0
        public void TwoDim_CorrectlyIdentifiesIllegalSolution()
        {
            var evaluator = new Schwefel(2);
            var ds        = DecisionSpace.CreateForUniformDoubleArray(2, double.MinValue, double.MaxValue);
            var legal     = evaluator.GetLegality(DecisionVector.CreateFromArray(ds, new[] { -501.0, 210.0 }));

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

            Assert.False(legal2);
        }
Esempio n. 29
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);
        }
Esempio n. 30
0
 public void CreatedWithInfiniteBounds_Throws()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                 DecisionSpace.CreateForUniformDoubleArray(Dims, double.NegativeInfinity, double.MaxValue));
     Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                 DecisionSpace.CreateForUniformDoubleArray(Dims, double.NegativeInfinity, 5.6));
     Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                 DecisionSpace.CreateForUniformDoubleArray(Dims, double.MinValue, double.PositiveInfinity));
     Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                 DecisionSpace.CreateForUniformDoubleArray(Dims, -3.6, double.PositiveInfinity));
 }