Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17657


Ignore:
Timestamp:
07/07/20 21:51:44 (4 years ago)
Author:
dleko
Message:

#2825 Implement recombination.

Location:
branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/HeuristicLab.Algorithms.NSGA3-3.3.csproj

    r17558 r17657  
    6969      <Private>False</Private>
    7070    </Reference>
     71    <Reference Include="HeuristicLab.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec" />
    7172    <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    7273      <SpecificVersion>False</SpecificVersion>
     
    112113    <Compile Include="Properties\AssemblyInfo.cs" />
    113114    <Compile Include="ReferencePoint.cs" />
     115    <Compile Include="SimulatedBinaryCrossover.cs" />
    114116    <Compile Include="Solution.cs" />
    115117    <Compile Include="Utility.cs" />
  • branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/NSGA3.cs

    r17619 r17657  
    11using System;
    22using System.Collections.Generic;
     3using System.Diagnostics;
    34using System.Linq;
    45using System.Threading;
     
    6465        private const string SetSeedRandomlyName = "SetSeedRandomly";
    6566        private const string PopulationSizeName = "PopulationSize";
    66         private const string CrossoverProbabilityName = "CrossOverProbability";
     67        private const string CrossoverProbabilityName = "CrossoverProbability";
     68        private const string CrossoverContiguityName = "CrossoverContiguity";
    6769        private const string MutationProbabilityName = "MutationProbability";
    6870        private const string MaximumGenerationsName = "MaximumGenerations";
     
    98100        }
    99101
     102        private IFixedValueParameter<DoubleValue> CrossoverContiguityParameter
     103        {
     104            get { return (IFixedValueParameter<DoubleValue>)Parameters[CrossoverContiguityName]; }
     105        }
     106
    100107        private IFixedValueParameter<PercentValue> MutationProbabilityParameter
    101108        {
     
    124131
    125132        public PercentValue CrossoverProbability => CrossoverProbabilityParameter.Value;
     133
     134        public DoubleValue CrossoverContiguity => CrossoverContiguityParameter.Value;
    126135
    127136        public PercentValue MutationProbability => MutationProbabilityParameter.Value;
     
    159168            Parameters.Add(new FixedValueParameter<IntValue>(SeedName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
    160169            Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyName, "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
    161             Parameters.Add(new FixedValueParameter<IntValue>(PopulationSizeName, "The size of the population of Individuals.", new IntValue(100)));
     170            Parameters.Add(new FixedValueParameter<IntValue>(PopulationSizeName, "The size of the population of Individuals.", new IntValue(200)));
    162171            Parameters.Add(new FixedValueParameter<PercentValue>(CrossoverProbabilityName, "The probability that the crossover operator is applied on two parents.", new PercentValue(0.9)));
     172            Parameters.Add(new FixedValueParameter<DoubleValue>(CrossoverContiguityName, "The contiguity value for the Simulated Binary Crossover that specifies how close a child should be to its parents (larger value means closer). The value must be greater than or equal than 0. Typical values are in the range [2;5]."));
    163173            Parameters.Add(new FixedValueParameter<PercentValue>(MutationProbabilityName, "The probability that the mutation operator is applied on a Individual.", new PercentValue(0.05)));
    164174            Parameters.Add(new FixedValueParameter<IntValue>(MaximumGenerationsName, "The maximum number of generations which should be processed.", new IntValue(1000)));
     
    195205
    196206            InitFields();
     207            InitResults();
    197208            InitReferencePoints();
    198             InitResults();
    199209            Analyze();
    200210        }
     
    218228                RealVector randomRealVector = new RealVector(Problem.Encoding.Length, random, minBound, maxBound);
    219229
    220                 solutions.Add(new Solution(StorableConstructorFlag.Default)
    221                 {
    222                     Chromosome = randomRealVector
    223                 });
     230                solutions.Add(new Solution(randomRealVector));
    224231                solutions[i].Fitness = Evaluate(solutions[i].Chromosome);
    225232            }
     
    236243        private void InitResults()
    237244        {
    238             Results.Add(new Result(GeneratedReferencePointsResultName, "The initially generated reference points", Utility.ConvertToDoubleMatrix(ReferencePoints)));
     245            Results.Add(new Result(GeneratedReferencePointsResultName, "The initially generated reference points", new DoubleMatrix()));
    239246            Results.Add(new Result(CurrentFrontResultName, "The Pareto Front", new DoubleMatrix()));
    240247        }
     
    288295
    289296            // Do non-dominated sort
    290             var qualities = Utility.ToFitnessMatrix(solutions);
     297            var qualities = Utility.ToFitnessMatrix(rt);
    291298            // compute the pareto fronts using the DominationCalculator and discard the qualities
    292299            // part in the inner tuples
     
    578585        private List<Solution> Recombine(List<Solution> solutions)
    579586        {
    580             throw new NotImplementedException();
     587            List<Solution> childSolutions = new List<Solution>();
     588
     589            for (int i = 0; i < solutions.Count; i += 2)
     590            {
     591                int parentIndex1 = random.Next(solutions.Count);
     592                int parentIndex2 = random.Next(solutions.Count);
     593                // ensure that the parents are not the same object
     594                if (parentIndex1 == parentIndex2) parentIndex2 = (parentIndex2 + 1) % solutions.Count;
     595                var parent1 = solutions[parentIndex1];
     596                var parent2 = solutions[parentIndex2];
     597
     598                // Do crossover with crossoverProbabilty == 1 in order to guarantee that a crossover happens
     599                var children = SimulatedBinaryCrossover.Apply(random, Problem.Encoding.Bounds, parent1.Chromosome, parent2.Chromosome, 1);
     600                Debug.Assert(children != null);
     601
     602                var child1 = new Solution(children.Item1);
     603                var child2 = new Solution(children.Item2);
     604                child1.Fitness = Evaluate(child1.Chromosome);
     605                child2.Fitness = Evaluate(child1.Chromosome);
     606
     607                childSolutions.Add(child1);
     608                childSolutions.Add(child2);
     609            }
     610
     611            return childSolutions;
    581612        }
    582613
    583614        private List<Solution> Mutate(List<Solution> solutions)
    584615        {
    585             throw new NotImplementedException();
     616            foreach (var solution in solutions)
     617            {
     618                UniformOnePositionManipulator.Apply(random, solution.Chromosome, Problem.Encoding.Bounds);
     619            }
     620            return solutions;
    586621        }
    587622
  • branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/Plugin.cs

    r17557 r17657  
    1717    [PluginDependency("HeuristicLab.Encodings.BinaryVectorEncoding", "3.3")]
    1818    [PluginDependency("HeuristicLab.Encodings.RealVectorEncoding", "3.3")]
     19    [PluginDependency("HeuristicLab.Operators", "3.3")]
    1920    [PluginDependency("HeuristicLab.Optimization", "3.3")]
    2021    [PluginDependency("HeuristicLab.Parameters", "3.3")]
  • branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/Solution.cs

    r17618 r17657  
    33using HeuristicLab.Common;
    44using HeuristicLab.Encodings.RealVectorEncoding;
    5 using HeuristicLab.Optimization;
    65
    76namespace HeuristicLab.Algorithms.NSGA3
    87{
    98    [StorableType("D35C9D79-77DF-4CF3-AB44-FCCC00E44C5F")]
    10     public class Solution : Individual, IDeepCloneable
     9    public class Solution : IDeepCloneable
    1110    {
    1211        // Chromosome
     
    1615        public double[] Fitness { get; set; }
    1716
    18         public Solution(StorableConstructorFlag _) : base(_)
     17        public Solution(RealVector chromosome)
    1918        {
     19            Chromosome = chromosome;
     20        }
     21
     22        public Solution(Solution solution, Cloner cloner)
     23        {
     24            Chromosome = cloner.Clone(solution.Chromosome);
     25            Fitness = new double[solution.Fitness.Length];
     26            Array.Copy(solution.Fitness, Fitness, solution.Fitness.Length);
    2027        }
    2128
    2229        public IDeepCloneable Clone(Cloner cloner)
    2330        {
    24             throw new NotImplementedException();
     31            return new Solution(this, cloner);
    2532        }
    2633
    2734        public object Clone()
    2835        {
    29             throw new NotImplementedException();
    30         }
    31 
    32         public override TEncoding GetEncoding<TEncoding>()
    33         {
    34             throw new NotImplementedException();
    35         }
    36 
    37         public override Individual Copy()
    38         {
    39             throw new NotImplementedException();
     36            return new Cloner().Clone(this);
    4037        }
    4138    }
Note: See TracChangeset for help on using the changeset viewer.