#region License Information
/* HeuristicLab
* Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using HeuristicLab.Analysis;
using HeuristicLab.Collections;
using HeuristicLab.Common;
using HeuristicLab.Core;
using HeuristicLab.Core.Views;
using HeuristicLab.Data;
using HeuristicLab.MainForm;
using HeuristicLab.MainForm.WindowsForms;
namespace HeuristicLab.Optimization.Views {
[View("Run-length Distribution View")]
[Content(typeof(RunCollection), false)]
public partial class RunCollectionRLDView : ItemView {
private List invisibleTargetSeries;
private const string AllInstances = "All Instances";
private static readonly Color[] colors = new[] {
Color.FromArgb(0x40, 0x6A, 0xB7),
Color.FromArgb(0xB1, 0x6D, 0x01),
Color.FromArgb(0x4E, 0x8A, 0x06),
Color.FromArgb(0x75, 0x50, 0x7B),
Color.FromArgb(0x72, 0x9F, 0xCF),
Color.FromArgb(0xA4, 0x00, 0x00),
Color.FromArgb(0xAD, 0x7F, 0xA8),
Color.FromArgb(0x29, 0x50, 0xCF),
Color.FromArgb(0x90, 0xB0, 0x60),
Color.FromArgb(0xF5, 0x89, 0x30),
Color.FromArgb(0x55, 0x57, 0x53),
Color.FromArgb(0xEF, 0x59, 0x59),
Color.FromArgb(0xED, 0xD4, 0x30),
Color.FromArgb(0x63, 0xC2, 0x16),
};
private static readonly ChartDashStyle[] lineStyles = new[] {
ChartDashStyle.Solid,
ChartDashStyle.Dash,
ChartDashStyle.DashDot,
ChartDashStyle.Dot
};
private static readonly DataRowVisualProperties.DataRowLineStyle[] hlLineStyles = new[] {
DataRowVisualProperties.DataRowLineStyle.Solid,
DataRowVisualProperties.DataRowLineStyle.Dash,
DataRowVisualProperties.DataRowLineStyle.DashDot,
DataRowVisualProperties.DataRowLineStyle.Dot
};
public new RunCollection Content {
get { return (RunCollection)base.Content; }
set { base.Content = value; }
}
private List groups;
private double[] targets;
private double[] budgets;
private bool targetsAreRelative = true;
private bool showLabelsInTargetChart = true;
private readonly BindingList problems;
private bool updateInProgress;
private bool suppressContentEvents;
private readonly IndexedDataTable byCostDataTable;
public IndexedDataTable ByCostDataTable {
get { return byCostDataTable; }
}
public RunCollectionRLDView() {
InitializeComponent();
invisibleTargetSeries = new List();
try {
updateInProgress = true;
targetChart.CustomizeAllChartAreas();
targetChart.ChartAreas[0].CursorX.Interval = 1;
targetChart.SuppressExceptions = true;
byCostDataTable = new IndexedDataTable("ECDF by Cost", "A data table containing the ECDF of function values (relative to best-known).") {
VisualProperties = {
YAxisTitle = "Proportion of runs",
YAxisMinimumFixedValue = 0,
YAxisMinimumAuto = false,
YAxisMaximumFixedValue = 1,
YAxisMaximumAuto = false
}
};
byCostViewHost.Content = byCostDataTable;
relativeOrAbsoluteComboBox.SelectedItem = targetsAreRelative ? "relative" : "absolute";
problems = new BindingList();
problemComboBox.DataSource = new BindingSource() { DataSource = problems };
problemComboBox.DataBindings.DefaultDataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
} finally { updateInProgress = false; }
}
#region Content events
protected override void RegisterContentEvents() {
base.RegisterContentEvents();
Content.ItemsAdded += Content_ItemsAdded;
Content.ItemsRemoved += Content_ItemsRemoved;
Content.CollectionReset += Content_CollectionReset;
Content.UpdateOfRunsInProgressChanged += Content_UpdateOfRunsInProgressChanged;
Content.OptimizerNameChanged += Content_AlgorithmNameChanged;
}
protected override void DeregisterContentEvents() {
Content.ItemsAdded -= Content_ItemsAdded;
Content.ItemsRemoved -= Content_ItemsRemoved;
Content.CollectionReset -= Content_CollectionReset;
Content.UpdateOfRunsInProgressChanged -= Content_UpdateOfRunsInProgressChanged;
Content.OptimizerNameChanged -= Content_AlgorithmNameChanged;
base.DeregisterContentEvents();
}
private void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs e) {
foreach (var run in e.Items) RegisterRunEvents(run);
if (suppressContentEvents) return;
if (InvokeRequired) {
Invoke(new CollectionItemsChangedEventHandler(Content_ItemsAdded), sender, e);
return;
}
if (updateInProgress) return;
try {
updateInProgress = true;
UpdateComboBoxes();
GroupRuns();
} finally { updateInProgress = false; }
}
private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs e) {
foreach (var run in e.Items) DeregisterRunEvents(run);
if (suppressContentEvents) return;
if (InvokeRequired) {
Invoke(new CollectionItemsChangedEventHandler(Content_ItemsRemoved), sender, e);
return;
}
if (updateInProgress) return;
try {
updateInProgress = true;
UpdateComboBoxes();
GroupRuns();
} finally { updateInProgress = false; }
}
private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs e) {
foreach (var run in e.OldItems) DeregisterRunEvents(run);
foreach (var run in e.Items) RegisterRunEvents(run);
if (suppressContentEvents) return;
if (InvokeRequired) {
Invoke(new CollectionItemsChangedEventHandler(Content_CollectionReset), sender, e);
return;
}
if (updateInProgress) return;
try {
updateInProgress = true;
UpdateComboBoxes();
GroupRuns();
} finally { updateInProgress = false; }
}
private void Content_AlgorithmNameChanged(object sender, EventArgs e) {
if (InvokeRequired)
Invoke(new EventHandler(Content_AlgorithmNameChanged), sender, e);
else UpdateCaption();
}
private void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
if (InvokeRequired) {
Invoke(new EventHandler(Content_UpdateOfRunsInProgressChanged), sender, e);
return;
}
suppressContentEvents = Content.UpdateOfRunsInProgress;
if (!suppressContentEvents) {
if (updateInProgress) return;
try {
updateInProgress = true;
UpdateComboBoxes();
GroupRuns();
} finally { updateInProgress = false; }
}
}
private void RegisterRunEvents(IRun run) {
run.PropertyChanged += run_PropertyChanged;
}
private void DeregisterRunEvents(IRun run) {
run.PropertyChanged -= run_PropertyChanged;
}
private void run_PropertyChanged(object sender, PropertyChangedEventArgs e) {
if (suppressContentEvents) return;
if (InvokeRequired) {
Invoke((Action