source: branches/2521_ProblemRefactoring/HeuristicLab.Analysis/3.3/MultiObjective/ParetoFrontScatterPlot.cs @ 17230

Last change on this file since 17230 was 17230, checked in by abeham, 11 months ago

#2521: add multi-objective analysis to all multi-objective encoding-base problems

File size: 6.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 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 System;
23using System.Collections.Generic;
24using System.Drawing;
25using System.Linq;
26using HEAL.Attic;
27using HeuristicLab.Common;
28using HeuristicLab.Core;
29
30namespace HeuristicLab.Analysis {
31  [StorableType("1bc5f640-ed3a-49dd-9dca-aa034cc81e12")]
32  [Item("Pareto Front Scatter Plot", "The optimal front, current front(s) and associated items.")]
33  public class ParetoFrontScatterPlot<T> : Item where T: class, IItem {
34
35    public static new Image StaticItemImage {
36      get { return HeuristicLab.Common.Resources.VSImageLibrary.Performance; }
37    }
38
39    [Storable]
40    private int objectives;
41    public int Objectives {
42      get { return objectives; }
43    }
44
45    [Storable]
46    private IReadOnlyList<double[][]> fronts;
47    public IReadOnlyList<double[][]> Fronts {
48      get { return fronts; }
49    }
50
51    [Storable]
52    private IReadOnlyList<T[]> items;
53    public IReadOnlyList<T[]> Items {
54      get { return items; }
55    }
56
57    [Storable]
58    private IReadOnlyList<double[]> bestKnownFront;
59    public IReadOnlyList<double[]> BestKnownFront {
60      get { return bestKnownFront; }
61    }
62
63    [StorableConstructor]
64    protected ParetoFrontScatterPlot(StorableConstructorFlag _) : base(_) { }
65    public ParetoFrontScatterPlot() { }
66    /// <summary>
67    /// Provides the data for displaying a multi-objective population in a scatter plot.
68    /// </summary>
69    /// <param name="items">The solutions grouped by pareto front (first is best).</param>
70    /// <param name="qualities">The objective vectors grouped by pareto front (first is best).</param>
71    /// <param name="objectives">The number of objectives.</param>
72    /// <param name="bestKnownParetoFront">Optional, the best known front in objective space.</param>
73    public ParetoFrontScatterPlot(IReadOnlyList<T[]> items, IReadOnlyList<double[][]> qualities, int objectives, IReadOnlyList<double[]> bestKnownParetoFront = null)
74    {
75      this.fronts = qualities;
76      this.items = items;
77      this.bestKnownFront = bestKnownParetoFront;
78      this.objectives = objectives;
79    }
80    /// <summary>
81    /// Provides the data for displaying a multi-objective population in a scatter plot.
82    /// </summary>
83    /// <param name="fronts">The fronts (first is best) with the indices of the solutions and qualities.</param>
84    /// <param name="items">The solutions.</param>
85    /// <param name="qualities">The objective vectors for each solution.</param>
86    /// <param name="objectives">The number of objectives.</param>
87    /// <param name="bestKnownParetoFront">Optional, the best known front in objective space.</param>
88    public ParetoFrontScatterPlot(List<List<int>> fronts, IReadOnlyList<T> items, IReadOnlyList<double[]> qualities, int objectives, IReadOnlyList<double[]> bestKnownParetoFront = null)
89    {
90      this.fronts = fronts.Select(x => x.Select(y => qualities[y]).ToArray()).ToArray();
91      this.items = fronts.Select(x => x.Select(y => items[y]).ToArray()).ToArray();
92      this.bestKnownFront = bestKnownParetoFront;
93      this.objectives = objectives;
94
95    }
96    protected ParetoFrontScatterPlot(ParetoFrontScatterPlot<T> original, Cloner cloner)
97      : base(original, cloner) {
98      if (original.fronts != null) fronts = original.fronts.Select(s => s.Select(x => x.ToArray()).ToArray()).ToArray();
99      if (original.items != null) items = original.items.Select(s => s.Select(cloner.Clone).ToArray()).ToArray();
100      if (original.bestKnownFront != null) bestKnownFront = original.bestKnownFront.Select(s => s.ToArray()).ToArray();
101      objectives = original.objectives;
102    }
103    public override IDeepCloneable Clone(Cloner cloner) {
104      return new ParetoFrontScatterPlot<T>(this, cloner);
105    }
106  }
107
108  [StorableType("3BF7AD0E-8D55-4033-974A-01DB16F9E41A")]
109  [Item("Pareto Front Scatter Plot", "The optimal front, current front and its associated Points in the searchspace")]
110  [Obsolete("Use the generic ParetoFrontScatterPlot<T> instead.")]
111  public class ParetoFrontScatterPlot : Item {
112    public static new Image StaticItemImage {
113      get { return HeuristicLab.Common.Resources.VSImageLibrary.Performance; }
114    }
115
116    [Storable]
117    private int objectives;
118    public int Objectives {
119      get { return objectives; }
120    }
121
122    [Storable]
123    private int problemSize;
124    public int ProblemSize {
125      get { return problemSize; }
126    }
127
128    [Storable]
129    private double[][] qualities;
130    public double[][] Qualities {
131      get { return qualities; }
132    }
133
134    [Storable]
135    private double[][] solutions;
136    public double[][] Solutions {
137      get { return solutions; }
138    }
139
140    [Storable]
141    private double[][] paretoFront;
142    public double[][] ParetoFront {
143      get { return paretoFront; }
144    }
145
146    #region Constructor, Cloning & Persistance
147    public ParetoFrontScatterPlot(double[][] qualities, double[][] solutions, double[][] paretoFront, int objectives, int problemSize) {
148      this.qualities = qualities;
149      this.solutions = solutions;
150      this.paretoFront = paretoFront;
151      this.objectives = objectives;
152      this.problemSize = problemSize;
153    }
154    public ParetoFrontScatterPlot() { }
155
156    protected ParetoFrontScatterPlot(ParetoFrontScatterPlot original, Cloner cloner)
157      : base(original, cloner) {
158      if (original.qualities != null) qualities = original.qualities.Select(s => s.ToArray()).ToArray();
159      if (original.solutions != null) solutions = original.solutions.Select(s => s.ToArray()).ToArray();
160      if (original.paretoFront != null) paretoFront = original.paretoFront.Select(s => s.ToArray()).ToArray();
161      objectives = original.objectives;
162      problemSize = original.problemSize;
163    }
164    public override IDeepCloneable Clone(Cloner cloner) {
165      return new ParetoFrontScatterPlot(this, cloner);
166    }
167
168    [StorableConstructor]
169    protected ParetoFrontScatterPlot(StorableConstructorFlag _) : base(_) { }
170    #endregion
171  }
172}
Note: See TracBrowser for help on using the repository browser.