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

Last change on this file since 16560 was 16560, checked in by bburlacu, 2 years ago

#2987: Create separate plugin for MOEA/D

File size: 2.6 KB
Line 
1using HeuristicLab.Common;
2using HeuristicLab.Core;
3using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
4
5namespace HeuristicLab.Algorithms.MOEAD {
6  public interface IMOEADSolution : IItem {
7    IItem Individual { get; set; }
8    double[] Qualities { get; set; }
9    double[] Constraints { get; set; }
10    int Dimensions { get; }
11  }
12
13  [Item("MOEADSolution", "Represents a solution inside the MOEA/D population")]
14  [StorableClass]
15  public class MOEADSolution : Item, IMOEADSolution {
16    [Storable]
17    public IItem Individual { get; set; }
18
19    [Storable]
20    public double[] Qualities { get; set; }
21
22    [Storable]
23    public double[] Constraints { get; set; }
24
25    public MOEADSolution(int nObjectives, int nConstraints) {
26      Qualities = new double[nObjectives];
27      Constraints = new double[nConstraints];
28    }
29
30    public MOEADSolution(IItem individual, int nObjectives, int nConstraints) : this(nObjectives, nConstraints) {
31      Individual = individual;
32    }
33
34    public MOEADSolution(IItem individual, double[] qualities, double[] constraints) {
35      Individual = individual;
36      Qualities = qualities;
37      Constraints = constraints;
38    }
39
40    public MOEADSolution(double[] qualities) {
41      Qualities = (double[])qualities.Clone();
42    }
43
44    public int Dimensions => Qualities == null ? 0 : Qualities.Length;
45
46    public override IDeepCloneable Clone(Cloner cloner) {
47      return new MOEADSolution(this, cloner);
48    }
49
50    protected MOEADSolution(MOEADSolution original, Cloner cloner) : base(original, cloner) {
51      Qualities = (double[])original.Qualities.Clone();
52      Constraints = (double[])original.Qualities.Clone();
53      Individual = (IItem)original.Individual.Clone(cloner);
54    }
55
56    [StorableConstructor]
57    protected MOEADSolution(bool deserializing) : base(deserializing) { }
58  }
59
60  [Item("MOEADSolution", "Represents a solution inside the MOEA/D population")]
61  [StorableClass]
62  public class MOEADSolution<T> : MOEADSolution where T : class, IItem {
63    public new T Individual {
64      get { return (T)base.Individual; }
65      set { base.Individual = value; }
66    }
67
68    public MOEADSolution(T individual, int nObjectives, int nConstraints) : base(individual, nObjectives, nConstraints) { }
69
70    protected MOEADSolution(MOEADSolution<T> original, Cloner cloner) : base(original, cloner) { }
71
72    public override IDeepCloneable Clone(Cloner cloner) {
73      return new MOEADSolution<T>(this, cloner);
74    }
75
76    [StorableConstructor]
77    protected MOEADSolution(bool deserializing) : base(deserializing) { }
78  }
79}
Note: See TracBrowser for help on using the repository browser.