[8498] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2012 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 |
|
---|
| 22 | using System.Collections.Generic;
|
---|
[8511] | 23 | using System.Linq;
|
---|
[8498] | 24 | using HeuristicLab.Common;
|
---|
[8501] | 25 | using HeuristicLab.Core;
|
---|
[8498] | 26 | using HeuristicLab.Optimization;
|
---|
[8501] | 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[8498] | 28 |
|
---|
| 29 | namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers {
|
---|
[8501] | 30 | [Item("ScatterPlotHelper", "Helper class for creating scatter plots.")]
|
---|
| 31 | [StorableClass]
|
---|
| 32 | public class ScatterPlotHelper : Item {
|
---|
[8498] | 33 |
|
---|
[8505] | 34 | [Storable]
|
---|
[8498] | 35 | private ResultCollection resultsCol;
|
---|
[8505] | 36 | [Storable]
|
---|
[8498] | 37 | private string chartName;
|
---|
[8505] | 38 | [Storable]
|
---|
[8498] | 39 | private string xAxisTitle;
|
---|
[8505] | 40 | [Storable]
|
---|
[8498] | 41 | private string yAxisTitle;
|
---|
[8511] | 42 | [Storable]
|
---|
| 43 | public bool StoreHistory { get; set; }
|
---|
| 44 | [Storable]
|
---|
| 45 | public bool CreateDataTable { get; set; }
|
---|
| 46 | [Storable]
|
---|
| 47 | public DataTableHelper dataTableHelper;
|
---|
| 48 | [Storable]
|
---|
| 49 | private string lastRowName;
|
---|
[8498] | 50 |
|
---|
[8505] | 51 | [Storable]
|
---|
[8498] | 52 | private ScatterPlot plot;
|
---|
| 53 | public ScatterPlot Plot {
|
---|
| 54 | get { return plot; }
|
---|
| 55 | private set { plot = value; }
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[8501] | 58 | [StorableConstructor]
|
---|
| 59 | private ScatterPlotHelper(bool deserializing) : base(deserializing) { }
|
---|
| 60 | private ScatterPlotHelper(ScatterPlotHelper original, Cloner cloner)
|
---|
| 61 | : base(original, cloner) {
|
---|
[8511] | 62 | StoreHistory = original.StoreHistory;
|
---|
| 63 | CreateDataTable = original.CreateDataTable;
|
---|
[8501] | 64 | }
|
---|
| 65 |
|
---|
[8511] | 66 | public ScatterPlotHelper()
|
---|
| 67 | : base() {
|
---|
| 68 | StoreHistory = true;
|
---|
| 69 | CreateDataTable = false;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | public ScatterPlotHelper(bool storeHistory, bool createDataTable)
|
---|
| 73 | : base() {
|
---|
| 74 | StoreHistory = storeHistory;
|
---|
| 75 | CreateDataTable = createDataTable;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[8501] | 78 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 79 | return new ScatterPlotHelper(this, cloner);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[8498] | 82 | public void InitializePlot(ResultCollection results, string chartName, string xAxisTitle, string yAxisTitle) {
|
---|
[8511] | 83 | if (CreateDataTable) {
|
---|
| 84 | if (dataTableHelper == null) {
|
---|
| 85 | dataTableHelper = new DataTableHelper();
|
---|
| 86 | }
|
---|
[8797] | 87 | dataTableHelper.InitializeChart(results, chartName + " Chart", new string[] { yAxisTitle });
|
---|
[8511] | 88 | }
|
---|
| 89 |
|
---|
[8498] | 90 | if (!results.ContainsKey(chartName)) {
|
---|
| 91 | this.chartName = chartName;
|
---|
| 92 | this.resultsCol = results;
|
---|
| 93 | this.xAxisTitle = xAxisTitle;
|
---|
| 94 | this.yAxisTitle = yAxisTitle;
|
---|
| 95 |
|
---|
| 96 | Initialize();
|
---|
[8515] | 97 | lastRowName = null;
|
---|
[8498] | 98 |
|
---|
| 99 | results.Add(new Result(chartName, Plot));
|
---|
[8511] | 100 | if (StoreHistory)
|
---|
| 101 | results.Add(new Result(chartName + " History", new ScatterPlotHistory()));
|
---|
[8498] | 102 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | public void AddPoint(string rowName, Point2D<double> point) {
|
---|
| 106 | if (!Plot.Rows.ContainsKey(rowName)) {
|
---|
[8511] | 107 | if (StoreHistory)
|
---|
| 108 | ((ScatterPlotHistory)resultsCol[chartName + " History"].Value).Add(Plot);
|
---|
| 109 |
|
---|
| 110 | if (CreateDataTable && lastRowName != null && lastRowName != string.Empty) {
|
---|
| 111 | double avg = Plot.Rows[lastRowName].Points.Average(x => x.Y);
|
---|
| 112 | dataTableHelper.AddPoint(avg);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[8498] | 115 | Initialize();
|
---|
| 116 | resultsCol[chartName].Value = Plot;
|
---|
| 117 |
|
---|
| 118 | var points = new List<Point2D<double>>();
|
---|
| 119 | points.Add(point);
|
---|
| 120 | ScatterPlotDataRow row = new ScatterPlotDataRow(rowName, null, points);
|
---|
| 121 | row.VisualProperties.PointStyle = ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Circle;
|
---|
| 122 | row.VisualProperties.PointSize = 5;
|
---|
| 123 | Plot.Rows.Add(row);
|
---|
[8511] | 124 | lastRowName = rowName;
|
---|
[8498] | 125 | } else {
|
---|
| 126 | Plot.Rows[rowName].Points.Add(point);
|
---|
| 127 | }
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | private void Initialize() {
|
---|
| 131 | Plot = new ScatterPlot(chartName, null);
|
---|
| 132 | Plot.VisualProperties.XAxisTitle = xAxisTitle;
|
---|
| 133 | Plot.VisualProperties.YAxisTitle = yAxisTitle;
|
---|
| 134 | }
|
---|
| 135 | }
|
---|
| 136 | }
|
---|