Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3055_SMSEMOA/HeuristicLab.Algorithms.SMSEMOA/3.4/SMSEMOASolution.cs @ 17912

Last change on this file since 17912 was 17425, checked in by kyang, 5 years ago

#3055: Added the first version of SMS-EMOA

File size: 4.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HEAL.Attic;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25
26namespace HeuristicLab.Algorithms.SMSEMOA
27{
28  [StorableType("A232DF5F-1499-4BED-A80F-8EE090F6F1F7")]
29  public interface ISMSEMOASolution : IItem
30  {
31    IItem Individual { get; set; }
32    double[] Qualities { get; set; }
33    double[] Constraints { get; set; }
34    // KF, SMS-EMOA
35    double[] HypervolumeContribution { get; set; }
36    int[] NondominanceRanking { get; set; }
37
38    int Dimensions { get; }
39  }
40
41  [Item("SMSEMOASolution", "Represents a solution inside the SMSEMOA population")]
42  [StorableType("DC19B54D-7D95-4CA0-83A0-2F9893064C23")]
43  public class SMSEMOASolution : Item, ISMSEMOASolution
44  {
45    [Storable]
46    public IItem Individual { get; set; }
47
48    [Storable]
49    public double[] Qualities { get; set; }
50
51    [Storable]
52    public double[] Constraints { get; set; }
53
54    //kf, sms-emoa
55    [Storable]
56    public double[] HypervolumeContribution { get; set; }
57
58    [Storable]
59    public int[] NondominanceRanking { get; set; }
60
61    public SMSEMOASolution(int nObjectives, int nConstraints)
62    {
63      Qualities = new double[nObjectives];
64      Constraints = new double[nConstraints];
65      HypervolumeContribution = new double[1];
66      NondominanceRanking = new int[1];
67    }
68
69    public SMSEMOASolution(IItem individual, int nObjectives, int nConstraints) : this(nObjectives, nConstraints)
70    {
71      Individual = individual;
72    }
73
74    public SMSEMOASolution(IItem individual, double[] qualities, double[] constraints, double[] hypervolumecontribution, int[] nondominanceranking)
75    {
76      Individual = individual;
77      Qualities = qualities;
78      Constraints = constraints;
79      HypervolumeContribution = hypervolumecontribution;
80      NondominanceRanking = nondominanceranking;
81    }
82
83    public SMSEMOASolution(double[] qualities)
84    {
85      Qualities = (double[])qualities.Clone();
86    }
87
88    public int Dimensions => Qualities == null ? 0 : Qualities.Length;
89
90    public override IDeepCloneable Clone(Cloner cloner)
91    {
92      return new SMSEMOASolution(this, cloner);
93    }
94
95    protected SMSEMOASolution(SMSEMOASolution original, Cloner cloner) : base(original, cloner)
96    {
97      Qualities = (double[])original.Qualities.Clone();
98      Constraints = (double[])original.Qualities.Clone();
99      HypervolumeContribution = (double[])original.HypervolumeContribution.Clone();       // kf, sms-emoa
100      NondominanceRanking = (int[])original.NondominanceRanking.Clone();                  // kf, sms-emoa
101      Individual = (IItem)original.Individual.Clone(cloner);
102    }
103
104    [StorableConstructor]
105    protected SMSEMOASolution(StorableConstructorFlag deserializing) : base(deserializing) { }
106  }
107
108  [Item("SMSEMOASolution", "Represents a solution inside the SMSEMOA population")]
109  [StorableType("F33FFA68-9E0A-4C1B-964B-4F35BC6D78FC")]
110  public class SMSEMOASolution<T> : SMSEMOASolution where T : class, IItem
111  {
112    public new T Individual
113    {
114      get { return (T)base.Individual; }
115      set { base.Individual = value; }
116    }
117
118    public SMSEMOASolution(T individual, int nObjectives, int nConstraints) : base(individual, nObjectives, nConstraints) { }
119
120    protected SMSEMOASolution(SMSEMOASolution<T> original, Cloner cloner) : base(original, cloner) { }
121
122    public override IDeepCloneable Clone(Cloner cloner)
123    {
124      return new SMSEMOASolution<T>(this, cloner);
125    }
126
127    [StorableConstructor]
128    protected SMSEMOASolution(StorableConstructorFlag deserializing) : base(deserializing) { }
129  }
130}
Note: See TracBrowser for help on using the repository browser.