Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2987_MOEAD_Algorithm/HeuristicLab.Algorithms.MOEAD/3.4/MOEADSolution.cs @ 16684

Last change on this file since 16684 was 16630, checked in by bburlacu, 6 years ago

#2987: Migrate to new persistence. Add support for objective scaling.

File size: 3.6 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.MOEAD {
27  [StorableType("DFE1AC99-9AEF-4A35-884B-C82E2B3D84F7")]
28  public interface IMOEADSolution : IItem {
29    IItem Individual { get; set; }
30    double[] Qualities { get; set; }
31    double[] Constraints { get; set; }
32    int Dimensions { get; }
33  }
34
35  [Item("MOEADSolution", "Represents a solution inside the MOEA/D population")]
36  [StorableType("8D7DE459-E6D5-4B74-9135-00E27CF451D3")]
37  public class MOEADSolution : Item, IMOEADSolution {
38    [Storable]
39    public IItem Individual { get; set; }
40
41    [Storable]
42    public double[] Qualities { get; set; }
43
44    [Storable]
45    public double[] Constraints { get; set; }
46
47    public MOEADSolution(int nObjectives, int nConstraints) {
48      Qualities = new double[nObjectives];
49      Constraints = new double[nConstraints];
50    }
51
52    public MOEADSolution(IItem individual, int nObjectives, int nConstraints) : this(nObjectives, nConstraints) {
53      Individual = individual;
54    }
55
56    public MOEADSolution(IItem individual, double[] qualities, double[] constraints) {
57      Individual = individual;
58      Qualities = qualities;
59      Constraints = constraints;
60    }
61
62    public MOEADSolution(double[] qualities) {
63      Qualities = (double[])qualities.Clone();
64    }
65
66    public int Dimensions => Qualities == null ? 0 : Qualities.Length;
67
68    public override IDeepCloneable Clone(Cloner cloner) {
69      return new MOEADSolution(this, cloner);
70    }
71
72    protected MOEADSolution(MOEADSolution original, Cloner cloner) : base(original, cloner) {
73      Qualities = (double[])original.Qualities.Clone();
74      Constraints = (double[])original.Qualities.Clone();
75      Individual = (IItem)original.Individual.Clone(cloner);
76    }
77
78    [StorableConstructor]
79    protected MOEADSolution(StorableConstructorFlag deserializing) : base(deserializing) { }
80  }
81
82  [Item("MOEADSolution", "Represents a solution inside the MOEA/D population")]
83  [StorableType("24B4B79B-5828-4E6B-BE35-452DEA1FF538")]
84  public class MOEADSolution<T> : MOEADSolution where T : class, IItem {
85    public new T Individual {
86      get { return (T)base.Individual; }
87      set { base.Individual = value; }
88    }
89
90    public MOEADSolution(T individual, int nObjectives, int nConstraints) : base(individual, nObjectives, nConstraints) { }
91
92    protected MOEADSolution(MOEADSolution<T> original, Cloner cloner) : base(original, cloner) { }
93
94    public override IDeepCloneable Clone(Cloner cloner) {
95      return new MOEADSolution<T>(this, cloner);
96    }
97
98    [StorableConstructor]
99    protected MOEADSolution(StorableConstructorFlag deserializing) : base(deserializing) { }
100  }
101}
Note: See TracBrowser for help on using the repository browser.