Changeset 17615


Ignore:
Timestamp:
06/20/20 12:33:24 (3 weeks ago)
Author:
dleko
Message:

#2825 The list of Reference Points are now a storable field in the NSGA3 class.

Location:
branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3
Files:
2 edited

Legend:

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

    r17559 r17615  
    2222    [Item("NSGA-III", "The Reference Point Based Non-dominated Sorting Genetic Algorithm III was introduced in Deb et al. 2013. An Evolutionary Many-Objective Optimization Algorithm Using Reference Point Based Non-dominated Sorting Approach. IEEE Transactions on Evolutionary Computation, 18(4), pp. 577-601.")]
    2323    [Creatable(Category = CreatableAttribute.Categories.PopulationBasedAlgorithms, Priority = 136)]
    24     [StorableType("30DF878D-D655-4E76-B3AD-2292C9DD6C5F")]
     24    [StorableType("07C745F7-A8A3-4F99-8B2C-F97E639F9AC3")]
    2525    public class NSGA3 : BasicAlgorithm
    2626    {
     
    4949        [Storable]
    5050        private Solution[] solutions;
     51
     52        [Storable]
     53        private List<ReferencePoint> referencePoints;
    5154
    5255        #endregion Storable fields
     
    182185
    183186            InitFields();
     187            InitReferencePoints();
    184188            InitResults();
    185             InitReferencePoints();
    186189            Analyze();
    187190        }
     
    200203            random = new MersenneTwister();
    201204            InitSolutions();
    202         }
    203 
    204         private void InitResults()
    205         {
    206             Results.Add(new Result(GeneratedReferencePointsResultName, "The initially generated reference points", new DoubleMatrix()));
    207             Results.Add(new Result(CurrentFrontResultName, "The Pareto Front", new DoubleMatrix()));
    208         }
    209 
    210         private void InitReferencePoints()
    211         {
    212             // Generate reference points and add them to results
    213             int nDiv = 5; // todo: figure out the correct number of divisions
    214             List<ReferencePoint> referencePoints = ReferencePoint.GenerateReferencePoints(Problem.Encoding.Length, nDiv);
    215             ResultsGeneratedReferencePoints = Utility.ConvertToDoubleMatrix(referencePoints);
    216205        }
    217206
     
    233222                solutions[i].Fitness = Evaluate(solutions[i].Chromosome);
    234223            }
     224        }
     225
     226        private void InitReferencePoints()
     227        {
     228            // Generate reference points and add them to results
     229            int nDiv = 5; // todo: figure out the correct number of divisions
     230            referencePoints = ReferencePoint.GenerateReferencePoints(Problem.Encoding.Length, nDiv);
     231            ResultsGeneratedReferencePoints = Utility.ConvertToDoubleMatrix(referencePoints);
     232        }
     233
     234        private void InitResults()
     235        {
     236            Results.Add(new Result(GeneratedReferencePointsResultName, "The initially generated reference points", Utility.ConvertToDoubleMatrix(referencePoints)));
     237            Results.Add(new Result(CurrentFrontResultName, "The Pareto Front", new DoubleMatrix()));
     238        }
     239
     240        private void Analyze()
     241        {
     242            ResultsSolutions = solutions.Select(s => s.Chromosome.ToArray()).ToMatrix();
     243            Problem.Analyze(
     244                solutions.Select(s => (Individual)new SingleEncodingIndividual(Problem.Encoding, new Scope { Variables = { new Variable(Problem.Encoding.Name, s.Chromosome) } })).ToArray(),
     245                solutions.Select(s => s.Fitness).ToArray(),
     246                Results,
     247                random
     248                );
    235249        }
    236250
     
    246260        }
    247261
    248         private void Analyze()
    249         {
    250             ResultsSolutions = solutions.Select(s => s.Chromosome.ToArray()).ToMatrix();
    251             Problem.Analyze(
    252                 solutions.Select(s => (Individual)new SingleEncodingIndividual(Problem.Encoding, new Scope { Variables = { new Variable(Problem.Encoding.Name, s.Chromosome) } })).ToArray(),
    253                 solutions.Select(s => s.Fitness).ToArray(),
    254                 Results,
    255                 random
    256                 );
    257         }
    258 
    259262        #endregion Private Methods
    260263    }
  • branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/ReferencePoint.cs

    r17558 r17615  
    11using System.Collections.Generic;
     2using HEAL.Attic;
     3using HeuristicLab.Common;
    24
    35namespace HeuristicLab.Algorithms.NSGA3
     
    911     */
    1012
    11     internal class ReferencePoint
     13    [StorableType("96DCBD85-7C8B-4546-B6F5-FB4AE0DF7158")]
     14    internal class ReferencePoint : IDeepCloneable
    1215    {
     16        #region Storable Properties
     17
     18        public double[] Values { get; }
     19
     20        #endregion Storable Properties
     21
     22        #region Properties
     23
     24        public int NumberOfDimensions => Values.Length;
     25
     26        #endregion Properties
     27
    1328        public ReferencePoint(int numberOfDimensions)
    1429        {
    15             NumberOfDimensions = numberOfDimensions;
    16             Values = new double[NumberOfDimensions];
     30            Values = new double[numberOfDimensions];
    1731        }
    1832
    1933        public ReferencePoint(ReferencePoint other)
    2034        {
    21             NumberOfDimensions = other.NumberOfDimensions;
    22             Values = new double[NumberOfDimensions];
    23             for (int i = 0; i < NumberOfDimensions; i++)
     35            Values = new double[other.NumberOfDimensions];
     36            for (int i = 0; i < other.NumberOfDimensions; i++)
    2437                Values[i] = other.Values[i];
    2538        }
    2639
    27         public int NumberOfDimensions { get; }
     40        public IDeepCloneable Clone(Cloner cloner)
     41        {
     42            // no cloner is required to copy a Reference Point
     43            return new ReferencePoint(this);
     44        }
    2845
    29         public double[] Values { get; }
     46        public object Clone()
     47        {
     48            return new Cloner().Clone(this);
     49        }
    3050
    3151        // todo: use this (for optimization)
     
    4363        }
    4464
     65        // maybe todo: move this to another class?
    4566        /// <summary>
    4667        /// Generate reference points that are evenly distributed over a hyperplane with dimensions
Note: See TracChangeset for help on using the changeset viewer.