Changeset 17617


Ignore:
Timestamp:
06/21/20 16:51:58 (3 weeks ago)
Author:
dleko
Message:

#2825 The reference points and the fronts are no longer stored.
Minor restructuring in NSGA3.

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

    r17616 r17617  
    5252        private List<Solution> solutions;
    5353
    54         [Storable]
    55         private List<List<Solution>> fronts;
    56 
    57         [Storable]
    58         private List<ReferencePoint> referencePoints;
    59 
    6054        #endregion Storable fields
    6155
     
    134128        public BoolValue DominateOnEqualQualities => DominateOnEqualQualitiesParameter.Value;
    135129
     130        public List<List<Solution>> Fronts { get; private set; }
     131
     132        public List<ReferencePoint> ReferencePoints { get; private set; }
     133
    136134        #endregion Properties
    137135
     
    151149
    152150        #endregion ResultsProperties
     151
     152        #region Constructors
    153153
    154154        public NSGA3() : base()
     
    178178        }
    179179
    180         #region Overriden Methods
    181 
    182180        public override IDeepCloneable Clone(Cloner cloner)
    183181        {
    184182            return new NSGA3(this, cloner);
    185183        }
     184
     185        #endregion Constructors
     186
     187        #region Initialization
    186188
    187189        protected override void Initialize(CancellationToken cancellationToken)
     
    195197        }
    196198
    197         protected override void Run(CancellationToken cancellationToken)
    198         {
    199             referencePoints = new List<ReferencePoint>(); // todo: use existing list of reference points
    200             for (int iteration = 0; iteration < MaximumGenerations.Value; iteration++)
    201                 ToNextGeneration();
    202         }
    203 
    204         #endregion Overriden Methods
    205 
    206         #region Private Methods
    207 
    208199        private void InitFields()
    209200        {
     
    235226            // Generate reference points and add them to results
    236227            int nDiv = 5; // todo: figure out the correct number of divisions
    237             referencePoints = ReferencePoint.GenerateReferencePoints(Problem.Encoding.Length, nDiv);
    238             ResultsGeneratedReferencePoints = Utility.ConvertToDoubleMatrix(referencePoints);
     228            ReferencePoints = ReferencePoint.GenerateReferencePoints(Problem.Encoding.Length, nDiv);
     229            ResultsGeneratedReferencePoints = Utility.ConvertToDoubleMatrix(ReferencePoints);
    239230        }
    240231
    241232        private void InitResults()
    242233        {
    243             Results.Add(new Result(GeneratedReferencePointsResultName, "The initially generated reference points", Utility.ConvertToDoubleMatrix(referencePoints)));
     234            Results.Add(new Result(GeneratedReferencePointsResultName, "The initially generated reference points", Utility.ConvertToDoubleMatrix(ReferencePoints)));
    244235            Results.Add(new Result(CurrentFrontResultName, "The Pareto Front", new DoubleMatrix()));
    245236        }
     237
     238        #endregion Initialization
     239
     240        #region Overriden Methods
     241
     242        protected override void Run(CancellationToken cancellationToken)
     243        {
     244            ReferencePoints = new List<ReferencePoint>(); // todo: use existing list of reference points
     245            for (int iteration = 0; iteration < MaximumGenerations.Value; iteration++)
     246                ToNextGeneration();
     247        }
     248
     249        #endregion Overriden Methods
     250
     251        #region Private Methods
    246252
    247253        private void Analyze()
     
    278284            // compute the pareto fronts using the DominationCalculator and discard the qualities
    279285            // part in the inner tuples
    280             fronts = DominationCalculator<Solution>.CalculateAllParetoFronts(rt.ToArray(), qualities, Problem.Maximization, out int[] rank, true)
     286            Fronts = DominationCalculator<Solution>.CalculateAllParetoFronts(rt.ToArray(), qualities, Problem.Maximization, out int[] rank, true)
    281287                .Select(list => new List<Solution>(list.Select(pair => pair.Item1))).ToList();
    282288
    283289            int i = 0;
    284290            List<Solution> lf = null; // last front to be included
    285             while (i < fronts.Count && st.Count < PopulationSize.Value)
    286             {
    287                 lf = fronts[i];
     291            while (i < Fronts.Count && st.Count < PopulationSize.Value)
     292            {
     293                lf = Fronts[i];
    288294                st = Utility.Concat(st, lf);
    289295                i++;
     
    297303                nextGeneration = new List<Solution>();
    298304                for (int f = 0; f < l; f++)
    299                     nextGeneration = Utility.Concat(nextGeneration, fronts[f]);
     305                    nextGeneration = Utility.Concat(nextGeneration, Fronts[f]);
    300306                Normalize(st);
    301307                Associate();
     
    328334                for (int i = 0; i < Problem.Encoding.Length; i++) weights[i] = EPSILON;
    329335                weights[j] = 1;
    330                 Func<Solution, double> func = s => ASF(s.Fitness, weights);
     336                double func(Solution s) => ASF(s.Fitness, weights);
    331337                extremePoints[j] = Utility.ArgMin(func, solutions);
    332338            }
     
    344350        private void NormalizeObjectives(List<double> intercepts, double[] idealPoint)
    345351        {
    346             for (int f = 0; f < fronts.Count; f++)
    347             {
    348                 foreach (var solution in fronts[f])
     352            for (int f = 0; f < Fronts.Count; f++)
     353            {
     354                foreach (var solution in Fronts[f])
    349355                {
    350356                    for (int i = 0; i < Problem.Encoding.Length; i++)
     
    365371        private void Associate()
    366372        {
    367             for (int f = 0; f < fronts.Count; f++)
    368             {
    369                 foreach (var solution in fronts[f])
     373            for (int f = 0; f < Fronts.Count; f++)
     374            {
     375                foreach (var solution in Fronts[f])
    370376                {
    371377                    // find reference point for which the perpendicular distance to the current
    372378                    // solution is the lowest
    373                     var rpAndDist = Utility.MinArgMin(rp => GetPerpendicularDistance(rp.Values, solution.Fitness), referencePoints);
     379                    var rpAndDist = Utility.MinArgMin(rp => GetPerpendicularDistance(rp.Values, solution.Fitness), ReferencePoints);
    374380
    375381                    //// todo: use ArgMin here
     
    385391                    //    }
    386392                    //}
    387                     if (f + 1 != fronts.Count)
     393                    if (f + 1 != Fronts.Count)
    388394                    {
    389395                        // Todo: Add member for reference point on index min_rp
     
    422428            List<int> dimensions = new List<int>();
    423429            for (int i = 0; i < Problem.Encoding.Length; i++) dimensions.Add(i);
    424             Func<int, double> f = dim => x[dim] / weight[dim];
     430            double f(int dim) => x[dim] / weight[dim];
    425431            return Utility.Max(f, dimensions);
    426432        }
  • branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/ReferencePoint.cs

    r17615 r17617  
    11using System.Collections.Generic;
    2 using HEAL.Attic;
    3 using HeuristicLab.Common;
    42
    53namespace HeuristicLab.Algorithms.NSGA3
     
    119     */
    1210
    13     [StorableType("96DCBD85-7C8B-4546-B6F5-FB4AE0DF7158")]
    14     internal class ReferencePoint : IDeepCloneable
     11    public class ReferencePoint
    1512    {
    16         #region Storable Properties
     13        #region Properties
    1714
    1815        public double[] Values { get; }
    19 
    20         #endregion Storable Properties
    21 
    22         #region Properties
    23 
    2416        public int NumberOfDimensions => Values.Length;
    2517
    2618        #endregion Properties
     19
     20        #region Constructors
    2721
    2822        public ReferencePoint(int numberOfDimensions)
     
    3832        }
    3933
    40         public IDeepCloneable Clone(Cloner cloner)
    41         {
    42             // no cloner is required to copy a Reference Point
    43             return new ReferencePoint(this);
    44         }
    45 
    46         public object Clone()
    47         {
    48             return new Cloner().Clone(this);
    49         }
     34        #endregion Constructors
    5035
    5136        // todo: use this (for optimization)
Note: See TracChangeset for help on using the changeset viewer.