[13718] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
[13752] | 22 | using HeuristicLab.Common.Resources;
|
---|
[13751] | 23 | using HeuristicLab.Core;
|
---|
[13752] | 24 | using HeuristicLab.Core.Views;
|
---|
| 25 | using HeuristicLab.Data;
|
---|
[13718] | 26 | using HeuristicLab.MainForm;
|
---|
| 27 | using HeuristicLab.OptimizationExpertSystem.Common;
|
---|
| 28 | using System;
|
---|
| 29 | using System.Collections.Generic;
|
---|
| 30 | using System.Linq;
|
---|
| 31 | using System.Text.RegularExpressions;
|
---|
[13752] | 32 | using System.Windows.Forms;
|
---|
[13718] | 33 | using System.Windows.Forms.DataVisualization.Charting;
|
---|
| 34 |
|
---|
| 35 | namespace HeuristicLab.OptimizationExpertSystem {
|
---|
| 36 | [View("Understanding Problem Instance")]
|
---|
[13722] | 37 | [Content(typeof(KnowledgeCenter), IsDefaultView = false)]
|
---|
[13751] | 38 | public sealed partial class UnderstandingProblemInstanceView : KnowledgeCenterViewBase {
|
---|
| 39 | private bool SuppressEvents { get; set; }
|
---|
[13752] | 40 | private readonly CheckedItemListView<StringValue> characteristicsView;
|
---|
| 41 |
|
---|
[13718] | 42 | public UnderstandingProblemInstanceView() {
|
---|
| 43 | InitializeComponent();
|
---|
[13752] | 44 | showCharacteristicsCheckBox.Text = string.Empty;
|
---|
| 45 | showCharacteristicsCheckBox.Image = VSImageLibrary.Properties;
|
---|
| 46 | characteristicsView = new CheckedItemListView<StringValue>() {
|
---|
| 47 | Dock = DockStyle.Fill
|
---|
| 48 | };
|
---|
| 49 | mapSplitContainer.Panel2.Controls.Add(characteristicsView);
|
---|
[13718] | 50 | }
|
---|
| 51 |
|
---|
| 52 | protected override void OnContentChanged() {
|
---|
| 53 | base.OnContentChanged();
|
---|
| 54 | if (Content == null) {
|
---|
| 55 | problemInstancesView.Content = null;
|
---|
[13752] | 56 | characteristicsView.Content = null;
|
---|
[13718] | 57 | instanceMapChart.Series["InstancesSeries"].Points.Clear();
|
---|
| 58 | instanceMapChart.Series["CurrentInstanceSeries"].Points.Clear();
|
---|
| 59 | } else {
|
---|
| 60 | problemInstancesView.Content = Content.ProblemInstances;
|
---|
[13752] | 61 | characteristicsView.Content = Content.ProblemCharacteristics;
|
---|
[13718] | 62 | UpdateProjectionComboBox();
|
---|
[13751] | 63 | UpdateSizeComboBox();
|
---|
[13718] | 64 | }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
[13720] | 67 | #region Content Event Handlers
|
---|
| 68 | protected override void OnProblemChanged() {
|
---|
| 69 | base.OnProblemChanged();
|
---|
[13718] | 70 | SetEnabledStateOfControls();
|
---|
| 71 | }
|
---|
| 72 |
|
---|
[13720] | 73 | protected override void OnProblemInstancesChanged() {
|
---|
| 74 | base.OnProblemInstancesChanged();
|
---|
| 75 | if (Content.ProblemInstances.UpdateOfRunsInProgress) return;
|
---|
| 76 | UpdateProjectionComboBox();
|
---|
[13751] | 77 | UpdateSizeComboBox();
|
---|
| 78 | UpdateProjection();
|
---|
[13720] | 79 | }
|
---|
[13751] | 80 | #endregion
|
---|
[13720] | 81 |
|
---|
[13751] | 82 | private void UpdateProjectionComboBox() {
|
---|
| 83 | try {
|
---|
| 84 | SuppressEvents = true;
|
---|
| 85 | var selected = projectionComboBox.SelectedIndex >= 0 ? (string)projectionComboBox.SelectedItem : null;
|
---|
| 86 | projectionComboBox.Items.Clear();
|
---|
| 87 | foreach (var str in GetProjections()) {
|
---|
| 88 | projectionComboBox.Items.Add(str);
|
---|
| 89 | if (selected == str) projectionComboBox.SelectedItem = str;
|
---|
| 90 | }
|
---|
| 91 | if (selected == null && projectionComboBox.Items.Count > 0)
|
---|
| 92 | projectionComboBox.SelectedIndex = 0;
|
---|
| 93 | } finally { SuppressEvents = false; }
|
---|
[13718] | 94 | }
|
---|
[13751] | 95 |
|
---|
| 96 | private void UpdateSizeComboBox() {
|
---|
| 97 | try {
|
---|
| 98 | SuppressEvents = true;
|
---|
| 99 | var selected = sizeComboBox.SelectedIndex >= 0 ? (string)sizeComboBox.SelectedItem : null;
|
---|
| 100 | sizeComboBox.Items.Clear();
|
---|
| 101 | sizeComboBox.Items.Add(string.Empty);
|
---|
| 102 | foreach (var str in Content.ProblemInstances.ResultNames.Where(x => !(x.StartsWith("Projection.") && (x.EndsWith(".X") || x.EndsWith(".Y"))))) {
|
---|
| 103 | sizeComboBox.Items.Add(str);
|
---|
| 104 | if (selected == str) sizeComboBox.SelectedItem = str;
|
---|
| 105 | }
|
---|
| 106 | if (selected == null && sizeComboBox.Items.Count > 0)
|
---|
| 107 | sizeComboBox.SelectedIndex = 0;
|
---|
| 108 | } finally { SuppressEvents = false; }
|
---|
| 109 | }
|
---|
[13720] | 110 |
|
---|
[13751] | 111 | private IEnumerable<string> GetProjections() {
|
---|
[13718] | 112 | return Content.ProblemInstances
|
---|
| 113 | .SelectMany(x => x.Results.Where(y => Regex.IsMatch(y.Key, "^Projection[.].*[.][XY]$")))
|
---|
| 114 | .Select(x => Regex.Match(x.Key, "Projection[.](?<g>.*)[.][XY]").Groups["g"].Value)
|
---|
| 115 | .Distinct();
|
---|
| 116 | }
|
---|
| 117 |
|
---|
[13751] | 118 | private void UpdateProjection() {
|
---|
| 119 | if (InvokeRequired) { Invoke((Action)UpdateProjection); return; }
|
---|
| 120 |
|
---|
| 121 | var instancesSeries = instanceMapChart.Series["InstancesSeries"];
|
---|
| 122 | var currentInstanceSeries = instanceMapChart.Series["CurrentInstanceSeries"];
|
---|
| 123 |
|
---|
| 124 | if (projectionComboBox.SelectedIndex < 0) {
|
---|
| 125 | instancesSeries.Points.Clear();
|
---|
| 126 | currentInstanceSeries.Points.Clear();
|
---|
| 127 | return;
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | var projection = (string)projectionComboBox.SelectedItem;
|
---|
| 131 | var size = sizeComboBox.SelectedIndex >= 0 ? (string)sizeComboBox.SelectedItem : string.Empty;
|
---|
| 132 |
|
---|
| 133 | DoProjectProblemInstances(instancesSeries, currentInstanceSeries, projection, size, invPropCheckBox.Checked);
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | private void DoProjectProblemInstances(Series instancesSeries, Series currentInstanceSeries, string projection, string size, bool invProp) {
|
---|
[13718] | 137 | instancesSeries.Points.Clear();
|
---|
| 138 | currentInstanceSeries.Points.Clear();
|
---|
| 139 |
|
---|
[13751] | 140 | double maxSize = 0, minSize = 0;
|
---|
| 141 | if (!string.IsNullOrEmpty(size)) {
|
---|
| 142 | var sizes = Content.ProblemInstances.Where(x => x.Results.ContainsKey(size)).Select(x => x.Results[size]).OfType<Data.DoubleValue>().Where(x => !double.IsNaN(x.Value)).ToList();
|
---|
| 143 | if (sizes.Count > 0) {
|
---|
| 144 | maxSize = sizes.Max(x => x.Value);
|
---|
| 145 | minSize = sizes.Min(x => x.Value);
|
---|
| 146 | }
|
---|
| 147 | }
|
---|
[13718] | 148 | foreach (var run in Content.ProblemInstances) {
|
---|
| 149 | var xKey = "Projection." + projection + ".X";
|
---|
| 150 | var yKey = "Projection." + projection + ".Y";
|
---|
| 151 | if (!run.Results.ContainsKey(xKey) || !run.Results.ContainsKey(yKey)
|
---|
| 152 | || !(run.Results[xKey] is Data.DoubleValue) || !(run.Results[yKey] is Data.DoubleValue)) continue;
|
---|
| 153 | var x = ((Data.DoubleValue)run.Results[xKey]).Value;
|
---|
| 154 | var y = ((Data.DoubleValue)run.Results[yKey]).Value;
|
---|
| 155 | var dataPoint = new DataPoint(x, y) {
|
---|
[13751] | 156 | Label = run.Name,
|
---|
[13718] | 157 | };
|
---|
[13751] | 158 | IItem item;
|
---|
| 159 | if (maxSize > minSize && run.Results.TryGetValue(size, out item)) {
|
---|
| 160 | var dItem = item as Data.DoubleValue;
|
---|
| 161 | if (dItem != null) {
|
---|
| 162 | if (double.IsNaN(dItem.Value))
|
---|
| 163 | dataPoint.MarkerSize = 1;
|
---|
| 164 | else {
|
---|
| 165 | if (invProp) dataPoint.MarkerSize = (int)Math.Round(5 + 15 * (maxSize - dItem.Value) / (maxSize - minSize));
|
---|
| 166 | else dataPoint.MarkerSize = (int)Math.Round(5 + 15 * (dItem.Value - minSize) / (maxSize - minSize));
|
---|
| 167 | }
|
---|
| 168 | }
|
---|
| 169 | } else if (maxSize == minSize) {
|
---|
| 170 | dataPoint.MarkerSize = instancesSeries.MarkerSize;
|
---|
| 171 | } else dataPoint.MarkerSize = 1;
|
---|
[13718] | 172 |
|
---|
[13751] | 173 | if (Content.IsCurrentInstance(run)) currentInstanceSeries.Points.Add(dataPoint);
|
---|
| 174 | else instancesSeries.Points.Add(dataPoint);
|
---|
[13718] | 175 | }
|
---|
| 176 | }
|
---|
| 177 |
|
---|
[13751] | 178 | #region Control Event Handlers
|
---|
[13718] | 179 | private void ProjectionComboBoxOnSelectedIndexChanged(object sender, EventArgs e) {
|
---|
[13751] | 180 | UpdateProjection();
|
---|
| 181 | }
|
---|
[13718] | 182 |
|
---|
[13751] | 183 | private void SizeComboBoxOnSelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 184 | UpdateProjection();
|
---|
[13718] | 185 | }
|
---|
| 186 |
|
---|
[13751] | 187 | private void InvPropCheckBoxOnCheckedChanged(object sender, EventArgs e) {
|
---|
| 188 | UpdateProjection();
|
---|
[13718] | 189 | }
|
---|
[13752] | 190 |
|
---|
| 191 | private void showCharacteristicsCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 192 | mapSplitContainer.Panel2Collapsed = !showCharacteristicsCheckBox.Checked;
|
---|
| 193 | }
|
---|
[13751] | 194 | #endregion
|
---|
[13718] | 195 | }
|
---|
| 196 | }
|
---|