Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3057_DynamicALPS/HeuristicLab.Algorithms.DynamicALPS/3.4/DynamicALPSASolution.cs @ 17438

Last change on this file since 17438 was 17438, checked in by kyang, 4 years ago

#3057 The first draft of Dynamic ALPS with SMS-EMOA by using a main-loop structure.

File size: 5.0 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.DynamicALPS
27{
28  [StorableType("F405DFE4-CCC9-4CAF-9EFC-1AF45DC81FE6")]
29
30  public interface IDynamicALPSSolution : IItem {
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    // KF, DynamicALPS, could also be used for any self-adpative EA
39    double IndividualPc { get; set; }   // individual crossover rate
40    double IndividualPm { get; set; }   // individual mutation rate
41    int Age { get; set; }               // age info for ALPS
42
43    int Dimensions { get; }
44  }
45
46
47
48  [Item("DynamicALPSSolution", "Represents a solution inside the DynamicALPS population")]
49  [StorableType("457A8E67-2B70-4767-896B-47056BD89732")]
50  public class DynamicALPSSolution : Item, IDynamicALPSSolution
51  {
52    [Storable]
53    public IItem Individual { get; set; }
54
55    [Storable]
56    public double[] Qualities { get; set; }
57
58    [Storable]
59    public double[] Constraints { get; set; }
60
61    //kf, sms-emoa
62    [Storable]
63    public double[] HypervolumeContribution { get; set; }
64
65    [Storable]
66    public int[] NondominanceRanking { get; set; }
67
68    [Storable]
69    public double IndividualPc { get; set; }
70
71    [Storable]
72    public double IndividualPm { get; set; }
73
74    [Storable]
75    public int Age { get; set; }
76
77    public DynamicALPSSolution(int nObjectives, int nConstraints)
78    {
79      Qualities = new double[nObjectives];
80      Constraints = new double[nConstraints];
81      HypervolumeContribution = new double[1];
82      NondominanceRanking = new int[1];
83      IndividualPc = 0;
84      IndividualPm = 0;
85      Age = 0;
86    }
87
88    public DynamicALPSSolution(IItem individual, int nObjectives, int nConstraints) : this(nObjectives, nConstraints)
89    {
90      Individual = individual;
91    }
92
93    public DynamicALPSSolution(IItem individual, double[] qualities, double[] constraints, double[] hypervolumecontribution, int[] nondominanceranking)
94    {
95      Individual = individual;
96      Qualities = qualities;
97      Constraints = constraints;
98      HypervolumeContribution = hypervolumecontribution;
99      NondominanceRanking = nondominanceranking;
100    }
101
102    public DynamicALPSSolution(double[] qualities)
103    {
104      Qualities = (double[])qualities.Clone();
105    }
106
107    public int Dimensions => Qualities == null ? 0 : Qualities.Length;
108
109    public override IDeepCloneable Clone(Cloner cloner)
110    {
111      return new DynamicALPSSolution(this, cloner);
112    }
113
114    protected DynamicALPSSolution(DynamicALPSSolution original, Cloner cloner) : base(original, cloner)
115    {
116      Qualities = (double[])original.Qualities.Clone();
117      Constraints = (double[])original.Qualities.Clone();
118      HypervolumeContribution = (double[])original.HypervolumeContribution.Clone();       // kf, sms-emoa
119      NondominanceRanking = (int[])original.NondominanceRanking.Clone();                  // kf, sms-emoa
120      Individual = (IItem)original.Individual.Clone(cloner);
121    }
122
123    [StorableConstructor]
124    protected DynamicALPSSolution(StorableConstructorFlag deserializing) : base(deserializing) { }
125  }
126
127  [Item("DynamicALPSSolution", "Represents a solution inside the DynamicALPS population")]
128
129
130
131  [StorableType("1EFC2459-C52E-4F95-9E14-23E69DCB23E0")]
132  public class DynamicALPSSolution<T> : DynamicALPSSolution where T : class, IItem
133  {
134    public new T Individual
135    {
136      get { return (T)base.Individual; }
137      set { base.Individual = value; }
138    }
139
140    public DynamicALPSSolution(T individual, int nObjectives, int nConstraints) : base(individual, nObjectives, nConstraints) { }
141
142    protected DynamicALPSSolution(DynamicALPSSolution<T> original, Cloner cloner) : base(original, cloner) { }
143
144    public override IDeepCloneable Clone(Cloner cloner)
145    {
146      return new DynamicALPSSolution<T>(this, cloner);
147    }
148
149    [StorableConstructor]
150    protected DynamicALPSSolution(StorableConstructorFlag deserializing) : base(deserializing) { }
151  }
152}
Note: See TracBrowser for help on using the repository browser.