Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15203 for trunk


Ignore:
Timestamp:
07/11/17 19:36:03 (7 years ago)
Author:
pfleck
Message:

#2592

  • Renamed ScatterPlotContent to ParetoFrontScatterPlot (also renamed corresponding view).
  • Refactored ParetoFrontScatterPlotView (use ScatterPlot internally).
Location:
trunk/sources
Files:
5 edited
3 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/MOCMAEvolutionStrategy.cs

    r15177 r15203  
    245245      set { Results[CurrentFrontResultName].Value = value; }
    246246    }
    247     private ScatterPlotContent ResultsScatterPlot {
    248       get { return (ScatterPlotContent)Results[ScatterPlotResultName].Value; }
     247    private ParetoFrontScatterPlot ResultsScatterPlot {
     248      get { return (ParetoFrontScatterPlot)Results[ScatterPlotResultName].Value; }
    249249      set { Results[ScatterPlotResultName].Value = value; }
    250250    }
     
    353353      Results.Add(new Result(TimetableResultName, "Different quality meassures in a timeseries", table));
    354354      Results.Add(new Result(CurrentFrontResultName, "The current front", new DoubleMatrix()));
    355       Results.Add(new Result(ScatterPlotResultName, "A scatterplot displaying the evaluated solutions and (if available) the analytically optimal front", new ScatterPlotContent(null, null, null, 2)));
     355      Results.Add(new Result(ScatterPlotResultName, "A scatterplot displaying the evaluated solutions and (if available) the analytically optimal front", new ParetoFrontScatterPlot()));
    356356
    357357      var problem = Problem as MultiObjectiveTestFunctionProblem;
     
    361361        ResultsDifferenceBestKnownHypervolume = ResultsBestKnownHypervolume;
    362362      }
    363       ResultsScatterPlot = new ScatterPlotContent(new double[0][], new double[0][], problem.BestKnownFront.ToJaggedArray(), problem.Objectives);
     363      ResultsScatterPlot = new ParetoFrontScatterPlot(new double[0][], new double[0][], problem.BestKnownFront.ToJaggedArray(), problem.Objectives, problem.ProblemSize);
    364364    }
    365365    #endregion
     
    470470
    471471    private void Analyze() {
    472       ResultsScatterPlot = new ScatterPlotContent(solutions.Select(x => x.Fitness).ToArray(), solutions.Select(x => x.Mean.ToArray()).ToArray(), ResultsScatterPlot.ParetoFront, ResultsScatterPlot.Objectives);
     472      ResultsScatterPlot = new ParetoFrontScatterPlot(solutions.Select(x => x.Fitness).ToArray(), solutions.Select(x => x.Mean.ToArray()).ToArray(), ResultsScatterPlot.ParetoFront, ResultsScatterPlot.Objectives, ResultsScatterPlot.ProblemSize);
    473473      ResultsSolutions = solutions.Select(x => x.Mean.ToArray()).ToMatrix();
    474474
  • trunk/sources/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Analyzers/ScatterPlotAnalyzer.cs

    r14111 r15203  
    3737    }
    3838
    39     public IResultParameter<ScatterPlotContent> ScatterPlotResultParameter {
    40       get { return (IResultParameter<ScatterPlotContent>)Parameters["Scatterplot"]; }
     39    public IResultParameter<ParetoFrontScatterPlot> ScatterPlotResultParameter {
     40      get { return (IResultParameter<ParetoFrontScatterPlot>)Parameters["Scatterplot"]; }
    4141    }
    4242
     
    5151    public ScatterPlotAnalyzer() {
    5252      Parameters.Add(new ScopeTreeLookupParameter<RealVector>("Individuals", "The individual solutions to the problem"));
    53       Parameters.Add(new ResultParameter<ScatterPlotContent>("Scatterplot", "The scatterplot for the current and optimal (if known front)"));
     53      Parameters.Add(new ResultParameter<ParetoFrontScatterPlot>("Scatterplot", "The scatterplot for the current and optimal (if known front)"));
    5454
    5555    }
     
    5757    public override IOperation Apply() {
    5858      var qualities = QualitiesParameter.ActualValue;
     59      var individuals = IndividualsParameter.ActualValue;
    5960      var testFunction = TestFunctionParameter.ActualValue;
    6061      int objectives = qualities[0].Length;
    61       var individuals = IndividualsParameter.ActualValue;
     62      int problemSize = individuals[0].Length;
    6263
    6364      double[][] optimalFront = new double[0][];
     
    6869      var solutionClones = individuals.Select(s => s.ToArray()).ToArray();
    6970
    70       ScatterPlotResultParameter.ActualValue = new ScatterPlotContent(qualityClones, solutionClones, optimalFront, objectives);
     71      ScatterPlotResultParameter.ActualValue = new ParetoFrontScatterPlot(qualityClones, solutionClones, optimalFront, objectives, problemSize);
    7172
    7273      return base.Apply();
  • trunk/sources/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/HeuristicLab.Problems.TestFunctions.MultiObjective-3.3.csproj

    r14168 r15203  
    111111    <Compile Include="Calculators\InvertedGenerationalDistance.cs" />
    112112    <Compile Include="Calculators\GenerationalDistance.cs" />
    113     <Compile Include="ScatterPlotContent.cs" />
     113    <Compile Include="ParetoFrontScatterPlot.cs" />
    114114    <Compile Include="Utilities.cs" />
    115115    <Compile Include="Instances\MISCInstanceProvider.cs" />
  • trunk/sources/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/ParetoFrontScatterPlot.cs

    r15202 r15203  
    1919 */
    2020#endregion
     21
    2122using System.Linq;
    2223using HeuristicLab.Common;
     
    2627namespace HeuristicLab.Problems.TestFunctions.MultiObjective {
    2728  [StorableClass]
    28   [Item("ScatterPlot", "The optimal front, current front and its associated Points in the searchspace")]
    29   public class ScatterPlotContent : Item {
     29  [Item("Pareto Front Scatter Plot", "The optimal front, current front and its associated Points in the searchspace")]
     30  public class ParetoFrontScatterPlot : Item {
     31
     32    [Storable]
     33    private int objectives;
     34    public int Objectives {
     35      get { return objectives; }
     36    }
     37
     38    [Storable]
     39    private int problemSize;
     40    public int ProblemSize {
     41      get { return problemSize; }
     42    }
    3043
    3144    [Storable]
    3245    private double[][] qualities;
    3346    public double[][] Qualities {
    34       get {
    35         return qualities;
    36       }
    37 
    38       private set {
    39         qualities = value;
    40       }
    41     }
    42 
    43     [Storable]
    44     private int objectives;
    45     public int Objectives {
    46       get {
    47         return objectives;
    48       }
    49 
    50       private set {
    51         objectives = value;
    52       }
     47      get { return qualities; }
    5348    }
    5449
     
    5651    private double[][] solutions;
    5752    public double[][] Solutions {
    58       get {
    59         return solutions;
    60       }
    61 
    62       private set {
    63         solutions = value;
    64       }
     53      get { return solutions; }
    6554    }
    6655
     
    6857    private double[][] paretoFront;
    6958    public double[][] ParetoFront {
    70       get {
    71         return paretoFront;
    72       }
    73 
    74       private set {
    75         paretoFront = value;
    76       }
     59      get { return paretoFront; }
    7760    }
    7861
    79     [StorableConstructor]
    80     protected ScatterPlotContent(bool deserializing) : base() { }
    81 
    82     protected ScatterPlotContent(ScatterPlotContent original, Cloner cloner)
    83       : this() {
    84       this.qualities = original.qualities.Select(s => s.ToArray()).ToArray();
    85       this.solutions = original.solutions.Select(s => s.ToArray()).ToArray();
    86       this.paretoFront = original.paretoFront.Select(s => s.ToArray()).ToArray();
    87       this.objectives = original.objectives;
    88     }
    89     protected ScatterPlotContent() : base() { }
    90     public ScatterPlotContent(double[][] qualities, double[][] solutions, double[][] paretoFront, int objectives) {
     62    #region Constructor, Cloning & Persistance
     63    public ParetoFrontScatterPlot(double[][] qualities, double[][] solutions, double[][] paretoFront, int objectives, int problemSize) {
    9164      this.qualities = qualities;
    9265      this.solutions = solutions;
    9366      this.paretoFront = paretoFront;
    9467      this.objectives = objectives;
     68      this.problemSize = problemSize;
     69    }
     70    public ParetoFrontScatterPlot() { }
     71
     72    protected ParetoFrontScatterPlot(ParetoFrontScatterPlot original, Cloner cloner)
     73      : base(original, cloner) {
     74      if (original.qualities != null) qualities = original.qualities.Select(s => s.ToArray()).ToArray();
     75      if (original.solutions != null) solutions = original.solutions.Select(s => s.ToArray()).ToArray();
     76      if (original.paretoFront != null) paretoFront = original.paretoFront.Select(s => s.ToArray()).ToArray();
     77      objectives = original.objectives;
     78      problemSize = original.problemSize;
     79    }
     80    public override IDeepCloneable Clone(Cloner cloner) {
     81      return new ParetoFrontScatterPlot(this, cloner);
    9582    }
    9683
    97     public override IDeepCloneable Clone(Cloner cloner) {
    98       return new ScatterPlotContent(this, cloner);
    99     }
     84    [StorableConstructor]
     85    protected ParetoFrontScatterPlot(bool deserializing)
     86      : base(deserializing) { }
     87    #endregion
    10088  }
    10189}
  • trunk/sources/HeuristicLab.Problems.TestFunctions.Views/3.3/HeuristicLab.Problems.TestFunctions.Views-3.3.csproj

    r14125 r15203  
    105105    <Reference Include="System.Drawing" />
    106106    <Reference Include="System.Windows.Forms" />
    107     <Reference Include="System.Windows.Forms.DataVisualization" />
    108     <Reference Include="System.Xml.Linq">
    109       <RequiredTargetFramework>3.5</RequiredTargetFramework>
    110     </Reference>
    111     <Reference Include="System.Data.DataSetExtensions">
    112       <RequiredTargetFramework>3.5</RequiredTargetFramework>
    113     </Reference>
    114     <Reference Include="System.Data" />
    115     <Reference Include="System.Xml" />
    116   </ItemGroup>
    117   <ItemGroup>
    118     <Compile Include="MultiObjectiveTestFunctionParetoFrontScatterPlotView.cs">
     107  </ItemGroup>
     108  <ItemGroup>
     109    <Compile Include="ParetoFrontScatterPlotView.cs">
    119110      <SubType>UserControl</SubType>
    120111    </Compile>
    121     <Compile Include="MultiObjectiveTestFunctionParetoFrontScatterPlotView.Designer.cs">
    122       <DependentUpon>MultiObjectiveTestFunctionParetoFrontScatterPlotView.cs</DependentUpon>
     112    <Compile Include="ParetoFrontScatterPlotView.Designer.cs">
     113      <DependentUpon>ParetoFrontScatterPlotView.cs</DependentUpon>
    123114    </Compile>
    124115    <Compile Include="Plugin.cs" />
     
    143134  </ItemGroup>
    144135  <ItemGroup>
     136    <ProjectReference Include="..\..\HeuristicLab.Analysis.Views\3.3\HeuristicLab.Analysis.Views-3.3.csproj">
     137      <Project>{76945d76-ca61-4147-9dc2-0acdcddf87f9}</Project>
     138      <Name>HeuristicLab.Analysis.Views-3.3</Name>
     139      <Private>False</Private>
     140    </ProjectReference>
     141    <ProjectReference Include="..\..\HeuristicLab.Analysis\3.3\HeuristicLab.Analysis-3.3.csproj">
     142      <Project>{887425B4-4348-49ED-A457-B7D2C26DDBF9}</Project>
     143      <Name>HeuristicLab.Analysis-3.3</Name>
     144      <Private>False</Private>
     145    </ProjectReference>
    145146    <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj">
    146147      <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project>
     
    211212      <Project>{88B9B0E3-344E-4196-82A3-0F9732506FE8}</Project>
    212213      <Name>HeuristicLab.Problems.TestFunctions-3.3</Name>
    213       <Private>False</Private>
    214     </ProjectReference>
    215     <ProjectReference Include="..\..\HeuristicLab.Visualization.ChartControlsExtensions\3.3\HeuristicLab.Visualization.ChartControlsExtensions-3.3.csproj">
    216       <Project>{315bda09-3f4f-49b3-9790-b37cfc1c5750}</Project>
    217       <Name>HeuristicLab.Visualization.ChartControlsExtensions-3.3</Name>
    218214      <Private>False</Private>
    219215    </ProjectReference>
  • trunk/sources/HeuristicLab.Problems.TestFunctions.Views/3.3/ParetoFrontScatterPlotView.Designer.cs

    r15202 r15203  
    2121
    2222namespace HeuristicLab.Problems.TestFunctions.Views {
    23   partial class MultiObjectiveTestFunctionParetoFrontScatterPlotView {
     23  partial class ParetoFrontScatterPlotView {
    2424    /// <summary>
    2525    /// Required designer variable.
     
    4545    /// </summary>
    4646    private void InitializeComponent() {
    47       this.components = new System.ComponentModel.Container();
    48       System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
    49       System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend();
    50       this.chart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart();
    51       this.menuStrip1 = new System.Windows.Forms.MenuStrip();
    52       this.chooseDimensionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    53       this.chooseYDimensionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    54       this.testToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
    55       ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit();
    56       this.menuStrip1.SuspendLayout();
     47      this.scatterPlotView = new HeuristicLab.Analysis.Views.ScatterPlotView();
     48      this.xAxisComboBox = new System.Windows.Forms.ComboBox();
     49      this.yAxisComboBox = new System.Windows.Forms.ComboBox();
     50      this.xLabel = new System.Windows.Forms.Label();
     51      this.yLabel = new System.Windows.Forms.Label();
    5752      this.SuspendLayout();
    5853      //
    59       // chart
     54      // scatterPlotView
    6055      //
    61       chartArea2.Name = "ChartArea";
    62       this.chart.ChartAreas.Add(chartArea2);
    63       this.chart.Dock = System.Windows.Forms.DockStyle.Fill;
    64       legend2.Alignment = System.Drawing.StringAlignment.Center;
    65       legend2.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top;
    66       legend2.Name = "Default";
    67       this.chart.Legends.Add(legend2);
    68       this.chart.Location = new System.Drawing.Point(0, 42);
    69       this.chart.Margin = new System.Windows.Forms.Padding(6);
    70       this.chart.Name = "chart";
    71       this.chart.Size = new System.Drawing.Size(1054, 712);
    72       this.chart.TabIndex = 1;
    73       this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend);
    74       this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
    75       this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
     56      this.scatterPlotView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     57            | System.Windows.Forms.AnchorStyles.Left)
     58            | System.Windows.Forms.AnchorStyles.Right)));
     59      this.scatterPlotView.Caption = "ScatterPlot View";
     60      this.scatterPlotView.Content = null;
     61      this.scatterPlotView.Location = new System.Drawing.Point(3, 37);
     62      this.scatterPlotView.Name = "scatterPlotView";
     63      this.scatterPlotView.ReadOnly = false;
     64      this.scatterPlotView.ShowName = false;
     65      this.scatterPlotView.Size = new System.Drawing.Size(615, 342);
     66      this.scatterPlotView.TabIndex = 3;
    7667      //
    77       // menuStrip1
     68      // xAxisComboBox
    7869      //
    79       this.menuStrip1.ImageScalingSize = new System.Drawing.Size(32, 32);
    80       this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
    81             this.chooseDimensionToolStripMenuItem,
    82             this.chooseYDimensionToolStripMenuItem});
    83       this.menuStrip1.Location = new System.Drawing.Point(0, 0);
    84       this.menuStrip1.Name = "menuStrip1";
    85       this.menuStrip1.Size = new System.Drawing.Size(1054, 42);
    86       this.menuStrip1.TabIndex = 2;
    87       this.menuStrip1.Text = "menuStrip1";
    88       this.menuStrip1.ShowItemToolTips = true;
     70      this.xAxisComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     71      this.xAxisComboBox.FormattingEnabled = true;
     72      this.xAxisComboBox.Location = new System.Drawing.Point(29, 3);
     73      this.xAxisComboBox.Name = "xAxisComboBox";
     74      this.xAxisComboBox.Size = new System.Drawing.Size(135, 28);
     75      this.xAxisComboBox.TabIndex = 4;
     76      this.xAxisComboBox.SelectedIndexChanged += new System.EventHandler(this.axisComboBox_SelectedIndexChanged);
    8977      //
    90       // chooseDimensionToolStripMenuItem
     78      // yAxisComboBox
    9179      //
    92       this.chooseDimensionToolStripMenuItem.Name = "chooseDimensionToolStripMenuItem";
    93       this.chooseDimensionToolStripMenuItem.Size = new System.Drawing.Size(253, 38);
    94       this.chooseDimensionToolStripMenuItem.Text = "Objective 0";
    95       this.chooseDimensionToolStripMenuItem.ToolTipText = "Choose X-Dimension";
     80      this.yAxisComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     81      this.yAxisComboBox.FormattingEnabled = true;
     82      this.yAxisComboBox.Location = new System.Drawing.Point(240, 3);
     83      this.yAxisComboBox.Name = "yAxisComboBox";
     84      this.yAxisComboBox.Size = new System.Drawing.Size(135, 28);
     85      this.yAxisComboBox.TabIndex = 5;
     86      this.yAxisComboBox.SelectedIndexChanged += new System.EventHandler(this.axisComboBox_SelectedIndexChanged);
    9687      //
    97       // chooseYDimensionToolStripMenuItem
     88      // xLabel
    9889      //
    99       this.chooseYDimensionToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
    100             this.testToolStripMenuItem});
    101       this.chooseYDimensionToolStripMenuItem.Name = "chooseYDimensionToolStripMenuItem";
    102       this.chooseYDimensionToolStripMenuItem.Size = new System.Drawing.Size(252, 38);
    103       this.chooseYDimensionToolStripMenuItem.Text = "Objective 1";
    104       this.chooseYDimensionToolStripMenuItem.ToolTipText = "Choose Y-Dimension";
     90      this.xLabel.AutoSize = true;
     91      this.xLabel.Location = new System.Drawing.Point(3, 6);
     92      this.xLabel.Name = "xLabel";
     93      this.xLabel.Size = new System.Drawing.Size(20, 20);
     94      this.xLabel.TabIndex = 6;
     95      this.xLabel.Text = "x:";
    10596      //
    106       // testToolStripMenuItem
     97      // yLabel
    10798      //
    108       this.testToolStripMenuItem.Name = "testToolStripMenuItem";
    109       this.testToolStripMenuItem.Size = new System.Drawing.Size(269, 38);
    110       this.testToolStripMenuItem.Text = "Test";
     99      this.yLabel.AutoSize = true;
     100      this.yLabel.Location = new System.Drawing.Point(214, 6);
     101      this.yLabel.Name = "yLabel";
     102      this.yLabel.Size = new System.Drawing.Size(20, 20);
     103      this.yLabel.TabIndex = 7;
     104      this.yLabel.Text = "y:";
    111105      //
    112       // MOQualitiesScatterPlotView
     106      // ParetoFrontScatterPlotView
    113107      //
    114108      this.AllowDrop = true;
    115       this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 25F);
    116       this.Controls.Add(this.chart);
    117       this.Controls.Add(this.menuStrip1);
     109      this.Controls.Add(this.yLabel);
     110      this.Controls.Add(this.xLabel);
     111      this.Controls.Add(this.yAxisComboBox);
     112      this.Controls.Add(this.xAxisComboBox);
     113      this.Controls.Add(this.scatterPlotView);
    118114      this.Margin = new System.Windows.Forms.Padding(6);
    119       this.Name = "MOQualitiesScatterPlotView";
    120       this.Size = new System.Drawing.Size(1054, 754);
    121       ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
    122       this.menuStrip1.ResumeLayout(false);
    123       this.menuStrip1.PerformLayout();
     115      this.Name = "ParetoFrontScatterPlotView";
     116      this.Size = new System.Drawing.Size(621, 382);
    124117      this.ResumeLayout(false);
    125118      this.PerformLayout();
     
    128121
    129122    #endregion
    130 
    131     private HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart chart;
    132     private System.Windows.Forms.MenuStrip menuStrip1;
    133     private System.Windows.Forms.ToolStripMenuItem chooseDimensionToolStripMenuItem;
    134     private System.Windows.Forms.ToolStripMenuItem chooseYDimensionToolStripMenuItem;
    135     private System.Windows.Forms.ToolStripMenuItem testToolStripMenuItem;
     123    private HeuristicLab.Analysis.Views.ScatterPlotView scatterPlotView;
     124    private System.Windows.Forms.ComboBox xAxisComboBox;
     125    private System.Windows.Forms.ComboBox yAxisComboBox;
     126    private System.Windows.Forms.Label xLabel;
     127    private System.Windows.Forms.Label yLabel;
    136128  }
    137129}
  • trunk/sources/HeuristicLab.Problems.TestFunctions.Views/3.3/ParetoFrontScatterPlotView.cs

    r15202 r15203  
    1919 */
    2020#endregion
     21
    2122using System;
    22 using System.Drawing;
    2323using System.Linq;
    24 using System.Text;
    25 using System.Windows.Forms;
    26 using System.Windows.Forms.DataVisualization.Charting;
     24using HeuristicLab.Analysis;
     25using HeuristicLab.Common;
    2726using HeuristicLab.Core.Views;
    2827using HeuristicLab.MainForm;
     
    3130namespace HeuristicLab.Problems.TestFunctions.Views {
    3231  [View("Scatter Plot")]
    33   [Content(typeof(ScatterPlotContent))]
    34   public partial class MultiObjectiveTestFunctionParetoFrontScatterPlotView : ItemView {
    35     private const string QUALITIES = "Qualities";
    36     private const string PARETO_FRONT = "Best Known Pareto Front";
    37     private Series qualitySeries;
    38     private Series paretoSeries;
    39     private int xDim = 0;
    40     private int yDim = 1;
    41     int objectives = -1;
     32  [Content(typeof(ParetoFrontScatterPlot))]
     33  public partial class ParetoFrontScatterPlotView : ItemView {
    4234
    43     public new ScatterPlotContent Content {
    44       get { return (ScatterPlotContent)base.Content; }
     35    private readonly ScatterPlot scatterPlot;
     36    private readonly ScatterPlotDataRow qualitiesRow;
     37    private readonly ScatterPlotDataRow paretoFrontRow;
     38
     39    private int oldObjectives = -1;
     40    private int oldProblemSize = -1;
     41
     42    private bool suppressEvents;
     43
     44    public new ParetoFrontScatterPlot Content {
     45      get { return (ParetoFrontScatterPlot)base.Content; }
    4546      set { base.Content = value; }
    4647    }
    4748
    48     public MultiObjectiveTestFunctionParetoFrontScatterPlotView()
    49       : base() {
     49    public ParetoFrontScatterPlotView() {
    5050      InitializeComponent();
    5151
    52       BuildEmptySeries();
     52      scatterPlot = new ScatterPlot();
    5353
    54       //start with qualities toggled ON
    55       qualitySeries.Points.AddXY(0, 0);
     54      qualitiesRow = new ScatterPlotDataRow("Qualities", string.Empty, Enumerable.Empty<Point2D<double>>()) {
     55        VisualProperties = {
     56          PointSize = 8 ,
     57          PointStyle = ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Circle
     58        }
     59      };
     60      scatterPlot.Rows.Add(qualitiesRow);
    5661
    57       this.chart.TextAntiAliasingQuality = TextAntiAliasingQuality.High;
    58       this.chart.AxisViewChanged += new EventHandler<System.Windows.Forms.DataVisualization.Charting.ViewEventArgs>(chart_AxisViewChanged);
    59       this.chart.GetToolTipText += new System.EventHandler<ToolTipEventArgs>(this.Chart_GetToolTipText);
    60 
    61       //configure axis
    62       this.chart.CustomizeAllChartAreas();
    63       this.chart.ChartAreas[0].AxisX.Title = "Objective " + xDim;
    64       this.chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
    65       this.chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
    66       this.chart.ChartAreas[0].CursorX.Interval = 1;
    67       this.chart.ChartAreas[0].CursorY.Interval = 1;
    68 
    69       this.chart.ChartAreas[0].AxisY.Title = "Objective " + yDim;
    70       this.chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
    71       this.chart.ChartAreas[0].AxisY.ScaleView.Zoomable = true;
    72       this.chart.ChartAreas[0].AxisY.IsStartedFromZero = true;
    73     }
    74 
    75 
    76     private void Chart_GetToolTipText(object sender, ToolTipEventArgs e) {
    77       if (e.HitTestResult.ChartElementType == ChartElementType.LegendItem) {
    78         if (e.HitTestResult.Series == paretoSeries && (Content.ParetoFront == null || Content.ParetoFront.Length == 0)) {
    79           e.Text = "No optimal pareto front is available for this problem with this number of objectives";
    80         }
    81         if (e.HitTestResult.Series == paretoSeries && (xDim >= Content.Objectives || yDim >= Content.Objectives)) {
    82           e.Text = "The optimal pareto front can only be displayed in  Objective Space";
    83         }
    84       }
    85 
    86       // Check selected chart element and set tooltip text
    87       if (e.HitTestResult.ChartElementType == ChartElementType.DataPoint) {
    88         int i = e.HitTestResult.PointIndex;
    89         StringBuilder toolTippText = new StringBuilder();
    90         DataPoint qp = e.HitTestResult.Series.Points[i];
    91         toolTippText.Append("Objective " + xDim + " = " + qp.XValue + "\n");
    92         toolTippText.Append("Objective " + yDim + " = " + qp.YValues[0]);
    93 
    94         Series s = e.HitTestResult.Series;
    95         if (s.Equals(this.chart.Series[QUALITIES])) {
    96           double[] dp = Content.Solutions[i];
    97           toolTippText.Append("\nSolution: {");
    98           for (int j = 0; j < dp.Length; j++) {
    99             toolTippText.Append(dp[j]);
    100             toolTippText.Append(";");
     62      paretoFrontRow = new ScatterPlotDataRow("Best Known Pareto Front", string.Empty, Enumerable.Empty<Point2D<double>>()) {
     63        VisualProperties = {
     64            PointSize = 4,
     65            PointStyle = ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Square
    10166          }
    102           toolTippText.Remove(toolTippText.Length - 1, 1);
    103           toolTippText.Append("}");
    104           e.Text = toolTippText.ToString();
    105         }
    106 
    107 
    108       }
     67      };
     68      scatterPlot.Rows.Add(paretoFrontRow);
    10969    }
    11070
    11171    protected override void OnContentChanged() {
    11272      base.OnContentChanged();
    113       if (Content == null) return;
    114       if (objectives != Content.Objectives) {
    115         AddMenuItems();
    116         objectives = Content.Objectives;
     73
     74      if (Content == null) {
     75        scatterPlotView.Content = null;
     76        xAxisComboBox.Items.Clear();
     77        xAxisComboBox.SelectedIndex = -1;
     78        yAxisComboBox.Items.Clear();
     79        yAxisComboBox.SelectedIndex = -1;
     80        return;
    11781      }
    118       if (Content.ParetoFront == null && chart.Series.Contains(paretoSeries)) {
    119         Series s = this.chart.Series[PARETO_FRONT];
    120         paretoSeries = null;
    121         this.chart.Series.Remove(s);
    12282
    123       } else if (Content.ParetoFront != null && !chart.Series.Contains(paretoSeries)) {
    124         this.chart.Series.Add(PARETO_FRONT);
    125         paretoSeries = this.chart.Series[PARETO_FRONT];
    126         this.chart.Series[PARETO_FRONT].LegendText = PARETO_FRONT;
    127         this.chart.Series[PARETO_FRONT].ChartType = SeriesChartType.FastPoint;
    128       }
    129       UpdateChart();
     83      scatterPlotView.Content = scatterPlot;
     84
     85      if (oldObjectives != Content.Objectives || oldProblemSize != Content.ProblemSize)
     86        UpdateAxisComboBoxes();
     87
     88      UpdateChartData();
     89
     90      oldObjectives = Content.Objectives;
     91      oldProblemSize = Content.ProblemSize;
    13092    }
    13193
    132     private void UpdateChart() {
    133       if (InvokeRequired) Invoke((Action)UpdateChart);
    134       else {
    135         if (Content != null) {
    136           this.UpdateSeries();
    137           if (!this.chart.Series.Any(s => s.Points.Count > 0))
    138             this.ClearChart();
     94    private void UpdateChartData() {
     95      if (InvokeRequired) {
     96        Invoke((Action)UpdateChartData);
     97        return;
     98      }
     99
     100      int xDimGlobal = xAxisComboBox.SelectedIndex;
     101      int yDimGlobal = yAxisComboBox.SelectedIndex;
     102
     103      qualitiesRow.Points.Replace(CreatePoints(Content.Qualities, Content.Solutions, xDimGlobal, yDimGlobal));
     104
     105      paretoFrontRow.Points.Replace(CreatePoints(Content.ParetoFront, null, xDimGlobal, yDimGlobal));
     106      paretoFrontRow.VisualProperties.IsVisibleInLegend = paretoFrontRow.Points.Count > 0; // hide if empty
     107    }
     108
     109    private void UpdateAxisComboBoxes() {
     110      try {
     111        suppressEvents = true;
     112
     113        string prevSelectedX = (string)xAxisComboBox.SelectedItem;
     114        string prevSelectedY = (string)yAxisComboBox.SelectedItem;
     115
     116        xAxisComboBox.Items.Clear();
     117        yAxisComboBox.Items.Clear();
     118
     119        // Add Objectives first
     120        for (int i = 0; i < Content.Objectives; i++) {
     121          xAxisComboBox.Items.Add("Objective " + i);
     122          yAxisComboBox.Items.Add("Objective " + i);
    139123        }
     124
     125        // Add Problem Dimension
     126        for (int i = 0; i < Content.ProblemSize; i++) {
     127          xAxisComboBox.Items.Add("Problem Dimension " + i);
     128          yAxisComboBox.Items.Add("Problem Dimension " + i);
     129        }
     130
     131        // Selection
     132        int count = xAxisComboBox.Items.Count;
     133        if (count > 0) {
     134          if (prevSelectedX != null && xAxisComboBox.Items.Contains(prevSelectedX))
     135            xAxisComboBox.SelectedItem = prevSelectedX;
     136          else xAxisComboBox.SelectedIndex = 0;
     137
     138          if (prevSelectedY != null && yAxisComboBox.Items.Contains(prevSelectedY))
     139            yAxisComboBox.SelectedItem = prevSelectedY;
     140          else yAxisComboBox.SelectedIndex = Math.Min(1, count - 1);
     141        } else {
     142          xAxisComboBox.SelectedIndex = -1;
     143          yAxisComboBox.SelectedIndex = -1;
     144        }
     145
     146        UpdateAxisDescription();
     147      } finally {
     148        suppressEvents = false;
    140149      }
    141150    }
    142151
    143     private void UpdateCursorInterval() {
    144       var estimatedValues = this.chart.Series[QUALITIES].Points.Select(x => x.XValue).DefaultIfEmpty(1.0);
    145       var targetValues = this.chart.Series[QUALITIES].Points.Select(x => x.YValues[0]).DefaultIfEmpty(1.0);
    146       double estimatedValuesRange = estimatedValues.Max() - estimatedValues.Min();
    147       double targetValuesRange = targetValues.Max() - targetValues.Min();
    148       double interestingValuesRange = Math.Min(Math.Max(targetValuesRange, 1.0), Math.Max(estimatedValuesRange, 1.0));
    149       double digits = (int)Math.Log10(interestingValuesRange) - 3;
    150       double zoomInterval = Math.Max(Math.Pow(10, digits), 10E-5);
    151       this.chart.ChartAreas[0].CursorX.Interval = zoomInterval;
    152       this.chart.ChartAreas[0].CursorY.Interval = zoomInterval;
    153 
    154       this.chart.ChartAreas[0].AxisX.ScaleView.SmallScrollSize = zoomInterval;
    155       this.chart.ChartAreas[0].AxisY.ScaleView.SmallScrollSize = zoomInterval;
    156 
    157       this.chart.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSizeType = DateTimeIntervalType.Number;
    158       this.chart.ChartAreas[0].AxisX.ScaleView.SmallScrollMinSize = zoomInterval;
    159       this.chart.ChartAreas[0].AxisY.ScaleView.SmallScrollMinSizeType = DateTimeIntervalType.Number;
    160       this.chart.ChartAreas[0].AxisY.ScaleView.SmallScrollMinSize = zoomInterval;
    161 
    162       if (digits < 0) {
    163         this.chart.ChartAreas[0].AxisX.LabelStyle.Format = "F" + (int)Math.Abs(digits);
    164         this.chart.ChartAreas[0].AxisY.LabelStyle.Format = "F" + (int)Math.Abs(digits);
    165       } else {
    166         this.chart.ChartAreas[0].AxisX.LabelStyle.Format = "F0";
    167         this.chart.ChartAreas[0].AxisY.LabelStyle.Format = "F0";
    168       }
     152    private void UpdateAxisDescription() {
     153      scatterPlot.VisualProperties.XAxisTitle = (string)xAxisComboBox.SelectedItem;
     154      scatterPlot.VisualProperties.YAxisTitle = (string)yAxisComboBox.SelectedItem;
    169155    }
    170156
    171     private void UpdateSeries() {
    172       if (InvokeRequired) Invoke((Action)UpdateSeries);
    173       else {
     157    private static Point2D<double>[] CreatePoints(double[][] qualities, double[][] solutions, int xDimGlobal, int yDimGlobal) {
     158      if (qualities == null || qualities.Length == 0) return new Point2D<double>[0];
    174159
    175         if (this.chart.Series.Contains(qualitySeries) && qualitySeries.Points.Count() != 0) {
    176           FillSeries(Content.Qualities, Content.Solutions, qualitySeries);
    177         }
    178         if (this.chart.Series.Contains(paretoSeries) && paretoSeries.Points.Count() != 0) {
    179           FillSeries(Content.ParetoFront, null, paretoSeries);
    180         }
     160      int objectives = qualities[0].Length;
    181161
     162      // "Global" dimension index describes the index as if the qualities and solutions would be in a single array
     163      // If the global dimension index is too long for the qualities, use solutions
     164      var xDimArray = xDimGlobal < objectives ? qualities : solutions;
     165      var yDimArray = yDimGlobal < objectives ? qualities : solutions;
     166      var xDimIndex = xDimGlobal < objectives ? xDimGlobal : xDimGlobal - objectives;
     167      var yDimIndex = yDimGlobal < objectives ? yDimGlobal : yDimGlobal - objectives;
    182168
    183         double minX = Double.MaxValue;
    184         double maxX = Double.MinValue;
    185         double minY = Double.MaxValue;
    186         double maxY = Double.MinValue;
    187         foreach (Series s in this.chart.Series) {
    188           if (s.Points.Count == 0) continue;
    189           minX = Math.Min(minX, s.Points.Select(p => p.XValue).Min());
    190           maxX = Math.Max(maxX, s.Points.Select(p => p.XValue).Max());
    191           minY = Math.Min(minY, s.Points.Select(p => p.YValues.Min()).Min());
    192           maxY = Math.Max(maxY, s.Points.Select(p => p.YValues.Max()).Max());
    193         }
     169      if (xDimArray == null || yDimArray == null)
     170        return new Point2D<double>[0];
    194171
    195         maxX = maxX + 0.2 * Math.Abs(maxX);
    196         minX = minX - 0.2 * Math.Abs(minX);
    197         maxY = maxY + 0.2 * Math.Abs(maxY);
    198         minY = minY - 0.2 * Math.Abs(minY);
    199 
    200         double interestingValuesRangeX = maxX - minX;
    201         double interestingValuesRangeY = maxY - minY;
    202 
    203         int digitsX = Math.Max(0, 3 - (int)Math.Log10(interestingValuesRangeX));
    204         int digitsY = Math.Max(0, 3 - (int)Math.Log10(interestingValuesRangeY));
    205 
    206 
    207         maxX = Math.Round(maxX, digitsX);
    208         minX = Math.Round(minX, digitsX);
    209         maxY = Math.Round(maxY, digitsY);
    210         minY = Math.Round(minY, digitsY);
    211         if (minX > maxX) {
    212           minX = 0;
    213           maxX = 1;
    214         }
    215         if (minY > maxY) {
    216           minY = 0;
    217           maxY = 1;
    218         }
    219 
    220 
    221         this.chart.ChartAreas[0].AxisX.Maximum = maxX;
    222         this.chart.ChartAreas[0].AxisX.Minimum = minX;
    223         this.chart.ChartAreas[0].AxisY.Maximum = maxY;
    224         this.chart.ChartAreas[0].AxisY.Minimum = minY;
    225         UpdateCursorInterval();
     172      var points = new Point2D<double>[xDimArray.Length];
     173      for (int i = 0; i < xDimArray.Length; i++) {
     174        points[i] = new Point2D<double>(xDimArray[i][xDimIndex], yDimArray[i][yDimIndex]);
    226175      }
     176      return points;
    227177    }
    228178
    229     private void ClearChart() {
    230       if (chart.Series.Contains(qualitySeries)) chart.Series.Remove(qualitySeries);
    231       if (chart.Series.Contains(paretoSeries)) chart.Series.Remove(paretoSeries);
    232       BuildEmptySeries();
     179    #region Event Handler
     180    private void axisComboBox_SelectedIndexChanged(object sender, EventArgs e) {
     181      if (suppressEvents) return;
     182      UpdateAxisDescription();
     183      UpdateChartData();
    233184    }
    234 
    235     private void ToggleSeriesData(Series series) {
    236       if (series.Points.Count > 0) {  //checks if series is shown
    237         series.Points.Clear();
    238       } else if (Content != null) {
    239         switch (series.Name) {
    240           case PARETO_FRONT:
    241             FillSeries(Content.ParetoFront, null, this.chart.Series[PARETO_FRONT]);
    242             break;
    243           case QUALITIES:
    244             FillSeries(Content.Qualities, Content.Solutions, this.chart.Series[QUALITIES]);
    245             break;
    246         }
    247       }
    248     }
    249 
    250     private void chart_MouseDown(object sender, MouseEventArgs e) {
    251       HitTestResult result = chart.HitTest(e.X, e.Y);
    252       if (result.ChartElementType == ChartElementType.LegendItem) {
    253         this.ToggleSeriesData(result.Series);
    254       }
    255 
    256     }
    257 
    258     private void chart_MouseMove(object sender, MouseEventArgs e) {
    259       HitTestResult result = chart.HitTest(e.X, e.Y);
    260       if (result.ChartElementType == ChartElementType.LegendItem)
    261         this.Cursor = Cursors.Hand;
    262       else
    263         this.Cursor = Cursors.Default;
    264     }
    265 
    266     private void chart_AxisViewChanged(object sender, System.Windows.Forms.DataVisualization.Charting.ViewEventArgs e) {
    267       this.chart.ChartAreas[0].AxisX.ScaleView.Size = e.NewSize;
    268       this.chart.ChartAreas[0].AxisY.ScaleView.Size = e.NewSize;
    269     }
    270 
    271     private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) {
    272       if (this.chart.Series.Contains(qualitySeries)) e.LegendItems[0].Cells[1].ForeColor = this.chart.Series[QUALITIES].Points.Count == 0 ? Color.Gray : Color.Black;
    273       if (this.chart.Series.Contains(paretoSeries)) e.LegendItems[1].Cells[1].ForeColor = this.chart.Series[PARETO_FRONT].Points.Count == 0 ? Color.Gray : Color.Black;
    274     }
    275 
    276     private void AddMenuItems() {
    277       chooseDimensionToolStripMenuItem.DropDownItems.Clear();
    278       chooseYDimensionToolStripMenuItem.DropDownItems.Clear();
    279       if (Content == null) { return; }
    280       int i = 0;
    281       for (; i < Content.Objectives; i++) {
    282         //add Menu Points
    283         ToolStripMenuItem xItem = MakeMenuItem("X", "Objective " + i, i);
    284         ToolStripMenuItem yItem = MakeMenuItem("Y", "Objective " + i, i);
    285         xItem.Click += new System.EventHandler(this.XMenu_Click);
    286         yItem.Click += new System.EventHandler(this.YMenu_Click);
    287         chooseDimensionToolStripMenuItem.DropDownItems.Add(xItem);
    288         chooseYDimensionToolStripMenuItem.DropDownItems.Add(yItem);
    289       }
    290 
    291       for (; i < Content.Solutions[0].Length + Content.Objectives; i++) {
    292         ToolStripMenuItem xItem = MakeMenuItem("X", "ProblemDimension " + (i - Content.Objectives), i);
    293         ToolStripMenuItem yItem = MakeMenuItem("Y", "ProblemDimension " + (i - Content.Objectives), i); ;
    294         xItem.Click += new System.EventHandler(this.XMenu_Click);
    295         yItem.Click += new System.EventHandler(this.YMenu_Click);
    296         chooseDimensionToolStripMenuItem.DropDownItems.Add(xItem);
    297         chooseYDimensionToolStripMenuItem.DropDownItems.Add(yItem);
    298       }
    299     }
    300 
    301     private ToolStripMenuItem MakeMenuItem(String axis, String label, int i) {
    302       ToolStripMenuItem xItem = new ToolStripMenuItem();
    303       xItem.Name = "obj" + i;
    304       xItem.Size = new System.Drawing.Size(269, 38);
    305       xItem.Text = label;
    306       return xItem;
    307     }
    308 
    309     private void YMenu_Click(object sender, EventArgs e) {
    310       ToolStripMenuItem item = (ToolStripMenuItem)sender;
    311       yDim = Int32.Parse(item.Name.Remove(0, 3));
    312       String label = item.Text;
    313       this.chooseYDimensionToolStripMenuItem.Text = label;
    314       this.chart.ChartAreas[0].AxisY.Title = label;
    315       UpdateChart();
    316     }
    317 
    318     private void XMenu_Click(object sender, EventArgs e) {
    319       ToolStripMenuItem item = (ToolStripMenuItem)sender;
    320       xDim = Int32.Parse(item.Name.Remove(0, 3));
    321       String label = item.Text;
    322       this.chooseDimensionToolStripMenuItem.Text = label;
    323       this.chart.ChartAreas[0].AxisX.Title = label;
    324       UpdateChart();
    325     }
    326 
    327     private void FillSeries(double[][] qualities, double[][] solutions, Series series) {
    328       series.Points.Clear();
    329       if (qualities == null || qualities.Length == 0) return;
    330       int jx = xDim - qualities[0].Length;
    331       int jy = yDim - qualities[0].Length;
    332       if ((jx >= 0 || jy >= 0) && solutions == null) {
    333         return;
    334       }
    335       for (int i = 0; i < qualities.Length; i++) {   //Assumtion: Columnwise
    336         double[] d = qualities[i];
    337         double[] q = null;
    338         if (jx >= 0 || jy >= 0) { q = solutions[i]; }
    339         series.Points.AddXY(jx < 0 ? d[xDim] : q[jx], jy < 0 ? d[yDim] : q[jy]);
    340       }
    341     }
    342 
    343     private void BuildEmptySeries() {
    344 
    345       this.chart.Series.Add(QUALITIES);
    346       qualitySeries = this.chart.Series[QUALITIES];
    347 
    348       this.chart.Series[QUALITIES].LegendText = QUALITIES;
    349       this.chart.Series[QUALITIES].ChartType = SeriesChartType.FastPoint;
    350 
    351       this.chart.Series.Add(PARETO_FRONT);
    352       paretoSeries = this.chart.Series[PARETO_FRONT];
    353       paretoSeries.Color = Color.FromArgb(100, Color.Orange);
    354       this.chart.Series[PARETO_FRONT].LegendText = PARETO_FRONT;
    355       this.chart.Series[PARETO_FRONT].ChartType = SeriesChartType.FastPoint;
    356     }
     185    #endregion
    357186  }
    358187}
    359 
  • trunk/sources/HeuristicLab.Problems.TestFunctions.Views/3.3/Plugin.cs.frame

    r14195 r15203  
    2828  [Plugin("HeuristicLab.Problems.TestFunctions.Views", "3.3.14.$WCREV$")]
    2929  [PluginFile("HeuristicLab.Problems.TestFunctions.Views-3.3.dll", PluginFileType.Assembly)]
     30  [PluginDependency("HeuristicLab.Analysis", "3.3")]
     31  [PluginDependency("HeuristicLab.Analysis.Views", "3.3")]
    3032  [PluginDependency("HeuristicLab.Collections", "3.3")]
    3133  [PluginDependency("HeuristicLab.Common", "3.3")]
     
    4042  [PluginDependency("HeuristicLab.Problems.TestFunctions", "3.3")]
    4143  [PluginDependency("HeuristicLab.Problems.TestFunctions.MultiObjective", "3.3")]
    42   [PluginDependency("HeuristicLab.Visualization.ChartControlsExtensions", "3.3")]
    4344  public class HeuristicLabProblemsTestFunctionsViewsPlugin : PluginBase {
    4445  }
Note: See TracChangeset for help on using the changeset viewer.