Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4739


Ignore:
Timestamp:
11/08/10 03:00:46 (14 years ago)
Author:
swagner
Message:

Worked on population diversity analysis (#1188)

Location:
trunk/sources
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Analysis.Views/3.3/HeatMapView.Designer.cs

    r4703 r4739  
    4646    private void InitializeComponent() {
    4747      System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
    48       System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
    49       System.Windows.Forms.DataVisualization.Charting.Title title1= new System.Windows.Forms.DataVisualization.Charting.Title();
     48      System.Windows.Forms.DataVisualization.Charting.Title title1 = new System.Windows.Forms.DataVisualization.Charting.Title();
    5049      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(HeatMapView));
    5150      this.chart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart();
    52       this.ColorsPictureBox = new System.Windows.Forms.PictureBox();
    53       this.ZeroLabel = new System.Windows.Forms.Label();
    54       this.OneLabel = new System.Windows.Forms.Label();
    55       this.GrayscalesPictureBox = new System.Windows.Forms.PictureBox();
    56       this.grayscaledImagesCheckBox = new System.Windows.Forms.CheckBox();
     51      this.colorsPictureBox = new System.Windows.Forms.PictureBox();
     52      this.minimumLabel = new System.Windows.Forms.Label();
     53      this.maximumLabel = new System.Windows.Forms.Label();
     54      this.grayscalesPictureBox = new System.Windows.Forms.PictureBox();
     55      this.grayscaleCheckBox = new System.Windows.Forms.CheckBox();
    5756      ((System.ComponentModel.ISupportInitialize)(this.chart)).BeginInit();
    58       ((System.ComponentModel.ISupportInitialize)(this.ColorsPictureBox)).BeginInit();
    59       ((System.ComponentModel.ISupportInitialize)(this.GrayscalesPictureBox)).BeginInit();
     57      ((System.ComponentModel.ISupportInitialize)(this.colorsPictureBox)).BeginInit();
     58      ((System.ComponentModel.ISupportInitialize)(this.grayscalesPictureBox)).BeginInit();
    6059      this.SuspendLayout();
    6160      //
     
    6968      chartArea1.AxisX.IntervalAutoMode = System.Windows.Forms.DataVisualization.Charting.IntervalAutoMode.VariableCount;
    7069      chartArea1.AxisX.LabelAutoFitStyle = ((System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles)((System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles.IncreaseFont | System.Windows.Forms.DataVisualization.Charting.LabelAutoFitStyles.DecreaseFont)));
    71       chartArea1.AxisX.Title = "Solution Index";
    72       chartArea1.AxisY.Title = "Solution Index";
     70      chartArea1.AxisX.Title = "Column Index";
     71      chartArea1.AxisY.Title = "Row Index";
    7372      chartArea1.CursorX.IsUserEnabled = true;
    7473      chartArea1.CursorX.IsUserSelectionEnabled = true;
     
    7776      chartArea1.Name = "Default";
    7877      this.chart.ChartAreas.Add(chartArea1);
    79       legend1.Alignment = System.Drawing.StringAlignment.Center;
    80       legend1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top;
    81       legend1.Name = "Default";
    82       this.chart.Legends.Add(legend1);
    8378      this.chart.Location = new System.Drawing.Point(0, 0);
    8479      this.chart.Name = "chart";
    85       this.chart.Size = new System.Drawing.Size(403, 335);
     80      this.chart.Size = new System.Drawing.Size(406, 463);
    8681      this.chart.TabIndex = 0;
    8782      this.chart.Text = "chart";
    8883      title1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    8984      title1.Name = "Default";
    90       title1.Text = "Solution Similarities";
     85      title1.Text = "Heat Map";
    9186      this.chart.Titles.Add(title1);
    9287      //
    93       // ColorsPictureBox
     88      // colorsPictureBox
    9489      //
    95       this.ColorsPictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     90      this.colorsPictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    9691                  | System.Windows.Forms.AnchorStyles.Right)));
    97       this.ColorsPictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    98       this.ColorsPictureBox.Image = ((System.Drawing.Image)(resources.GetObject("ColorsPictureBox.Image")));
    99       this.ColorsPictureBox.Location = new System.Drawing.Point(409, 23);
    100       this.ColorsPictureBox.Name = "ColorsPictureBox";
    101       this.ColorsPictureBox.Size = new System.Drawing.Size(35, 312);
    102       this.ColorsPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
    103       this.ColorsPictureBox.TabIndex = 11;
    104       this.ColorsPictureBox.TabStop = false;
     92      this.colorsPictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
     93      this.colorsPictureBox.Image = ((System.Drawing.Image)(resources.GetObject("colorsPictureBox.Image")));
     94      this.colorsPictureBox.Location = new System.Drawing.Point(430, 28);
     95      this.colorsPictureBox.Name = "colorsPictureBox";
     96      this.colorsPictureBox.Size = new System.Drawing.Size(35, 393);
     97      this.colorsPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
     98      this.colorsPictureBox.TabIndex = 11;
     99      this.colorsPictureBox.TabStop = false;
    105100      //
    106       // ZeroLabel
     101      // minimumLabel
    107102      //
    108       this.ZeroLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    109       this.ZeroLabel.AutoSize = true;
    110       this.ZeroLabel.BackColor = System.Drawing.Color.Transparent;
    111       this.ZeroLabel.Location = new System.Drawing.Point(416, 342);
    112       this.ZeroLabel.Name = "ZeroLabel";
    113       this.ZeroLabel.Size = new System.Drawing.Size(22, 13);
    114       this.ZeroLabel.TabIndex = 14;
    115       this.ZeroLabel.Text = "0.0";
     103      this.minimumLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     104      this.minimumLabel.BackColor = System.Drawing.Color.Transparent;
     105      this.minimumLabel.Location = new System.Drawing.Point(412, 424);
     106      this.minimumLabel.Name = "minimumLabel";
     107      this.minimumLabel.Size = new System.Drawing.Size(73, 19);
     108      this.minimumLabel.TabIndex = 2;
     109      this.minimumLabel.Text = "0.0";
     110      this.minimumLabel.TextAlign = System.Drawing.ContentAlignment.TopCenter;
    116111      //
    117       // OneLabel
     112      // maximumLabel
    118113      //
    119       this.OneLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
    120       this.OneLabel.AutoSize = true;
    121       this.OneLabel.BackColor = System.Drawing.Color.Transparent;
    122       this.OneLabel.Location = new System.Drawing.Point(416, 3);
    123       this.OneLabel.Name = "OneLabel";
    124       this.OneLabel.Size = new System.Drawing.Size(22, 13);
    125       this.OneLabel.TabIndex = 13;
    126       this.OneLabel.Text = "1.0";
     114      this.maximumLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     115      this.maximumLabel.BackColor = System.Drawing.Color.Transparent;
     116      this.maximumLabel.Location = new System.Drawing.Point(412, 0);
     117      this.maximumLabel.Name = "maximumLabel";
     118      this.maximumLabel.Size = new System.Drawing.Size(73, 25);
     119      this.maximumLabel.TabIndex = 1;
     120      this.maximumLabel.Text = "1.0";
     121      this.maximumLabel.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
    127122      //
    128       // GrayscalesPictureBox
     123      // grayscalesPictureBox
    129124      //
    130       this.GrayscalesPictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
     125      this.grayscalesPictureBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    131126                  | System.Windows.Forms.AnchorStyles.Right)));
    132       this.GrayscalesPictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
    133       this.GrayscalesPictureBox.Image = ((System.Drawing.Image)(resources.GetObject("GrayscalesPictureBox.Image")));
    134       this.GrayscalesPictureBox.Location = new System.Drawing.Point(409, 23);
    135       this.GrayscalesPictureBox.Name = "GrayscalesPictureBox";
    136       this.GrayscalesPictureBox.Size = new System.Drawing.Size(35, 312);
    137       this.GrayscalesPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
    138       this.GrayscalesPictureBox.TabIndex = 15;
    139       this.GrayscalesPictureBox.TabStop = false;
    140       this.GrayscalesPictureBox.Visible = false;
     127      this.grayscalesPictureBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
     128      this.grayscalesPictureBox.Image = ((System.Drawing.Image)(resources.GetObject("grayscalesPictureBox.Image")));
     129      this.grayscalesPictureBox.Location = new System.Drawing.Point(430, 28);
     130      this.grayscalesPictureBox.Name = "grayscalesPictureBox";
     131      this.grayscalesPictureBox.Size = new System.Drawing.Size(35, 393);
     132      this.grayscalesPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
     133      this.grayscalesPictureBox.TabIndex = 15;
     134      this.grayscalesPictureBox.TabStop = false;
     135      this.grayscalesPictureBox.Visible = false;
    141136      //
    142       // grayscaledImagesCheckBox
     137      // grayscaleCheckBox
    143138      //
    144       this.grayscaledImagesCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
    145       this.grayscaledImagesCheckBox.AutoSize = true;
    146       this.grayscaledImagesCheckBox.Location = new System.Drawing.Point(0, 338);
    147       this.grayscaledImagesCheckBox.Name = "grayscaledImagesCheckBox";
    148       this.grayscaledImagesCheckBox.Size = new System.Drawing.Size(115, 17);
    149       this.grayscaledImagesCheckBox.TabIndex = 16;
    150       this.grayscaledImagesCheckBox.Text = "Grayscaled images";
    151       this.grayscaledImagesCheckBox.UseVisualStyleBackColor = true;
    152       this.grayscaledImagesCheckBox.CheckedChanged += new System.EventHandler(this.grayscaledImagesCheckBox_CheckedChanged);
     139      this.grayscaleCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     140      this.grayscaleCheckBox.AutoSize = true;
     141      this.grayscaleCheckBox.Location = new System.Drawing.Point(412, 446);
     142      this.grayscaleCheckBox.Name = "grayscaleCheckBox";
     143      this.grayscaleCheckBox.Size = new System.Drawing.Size(73, 17);
     144      this.grayscaleCheckBox.TabIndex = 3;
     145      this.grayscaleCheckBox.Text = "Grayscale";
     146      this.grayscaleCheckBox.UseVisualStyleBackColor = true;
     147      this.grayscaleCheckBox.CheckedChanged += new System.EventHandler(this.grayscaledImagesCheckBox_CheckedChanged);
    153148      //
    154       // HeatmapView
     149      // HeatMapView
    155150      //
    156151      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    157152      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    158       this.Controls.Add(this.grayscaledImagesCheckBox);
    159       this.Controls.Add(this.ZeroLabel);
    160       this.Controls.Add(this.OneLabel);
    161       this.Controls.Add(this.ColorsPictureBox);
     153      this.Controls.Add(this.grayscaleCheckBox);
     154      this.Controls.Add(this.minimumLabel);
     155      this.Controls.Add(this.maximumLabel);
     156      this.Controls.Add(this.colorsPictureBox);
    162157      this.Controls.Add(this.chart);
    163       this.Controls.Add(this.GrayscalesPictureBox);
    164       this.Name = "HeatmapView";
    165       this.Size = new System.Drawing.Size(444, 358);
     158      this.Controls.Add(this.grayscalesPictureBox);
     159      this.Name = "HeatMapView";
     160      this.Size = new System.Drawing.Size(485, 463);
    166161      ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
    167       ((System.ComponentModel.ISupportInitialize)(this.ColorsPictureBox)).EndInit();
    168       ((System.ComponentModel.ISupportInitialize)(this.GrayscalesPictureBox)).EndInit();
     162      ((System.ComponentModel.ISupportInitialize)(this.colorsPictureBox)).EndInit();
     163      ((System.ComponentModel.ISupportInitialize)(this.grayscalesPictureBox)).EndInit();
    169164      this.ResumeLayout(false);
    170165      this.PerformLayout();
     
    174169    #endregion
    175170
    176     private HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart chart;
    177     private System.Windows.Forms.PictureBox ColorsPictureBox;
    178     private System.Windows.Forms.Label ZeroLabel;
    179     private System.Windows.Forms.Label OneLabel;
    180     private System.Windows.Forms.PictureBox GrayscalesPictureBox;
    181     private System.Windows.Forms.CheckBox grayscaledImagesCheckBox;
     171    protected HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart chart;
     172    protected System.Windows.Forms.PictureBox colorsPictureBox;
     173    protected System.Windows.Forms.Label minimumLabel;
     174    protected System.Windows.Forms.Label maximumLabel;
     175    protected System.Windows.Forms.PictureBox grayscalesPictureBox;
     176    protected System.Windows.Forms.CheckBox grayscaleCheckBox;
    182177  }
    183178}
  • trunk/sources/HeuristicLab.Analysis.Views/3.3/HeatMapView.cs

    r4703 r4739  
    3131  [Content(typeof(HeatMap), true)]
    3232  public partial class HeatMapView : ItemView {
     33    protected static Color[] colors = new Color[256];
     34    protected static Color[] grayscaleColors = new Color[256];
    3335
    34     private static Color[] Colors;
    35     private static int ColorsCount = 500;
    36     private static Color[] GrayscaleColors = new Color[256];
    37 
    38     #region InitializeColors
     36    #region Initialize Colors
    3937    static HeatMapView() {
    40       int stepWidth = (255 * 6) / ColorsCount;
    41       Color[] colors = new Color[ColorsCount];
     38      int stepWidth = (256 * 4) / colors.Length;
    4239      int currentValue;
    4340      int currentClass;
    44       for (int i = 0; i < ColorsCount; i++) {
    45         currentValue = (i * stepWidth) % 255;
    46         currentClass = (i * stepWidth) / 255;
     41      for (int i = 0; i < colors.Length; i++) {
     42        currentValue = (i * stepWidth) % 256;
     43        currentClass = (i * stepWidth) / 256;
    4744        switch (currentClass) {
    48           case 0: { colors[i] = Color.FromArgb(255, currentValue, 0); break; }
    49           case 1: { colors[i] = Color.FromArgb(255 - currentValue, 255, 0); break; }
    50           case 2: { colors[i] = Color.FromArgb(0, 255, currentValue); break; }
    51           case 3: { colors[i] = Color.FromArgb(0, 255 - currentValue, 255); break; }
    52           case 4: { colors[i] = Color.FromArgb(currentValue, 0, 255); break; }
    53           case 5: { colors[i] = Color.FromArgb(255, 0, 255 - currentValue); break; }
     45          case 0: { colors[i] = Color.FromArgb(0, currentValue, 255); break; }        // blue -> cyan
     46          case 1: { colors[i] = Color.FromArgb(0, 255, 255 - currentValue); break; }  // cyan -> green
     47          case 2: { colors[i] = Color.FromArgb(currentValue, 255, 0); break; }        // green -> yellow
     48          case 3: { colors[i] = Color.FromArgb(255, 255 - currentValue, 0); break; }  // yellow -> red
    5449        }
    5550      }
    56       int n = (int)(ColorsCount * 0.7);
    57       Colors = new Color[n];
    58       for (int i = 0; i < n; i++)
    59         Colors[i] = colors[i];
    6051      for (int i = 0; i < 256; i++)
    61         GrayscaleColors[i] = Color.FromArgb(i, i, i);
     52        grayscaleColors[i] = Color.FromArgb(255 - i, 255 - i, 255 - i);  // white -> black
    6253    }
    6354    #endregion
     
    7364    }
    7465
     66    protected override void DeregisterContentEvents() {
     67      Content.TitleChanged -= new EventHandler(Content_TitleChanged);
     68      Content.MinimumChanged -= new EventHandler(Content_MinimumChanged);
     69      Content.MaximumChanged -= new EventHandler(Content_MaximumChanged);
     70      base.DeregisterContentEvents();
     71    }
     72    protected override void RegisterContentEvents() {
     73      base.RegisterContentEvents();
     74      Content.TitleChanged += new EventHandler(Content_TitleChanged);
     75      Content.MinimumChanged += new EventHandler(Content_MinimumChanged);
     76      Content.MaximumChanged += new EventHandler(Content_MaximumChanged);
     77    }
     78
    7579    protected override void OnContentChanged() {
    7680      base.OnContentChanged();
    7781      if (Content == null) {
    7882        chart.Series.Clear();
     83        chart.Titles[0].Text = "Heat Map";
     84        minimumLabel.Text = "0.0";
     85        maximumLabel.Text = "1.0";
    7986      } else {
    80         UpdateChart();
     87        chart.Titles[0].Text = Content.Title;
     88        minimumLabel.Text = Content.Minimum.ToString();
     89        maximumLabel.Text = Content.Maximum.ToString();
     90        UpdatePoints();
    8191      }
    8292    }
    8393
    84     private void UpdateChart() {
     94    protected override void SetEnabledStateOfControls() {
     95      base.SetEnabledStateOfControls();
     96      chart.Enabled = Content != null;
     97      grayscaleCheckBox.Enabled = Content != null;
     98    }
     99
     100    protected virtual void UpdatePoints() {
    85101      chart.Series.Clear();
    86102      Series series = new Series();
     
    89105      series.YValueType = ChartValueType.Int32;
    90106      series.YAxisType = AxisType.Primary;
    91       for (int i = 0; i < Content.Rows; i++)
    92         for (int j = 0; j < Content.Columns; j++)
    93           series.Points.Add(CreateDataPoint(i, j, Content[i, j]));
     107      for (int i = 1; i < Content.Rows + 1; i++)
     108        for (int j = 1; j < Content.Columns + 1; j++)
     109          series.Points.Add(CreateDataPoint(j, i, Content[i - 1, j - 1]));
     110      chart.ChartAreas[0].AxisX.Minimum = 0;
     111      chart.ChartAreas[0].AxisX.Maximum = Content.Columns + 1;
    94112      chart.ChartAreas[0].AxisY.Minimum = 0;
    95       chart.ChartAreas[0].AxisY.Maximum = Content.Rows;
     113      chart.ChartAreas[0].AxisY.Maximum = Content.Rows + 1;
    96114      chart.Series.Add(series);
    97       chart.Legends.Clear();
    98115    }
    99116
    100     private DataPoint CreateDataPoint(int index1, int index2, double value) {
    101       bool grayScaleModus = grayscaledImagesCheckBox.Checked;
    102       int n = grayScaleModus ? GrayscaleColors.Length : Colors.Length;
    103       int colorIndex = (int)((n - 1) * value);
    104       if (colorIndex >= n) colorIndex = n - 1;
    105       if (colorIndex < 0) colorIndex = 0;
    106       // invert so that red is 1, blue 0 / black is 1, white 0
    107       colorIndex = n - colorIndex - 1;
    108       Color color = grayScaleModus ? GrayscaleColors[colorIndex] : Colors[colorIndex];
    109 
     117    protected virtual DataPoint CreateDataPoint(int index1, int index2, double value) {
    110118      DataPoint p = new DataPoint(index1, index2);
    111       p.Color = color;
     119      p.Color = GetDataPointColor(value, Content.Minimum, Content.Maximum, grayscaleCheckBox.Checked);
    112120      p.MarkerStyle = MarkerStyle.Square;
    113       p.ToolTip = string.Format("Solution {0} vs. solution {1}: {2}",
    114                                 index1, index2, value);
     121      //p.MarkerSize = 10;
     122      //string nl = Environment.NewLine;
     123      //p.ToolTip = string.Format("Row: {0}{3}Column: {1}{3}Value: {2}", index2, index1, value, nl);
    115124      return p;
    116125    }
    117126
    118     #region Chart Events
    119 
    120     private void grayscaledImagesCheckBox_CheckedChanged(object sender, EventArgs e) {
    121       GrayscalesPictureBox.Visible = grayscaledImagesCheckBox.Checked;
    122       ColorsPictureBox.Visible = !grayscaledImagesCheckBox.Checked;
    123       UpdateChart();
     127    protected virtual Color GetDataPointColor(double value, double min, double max, bool grayscale) {
     128      int count = grayscale ? grayscaleColors.Length : colors.Length;
     129      int index = (int)((count - 1) * (value - min) / (max - min));
     130      if (index >= count) index = count - 1;
     131      if (index < 0) index = 0;
     132      return grayscale ? grayscaleColors[index] : colors[index];
    124133    }
    125134
     135    #region Content Events
     136    protected virtual void Content_TitleChanged(object sender, EventArgs e) {
     137      if (InvokeRequired)
     138        Invoke(new EventHandler(Content_TitleChanged), sender, e);
     139      else {
     140        chart.Titles[0].Text = Content.Title;
     141      }
     142    }
     143    protected virtual void Content_MinimumChanged(object sender, EventArgs e) {
     144      if (InvokeRequired)
     145        Invoke(new EventHandler(Content_MinimumChanged), sender, e);
     146      else {
     147        minimumLabel.Text = Content.Minimum.ToString();
     148        UpdatePoints();
     149      }
     150    }
     151    protected virtual void Content_MaximumChanged(object sender, EventArgs e) {
     152      if (InvokeRequired)
     153        Invoke(new EventHandler(Content_MaximumChanged), sender, e);
     154      else {
     155        maximumLabel.Text = Content.Maximum.ToString();
     156        UpdatePoints();
     157      }
     158    }
    126159    #endregion
    127160
     161    #region Control Events
     162    protected virtual void grayscaledImagesCheckBox_CheckedChanged(object sender, EventArgs e) {
     163      grayscalesPictureBox.Visible = grayscaleCheckBox.Checked;
     164      colorsPictureBox.Visible = !grayscaleCheckBox.Checked;
     165      UpdatePoints();
     166    }
     167    #endregion
    128168  }
    129 
    130169}
  • trunk/sources/HeuristicLab.Analysis.Views/3.3/HeatMapView.resx

    r4703 r4739  
    119119  </resheader>
    120120  <assembly alias="System.Drawing" name="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    121   <data name="ColorsPictureBox.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
     121  <data name="colorsPictureBox.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
    122122    <value>
    123123        Qk0S0gAAAAAAADYAAAAoAAAAMQAAAGsBAAABABgAAAAAAAAAAADEDgAAxA4AAAAAAAAAAAAA/wAe/wAe
     
    10201020</value>
    10211021  </data>
    1022   <data name="GrayscalesPictureBox.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
     1022  <data name="grayscalesPictureBox.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
    10231023    <value>
    10241024        Qk0S0gAAAAAAADYAAAAoAAAAMQAAAGsBAAABABgAAAAAAAAAAADEDgAAxA4AAAAAAAAAAAAA////////
  • trunk/sources/HeuristicLab.Analysis/3.3/HeatMap.cs

    r4722 r4739  
    2020#endregion
    2121
    22 using System.Collections.Generic;
     22using System;
    2323using System.Drawing;
    2424using HeuristicLab.Common;
     
    3535    }
    3636
     37    private string title;
     38    public string Title {
     39      get { return title; }
     40      set {
     41        if (!(title.Equals(value) || (value == null) && (title == string.Empty))) {
     42          title = value == null ? string.Empty : value;
     43          OnTitleChanged();
     44        }
     45      }
     46    }
     47    private double minimum;
     48    public double Minimum {
     49      get { return minimum; }
     50      set {
     51        if (minimum != value) {
     52          minimum = value;
     53          if (minimum >= maximum) Maximum = minimum + 1.0;
     54          OnMinimumChanged();
     55        }
     56      }
     57    }
     58    private double maximum;
     59    public double Maximum {
     60      get { return maximum; }
     61      set {
     62        if (maximum != value) {
     63          maximum = value;
     64          if (maximum <= minimum) Minimum = maximum - 1.0;
     65          OnMaximumChanged();
     66        }
     67      }
     68    }
     69
     70    #region Storable Properties
     71    [Storable(Name = "Title")]
     72    private string StorableTitle {
     73      get { return title; }
     74      set { title = value; }
     75    }
     76    [Storable(Name = "Minimum")]
     77    private double StorableMinimum {
     78      get { return minimum; }
     79      set { minimum = value; }
     80    }
     81    [Storable(Name = "Maximum")]
     82    private double StorableMaximum {
     83      get { return maximum; }
     84      set { maximum = value; }
     85    }
     86    #endregion
     87
    3788    [StorableConstructor]
    3889    protected HeatMap(bool deserializing) : base(deserializing) { }
    39     protected HeatMap(HeatMap original, Cloner cloner) : base(original, cloner) { }
    40     public HeatMap() : base() { }
    41     public HeatMap(int rows, int columns) : base(rows, columns) { }
    42     public HeatMap(int rows, int columns, IEnumerable<string> columnNames) : base(rows, columns, columnNames) { }
    43     public HeatMap(int rows, int columns, IEnumerable<string> columnNames, IEnumerable<string> rowNames) : base(rows, columns, columnNames, rowNames) { }
    44     public HeatMap(double[,] elements) : base(elements) { }
    45     public HeatMap(double[,] elements, IEnumerable<string> columnNames) : base(elements, columnNames) { }
    46     public HeatMap(double[,] elements, IEnumerable<string> columnNames, IEnumerable<string> rowNames) : base(elements, columnNames, rowNames) { }
     90    protected HeatMap(HeatMap original, Cloner cloner)
     91      : base(original, cloner) {
     92      this.title = original.title;
     93      this.minimum = original.minimum;
     94      this.maximum = original.maximum;
     95    }
     96    public HeatMap()
     97      : base() {
     98      this.title = "Heat Map";
     99      this.minimum = 0.0;
     100      this.maximum = 1.0;
     101    }
     102    public HeatMap(int rows, int columns)
     103      : base(rows, columns) {
     104      this.title = "Heat Map";
     105      this.minimum = 0.0;
     106      this.maximum = 1.0;
     107    }
     108    public HeatMap(int rows, int columns, string title)
     109      : base(rows, columns) {
     110      this.title = title == null ? string.Empty : title;
     111      this.minimum = 0.0;
     112      this.maximum = 1.0;
     113    }
     114    public HeatMap(double[,] elements)
     115      : base(elements) {
     116      this.title = "Heat Map";
     117      this.minimum = 0.0;
     118      this.maximum = 1.0;
     119    }
     120    public HeatMap(double[,] elements, string title)
     121      : base(elements) {
     122      this.title = title == null ? string.Empty : title;
     123      this.minimum = 0.0;
     124      this.maximum = 1.0;
     125    }
     126    public HeatMap(double[,] elements, string title, double minimum, double maximum)
     127      : base(elements) {
     128      this.title = title == null ? string.Empty : title;
     129      if (minimum >= maximum) throw new ArgumentException("Minimum is larger than or equal to maximum");
     130      this.minimum = minimum;
     131      this.maximum = maximum;
     132    }
    47133
    48134    public override IDeepCloneable Clone(Cloner cloner) {
     
    51137
    52138    public override string ToString() {
    53       return ItemName;
     139      return Title;
     140    }
     141
     142    public event EventHandler TitleChanged;
     143    protected virtual void OnTitleChanged() {
     144      var handler = TitleChanged;
     145      if (handler != null) handler(this, EventArgs.Empty);
     146    }
     147    public event EventHandler MinimumChanged;
     148    protected virtual void OnMinimumChanged() {
     149      var handler = MinimumChanged;
     150      if (handler != null) handler(this, EventArgs.Empty);
     151    }
     152    public event EventHandler MaximumChanged;
     153    protected virtual void OnMaximumChanged() {
     154      var handler = MaximumChanged;
     155      if (handler != null) handler(this, EventArgs.Empty);
    54156    }
    55157  }
  • trunk/sources/HeuristicLab.Analysis/3.3/PopulationDiversityAnalyzer.cs

    r4722 r4739  
    8787        ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
    8888        bool storeHistory = StoreHistoryParameter.Value.Value;
    89 
    90         // sort solutions by quality
    91         T[] sortedSolutions = null;
    92         if (max)
    93           sortedSolutions = solutions.Select((x, index) => new { Solution = x, Quality = qualities[index] }).OrderByDescending(x => x.Quality).Select(x => x.Solution).ToArray();
    94         else
    95           sortedSolutions = solutions.Select((x, index) => new { Solution = x, Quality = qualities[index] }).OrderBy(x => x.Quality).Select(x => x.Solution).ToArray();
    96 
    97         // calculate solution similarities
    98         double[,] similarities = CalculateSimilarities(sortedSolutions);
    99 
    100         // calculate minimum, average and maximum similarities
    101         double similarity;
    102         int count = sortedSolutions.Length;
    103         double[] minSimilarities = new double[sortedSolutions.Length];
    104         double[] avgSimilarities = new double[sortedSolutions.Length];
    105         double[] maxSimilarities = new double[sortedSolutions.Length];
    106         double avgSimilarity = 0;
    107         for (int i = 0; i < count; i++) {
    108           minSimilarities[i] = 1;
    109           avgSimilarities[i] = 0;
    110           maxSimilarities[i] = 0;
    111           for (int j = 0; j < count; j++) {
    112             if (i != j) {
    113               similarity = similarities[i, j];
    114               avgSimilarity += similarity;
    115               if (minSimilarities[i] > similarity) minSimilarities[i] = similarity;
    116               avgSimilarities[i] += similarity;
    117               if (maxSimilarities[i] < similarity) maxSimilarities[i] = similarity;
     89        int count = solutions.Length;
     90
     91        if (count > 1) {
     92          // sort solutions by quality
     93          T[] sortedSolutions = null;
     94          if (max)
     95            sortedSolutions = solutions.Select((x, index) => new { Solution = x, Quality = qualities[index] }).OrderByDescending(x => x.Quality).Select(x => x.Solution).ToArray();
     96          else
     97            sortedSolutions = solutions.Select((x, index) => new { Solution = x, Quality = qualities[index] }).OrderBy(x => x.Quality).Select(x => x.Solution).ToArray();
     98
     99          // calculate solution similarities
     100          double[,] similarities = CalculateSimilarities(sortedSolutions);
     101
     102          // calculate minimum, average and maximum similarities
     103          double similarity;
     104          double[] minSimilarities = new double[sortedSolutions.Length];
     105          double[] avgSimilarities = new double[sortedSolutions.Length];
     106          double[] maxSimilarities = new double[sortedSolutions.Length];
     107          for (int i = 0; i < count; i++) {
     108            minSimilarities[i] = 1;
     109            avgSimilarities[i] = 0;
     110            maxSimilarities[i] = 0;
     111            for (int j = 0; j < count; j++) {
     112              if (i != j) {
     113                similarity = similarities[i, j];
     114                if (minSimilarities[i] > similarity) minSimilarities[i] = similarity;
     115                avgSimilarities[i] += similarity;
     116                if (maxSimilarities[i] < similarity) maxSimilarities[i] = similarity;
     117              }
    118118            }
    119           }
    120           avgSimilarities[i] = avgSimilarities[i] / (count - 1);
    121         }
    122         double avgMinSimilarity = minSimilarities.Average();
    123         double avgAvgSimilarity = avgSimilarities.Average();
    124         double avgMaxSimilarity = maxSimilarities.Average();
    125         avgSimilarity = avgSimilarity / (count * count - count);
    126 
    127         // fetch results collection
    128         ResultCollection results;
    129         if (!ResultsParameter.ActualValue.ContainsKey("Population Diversity Analysis Results")) {
    130           results = new ResultCollection();
    131           ResultsParameter.ActualValue.Add(new Result("Population Diversity Analysis Results", results));
    132         } else {
    133           results = (ResultCollection)ResultsParameter.ActualValue["Population Diversity Analysis Results"].Value;
    134         }
    135 
    136         // store similarities
    137         HeatMap similaritiesHeatMap = new HeatMap(similarities);
    138         if (!results.ContainsKey("Solution Similarities"))
    139           results.Add(new Result("Solution Similarities", similaritiesHeatMap));
    140         else
    141           results["Solution Similarities"].Value = similaritiesHeatMap;
    142 
    143         // store similarities history
    144         if (storeHistory) {
    145           if (!results.ContainsKey("Solution Similarities History")) {
    146             HeatMapHistory history = new HeatMapHistory();
    147             history.Add(similaritiesHeatMap);
    148             results.Add(new Result("Solution Similarities History", history));
     119            avgSimilarities[i] = avgSimilarities[i] / (count - 1);
     120          }
     121          double avgMinSimilarity = minSimilarities.Average();
     122          double avgAvgSimilarity = avgSimilarities.Average();
     123          double avgMaxSimilarity = maxSimilarities.Average();
     124
     125          // fetch results collection
     126          ResultCollection results;
     127          if (!ResultsParameter.ActualValue.ContainsKey("Population Diversity Analysis Results")) {
     128            results = new ResultCollection();
     129            ResultsParameter.ActualValue.Add(new Result("Population Diversity Analysis Results", results));
    149130          } else {
    150             ((HeatMapHistory)results["Solution Similarities History"].Value).Add(similaritiesHeatMap);
    151           }
    152         }
    153 
    154         // store average similarity
    155         if (!results.ContainsKey("Average Population Similarity"))
    156           results.Add(new Result("Average Population Similarity", new DoubleValue(avgSimilarity)));
    157         else
    158           ((DoubleValue)results["Average Population Similarity"].Value).Value = avgSimilarity;
    159 
    160         // store average minimum, average and maximum similarity
    161         if (!results.ContainsKey("Average Minimum Solution Similarity"))
    162           results.Add(new Result("Average Minimum Solution Similarity", new DoubleValue(avgMinSimilarity)));
    163         else
    164           ((DoubleValue)results["Average Minimum Solution Similarity"].Value).Value = avgMinSimilarity;
    165 
    166         if (!results.ContainsKey("Average Average Solution Similarity"))
    167           results.Add(new Result("Average Average Solution Similarity", new DoubleValue(avgAvgSimilarity)));
    168         else
    169           ((DoubleValue)results["Average Average Solution Similarity"].Value).Value = avgAvgSimilarity;
    170 
    171         if (!results.ContainsKey("Average Maximum Solution Similarity"))
    172           results.Add(new Result("Average Maximum Solution Similarity", new DoubleValue(avgMaxSimilarity)));
    173         else
    174           ((DoubleValue)results["Average Maximum Solution Similarity"].Value).Value = avgMaxSimilarity;
    175 
    176         // store population similarity data table
    177         DataTable similarityDataTable;
    178         if (!results.ContainsKey("Average Solution Similarity")) {
    179           similarityDataTable = new DataTable("Average Solution Similarity");
    180           results.Add(new Result("Average Solution Similarity", similarityDataTable));
    181           DataRowVisualProperties visualProperties = new DataRowVisualProperties();
    182           visualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Line;
    183           visualProperties.StartIndexZero = true;
    184           similarityDataTable.Rows.Add(new DataRow("Average Population Similarity", null, visualProperties));
    185           similarityDataTable.Rows.Add(new DataRow("Average Minimum Solution Similarity", null, visualProperties));
    186           similarityDataTable.Rows.Add(new DataRow("Average Average Solution Similarity", null, visualProperties));
    187           similarityDataTable.Rows.Add(new DataRow("Average Maximum Solution Similarity", null, visualProperties));
    188         } else {
    189           similarityDataTable = (DataTable)results["Average Solution Similarity"].Value;
    190         }
    191         similarityDataTable.Rows["Average Population Similarity"].Values.Add(avgSimilarity);
    192         similarityDataTable.Rows["Average Minimum Solution Similarity"].Values.Add(avgMinSimilarity);
    193         similarityDataTable.Rows["Average Average Solution Similarity"].Values.Add(avgAvgSimilarity);
    194         similarityDataTable.Rows["Average Maximum Solution Similarity"].Values.Add(avgMaxSimilarity);
    195 
    196         // store maximum similarities
    197         DataTable minAvgMaxSimilaritiesDataTable = new DataTable("Minimum/Average/Maximum Solution Similarities");
    198         minAvgMaxSimilaritiesDataTable.Rows.Add(new DataRow("Minimum Solution Similarity"));
    199         minAvgMaxSimilaritiesDataTable.Rows["Minimum Solution Similarity"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Columns;
    200         minAvgMaxSimilaritiesDataTable.Rows["Minimum Solution Similarity"].Values.AddRange(minSimilarities);
    201         minAvgMaxSimilaritiesDataTable.Rows.Add(new DataRow("Average Solution Similarity"));
    202         minAvgMaxSimilaritiesDataTable.Rows["Average Solution Similarity"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Columns;
    203         minAvgMaxSimilaritiesDataTable.Rows["Average Solution Similarity"].Values.AddRange(avgSimilarities);
    204         minAvgMaxSimilaritiesDataTable.Rows.Add(new DataRow("Maximum Solution Similarity"));
    205         minAvgMaxSimilaritiesDataTable.Rows["Maximum Solution Similarity"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Columns;
    206         minAvgMaxSimilaritiesDataTable.Rows["Maximum Solution Similarity"].Values.AddRange(maxSimilarities);
    207         if (!results.ContainsKey("Minimum/Average/Maximum Solution Similarities")) {
    208           results.Add(new Result("Minimum/Average/Maximum Solution Similarities", minAvgMaxSimilaritiesDataTable));
    209         } else {
    210           results["Minimum/Average/Maximum Solution Similarities"].Value = minAvgMaxSimilaritiesDataTable;
    211         }
    212 
    213         // store maximum similarities history
    214         if (storeHistory) {
    215           if (!results.ContainsKey("Minimum/Average/Maximum Solution Similarities History")) {
    216             DataTableHistory history = new DataTableHistory();
    217             history.Add(minAvgMaxSimilaritiesDataTable);
    218             results.Add(new Result("Minimum/Average/Maximum Solution Similarities History", history));
     131            results = (ResultCollection)ResultsParameter.ActualValue["Population Diversity Analysis Results"].Value;
     132          }
     133
     134          // store similarities
     135          HeatMap similaritiesHeatMap = new HeatMap(similarities, "Solution Similarities", 0.0, 1.0);
     136          if (!results.ContainsKey("Solution Similarities"))
     137            results.Add(new Result("Solution Similarities", similaritiesHeatMap));
     138          else
     139            results["Solution Similarities"].Value = similaritiesHeatMap;
     140
     141          // store similarities history
     142          if (storeHistory) {
     143            if (!results.ContainsKey("Solution Similarities History")) {
     144              HeatMapHistory history = new HeatMapHistory();
     145              history.Add(similaritiesHeatMap);
     146              results.Add(new Result("Solution Similarities History", history));
     147            } else {
     148              ((HeatMapHistory)results["Solution Similarities History"].Value).Add(similaritiesHeatMap);
     149            }
     150          }
     151
     152          // store average minimum, average and maximum similarity
     153          if (!results.ContainsKey("Average Minimum Solution Similarity"))
     154            results.Add(new Result("Average Minimum Solution Similarity", new DoubleValue(avgMinSimilarity)));
     155          else
     156            ((DoubleValue)results["Average Minimum Solution Similarity"].Value).Value = avgMinSimilarity;
     157
     158          if (!results.ContainsKey("Average Average Solution Similarity"))
     159            results.Add(new Result("Average Average Solution Similarity", new DoubleValue(avgAvgSimilarity)));
     160          else
     161            ((DoubleValue)results["Average Average Solution Similarity"].Value).Value = avgAvgSimilarity;
     162
     163          if (!results.ContainsKey("Average Maximum Solution Similarity"))
     164            results.Add(new Result("Average Maximum Solution Similarity", new DoubleValue(avgMaxSimilarity)));
     165          else
     166            ((DoubleValue)results["Average Maximum Solution Similarity"].Value).Value = avgMaxSimilarity;
     167
     168          // store average minimum, average and maximum solution similarity data table
     169          DataTable minAvgMaxSimilarityDataTable;
     170          if (!results.ContainsKey("Average Minimum/Average/Maximum Solution Similarity")) {
     171            minAvgMaxSimilarityDataTable = new DataTable("Average Minimum/Average/Maximum Solution Similarity");
     172            results.Add(new Result("Average Minimum/Average/Maximum Solution Similarity", minAvgMaxSimilarityDataTable));
     173            DataRowVisualProperties visualProperties = new DataRowVisualProperties();
     174            visualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Line;
     175            visualProperties.StartIndexZero = true;
     176            minAvgMaxSimilarityDataTable.Rows.Add(new DataRow("Average Minimum Solution Similarity", null, visualProperties));
     177            minAvgMaxSimilarityDataTable.Rows.Add(new DataRow("Average Average Solution Similarity", null, visualProperties));
     178            minAvgMaxSimilarityDataTable.Rows.Add(new DataRow("Average Maximum Solution Similarity", null, visualProperties));
    219179          } else {
    220             ((DataTableHistory)results["Minimum/Average/Maximum Solution Similarities History"].Value).Add(minAvgMaxSimilaritiesDataTable);
     180            minAvgMaxSimilarityDataTable = (DataTable)results["Average Minimum/Average/Maximum Solution Similarity"].Value;
     181          }
     182          minAvgMaxSimilarityDataTable.Rows["Average Minimum Solution Similarity"].Values.Add(avgMinSimilarity);
     183          minAvgMaxSimilarityDataTable.Rows["Average Average Solution Similarity"].Values.Add(avgAvgSimilarity);
     184          minAvgMaxSimilarityDataTable.Rows["Average Maximum Solution Similarity"].Values.Add(avgMaxSimilarity);
     185
     186          // store minimum, average, maximum similarities data table
     187          DataTable minAvgMaxSimilaritiesDataTable = new DataTable("Minimum/Average/Maximum Solution Similarities");
     188          minAvgMaxSimilaritiesDataTable.Rows.Add(new DataRow("Minimum Solution Similarity"));
     189          minAvgMaxSimilaritiesDataTable.Rows["Minimum Solution Similarity"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Columns;
     190          minAvgMaxSimilaritiesDataTable.Rows["Minimum Solution Similarity"].Values.AddRange(minSimilarities);
     191          minAvgMaxSimilaritiesDataTable.Rows.Add(new DataRow("Average Solution Similarity"));
     192          minAvgMaxSimilaritiesDataTable.Rows["Average Solution Similarity"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Columns;
     193          minAvgMaxSimilaritiesDataTable.Rows["Average Solution Similarity"].Values.AddRange(avgSimilarities);
     194          minAvgMaxSimilaritiesDataTable.Rows.Add(new DataRow("Maximum Solution Similarity"));
     195          minAvgMaxSimilaritiesDataTable.Rows["Maximum Solution Similarity"].VisualProperties.ChartType = DataRowVisualProperties.DataRowChartType.Columns;
     196          minAvgMaxSimilaritiesDataTable.Rows["Maximum Solution Similarity"].Values.AddRange(maxSimilarities);
     197          if (!results.ContainsKey("Minimum/Average/Maximum Solution Similarities")) {
     198            results.Add(new Result("Minimum/Average/Maximum Solution Similarities", minAvgMaxSimilaritiesDataTable));
     199          } else {
     200            results["Minimum/Average/Maximum Solution Similarities"].Value = minAvgMaxSimilaritiesDataTable;
     201          }
     202
     203          // store minimum, average, maximum similarities history
     204          if (storeHistory) {
     205            if (!results.ContainsKey("Minimum/Average/Maximum Solution Similarities History")) {
     206              DataTableHistory history = new DataTableHistory();
     207              history.Add(minAvgMaxSimilaritiesDataTable);
     208              results.Add(new Result("Minimum/Average/Maximum Solution Similarities History", history));
     209            } else {
     210              ((DataTableHistory)results["Minimum/Average/Maximum Solution Similarities History"].Value).Add(minAvgMaxSimilaritiesDataTable);
     211            }
    221212          }
    222213        }
  • trunk/sources/HeuristicLab.Visualization.ChartControlsExtensions/3.3/EnhancedChart.Designer.cs

    r4654 r4739  
    7878      // saveFileDialog
    7979      //
    80       this.saveFileDialog.Filter = "\"Bitmap (*.bmp)|*.bmp|JPEG (*.jpg)|*.jpg|EMF (*.emf)|*.emf|PNG (*.png)|*.png|GIF " +
     80      this.saveFileDialog.Filter = "Bitmap (*.bmp)|*.bmp|JPEG (*.jpg)|*.jpg|EMF (*.emf)|*.emf|PNG (*.png)|*.png|GIF " +
    8181          "(*.gif)|*.gif|TIFF (*.tif)|*.tif\"";
    8282      this.saveFileDialog.FilterIndex = 2;
Note: See TracChangeset for help on using the changeset viewer.