Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2825-NSGA3/HeuristicLab.Algorithms.NSGA3/3.3/Solution.cs @ 17958

Last change on this file since 17958 was 17727, checked in by dleko, 5 years ago

#2825 Refactoring.

File size: 1.8 KB
Line 
1using System;
2using HEAL.Attic;
3using HeuristicLab.Common;
4using HeuristicLab.Encodings.RealVectorEncoding;
5
6namespace HeuristicLab.Algorithms.NSGA3
7{
8    [StorableType("D35C9D79-77DF-4CF3-AB44-FCCC00E44C5F")]
9    public class Solution : IDeepCloneable
10    {
11        // Chromosome
12        [Storable]
13        public RealVector Chromosome { get; set; }
14
15        // actual fitness of solution as given by Problem
16        [Storable]
17        public double[] Objectives { get; set; }
18
19        // normalized fitness used in selection process (in order to not overwrite the original Fitness)
20        [Storable]
21        public double[] NormalizedObjectives { get; set; }
22
23        [StorableConstructor]
24        public Solution(StorableConstructorFlag _) { }
25
26        public Solution(RealVector chromosome)
27        {
28            Chromosome = chromosome;
29        }
30
31        public Solution(Solution solution, Cloner cloner)
32        {
33            Chromosome = cloner.Clone(solution.Chromosome);
34            if (solution.Objectives != null)
35            {
36                Objectives = new double[solution.Objectives.Length];
37                Array.Copy(solution.Objectives, Objectives, solution.Objectives.Length);
38            }
39            if (solution.NormalizedObjectives != null)
40            {
41                NormalizedObjectives = new double[solution.NormalizedObjectives.Length];
42                Array.Copy(solution.NormalizedObjectives, NormalizedObjectives, solution.NormalizedObjectives.Length);
43            }
44        }
45
46        public IDeepCloneable Clone(Cloner cloner)
47        {
48            return new Solution(this, cloner);
49        }
50
51        public object Clone()
52        {
53            return new Cloner().Clone(this);
54        }
55    }
56}
Note: See TracBrowser for help on using the repository browser.