Changeset 17615 for branches/2825-NSGA3
- Timestamp:
- 06/20/20 12:33:24 (4 years ago)
- 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 22 22 [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.")] 23 23 [Creatable(Category = CreatableAttribute.Categories.PopulationBasedAlgorithms, Priority = 136)] 24 [StorableType(" 30DF878D-D655-4E76-B3AD-2292C9DD6C5F")]24 [StorableType("07C745F7-A8A3-4F99-8B2C-F97E639F9AC3")] 25 25 public class NSGA3 : BasicAlgorithm 26 26 { … … 49 49 [Storable] 50 50 private Solution[] solutions; 51 52 [Storable] 53 private List<ReferencePoint> referencePoints; 51 54 52 55 #endregion Storable fields … … 182 185 183 186 InitFields(); 187 InitReferencePoints(); 184 188 InitResults(); 185 InitReferencePoints();186 189 Analyze(); 187 190 } … … 200 203 random = new MersenneTwister(); 201 204 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 results213 int nDiv = 5; // todo: figure out the correct number of divisions214 List<ReferencePoint> referencePoints = ReferencePoint.GenerateReferencePoints(Problem.Encoding.Length, nDiv);215 ResultsGeneratedReferencePoints = Utility.ConvertToDoubleMatrix(referencePoints);216 205 } 217 206 … … 233 222 solutions[i].Fitness = Evaluate(solutions[i].Chromosome); 234 223 } 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 ); 235 249 } 236 250 … … 246 260 } 247 261 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 random256 );257 }258 259 262 #endregion Private Methods 260 263 } -
branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/ReferencePoint.cs
r17558 r17615 1 1 using System.Collections.Generic; 2 using HEAL.Attic; 3 using HeuristicLab.Common; 2 4 3 5 namespace HeuristicLab.Algorithms.NSGA3 … … 9 11 */ 10 12 11 internal class ReferencePoint 13 [StorableType("96DCBD85-7C8B-4546-B6F5-FB4AE0DF7158")] 14 internal class ReferencePoint : IDeepCloneable 12 15 { 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 13 28 public ReferencePoint(int numberOfDimensions) 14 29 { 15 NumberOfDimensions = numberOfDimensions; 16 Values = new double[NumberOfDimensions]; 30 Values = new double[numberOfDimensions]; 17 31 } 18 32 19 33 public ReferencePoint(ReferencePoint other) 20 34 { 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++) 24 37 Values[i] = other.Values[i]; 25 38 } 26 39 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 } 28 45 29 public double[] Values { get; } 46 public object Clone() 47 { 48 return new Cloner().Clone(this); 49 } 30 50 31 51 // todo: use this (for optimization) … … 43 63 } 44 64 65 // maybe todo: move this to another class? 45 66 /// <summary> 46 67 /// Generate reference points that are evenly distributed over a hyperplane with dimensions
Note: See TracChangeset
for help on using the changeset viewer.