Changeset 15203
- Timestamp:
- 07/11/17 19:36:03 (7 years ago)
- Location:
- trunk/sources
- Files:
-
- 5 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.MOCMAEvolutionStrategy/3.3/MOCMAEvolutionStrategy.cs
r15177 r15203 245 245 set { Results[CurrentFrontResultName].Value = value; } 246 246 } 247 private ScatterPlotContent ResultsScatterPlot {248 get { return ( ScatterPlotContent)Results[ScatterPlotResultName].Value; }247 private ParetoFrontScatterPlot ResultsScatterPlot { 248 get { return (ParetoFrontScatterPlot)Results[ScatterPlotResultName].Value; } 249 249 set { Results[ScatterPlotResultName].Value = value; } 250 250 } … … 353 353 Results.Add(new Result(TimetableResultName, "Different quality meassures in a timeseries", table)); 354 354 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())); 356 356 357 357 var problem = Problem as MultiObjectiveTestFunctionProblem; … … 361 361 ResultsDifferenceBestKnownHypervolume = ResultsBestKnownHypervolume; 362 362 } 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); 364 364 } 365 365 #endregion … … 470 470 471 471 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); 473 473 ResultsSolutions = solutions.Select(x => x.Mean.ToArray()).ToMatrix(); 474 474 -
trunk/sources/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/Analyzers/ScatterPlotAnalyzer.cs
r14111 r15203 37 37 } 38 38 39 public IResultParameter< ScatterPlotContent> ScatterPlotResultParameter {40 get { return (IResultParameter< ScatterPlotContent>)Parameters["Scatterplot"]; }39 public IResultParameter<ParetoFrontScatterPlot> ScatterPlotResultParameter { 40 get { return (IResultParameter<ParetoFrontScatterPlot>)Parameters["Scatterplot"]; } 41 41 } 42 42 … … 51 51 public ScatterPlotAnalyzer() { 52 52 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)")); 54 54 55 55 } … … 57 57 public override IOperation Apply() { 58 58 var qualities = QualitiesParameter.ActualValue; 59 var individuals = IndividualsParameter.ActualValue; 59 60 var testFunction = TestFunctionParameter.ActualValue; 60 61 int objectives = qualities[0].Length; 61 var individuals = IndividualsParameter.ActualValue;62 int problemSize = individuals[0].Length; 62 63 63 64 double[][] optimalFront = new double[0][]; … … 68 69 var solutionClones = individuals.Select(s => s.ToArray()).ToArray(); 69 70 70 ScatterPlotResultParameter.ActualValue = new ScatterPlotContent(qualityClones, solutionClones, optimalFront, objectives);71 ScatterPlotResultParameter.ActualValue = new ParetoFrontScatterPlot(qualityClones, solutionClones, optimalFront, objectives, problemSize); 71 72 72 73 return base.Apply(); -
trunk/sources/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/HeuristicLab.Problems.TestFunctions.MultiObjective-3.3.csproj
r14168 r15203 111 111 <Compile Include="Calculators\InvertedGenerationalDistance.cs" /> 112 112 <Compile Include="Calculators\GenerationalDistance.cs" /> 113 <Compile Include=" ScatterPlotContent.cs" />113 <Compile Include="ParetoFrontScatterPlot.cs" /> 114 114 <Compile Include="Utilities.cs" /> 115 115 <Compile Include="Instances\MISCInstanceProvider.cs" /> -
trunk/sources/HeuristicLab.Problems.TestFunctions.MultiObjective/3.3/ParetoFrontScatterPlot.cs
r15202 r15203 19 19 */ 20 20 #endregion 21 21 22 using System.Linq; 22 23 using HeuristicLab.Common; … … 26 27 namespace HeuristicLab.Problems.TestFunctions.MultiObjective { 27 28 [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 } 30 43 31 44 [Storable] 32 45 private double[][] qualities; 33 46 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; } 53 48 } 54 49 … … 56 51 private double[][] solutions; 57 52 public double[][] Solutions { 58 get { 59 return solutions; 60 } 61 62 private set { 63 solutions = value; 64 } 53 get { return solutions; } 65 54 } 66 55 … … 68 57 private double[][] paretoFront; 69 58 public double[][] ParetoFront { 70 get { 71 return paretoFront; 72 } 73 74 private set { 75 paretoFront = value; 76 } 59 get { return paretoFront; } 77 60 } 78 61 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) { 91 64 this.qualities = qualities; 92 65 this.solutions = solutions; 93 66 this.paretoFront = paretoFront; 94 67 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); 95 82 } 96 83 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 100 88 } 101 89 } -
trunk/sources/HeuristicLab.Problems.TestFunctions.Views/3.3/HeuristicLab.Problems.TestFunctions.Views-3.3.csproj
r14125 r15203 105 105 <Reference Include="System.Drawing" /> 106 106 <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"> 119 110 <SubType>UserControl</SubType> 120 111 </Compile> 121 <Compile Include=" MultiObjectiveTestFunctionParetoFrontScatterPlotView.Designer.cs">122 <DependentUpon> MultiObjectiveTestFunctionParetoFrontScatterPlotView.cs</DependentUpon>112 <Compile Include="ParetoFrontScatterPlotView.Designer.cs"> 113 <DependentUpon>ParetoFrontScatterPlotView.cs</DependentUpon> 123 114 </Compile> 124 115 <Compile Include="Plugin.cs" /> … … 143 134 </ItemGroup> 144 135 <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> 145 146 <ProjectReference Include="..\..\HeuristicLab.Collections\3.3\HeuristicLab.Collections-3.3.csproj"> 146 147 <Project>{958B43BC-CC5C-4FA2-8628-2B3B01D890B6}</Project> … … 211 212 <Project>{88B9B0E3-344E-4196-82A3-0F9732506FE8}</Project> 212 213 <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>218 214 <Private>False</Private> 219 215 </ProjectReference> -
trunk/sources/HeuristicLab.Problems.TestFunctions.Views/3.3/ParetoFrontScatterPlotView.Designer.cs
r15202 r15203 21 21 22 22 namespace HeuristicLab.Problems.TestFunctions.Views { 23 partial class MultiObjectiveTestFunctionParetoFrontScatterPlotView {23 partial class ParetoFrontScatterPlotView { 24 24 /// <summary> 25 25 /// Required designer variable. … … 45 45 /// </summary> 46 46 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(); 57 52 this.SuspendLayout(); 58 53 // 59 // chart54 // scatterPlotView 60 55 // 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; 76 67 // 77 // menuStrip168 // xAxisComboBox 78 69 // 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); 89 77 // 90 // chooseDimensionToolStripMenuItem78 // yAxisComboBox 91 79 // 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); 96 87 // 97 // chooseYDimensionToolStripMenuItem88 // xLabel 98 89 // 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:"; 105 96 // 106 // testToolStripMenuItem97 // yLabel 107 98 // 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:"; 111 105 // 112 // MOQualitiesScatterPlotView106 // ParetoFrontScatterPlotView 113 107 // 114 108 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); 118 114 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); 124 117 this.ResumeLayout(false); 125 118 this.PerformLayout(); … … 128 121 129 122 #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; 136 128 } 137 129 } -
trunk/sources/HeuristicLab.Problems.TestFunctions.Views/3.3/ParetoFrontScatterPlotView.cs
r15202 r15203 19 19 */ 20 20 #endregion 21 21 22 using System; 22 using System.Drawing;23 23 using System.Linq; 24 using System.Text; 25 using System.Windows.Forms; 26 using System.Windows.Forms.DataVisualization.Charting; 24 using HeuristicLab.Analysis; 25 using HeuristicLab.Common; 27 26 using HeuristicLab.Core.Views; 28 27 using HeuristicLab.MainForm; … … 31 30 namespace HeuristicLab.Problems.TestFunctions.Views { 32 31 [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 { 42 34 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; } 45 46 set { base.Content = value; } 46 47 } 47 48 48 public MultiObjectiveTestFunctionParetoFrontScatterPlotView() 49 : base() { 49 public ParetoFrontScatterPlotView() { 50 50 InitializeComponent(); 51 51 52 BuildEmptySeries();52 scatterPlot = new ScatterPlot(); 53 53 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); 56 61 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 101 66 } 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); 109 69 } 110 70 111 71 protected override void OnContentChanged() { 112 72 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; 117 81 } 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);122 82 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; 130 92 } 131 93 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); 139 123 } 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; 140 149 } 141 150 } 142 151 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; 169 155 } 170 156 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]; 174 159 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; 181 161 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; 182 168 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]; 194 171 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]); 226 175 } 176 return points; 227 177 } 228 178 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(); 233 184 } 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 357 186 } 358 187 } 359 -
trunk/sources/HeuristicLab.Problems.TestFunctions.Views/3.3/Plugin.cs.frame
r14195 r15203 28 28 [Plugin("HeuristicLab.Problems.TestFunctions.Views", "3.3.14.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Problems.TestFunctions.Views-3.3.dll", PluginFileType.Assembly)] 30 [PluginDependency("HeuristicLab.Analysis", "3.3")] 31 [PluginDependency("HeuristicLab.Analysis.Views", "3.3")] 30 32 [PluginDependency("HeuristicLab.Collections", "3.3")] 31 33 [PluginDependency("HeuristicLab.Common", "3.3")] … … 40 42 [PluginDependency("HeuristicLab.Problems.TestFunctions", "3.3")] 41 43 [PluginDependency("HeuristicLab.Problems.TestFunctions.MultiObjective", "3.3")] 42 [PluginDependency("HeuristicLab.Visualization.ChartControlsExtensions", "3.3")]43 44 public class HeuristicLabProblemsTestFunctionsViewsPlugin : PluginBase { 44 45 }
Note: See TracChangeset
for help on using the changeset viewer.