[7980] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[14185] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[7980] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
[11344] | 24 | using System.ComponentModel;
|
---|
[12822] | 25 | using System.Drawing;
|
---|
[12841] | 26 | using System.Globalization;
|
---|
[7980] | 27 | using System.Linq;
|
---|
[12771] | 28 | using System.Windows.Forms;
|
---|
[14101] | 29 | using System.Windows.Forms.DataVisualization.Charting;
|
---|
| 30 | using HeuristicLab.Analysis;
|
---|
| 31 | using HeuristicLab.Collections;
|
---|
[14751] | 32 | using HeuristicLab.Core;
|
---|
[14101] | 33 | using HeuristicLab.Core.Views;
|
---|
| 34 | using HeuristicLab.Data;
|
---|
| 35 | using HeuristicLab.MainForm;
|
---|
| 36 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[7980] | 37 |
|
---|
| 38 | namespace HeuristicLab.Optimization.Views {
|
---|
[12803] | 39 | [View("Run-length Distribution View")]
|
---|
[7980] | 40 | [Content(typeof(RunCollection), false)]
|
---|
[12803] | 41 | public partial class RunCollectionRLDView : ItemView {
|
---|
[14101] | 42 | private List<Series> invisibleTargetSeries;
|
---|
| 43 |
|
---|
[12771] | 44 | private const string AllRuns = "All Runs";
|
---|
[7980] | 45 |
|
---|
[12822] | 46 | private static readonly Color[] colors = new[] {
|
---|
[12838] | 47 | Color.FromArgb(0x40, 0x6A, 0xB7),
|
---|
| 48 | Color.FromArgb(0xB1, 0x6D, 0x01),
|
---|
| 49 | Color.FromArgb(0x4E, 0x8A, 0x06),
|
---|
[12822] | 50 | Color.FromArgb(0x75, 0x50, 0x7B),
|
---|
| 51 | Color.FromArgb(0x72, 0x9F, 0xCF),
|
---|
| 52 | Color.FromArgb(0xA4, 0x00, 0x00),
|
---|
| 53 | Color.FromArgb(0xAD, 0x7F, 0xA8),
|
---|
[12838] | 54 | Color.FromArgb(0x29, 0x50, 0xCF),
|
---|
| 55 | Color.FromArgb(0x90, 0xB0, 0x60),
|
---|
| 56 | Color.FromArgb(0xF5, 0x89, 0x30),
|
---|
[12822] | 57 | Color.FromArgb(0x55, 0x57, 0x53),
|
---|
[12838] | 58 | Color.FromArgb(0xEF, 0x59, 0x59),
|
---|
| 59 | Color.FromArgb(0xED, 0xD4, 0x30),
|
---|
| 60 | Color.FromArgb(0x63, 0xC2, 0x16),
|
---|
[12822] | 61 | };
|
---|
[14101] | 62 | private static readonly ChartDashStyle[] lineStyles = new[] {
|
---|
| 63 | ChartDashStyle.Solid,
|
---|
| 64 | ChartDashStyle.Dash,
|
---|
| 65 | ChartDashStyle.DashDot,
|
---|
| 66 | ChartDashStyle.Dot
|
---|
| 67 | };
|
---|
| 68 | private static readonly DataRowVisualProperties.DataRowLineStyle[] hlLineStyles = new[] {
|
---|
[12838] | 69 | DataRowVisualProperties.DataRowLineStyle.Solid,
|
---|
| 70 | DataRowVisualProperties.DataRowLineStyle.Dash,
|
---|
| 71 | DataRowVisualProperties.DataRowLineStyle.DashDot,
|
---|
| 72 | DataRowVisualProperties.DataRowLineStyle.Dot
|
---|
| 73 | };
|
---|
[12822] | 74 |
|
---|
[7980] | 75 | public new RunCollection Content {
|
---|
| 76 | get { return (RunCollection)base.Content; }
|
---|
| 77 | set { base.Content = value; }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[12838] | 80 | private double[] targets;
|
---|
| 81 | private double[] budgets;
|
---|
[14751] | 82 | private bool targetsAreRelative = true;
|
---|
| 83 | private readonly BindingList<ProblemInstance> problems;
|
---|
[12804] | 84 |
|
---|
[7980] | 85 | private bool suppressUpdates;
|
---|
[12838] | 86 | private readonly IndexedDataTable<double> byCostDataTable;
|
---|
| 87 | public IndexedDataTable<double> ByCostDataTable {
|
---|
| 88 | get { return byCostDataTable; }
|
---|
| 89 | }
|
---|
[7980] | 90 |
|
---|
[12803] | 91 | public RunCollectionRLDView() {
|
---|
[8108] | 92 | InitializeComponent();
|
---|
[14101] | 93 | invisibleTargetSeries = new List<Series>();
|
---|
| 94 |
|
---|
| 95 | targetChart.CustomizeAllChartAreas();
|
---|
| 96 | targetChart.ChartAreas[0].CursorX.Interval = 1;
|
---|
| 97 | targetChart.SuppressExceptions = true;
|
---|
[12838] | 98 | byCostDataTable = new IndexedDataTable<double>("ECDF by Cost", "A data table containing the ECDF of each of a number of groups.") {
|
---|
| 99 | VisualProperties = {
|
---|
[12888] | 100 | YAxisTitle = "Proportion of unused budgets",
|
---|
[13583] | 101 | YAxisMinimumFixedValue = 0,
|
---|
| 102 | YAxisMinimumAuto = false,
|
---|
| 103 | YAxisMaximumFixedValue = 1,
|
---|
| 104 | YAxisMaximumAuto = false
|
---|
[12838] | 105 | }
|
---|
| 106 | };
|
---|
| 107 | byCostViewHost.Content = byCostDataTable;
|
---|
[14751] | 108 | suppressUpdates = true;
|
---|
| 109 | relativeOrAbsoluteComboBox.SelectedItem = targetsAreRelative ? "relative" : "absolute";
|
---|
| 110 | problems = new BindingList<ProblemInstance>();
|
---|
| 111 | problemComboBox.DataSource = new BindingSource() { DataSource = problems };
|
---|
| 112 | problemComboBox.DataBindings.DefaultDataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;
|
---|
[8108] | 113 | suppressUpdates = false;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
[7980] | 116 | #region Content events
|
---|
| 117 | protected override void RegisterContentEvents() {
|
---|
| 118 | base.RegisterContentEvents();
|
---|
[12631] | 119 | Content.ItemsAdded += Content_ItemsAdded;
|
---|
| 120 | Content.ItemsRemoved += Content_ItemsRemoved;
|
---|
| 121 | Content.CollectionReset += Content_CollectionReset;
|
---|
| 122 | Content.UpdateOfRunsInProgressChanged += Content_UpdateOfRunsInProgressChanged;
|
---|
| 123 | Content.OptimizerNameChanged += Content_AlgorithmNameChanged;
|
---|
[7980] | 124 | }
|
---|
| 125 | protected override void DeregisterContentEvents() {
|
---|
[12631] | 126 | Content.ItemsAdded -= Content_ItemsAdded;
|
---|
| 127 | Content.ItemsRemoved -= Content_ItemsRemoved;
|
---|
| 128 | Content.CollectionReset -= Content_CollectionReset;
|
---|
| 129 | Content.UpdateOfRunsInProgressChanged -= Content_UpdateOfRunsInProgressChanged;
|
---|
| 130 | Content.OptimizerNameChanged -= Content_AlgorithmNameChanged;
|
---|
[7980] | 131 | base.DeregisterContentEvents();
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | private void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {
|
---|
[12631] | 135 | if (suppressUpdates) return;
|
---|
[7980] | 136 | if (InvokeRequired) {
|
---|
| 137 | Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded), sender, e);
|
---|
| 138 | return;
|
---|
| 139 | }
|
---|
[12841] | 140 | UpdateGroupAndProblemComboBox();
|
---|
[12631] | 141 | UpdateDataTableComboBox();
|
---|
[12771] | 142 | foreach (var run in e.Items)
|
---|
| 143 | RegisterRunEvents(run);
|
---|
[7980] | 144 | }
|
---|
| 145 | private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
|
---|
[12631] | 146 | if (suppressUpdates) return;
|
---|
[7980] | 147 | if (InvokeRequired) {
|
---|
| 148 | Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved), sender, e);
|
---|
| 149 | return;
|
---|
| 150 | }
|
---|
[12841] | 151 | UpdateGroupAndProblemComboBox();
|
---|
[12631] | 152 | UpdateDataTableComboBox();
|
---|
[12771] | 153 | foreach (var run in e.Items)
|
---|
| 154 | DeregisterRunEvents(run);
|
---|
[7980] | 155 | }
|
---|
| 156 | private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
|
---|
[12631] | 157 | if (suppressUpdates) return;
|
---|
[7980] | 158 | if (InvokeRequired) {
|
---|
| 159 | Invoke(new CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset), sender, e);
|
---|
| 160 | return;
|
---|
| 161 | }
|
---|
[12841] | 162 | UpdateGroupAndProblemComboBox();
|
---|
[12631] | 163 | UpdateDataTableComboBox();
|
---|
[12771] | 164 | foreach (var run in e.OldItems)
|
---|
| 165 | DeregisterRunEvents(run);
|
---|
[7980] | 166 | }
|
---|
[8738] | 167 | private void Content_AlgorithmNameChanged(object sender, EventArgs e) {
|
---|
| 168 | if (InvokeRequired)
|
---|
| 169 | Invoke(new EventHandler(Content_AlgorithmNameChanged), sender, e);
|
---|
| 170 | else UpdateCaption();
|
---|
| 171 | }
|
---|
[7980] | 172 | private void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
|
---|
| 173 | if (InvokeRequired) {
|
---|
| 174 | Invoke(new EventHandler(Content_UpdateOfRunsInProgressChanged), sender, e);
|
---|
| 175 | return;
|
---|
| 176 | }
|
---|
| 177 | suppressUpdates = Content.UpdateOfRunsInProgress;
|
---|
[12631] | 178 | if (!suppressUpdates) {
|
---|
| 179 | UpdateDataTableComboBox();
|
---|
[12841] | 180 | UpdateGroupAndProblemComboBox();
|
---|
[12771] | 181 | UpdateRuns();
|
---|
[12631] | 182 | }
|
---|
[7980] | 183 | }
|
---|
| 184 |
|
---|
| 185 | private void RegisterRunEvents(IRun run) {
|
---|
[11344] | 186 | run.PropertyChanged += run_PropertyChanged;
|
---|
[7980] | 187 | }
|
---|
| 188 | private void DeregisterRunEvents(IRun run) {
|
---|
[11344] | 189 | run.PropertyChanged -= run_PropertyChanged;
|
---|
[7980] | 190 | }
|
---|
[11344] | 191 | private void run_PropertyChanged(object sender, PropertyChangedEventArgs e) {
|
---|
[7980] | 192 | if (suppressUpdates) return;
|
---|
[11344] | 193 | if (InvokeRequired) {
|
---|
| 194 | Invoke((Action<object, PropertyChangedEventArgs>)run_PropertyChanged, sender, e);
|
---|
| 195 | } else {
|
---|
[12771] | 196 | if (e.PropertyName == "Visible")
|
---|
| 197 | UpdateRuns();
|
---|
[11344] | 198 | }
|
---|
[7980] | 199 | }
|
---|
| 200 | #endregion
|
---|
| 201 |
|
---|
| 202 | protected override void OnContentChanged() {
|
---|
| 203 | base.OnContentChanged();
|
---|
| 204 | dataTableComboBox.Items.Clear();
|
---|
[12771] | 205 | groupComboBox.Items.Clear();
|
---|
[14101] | 206 | targetChart.ChartAreas[0].AxisX.IsLogarithmic = false;
|
---|
| 207 | targetChart.Series.Clear();
|
---|
| 208 | invisibleTargetSeries.Clear();
|
---|
| 209 | byCostDataTable.VisualProperties.XAxisLogScale = false;
|
---|
| 210 | byCostDataTable.Rows.Clear();
|
---|
[7980] | 211 |
|
---|
[8738] | 212 | UpdateCaption();
|
---|
[7980] | 213 | if (Content != null) {
|
---|
[12841] | 214 | UpdateGroupAndProblemComboBox();
|
---|
[7980] | 215 | UpdateDataTableComboBox();
|
---|
| 216 | }
|
---|
| 217 | }
|
---|
| 218 |
|
---|
[12806] | 219 |
|
---|
[12841] | 220 | private void UpdateGroupAndProblemComboBox() {
|
---|
| 221 | var selectedGroupItem = (string)groupComboBox.SelectedItem;
|
---|
[12599] | 222 |
|
---|
[12774] | 223 | var groupings = Content.ParameterNames.OrderBy(x => x).ToArray();
|
---|
[12771] | 224 | groupComboBox.Items.Clear();
|
---|
| 225 | groupComboBox.Items.Add(AllRuns);
|
---|
| 226 | groupComboBox.Items.AddRange(groupings);
|
---|
[12841] | 227 | if (selectedGroupItem != null && groupComboBox.Items.Contains(selectedGroupItem)) {
|
---|
| 228 | groupComboBox.SelectedItem = selectedGroupItem;
|
---|
[12771] | 229 | } else if (groupComboBox.Items.Count > 0) {
|
---|
| 230 | groupComboBox.SelectedItem = groupComboBox.Items[0];
|
---|
[7980] | 231 | }
|
---|
[12841] | 232 |
|
---|
[14751] | 233 | var table = (string)dataTableComboBox.SelectedItem;
|
---|
| 234 | var problemDict = CalculateBestTargetPerProblemInstance(table);
|
---|
[12841] | 235 |
|
---|
[14751] | 236 | var problemTypesDifferent = problemDict.Keys.Select(x => x.ProblemType).Where(x => !string.IsNullOrEmpty(x)).Distinct().Count() > 1;
|
---|
| 237 | var problemNamesDifferent = problemDict.Keys.Select(x => x.ProblemName).Where(x => !string.IsNullOrEmpty(x)).Distinct().Count() > 1;
|
---|
| 238 | var evaluatorDifferent = problemDict.Keys.Select(x => x.Evaluator).Where(x => !string.IsNullOrEmpty(x)).Distinct().Count() > 1;
|
---|
| 239 | var maximizationDifferent = problemDict.Keys.Select(x => x.Maximization).Distinct().Count() > 1;
|
---|
[13583] | 240 | var allEqual = !problemTypesDifferent && !problemNamesDifferent && !evaluatorDifferent && !maximizationDifferent;
|
---|
[12841] | 241 |
|
---|
[14751] | 242 | var selectedProblemItem = (ProblemInstance)problemComboBox.SelectedItem;
|
---|
| 243 | problems.Clear();
|
---|
| 244 | problems.Add(ProblemInstance.MatchAll);
|
---|
| 245 | if (problems[0].Equals(selectedProblemItem)) problemComboBox.SelectedItem = problems[0];
|
---|
| 246 | foreach (var p in problemDict.ToList()) {
|
---|
| 247 | p.Key.BestKnownQuality = p.Value;
|
---|
| 248 | p.Key.DisplayProblemType = problemTypesDifferent;
|
---|
| 249 | p.Key.DisplayProblemName = problemNamesDifferent || allEqual;
|
---|
| 250 | p.Key.DisplayEvaluator = evaluatorDifferent;
|
---|
| 251 | p.Key.DisplayMaximization = maximizationDifferent;
|
---|
| 252 | problems.Add(p.Key);
|
---|
| 253 | if (p.Key.Equals(selectedProblemItem)) problemComboBox.SelectedItem = p.Key;
|
---|
[12841] | 254 | }
|
---|
| 255 | SetEnabledStateOfControls();
|
---|
[7980] | 256 | }
|
---|
| 257 |
|
---|
| 258 | private void UpdateDataTableComboBox() {
|
---|
[12631] | 259 | string selectedItem = (string)dataTableComboBox.SelectedItem;
|
---|
| 260 |
|
---|
[7986] | 261 | dataTableComboBox.Items.Clear();
|
---|
[7980] | 262 | var dataTables = (from run in Content
|
---|
| 263 | from result in run.Results
|
---|
[12771] | 264 | where result.Value is IndexedDataTable<double>
|
---|
[7980] | 265 | select result.Key).Distinct().ToArray();
|
---|
| 266 |
|
---|
| 267 | dataTableComboBox.Items.AddRange(dataTables);
|
---|
[12631] | 268 | if (selectedItem != null && dataTableComboBox.Items.Contains(selectedItem)) {
|
---|
| 269 | dataTableComboBox.SelectedItem = selectedItem;
|
---|
| 270 | } else if (dataTableComboBox.Items.Count > 0) {
|
---|
| 271 | dataTableComboBox.SelectedItem = dataTableComboBox.Items[0];
|
---|
| 272 | }
|
---|
[7980] | 273 | }
|
---|
| 274 |
|
---|
[12838] | 275 | protected override void SetEnabledStateOfControls() {
|
---|
| 276 | base.SetEnabledStateOfControls();
|
---|
| 277 | groupComboBox.Enabled = Content != null;
|
---|
[12841] | 278 | problemComboBox.Enabled = Content != null && problemComboBox.Items.Count > 1;
|
---|
| 279 | dataTableComboBox.Enabled = Content != null && dataTableComboBox.Items.Count > 1;
|
---|
[12838] | 280 | addTargetsAsResultButton.Enabled = Content != null && targets != null && dataTableComboBox.SelectedIndex >= 0;
|
---|
| 281 | addBudgetsAsResultButton.Enabled = Content != null && budgets != null && dataTableComboBox.SelectedIndex >= 0;
|
---|
| 282 | }
|
---|
| 283 |
|
---|
[14751] | 284 | private Dictionary<string, Dictionary<ProblemInstance, List<IRun>>> GroupRuns() {
|
---|
| 285 | var groupedRuns = new Dictionary<string, Dictionary<ProblemInstance, List<IRun>>>();
|
---|
[12841] | 286 |
|
---|
| 287 | var table = (string)dataTableComboBox.SelectedItem;
|
---|
| 288 | if (string.IsNullOrEmpty(table)) return groupedRuns;
|
---|
| 289 |
|
---|
| 290 | var selectedGroup = (string)groupComboBox.SelectedItem;
|
---|
| 291 | if (string.IsNullOrEmpty(selectedGroup)) return groupedRuns;
|
---|
| 292 |
|
---|
[14751] | 293 | var selectedProblem = (ProblemInstance)problemComboBox.SelectedItem;
|
---|
[12864] | 294 | if (selectedProblem == null) return groupedRuns;
|
---|
[14751] | 295 |
|
---|
[12864] | 296 | foreach (var x in (from r in Content
|
---|
[12888] | 297 | where (selectedGroup == AllRuns || r.Parameters.ContainsKey(selectedGroup))
|
---|
[12864] | 298 | && selectedProblem.Match(r)
|
---|
| 299 | && r.Results.ContainsKey(table)
|
---|
| 300 | && r.Visible
|
---|
[14751] | 301 | let key = selectedGroup == AllRuns ? AllRuns : r.Parameters[selectedGroup].ToString()
|
---|
| 302 | group r by key into g
|
---|
[12864] | 303 | select Tuple.Create(g.Key, g.ToList()))) {
|
---|
[14751] | 304 | var pDict = problems.ToDictionary(r => r, _ => new List<IRun>());
|
---|
| 305 | foreach (var y in x.Item2) {
|
---|
| 306 | var pd = new ProblemInstance(y);
|
---|
| 307 | List<IRun> l;
|
---|
| 308 | if (pDict.TryGetValue(pd, out l)) l.Add(y);
|
---|
[12864] | 309 | }
|
---|
[14751] | 310 | groupedRuns[x.Item1] = pDict.Where(a => a.Value.Count > 0).ToDictionary(a => a.Key, a => a.Value);
|
---|
[12864] | 311 | }
|
---|
| 312 |
|
---|
[12841] | 313 | return groupedRuns;
|
---|
| 314 | }
|
---|
| 315 |
|
---|
[12838] | 316 | #region Performance analysis by (multiple) target(s)
|
---|
| 317 | private void UpdateResultsByTarget() {
|
---|
| 318 | // necessary to reset log scale -> empty chart cannot use log scaling
|
---|
[14101] | 319 | targetChart.ChartAreas[0].AxisX.IsLogarithmic = false;
|
---|
| 320 | targetChart.Series.Clear();
|
---|
| 321 | invisibleTargetSeries.Clear();
|
---|
[12838] | 322 |
|
---|
| 323 | var table = (string)dataTableComboBox.SelectedItem;
|
---|
| 324 | if (string.IsNullOrEmpty(table)) return;
|
---|
| 325 |
|
---|
[12864] | 326 | if (targets == null) GenerateDefaultTargets();
|
---|
[12838] | 327 |
|
---|
[12841] | 328 | var groupedRuns = GroupRuns();
|
---|
| 329 | if (groupedRuns.Count == 0) return;
|
---|
[12838] | 330 |
|
---|
| 331 | var xAxisTitles = new HashSet<string>();
|
---|
| 332 |
|
---|
[14751] | 333 | // hits describes the number of target hits at a certain time for a certain group
|
---|
| 334 | var hits = new Dictionary<string, SortedList<double, int>>();
|
---|
| 335 | // misses describes the number of target misses after a certain time for a certain group
|
---|
| 336 | // for instance when a run ends, but has not achieved all targets, misses describes
|
---|
| 337 | // how many targets have been left open at the point when the run ended
|
---|
| 338 | var misses = new Dictionary<string, SortedList<double, int>>();
|
---|
| 339 |
|
---|
| 340 | var aggregate = aggregateTargetsCheckBox.Checked;
|
---|
[14101] | 341 | double minEff = double.MaxValue, maxEff = double.MinValue;
|
---|
[14751] | 342 | var noRuns = 0;
|
---|
[12838] | 343 | foreach (var group in groupedRuns) {
|
---|
[14751] | 344 | SortedList<double, int> epdfHits = null, epdfMisses = null;
|
---|
| 345 | if (aggregate) {
|
---|
| 346 | hits[group.Key] = epdfHits = new SortedList<double, int>();
|
---|
| 347 | misses[group.Key] = epdfMisses = new SortedList<double, int>();
|
---|
| 348 | }
|
---|
[14035] | 349 | foreach (var problem in group.Value) {
|
---|
[14101] | 350 | var max = problem.Key.IsMaximization();
|
---|
[14751] | 351 | var absTargets = GetAbsoluteTargets(problem.Key).ToArray();
|
---|
| 352 | foreach (var run in problem.Value) {
|
---|
| 353 | noRuns++;
|
---|
| 354 | var resultsTable = (IndexedDataTable<double>)run.Results[table];
|
---|
| 355 | xAxisTitles.Add(resultsTable.VisualProperties.XAxisTitle);
|
---|
| 356 |
|
---|
| 357 | var efforts = absTargets.Select(t => GetEffortToHitTarget(resultsTable.Rows.First().Values, t, max)).ToArray();
|
---|
| 358 | minEff = Math.Min(minEff, efforts.Min(x => x.Item2));
|
---|
| 359 | maxEff = Math.Max(maxEff, efforts.Max(x => x.Item2));
|
---|
| 360 | for (var idx = 0; idx < efforts.Length; idx++) {
|
---|
| 361 | var e = efforts[idx];
|
---|
| 362 | if (!aggregate) {
|
---|
| 363 | var key = group.Key + "@" + (targetsAreRelative
|
---|
| 364 | ? (targets[idx] * 100).ToString(CultureInfo.CurrentCulture.NumberFormat) + "%"
|
---|
| 365 | : targets[idx].ToString(CultureInfo.CurrentCulture.NumberFormat));
|
---|
| 366 | if (!hits.TryGetValue(key, out epdfHits))
|
---|
| 367 | hits[key] = epdfHits = new SortedList<double, int>();
|
---|
| 368 | if (!misses.TryGetValue(key, out epdfMisses))
|
---|
| 369 | misses[key] = epdfMisses = new SortedList<double, int>();
|
---|
| 370 | }
|
---|
| 371 | var list = e.Item1 ? epdfHits : epdfMisses;
|
---|
| 372 | int v;
|
---|
| 373 | if (list.TryGetValue(e.Item2, out v))
|
---|
| 374 | list[e.Item2] = v + 1;
|
---|
| 375 | else list[e.Item2] = 1;
|
---|
| 376 | }
|
---|
[14035] | 377 | }
|
---|
| 378 | }
|
---|
| 379 | }
|
---|
| 380 |
|
---|
[14751] | 381 | UpdateTargetChartAxisXBounds(minEff, maxEff);
|
---|
[14101] | 382 |
|
---|
[14751] | 383 | DrawTargetsEcdf(hits, misses, noRuns);
|
---|
[12838] | 384 |
|
---|
[14751] | 385 | if (targets.Length == 1) {
|
---|
| 386 | if (targetsAreRelative)
|
---|
| 387 | targetChart.ChartAreas[0].AxisY.Title = "Probability to be " + (targets[0] * 100) + "% worse than best";
|
---|
| 388 | else targetChart.ChartAreas[0].AxisY.Title = "Probability to reach at least a fitness of " + targets[0];
|
---|
| 389 | } else targetChart.ChartAreas[0].AxisY.Title = "Proportion of reached targets";
|
---|
| 390 | targetChart.ChartAreas[0].AxisX.Title = string.Join(" / ", xAxisTitles);
|
---|
| 391 | targetChart.ChartAreas[0].AxisX.IsLogarithmic = CanDisplayLogarithmic();
|
---|
| 392 | targetChart.ChartAreas[0].CursorY.Interval = 0.05;
|
---|
[12838] | 393 |
|
---|
[14751] | 394 | UpdateErtTables(groupedRuns);
|
---|
| 395 | }
|
---|
[12838] | 396 |
|
---|
[14751] | 397 | private void DrawTargetsEcdf(Dictionary<string, SortedList<double, int>> hits, Dictionary<string, SortedList<double, int>> misses, int noRuns) {
|
---|
| 398 | var colorCount = 0;
|
---|
| 399 | var lineStyleCount = 0;
|
---|
| 400 |
|
---|
| 401 | var showMarkers = markerCheckBox.Checked;
|
---|
| 402 | foreach (var list in hits) {
|
---|
| 403 | var row = new Series(list.Key) {
|
---|
| 404 | ChartType = SeriesChartType.StepLine,
|
---|
| 405 | BorderWidth = 3,
|
---|
| 406 | Color = colors[colorCount],
|
---|
| 407 | BorderDashStyle = lineStyles[lineStyleCount],
|
---|
| 408 | };
|
---|
| 409 | var rowShade = new Series(list.Key + "-range") {
|
---|
| 410 | IsVisibleInLegend = false,
|
---|
| 411 | ChartType = SeriesChartType.Range,
|
---|
| 412 | Color = Color.FromArgb(32, colors[colorCount]),
|
---|
| 413 | YValuesPerPoint = 2
|
---|
| 414 | };
|
---|
| 415 |
|
---|
| 416 | var ecdf = 0.0;
|
---|
| 417 | var missedecdf = 0.0;
|
---|
| 418 | var iter = misses[list.Key].GetEnumerator();
|
---|
| 419 | var moreMisses = iter.MoveNext();
|
---|
| 420 | var totalTargets = noRuns;
|
---|
| 421 | if (aggregateTargetsCheckBox.Checked) totalTargets *= targets.Length;
|
---|
| 422 | var movingTargets = totalTargets;
|
---|
| 423 | var labelPrinted = false;
|
---|
| 424 | foreach (var h in list.Value) {
|
---|
| 425 | var prevmissedecdf = missedecdf;
|
---|
| 426 | while (moreMisses && iter.Current.Key <= h.Key) {
|
---|
| 427 | if (!labelPrinted && row.Points.Count > 0) {
|
---|
| 428 | var point = row.Points.Last();
|
---|
| 429 | point.Label = row.Name;
|
---|
| 430 | point.MarkerStyle = MarkerStyle.Cross;
|
---|
| 431 | point.MarkerBorderWidth = 1;
|
---|
| 432 | point.MarkerSize = 10;
|
---|
| 433 | labelPrinted = true;
|
---|
| 434 | rowShade.Points.Add(new DataPoint(point.XValue, new[] {ecdf / totalTargets, (ecdf + missedecdf) / totalTargets}));
|
---|
[14101] | 435 | }
|
---|
[14751] | 436 | missedecdf += iter.Current.Value;
|
---|
| 437 | movingTargets -= iter.Current.Value;
|
---|
| 438 | if (row.Points.Count > 0 && row.Points.Last().XValue == iter.Current.Key) {
|
---|
[14101] | 439 | row.Points.Last().SetValueY(ecdf / movingTargets);
|
---|
[14751] | 440 | row.Points.Last().Color = Color.FromArgb(255 - (int)Math.Floor(255 * (prevmissedecdf / totalTargets)), colors[colorCount]);
|
---|
| 441 | } else {
|
---|
| 442 | var dp = new DataPoint(iter.Current.Key, ecdf / movingTargets) {
|
---|
| 443 | Color = Color.FromArgb(255 - (int)Math.Floor(255 * (prevmissedecdf / totalTargets)), colors[colorCount])
|
---|
| 444 | };
|
---|
| 445 | if (showMarkers) {
|
---|
| 446 | dp.MarkerStyle = MarkerStyle.Circle;
|
---|
| 447 | dp.MarkerBorderWidth = 1;
|
---|
| 448 | dp.MarkerSize = 5;
|
---|
| 449 | }
|
---|
| 450 | row.Points.Add(dp);
|
---|
| 451 | prevmissedecdf = missedecdf;
|
---|
[13736] | 452 | }
|
---|
[14101] | 453 | if (boundShadingCheckBox.Checked) {
|
---|
| 454 | if (rowShade.Points.Count > 0 && rowShade.Points.Last().XValue == iter.Current.Key)
|
---|
| 455 | rowShade.Points.Last().SetValueY(ecdf / totalTargets, (ecdf + missedecdf) / totalTargets);
|
---|
[14751] | 456 | else rowShade.Points.Add(new DataPoint(iter.Current.Key, new[] {ecdf / totalTargets, (ecdf + missedecdf) / totalTargets}));
|
---|
[14101] | 457 | }
|
---|
| 458 | moreMisses = iter.MoveNext();
|
---|
[14751] | 459 | if (!labelPrinted) {
|
---|
| 460 | var point = row.Points.Last();
|
---|
| 461 | point.Label = row.Name;
|
---|
| 462 | point.MarkerStyle = MarkerStyle.Cross;
|
---|
| 463 | point.MarkerBorderWidth = 1;
|
---|
| 464 | point.MarkerSize = 10;
|
---|
| 465 | labelPrinted = true;
|
---|
| 466 | }
|
---|
[14101] | 467 | }
|
---|
[14751] | 468 | ecdf += h.Value;
|
---|
| 469 | if (row.Points.Count > 0 && row.Points.Last().XValue == h.Key) {
|
---|
| 470 | row.Points.Last().SetValueY(ecdf / movingTargets);
|
---|
| 471 | row.Points.Last().Color = Color.FromArgb(255 - (int)Math.Floor(255 * (missedecdf / totalTargets)), colors[colorCount]);
|
---|
| 472 | } else {
|
---|
| 473 | var dp = new DataPoint(h.Key, ecdf / movingTargets) {
|
---|
| 474 | Color = Color.FromArgb(255 - (int)Math.Floor(255 * (missedecdf / totalTargets)), colors[colorCount])
|
---|
| 475 | };
|
---|
| 476 | if (showMarkers) {
|
---|
| 477 | dp.MarkerStyle = MarkerStyle.Circle;
|
---|
| 478 | dp.MarkerBorderWidth = 1;
|
---|
| 479 | dp.MarkerSize = 5;
|
---|
| 480 | }
|
---|
| 481 | row.Points.Add(dp);
|
---|
| 482 | }
|
---|
| 483 | if (missedecdf > 0 && boundShadingCheckBox.Checked) {
|
---|
| 484 | if (rowShade.Points.Count > 0 && rowShade.Points.Last().XValue == h.Key)
|
---|
| 485 | rowShade.Points.Last().SetValueY(ecdf / totalTargets, (ecdf + missedecdf) / totalTargets);
|
---|
| 486 | else rowShade.Points.Add(new DataPoint(h.Key, new[] {ecdf / totalTargets, (ecdf + missedecdf) / totalTargets}));
|
---|
| 487 | }
|
---|
| 488 | }
|
---|
[12838] | 489 |
|
---|
[14751] | 490 | while (moreMisses) {
|
---|
| 491 | // if there are misses beyond the last hit we extend the shaded area
|
---|
| 492 | missedecdf += iter.Current.Value;
|
---|
| 493 | var dp = new DataPoint(iter.Current.Key, ecdf / movingTargets) {
|
---|
| 494 | Color = Color.FromArgb(255 - (int)Math.Floor(255 * (missedecdf / totalTargets)), colors[colorCount])
|
---|
| 495 | };
|
---|
| 496 | if (showMarkers) {
|
---|
| 497 | dp.MarkerStyle = MarkerStyle.Circle;
|
---|
| 498 | dp.MarkerBorderWidth = 1;
|
---|
| 499 | dp.MarkerSize = 5;
|
---|
| 500 | }
|
---|
| 501 | row.Points.Add(dp);
|
---|
| 502 | if (boundShadingCheckBox.Checked) {
|
---|
| 503 | rowShade.Points.Add(new DataPoint(iter.Current.Key, new[] {ecdf / totalTargets, (ecdf + missedecdf) / totalTargets}));
|
---|
| 504 | }
|
---|
| 505 | moreMisses = iter.MoveNext();
|
---|
[14101] | 506 |
|
---|
[14751] | 507 | if (!labelPrinted && row.Points.Count > 0) {
|
---|
[14101] | 508 | var point = row.Points.Last();
|
---|
| 509 | point.Label = row.Name;
|
---|
| 510 | point.MarkerStyle = MarkerStyle.Cross;
|
---|
| 511 | point.MarkerBorderWidth = 1;
|
---|
[14751] | 512 | point.MarkerSize = 10;
|
---|
| 513 | labelPrinted = true;
|
---|
[14101] | 514 | }
|
---|
[14751] | 515 | }
|
---|
[14101] | 516 |
|
---|
[14751] | 517 | if (!labelPrinted) {
|
---|
| 518 | var point = row.Points.Last();
|
---|
| 519 | point.Label = row.Name;
|
---|
| 520 | point.MarkerStyle = MarkerStyle.Cross;
|
---|
| 521 | point.MarkerBorderWidth = 1;
|
---|
| 522 | point.MarkerSize = 10;
|
---|
| 523 | rowShade.Points.Add(new DataPoint(point.XValue, new[] {ecdf / totalTargets, (ecdf + missedecdf) / totalTargets}));
|
---|
| 524 | labelPrinted = true;
|
---|
[12838] | 525 | }
|
---|
[14751] | 526 |
|
---|
| 527 | ConfigureSeries(row);
|
---|
| 528 | targetChart.Series.Add(rowShade);
|
---|
| 529 | targetChart.Series.Add(row);
|
---|
| 530 |
|
---|
[12838] | 531 | colorCount = (colorCount + 1) % colors.Length;
|
---|
| 532 | if (colorCount == 0) lineStyleCount = (lineStyleCount + 1) % lineStyles.Length;
|
---|
| 533 | }
|
---|
[14751] | 534 | }
|
---|
[12838] | 535 |
|
---|
[14751] | 536 | private void UpdateTargetChartAxisXBounds(double minEff, double maxEff) {
|
---|
| 537 | var minZeros = (int)Math.Floor(Math.Log10(minEff));
|
---|
| 538 | var maxZeros = (int)Math.Floor(Math.Log10(maxEff));
|
---|
| 539 | var axisMin = (decimal)Math.Pow(10, minZeros);
|
---|
| 540 | var axisMax = (decimal)Math.Pow(10, maxZeros);
|
---|
| 541 | if (!targetLogScalingCheckBox.Checked) {
|
---|
| 542 | var minAdd = (decimal)Math.Pow(10, minZeros - 1) * 2;
|
---|
| 543 | var maxAdd = (decimal)Math.Pow(10, maxZeros - 1) * 2;
|
---|
| 544 | while (axisMin + minAdd < (decimal)minEff) axisMin += minAdd;
|
---|
| 545 | while (axisMax <= (decimal)maxEff) axisMax += maxAdd;
|
---|
| 546 | } else axisMax = (decimal)Math.Pow(10, (int)Math.Ceiling(Math.Log10(maxEff)));
|
---|
| 547 | targetChart.ChartAreas[0].AxisX.Minimum = (double)axisMin;
|
---|
| 548 | targetChart.ChartAreas[0].AxisX.Maximum = (double)axisMax;
|
---|
[12838] | 549 | }
|
---|
| 550 |
|
---|
[14751] | 551 | private IEnumerable<double> GetAbsoluteTargets(ProblemInstance pInstance) {
|
---|
| 552 | if (!targetsAreRelative) return targets;
|
---|
| 553 | var maximization = pInstance.IsMaximization();
|
---|
| 554 | var bestKnown = pInstance.BestKnownQuality;
|
---|
| 555 | if (double.IsNaN(bestKnown)) throw new ArgumentException("Problem instance does not have a defined best - known quality.");
|
---|
| 556 | IEnumerable<double> tmp = null;
|
---|
| 557 | if (bestKnown > 0) {
|
---|
| 558 | tmp = targets.Select(x => (maximization ? (1 - x) : (1 + x)) * bestKnown);
|
---|
| 559 | } else if (bestKnown < 0) {
|
---|
| 560 | tmp = targets.Select(x => (!maximization ? (1 - x) : (1 + x)) * bestKnown);
|
---|
| 561 | } else {
|
---|
| 562 | // relative to 0 is impossible
|
---|
| 563 | tmp = targets;
|
---|
| 564 | }
|
---|
| 565 | return tmp;
|
---|
| 566 | }
|
---|
| 567 |
|
---|
| 568 | private double[] GetAbsoluteTargetsWorstToBest(ProblemInstance pInstance) {
|
---|
| 569 | if (double.IsNaN(pInstance.BestKnownQuality)) throw new ArgumentException("Problem instance does not have a defined best-known quality.");
|
---|
| 570 | var absTargets = GetAbsoluteTargets(pInstance);
|
---|
| 571 | return (pInstance.IsMaximization()
|
---|
| 572 | ? absTargets.OrderBy(x => x) : absTargets.OrderByDescending(x => x)).ToArray();
|
---|
| 573 | }
|
---|
| 574 |
|
---|
[12864] | 575 | private void GenerateDefaultTargets() {
|
---|
[14751] | 576 | targets = new[] { 0.1, 0.095, 0.09, 0.085, 0.08, 0.075, 0.07, 0.065, 0.06, 0.055, 0.05, 0.045, 0.04, 0.035, 0.03, 0.025, 0.02, 0.015, 0.01, 0.005, 0 };
|
---|
[12838] | 577 | suppressTargetsEvents = true;
|
---|
[12888] | 578 | targetsTextBox.Text = string.Join("% ; ", targets.Select(x => x * 100)) + "%";
|
---|
[12838] | 579 | suppressTargetsEvents = false;
|
---|
| 580 | }
|
---|
| 581 |
|
---|
[14751] | 582 | private Tuple<bool, double> GetEffortToHitTarget(
|
---|
| 583 | IEnumerable<Tuple<double, double>> convergenceGraph,
|
---|
| 584 | double absTarget, bool maximization) {
|
---|
| 585 | var hit = false;
|
---|
| 586 | var effort = double.NaN;
|
---|
| 587 | foreach (var dent in convergenceGraph) {
|
---|
| 588 | effort = dent.Item1;
|
---|
| 589 | hit = maximization && dent.Item2 >= absTarget || !maximization && dent.Item2 <= absTarget;
|
---|
| 590 | if (hit) break;
|
---|
[12838] | 591 | }
|
---|
[14751] | 592 | if (double.IsNaN(effort)) throw new ArgumentException("Convergence graph is empty.", "convergenceGraph");
|
---|
| 593 | return Tuple.Create(hit, effort);
|
---|
[12838] | 594 | }
|
---|
| 595 |
|
---|
[14751] | 596 | private void UpdateErtTables(Dictionary<string, Dictionary<ProblemInstance, List<IRun>>> groupedRuns) {
|
---|
[12888] | 597 | ertTableView.Content = null;
|
---|
[12841] | 598 | var columns = 1 + targets.Length + 1;
|
---|
[12864] | 599 | var matrix = new string[groupedRuns.Count * groupedRuns.Max(x => x.Value.Count) + groupedRuns.Max(x => x.Value.Count), columns];
|
---|
[12841] | 600 | var rowCount = 0;
|
---|
| 601 |
|
---|
[12956] | 602 | var tableName = (string)dataTableComboBox.SelectedItem;
|
---|
| 603 | if (string.IsNullOrEmpty(tableName)) return;
|
---|
[14751] | 604 |
|
---|
[12864] | 605 | var problems = groupedRuns.SelectMany(x => x.Value.Keys).Distinct().ToList();
|
---|
[12841] | 606 |
|
---|
[12864] | 607 | foreach (var problem in problems) {
|
---|
[14751] | 608 | var max = problem.IsMaximization();
|
---|
[13583] | 609 | matrix[rowCount, 0] = problem.ToString();
|
---|
[14751] | 610 | var absTargets = GetAbsoluteTargetsWorstToBest(problem);
|
---|
| 611 | for (var i = 0; i < absTargets.Length; i++) {
|
---|
| 612 | matrix[rowCount, i + 1] = absTargets[i].ToString(CultureInfo.CurrentCulture.NumberFormat);
|
---|
[12841] | 613 | }
|
---|
[12864] | 614 | matrix[rowCount, columns - 1] = "#succ";
|
---|
[12841] | 615 | rowCount++;
|
---|
[12864] | 616 |
|
---|
| 617 | foreach (var group in groupedRuns) {
|
---|
| 618 | matrix[rowCount, 0] = group.Key;
|
---|
[12939] | 619 | if (!group.Value.ContainsKey(problem)) {
|
---|
| 620 | matrix[rowCount, columns - 1] = "N/A";
|
---|
| 621 | rowCount++;
|
---|
| 622 | continue;
|
---|
| 623 | }
|
---|
[14751] | 624 | var runs = group.Value[problem];
|
---|
| 625 | var result = default(ErtCalculationResult);
|
---|
| 626 | for (var i = 0; i < absTargets.Length; i++) {
|
---|
| 627 | result = ExpectedRuntimeHelper.CalculateErt(runs, tableName, absTargets[i], max);
|
---|
[12956] | 628 | matrix[rowCount, i + 1] = result.ToString();
|
---|
[12864] | 629 | }
|
---|
[12956] | 630 | matrix[rowCount, columns - 1] = targets.Length > 0 ? result.SuccessfulRuns + "/" + result.TotalRuns : "-";
|
---|
[12864] | 631 | rowCount++;
|
---|
| 632 | }
|
---|
[12841] | 633 | }
|
---|
[14751] | 634 | ertTableView.Content = new StringMatrix(matrix);
|
---|
[12888] | 635 | ertTableView.DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
|
---|
[12841] | 636 | }
|
---|
[12838] | 637 | #endregion
|
---|
| 638 |
|
---|
| 639 | #region Performance analysis by (multiple) budget(s)
|
---|
| 640 | private void UpdateResultsByCost() {
|
---|
| 641 | // necessary to reset log scale -> empty chart cannot use log scaling
|
---|
| 642 | byCostDataTable.VisualProperties.XAxisLogScale = false;
|
---|
| 643 | byCostDataTable.Rows.Clear();
|
---|
| 644 |
|
---|
| 645 | var table = (string)dataTableComboBox.SelectedItem;
|
---|
| 646 | if (string.IsNullOrEmpty(table)) return;
|
---|
| 647 |
|
---|
| 648 | if (budgets == null) GenerateDefaultBudgets(table);
|
---|
| 649 |
|
---|
[12841] | 650 | var groupedRuns = GroupRuns();
|
---|
| 651 | if (groupedRuns.Count == 0) return;
|
---|
[12838] | 652 |
|
---|
| 653 | var colorCount = 0;
|
---|
| 654 | var lineStyleCount = 0;
|
---|
[14751] | 655 |
|
---|
[12838] | 656 | foreach (var group in groupedRuns) {
|
---|
| 657 | var hits = new Dictionary<string, SortedList<double, double>>();
|
---|
| 658 |
|
---|
[12864] | 659 | foreach (var problem in group.Value) {
|
---|
[14751] | 660 | foreach (var run in problem.Value) {
|
---|
[12864] | 661 | var resultsTable = (IndexedDataTable<double>)run.Results[table];
|
---|
[12838] | 662 |
|
---|
[14751] | 663 | if (aggregateBudgetsCheckBox.Checked) {
|
---|
| 664 | CalculateHitsForAllBudgets(hits, resultsTable.Rows.First(), group.Value.Count, problem.Key, group.Key, problem.Value.Count);
|
---|
[12864] | 665 | } else {
|
---|
[14751] | 666 | CalculateHitsForEachBudget(hits, resultsTable.Rows.First(), group.Value.Count, problem.Key, group.Key, problem.Value.Count);
|
---|
[12864] | 667 | }
|
---|
[12838] | 668 | }
|
---|
| 669 | }
|
---|
| 670 |
|
---|
| 671 | foreach (var list in hits) {
|
---|
| 672 | var row = new IndexedDataRow<double>(list.Key) {
|
---|
| 673 | VisualProperties = {
|
---|
| 674 | ChartType = DataRowVisualProperties.DataRowChartType.StepLine,
|
---|
| 675 | LineWidth = 2,
|
---|
| 676 | Color = colors[colorCount],
|
---|
[14101] | 677 | LineStyle = hlLineStyles[lineStyleCount],
|
---|
[13745] | 678 | StartIndexZero = false
|
---|
[12838] | 679 | }
|
---|
| 680 | };
|
---|
| 681 |
|
---|
| 682 | var total = 0.0;
|
---|
| 683 | foreach (var h in list.Value) {
|
---|
| 684 | total += h.Value;
|
---|
| 685 | row.Values.Add(Tuple.Create(h.Key, total));
|
---|
| 686 | }
|
---|
| 687 |
|
---|
| 688 | byCostDataTable.Rows.Add(row);
|
---|
| 689 | }
|
---|
| 690 | colorCount = (colorCount + 1) % colors.Length;
|
---|
| 691 | if (colorCount == 0) lineStyleCount = (lineStyleCount + 1) % lineStyles.Length;
|
---|
| 692 | }
|
---|
| 693 |
|
---|
[12865] | 694 | byCostDataTable.VisualProperties.XAxisTitle = "Targets to Best-Known Ratio";
|
---|
[12838] | 695 | byCostDataTable.VisualProperties.XAxisLogScale = byCostDataTable.Rows.Count > 0 && budgetLogScalingCheckBox.Checked;
|
---|
| 696 | }
|
---|
| 697 |
|
---|
| 698 | private void GenerateDefaultBudgets(string table) {
|
---|
[14751] | 699 | var runs = GroupRuns().SelectMany(x => x.Value.Values).SelectMany(x => x).ToList();
|
---|
[12841] | 700 | var min = runs.Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Select(y => y.Item1).Min()).Min();
|
---|
| 701 | var max = runs.Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Select(y => y.Item1).Max()).Max();
|
---|
[14751] | 702 | var points = 20;
|
---|
| 703 | budgets = Enumerable.Range(1, points).Select(x => min + (x / (double)points) * (max - min)).ToArray();
|
---|
[12838] | 704 | suppressBudgetsEvents = true;
|
---|
| 705 | budgetsTextBox.Text = string.Join(" ; ", budgets);
|
---|
| 706 | suppressBudgetsEvents = false;
|
---|
| 707 | }
|
---|
| 708 |
|
---|
[14751] | 709 | private void CalculateHitsForEachBudget(Dictionary<string, SortedList<double, double>> hits, IndexedDataRow<double> row, int groupCount, ProblemInstance problem, string groupName, int problemCount) {
|
---|
| 710 | var max = problem.IsMaximization();
|
---|
[12838] | 711 | foreach (var b in budgets) {
|
---|
| 712 | var key = groupName + "-" + b;
|
---|
| 713 | if (!hits.ContainsKey(key)) hits.Add(key, new SortedList<double, double>());
|
---|
| 714 | Tuple<double, double> prev = null;
|
---|
| 715 | foreach (var v in row.Values) {
|
---|
| 716 | if (v.Item1 >= b) {
|
---|
| 717 | // the budget may be too low to achieve any target
|
---|
| 718 | if (prev == null && v.Item1 != b) break;
|
---|
[12865] | 719 | var tgt = ((prev == null || v.Item1 == b) ? v.Item2 : prev.Item2);
|
---|
[14751] | 720 | var relTgt = CalculateRelativeDifference(max, problem.BestKnownQuality, tgt) + 1;
|
---|
| 721 | if (hits[key].ContainsKey(relTgt))
|
---|
| 722 | hits[key][relTgt] += 1.0 / (groupCount * problemCount);
|
---|
| 723 | else hits[key][relTgt] = 1.0 / (groupCount * problemCount);
|
---|
[12838] | 724 | break;
|
---|
| 725 | }
|
---|
| 726 | prev = v;
|
---|
| 727 | }
|
---|
| 728 | if (hits[key].Count == 0) hits.Remove(key);
|
---|
| 729 | }
|
---|
| 730 | }
|
---|
| 731 |
|
---|
[14751] | 732 | private void CalculateHitsForAllBudgets(Dictionary<string, SortedList<double, double>> hits, IndexedDataRow<double> row, int groupCount, ProblemInstance problem, string groupName, int problemCount) {
|
---|
[12838] | 733 | var values = row.Values;
|
---|
| 734 | if (!hits.ContainsKey(groupName)) hits.Add(groupName, new SortedList<double, double>());
|
---|
| 735 |
|
---|
| 736 | var i = 0;
|
---|
| 737 | var j = 0;
|
---|
| 738 | Tuple<double, double> prev = null;
|
---|
[14751] | 739 | var max = problem.IsMaximization();
|
---|
[12838] | 740 | while (i < budgets.Length && j < values.Count) {
|
---|
| 741 | var current = values[j];
|
---|
| 742 | if (current.Item1 >= budgets[i]) {
|
---|
| 743 | if (prev != null || current.Item1 == budgets[i]) {
|
---|
| 744 | var tgt = (prev == null || current.Item1 == budgets[i]) ? current.Item2 : prev.Item2;
|
---|
[14751] | 745 | var relTgt = CalculateRelativeDifference(max, problem.BestKnownQuality, tgt) + 1;
|
---|
| 746 | if (!hits[groupName].ContainsKey(relTgt)) hits[groupName][relTgt] = 0;
|
---|
| 747 | hits[groupName][relTgt] += 1.0 / (groupCount * problemCount * budgets.Length);
|
---|
[12838] | 748 | }
|
---|
| 749 | i++;
|
---|
| 750 | } else {
|
---|
| 751 | j++;
|
---|
| 752 | prev = current;
|
---|
| 753 | }
|
---|
| 754 | }
|
---|
| 755 | var lastTgt = values.Last().Item2;
|
---|
[14751] | 756 | var lastRelTgt = CalculateRelativeDifference(max, problem.BestKnownQuality, lastTgt) + 1;
|
---|
| 757 | if (i < budgets.Length && !hits[groupName].ContainsKey(lastRelTgt)) hits[groupName][lastRelTgt] = 0;
|
---|
[12838] | 758 | while (i < budgets.Length) {
|
---|
[14751] | 759 | hits[groupName][lastRelTgt] += 1.0 / (groupCount * problemCount * budgets.Length);
|
---|
[12838] | 760 | i++;
|
---|
| 761 | }
|
---|
| 762 | }
|
---|
| 763 | #endregion
|
---|
| 764 |
|
---|
[8738] | 765 | private void UpdateCaption() {
|
---|
[12803] | 766 | Caption = Content != null ? Content.OptimizerName + " RLD View" : ViewAttribute.GetViewName(GetType());
|
---|
[8738] | 767 | }
|
---|
| 768 |
|
---|
[12771] | 769 | private void groupComboBox_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 770 | UpdateRuns();
|
---|
[12806] | 771 | SetEnabledStateOfControls();
|
---|
[7980] | 772 | }
|
---|
[12841] | 773 | private void problemComboBox_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 774 | UpdateRuns();
|
---|
| 775 | SetEnabledStateOfControls();
|
---|
| 776 | }
|
---|
[12631] | 777 | private void dataTableComboBox_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
[12838] | 778 | if (dataTableComboBox.SelectedIndex >= 0)
|
---|
| 779 | GenerateDefaultBudgets((string)dataTableComboBox.SelectedItem);
|
---|
[14751] | 780 | UpdateBestKnownQualities();
|
---|
[12771] | 781 | UpdateRuns();
|
---|
[12806] | 782 | SetEnabledStateOfControls();
|
---|
[7980] | 783 | }
|
---|
[12771] | 784 |
|
---|
| 785 | private void logScalingCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
[14101] | 786 | UpdateResultsByTarget();
|
---|
[12838] | 787 | byCostDataTable.VisualProperties.XAxisLogScale = byCostDataTable.Rows.Count > 0 && budgetLogScalingCheckBox.Checked;
|
---|
[7980] | 788 | }
|
---|
[12804] | 789 |
|
---|
[14101] | 790 | private void boundShadingCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 791 | UpdateResultsByTarget();
|
---|
| 792 | }
|
---|
| 793 |
|
---|
[12838] | 794 | #region Event handlers for target analysis
|
---|
[12804] | 795 | private bool suppressTargetsEvents;
|
---|
| 796 | private void targetsTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
| 797 | if (suppressTargetsEvents) return;
|
---|
[12864] | 798 | var targetStrings = targetsTextBox.Text.Split(new[] { '%', ';', '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
---|
| 799 | var targetList = new List<decimal>();
|
---|
[12804] | 800 | foreach (var ts in targetStrings) {
|
---|
[12864] | 801 | decimal t;
|
---|
| 802 | if (!decimal.TryParse(ts, out t)) {
|
---|
[12804] | 803 | errorProvider.SetError(targetsTextBox, "Not all targets can be parsed: " + ts);
|
---|
| 804 | e.Cancel = true;
|
---|
| 805 | return;
|
---|
| 806 | }
|
---|
[14751] | 807 | if (targetsAreRelative)
|
---|
| 808 | targetList.Add(t / 100);
|
---|
| 809 | else targetList.Add(t);
|
---|
[12804] | 810 | }
|
---|
| 811 | if (targetList.Count == 0) {
|
---|
| 812 | errorProvider.SetError(targetsTextBox, "Give at least one target value!");
|
---|
| 813 | e.Cancel = true;
|
---|
| 814 | return;
|
---|
| 815 | }
|
---|
| 816 | e.Cancel = false;
|
---|
| 817 | errorProvider.SetError(targetsTextBox, null);
|
---|
[14751] | 818 | targets = targetsAreRelative ? targetList.Select(x => (double)x).OrderByDescending(x => x).ToArray() : targetList.Select(x => (double)x).ToArray();
|
---|
[12888] | 819 | suppressTargetsEvents = true;
|
---|
[14751] | 820 | try {
|
---|
| 821 | if (targetsAreRelative)
|
---|
| 822 | targetsTextBox.Text = string.Join("% ; ", targets.Select(x => x * 100)) + "%";
|
---|
| 823 | else targetsTextBox.Text = string.Join(" ; ", targets);
|
---|
| 824 | } finally { suppressTargetsEvents = false; }
|
---|
[12888] | 825 |
|
---|
[12838] | 826 | UpdateResultsByTarget();
|
---|
[12806] | 827 | SetEnabledStateOfControls();
|
---|
[12804] | 828 | }
|
---|
[12806] | 829 |
|
---|
[14101] | 830 | private void aggregateTargetsCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
[12838] | 831 | SuspendRepaint();
|
---|
| 832 | try {
|
---|
| 833 | UpdateResultsByTarget();
|
---|
| 834 | } finally { ResumeRepaint(true); }
|
---|
| 835 | }
|
---|
| 836 |
|
---|
[14751] | 837 | private void relativeOrAbsoluteComboBox_SelectedIndexChanged(object sender, EventArgs e) {
|
---|
| 838 | if (suppressUpdates) return;
|
---|
| 839 | var pd = (ProblemInstance)problemComboBox.SelectedItem;
|
---|
| 840 | if (!double.IsNaN(pd.BestKnownQuality)) {
|
---|
| 841 | var max = pd.IsMaximization();
|
---|
| 842 | if (targetsAreRelative) targets = GetAbsoluteTargets(pd).ToArray();
|
---|
| 843 | else {
|
---|
| 844 | // Rounding to 5 digits since it's certainly appropriate for this application
|
---|
| 845 | if (pd.BestKnownQuality > 0) {
|
---|
| 846 | targets = targets.Select(x => Math.Round(max ? 1.0 - (x / pd.BestKnownQuality) : (x / pd.BestKnownQuality) - 1.0, 5)).ToArray();
|
---|
| 847 | } else if (pd.BestKnownQuality < 0) {
|
---|
| 848 | targets = targets.Select(x => Math.Round(!max ? 1.0 - (x / pd.BestKnownQuality) : (x / pd.BestKnownQuality) - 1.0, 5)).ToArray();
|
---|
| 849 | }
|
---|
| 850 | }
|
---|
| 851 | }
|
---|
| 852 | targetsAreRelative = (string)relativeOrAbsoluteComboBox.SelectedItem == "relative";
|
---|
| 853 | SuspendRepaint();
|
---|
| 854 | suppressTargetsEvents = true;
|
---|
| 855 | try {
|
---|
| 856 | if (targetsAreRelative)
|
---|
| 857 | targetsTextBox.Text = string.Join("% ; ", targets.Select(x => x * 100)) + "%";
|
---|
| 858 | else targetsTextBox.Text = string.Join(" ; ", targets);
|
---|
| 859 |
|
---|
| 860 | UpdateResultsByTarget();
|
---|
| 861 | } finally { suppressTargetsEvents = false; ResumeRepaint(true); }
|
---|
| 862 | }
|
---|
| 863 |
|
---|
[12806] | 864 | private void generateTargetsButton_Click(object sender, EventArgs e) {
|
---|
| 865 | decimal max = 1, min = 0, count = 10;
|
---|
[12838] | 866 | if (targets != null) {
|
---|
| 867 | max = (decimal)targets.Max();
|
---|
| 868 | min = (decimal)targets.Min();
|
---|
| 869 | count = targets.Length;
|
---|
[12806] | 870 | } else if (Content.Count > 0 && dataTableComboBox.SelectedIndex >= 0) {
|
---|
| 871 | var table = (string)dataTableComboBox.SelectedItem;
|
---|
[12838] | 872 | max = (decimal)Content.Where(x => x.Results.ContainsKey(table)).Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Max(y => y.Item2)).Max();
|
---|
| 873 | min = (decimal)Content.Where(x => x.Results.ContainsKey(table)).Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Min(y => y.Item2)).Min();
|
---|
| 874 | count = 6;
|
---|
[12806] | 875 | }
|
---|
| 876 | using (var dialog = new DefineArithmeticProgressionDialog(false, min, max, (max - min) / count)) {
|
---|
| 877 | if (dialog.ShowDialog() == DialogResult.OK) {
|
---|
| 878 | if (dialog.Values.Any()) {
|
---|
[13583] | 879 | targets = dialog.Values.Select(x => (double)x).ToArray();
|
---|
[12808] | 880 | suppressTargetsEvents = true;
|
---|
[14751] | 881 | if (targetsAreRelative)
|
---|
| 882 | targetsTextBox.Text = string.Join("% ; ", targets);
|
---|
| 883 | else targetsTextBox.Text = string.Join(" ; ", targets);
|
---|
[12808] | 884 | suppressTargetsEvents = false;
|
---|
| 885 |
|
---|
[12838] | 886 | UpdateResultsByTarget();
|
---|
[12806] | 887 | SetEnabledStateOfControls();
|
---|
| 888 | }
|
---|
| 889 | }
|
---|
| 890 | }
|
---|
| 891 | }
|
---|
| 892 |
|
---|
[12838] | 893 | private void addTargetsAsResultButton_Click(object sender, EventArgs e) {
|
---|
[12806] | 894 | var table = (string)dataTableComboBox.SelectedItem;
|
---|
[14751] | 895 | if (string.IsNullOrEmpty(table)) return;
|
---|
| 896 |
|
---|
[12806] | 897 | foreach (var run in Content) {
|
---|
[12808] | 898 | if (!run.Results.ContainsKey(table)) continue;
|
---|
[12806] | 899 | var resultsTable = (IndexedDataTable<double>)run.Results[table];
|
---|
| 900 | var values = resultsTable.Rows.First().Values;
|
---|
| 901 | var i = 0;
|
---|
| 902 | var j = 0;
|
---|
[14751] | 903 | var pd = new ProblemInstance(run);
|
---|
| 904 | var max = pd.IsMaximization();
|
---|
| 905 | var absTargets = GetAbsoluteTargetsWorstToBest(problems.Single(x => x.Equals(pd)));
|
---|
| 906 | while (i < absTargets.Length && j < values.Count) {
|
---|
| 907 | var target = absTargets[i];
|
---|
[12838] | 908 | var current = values[j];
|
---|
[14751] | 909 | if (max && current.Item2 >= target || !max && current.Item2 <= target) {
|
---|
[12864] | 910 | run.Results[table + ".Target" + target] = new DoubleValue(current.Item1);
|
---|
[12806] | 911 | i++;
|
---|
| 912 | } else {
|
---|
| 913 | j++;
|
---|
| 914 | }
|
---|
| 915 | }
|
---|
| 916 | }
|
---|
| 917 | }
|
---|
[14751] | 918 |
|
---|
| 919 | private void markerCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 920 | SuspendRepaint();
|
---|
| 921 | try {
|
---|
| 922 | UpdateResultsByTarget();
|
---|
| 923 | } finally { ResumeRepaint(true); }
|
---|
| 924 | }
|
---|
[12838] | 925 | #endregion
|
---|
[12806] | 926 |
|
---|
[12838] | 927 | #region Event handlers for cost analysis
|
---|
| 928 | private bool suppressBudgetsEvents;
|
---|
| 929 | private void budgetsTextBox_Validating(object sender, CancelEventArgs e) {
|
---|
| 930 | if (suppressBudgetsEvents) return;
|
---|
| 931 | var budgetStrings = budgetsTextBox.Text.Split(new[] { ';', '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
---|
| 932 | var budgetList = new List<double>();
|
---|
| 933 | foreach (var ts in budgetStrings) {
|
---|
| 934 | double b;
|
---|
| 935 | if (!double.TryParse(ts, out b)) {
|
---|
| 936 | errorProvider.SetError(budgetsTextBox, "Not all targets can be parsed: " + ts);
|
---|
| 937 | e.Cancel = true;
|
---|
| 938 | return;
|
---|
| 939 | }
|
---|
| 940 | budgetList.Add(b);
|
---|
| 941 | }
|
---|
| 942 | if (budgetList.Count == 0) {
|
---|
| 943 | errorProvider.SetError(budgetsTextBox, "Give at least one target value!");
|
---|
| 944 | e.Cancel = true;
|
---|
| 945 | return;
|
---|
| 946 | }
|
---|
| 947 | e.Cancel = false;
|
---|
| 948 | errorProvider.SetError(budgetsTextBox, null);
|
---|
| 949 | budgets = budgetList.ToArray();
|
---|
| 950 | UpdateResultsByCost();
|
---|
| 951 | SetEnabledStateOfControls();
|
---|
| 952 | }
|
---|
| 953 |
|
---|
[14751] | 954 | private void aggregateBudgetsCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
[12838] | 955 | SuspendRepaint();
|
---|
| 956 | try {
|
---|
| 957 | UpdateResultsByCost();
|
---|
| 958 | } finally { ResumeRepaint(true); }
|
---|
| 959 | }
|
---|
| 960 |
|
---|
| 961 | private void generateBudgetsButton_Click(object sender, EventArgs e) {
|
---|
| 962 | decimal max = 1, min = 0, count = 10;
|
---|
| 963 | if (budgets != null) {
|
---|
| 964 | max = (decimal)budgets.Max();
|
---|
| 965 | min = (decimal)budgets.Min();
|
---|
| 966 | count = budgets.Length;
|
---|
| 967 | } else if (Content.Count > 0 && dataTableComboBox.SelectedIndex >= 0) {
|
---|
| 968 | var table = (string)dataTableComboBox.SelectedItem;
|
---|
| 969 | min = (decimal)Content.Where(x => x.Results.ContainsKey(table)).Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Min(y => y.Item1)).Min();
|
---|
| 970 | max = (decimal)Content.Where(x => x.Results.ContainsKey(table)).Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Max(y => y.Item1)).Max();
|
---|
| 971 | count = 6;
|
---|
| 972 | }
|
---|
| 973 | using (var dialog = new DefineArithmeticProgressionDialog(false, min, max, (max - min) / count)) {
|
---|
| 974 | if (dialog.ShowDialog() == DialogResult.OK) {
|
---|
| 975 | if (dialog.Values.Any()) {
|
---|
| 976 | budgets = dialog.Values.OrderBy(x => x).Select(x => (double)x).ToArray();
|
---|
| 977 |
|
---|
| 978 | suppressBudgetsEvents = true;
|
---|
| 979 | budgetsTextBox.Text = string.Join(" ; ", budgets);
|
---|
| 980 | suppressBudgetsEvents = false;
|
---|
| 981 |
|
---|
| 982 | UpdateResultsByCost();
|
---|
| 983 | SetEnabledStateOfControls();
|
---|
| 984 | }
|
---|
| 985 | }
|
---|
| 986 | }
|
---|
| 987 | }
|
---|
| 988 |
|
---|
| 989 | private void addBudgetsAsResultButton_Click(object sender, EventArgs e) {
|
---|
[12806] | 990 | var table = (string)dataTableComboBox.SelectedItem;
|
---|
| 991 | var budgetStrings = budgetsTextBox.Text.Split(new[] { ';', '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
---|
| 992 | if (budgetStrings.Length == 0) {
|
---|
| 993 | MessageBox.Show("Define a number of budgets.");
|
---|
| 994 | return;
|
---|
| 995 | }
|
---|
| 996 | var budgetList = new List<double>();
|
---|
| 997 | foreach (var bs in budgetStrings) {
|
---|
| 998 | double v;
|
---|
| 999 | if (!double.TryParse(bs, out v)) {
|
---|
| 1000 | MessageBox.Show("Budgets must be a valid number: " + bs);
|
---|
| 1001 | return;
|
---|
| 1002 | }
|
---|
| 1003 | budgetList.Add(v);
|
---|
| 1004 | }
|
---|
| 1005 | budgetList.Sort();
|
---|
| 1006 |
|
---|
| 1007 | foreach (var run in Content) {
|
---|
[12808] | 1008 | if (!run.Results.ContainsKey(table)) continue;
|
---|
[12806] | 1009 | var resultsTable = (IndexedDataTable<double>)run.Results[table];
|
---|
| 1010 | var values = resultsTable.Rows.First().Values;
|
---|
| 1011 | var i = 0;
|
---|
| 1012 | var j = 0;
|
---|
[12838] | 1013 | Tuple<double, double> prev = null;
|
---|
| 1014 | while (i < budgetList.Count && j < values.Count) {
|
---|
| 1015 | var current = values[j];
|
---|
| 1016 | if (current.Item1 >= budgetList[i]) {
|
---|
| 1017 | if (prev != null || current.Item1 == budgetList[i]) {
|
---|
| 1018 | var tgt = (prev == null || current.Item1 == budgetList[i]) ? current.Item2 : prev.Item2;
|
---|
| 1019 | run.Results[table + ".Cost" + budgetList[i]] = new DoubleValue(tgt);
|
---|
| 1020 | }
|
---|
[12806] | 1021 | i++;
|
---|
| 1022 | } else {
|
---|
| 1023 | j++;
|
---|
| 1024 | prev = current;
|
---|
| 1025 | }
|
---|
| 1026 | }
|
---|
| 1027 | }
|
---|
| 1028 | }
|
---|
[12838] | 1029 | #endregion
|
---|
[12808] | 1030 |
|
---|
[12838] | 1031 | #region Helpers
|
---|
[14751] | 1032 | private double CalculateRelativeDifference(bool maximization, double bestKnown, double fit) {
|
---|
| 1033 | if (bestKnown == 0) {
|
---|
| 1034 | // no relative difference with respect to bestKnown possible
|
---|
| 1035 | return maximization ? -fit : fit;
|
---|
| 1036 | }
|
---|
| 1037 | var absDiff = (fit - bestKnown);
|
---|
| 1038 | var relDiff = absDiff / bestKnown;
|
---|
| 1039 | if (maximization) {
|
---|
| 1040 | return bestKnown > 0 ? -relDiff : relDiff;
|
---|
| 1041 | } else {
|
---|
| 1042 | return bestKnown > 0 ? relDiff : -relDiff;
|
---|
| 1043 | }
|
---|
| 1044 | }
|
---|
| 1045 |
|
---|
| 1046 | private Dictionary<ProblemInstance, double> CalculateBestTargetPerProblemInstance(string table) {
|
---|
| 1047 | if (table == null) table = string.Empty;
|
---|
[12888] | 1048 | return (from r in Content
|
---|
| 1049 | where r.Visible
|
---|
[14751] | 1050 | let pd = new ProblemInstance(r)
|
---|
[12888] | 1051 | let target = r.Parameters.ContainsKey("BestKnownQuality")
|
---|
| 1052 | && r.Parameters["BestKnownQuality"] is DoubleValue
|
---|
| 1053 | ? ((DoubleValue)r.Parameters["BestKnownQuality"]).Value
|
---|
[14751] | 1054 | : (r.Results.ContainsKey(table) && r.Results[table] is IndexedDataTable<double>
|
---|
| 1055 | ? ((IndexedDataTable<double>)r.Results[table]).Rows.First().Values.Last().Item2
|
---|
| 1056 | : double.NaN)
|
---|
[12888] | 1057 | group target by pd into g
|
---|
[14751] | 1058 | select new { Problem = g.Key, Target = g.Any(x => !double.IsNaN(x)) ? (g.Key.IsMaximization() ? g.Max() : g.Where(x => !double.IsNaN(x)).Min()) : double.NaN })
|
---|
[12888] | 1059 | .ToDictionary(x => x.Problem, x => x.Target);
|
---|
| 1060 | }
|
---|
| 1061 |
|
---|
| 1062 | private void UpdateRuns() {
|
---|
| 1063 | if (InvokeRequired) {
|
---|
| 1064 | Invoke((Action)UpdateRuns);
|
---|
| 1065 | return;
|
---|
| 1066 | }
|
---|
| 1067 | SuspendRepaint();
|
---|
| 1068 | try {
|
---|
| 1069 | UpdateResultsByTarget();
|
---|
| 1070 | UpdateResultsByCost();
|
---|
| 1071 | } finally { ResumeRepaint(true); }
|
---|
| 1072 | }
|
---|
[14751] | 1073 |
|
---|
| 1074 | private void UpdateBestKnownQualities() {
|
---|
| 1075 | var table = (string)dataTableComboBox.SelectedItem;
|
---|
| 1076 | if (string.IsNullOrEmpty(table)) return;
|
---|
| 1077 |
|
---|
| 1078 | var targetsPerProblem = CalculateBestTargetPerProblemInstance(table);
|
---|
| 1079 | foreach (var pd in problems) {
|
---|
| 1080 | double bkq;
|
---|
| 1081 | if (targetsPerProblem.TryGetValue(pd, out bkq))
|
---|
| 1082 | pd.BestKnownQuality = bkq;
|
---|
| 1083 | else pd.BestKnownQuality = double.NaN;
|
---|
| 1084 | }
|
---|
| 1085 | //problemComboBox.ResetBindings();
|
---|
| 1086 | }
|
---|
[12838] | 1087 | #endregion
|
---|
[12841] | 1088 |
|
---|
[14101] | 1089 | private void ConfigureSeries(Series series) {
|
---|
| 1090 | series.SmartLabelStyle.Enabled = true;
|
---|
| 1091 | series.SmartLabelStyle.AllowOutsidePlotArea = LabelOutsidePlotAreaStyle.No;
|
---|
| 1092 | series.SmartLabelStyle.CalloutLineAnchorCapStyle = LineAnchorCapStyle.None;
|
---|
| 1093 | series.SmartLabelStyle.CalloutLineColor = series.Color;
|
---|
| 1094 | series.SmartLabelStyle.CalloutLineWidth = 2;
|
---|
| 1095 | series.SmartLabelStyle.CalloutStyle = LabelCalloutStyle.Underlined;
|
---|
| 1096 | series.SmartLabelStyle.IsOverlappedHidden = false;
|
---|
| 1097 | series.SmartLabelStyle.MaxMovingDistance = 200;
|
---|
| 1098 | series.ToolTip = series.LegendText + " X = #VALX, Y = #VALY";
|
---|
| 1099 | }
|
---|
[12841] | 1100 |
|
---|
[14101] | 1101 | private void chart_MouseDown(object sender, MouseEventArgs e) {
|
---|
| 1102 | HitTestResult result = targetChart.HitTest(e.X, e.Y);
|
---|
| 1103 | if (result.ChartElementType == ChartElementType.LegendItem) {
|
---|
| 1104 | ToggleTargetChartSeriesVisible(result.Series);
|
---|
| 1105 | }
|
---|
| 1106 | }
|
---|
| 1107 | private void chart_MouseMove(object sender, MouseEventArgs e) {
|
---|
| 1108 | HitTestResult result = targetChart.HitTest(e.X, e.Y);
|
---|
| 1109 | if (result.ChartElementType == ChartElementType.LegendItem)
|
---|
| 1110 | this.Cursor = Cursors.Hand;
|
---|
| 1111 | else
|
---|
| 1112 | this.Cursor = Cursors.Default;
|
---|
| 1113 | }
|
---|
| 1114 | private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) {
|
---|
| 1115 | foreach (LegendItem legendItem in e.LegendItems) {
|
---|
| 1116 | var series = targetChart.Series[legendItem.SeriesName];
|
---|
| 1117 | if (series != null) {
|
---|
| 1118 | bool seriesIsInvisible = invisibleTargetSeries.Any(x => x.Name == series.Name);
|
---|
| 1119 | foreach (LegendCell cell in legendItem.Cells) {
|
---|
| 1120 | cell.ForeColor = seriesIsInvisible ? Color.Gray : Color.Black;
|
---|
| 1121 | }
|
---|
| 1122 | }
|
---|
| 1123 | }
|
---|
| 1124 | }
|
---|
| 1125 |
|
---|
| 1126 | private void ToggleTargetChartSeriesVisible(Series series) {
|
---|
| 1127 | var indexList = invisibleTargetSeries.FindIndex(x => x.Name == series.Name);
|
---|
| 1128 | var indexChart = targetChart.Series.IndexOf(series);
|
---|
| 1129 | if (targetChart.Series.Count == 1) targetChart.ChartAreas[0].AxisX.IsLogarithmic = false;
|
---|
| 1130 | targetChart.Series.RemoveAt(indexChart);
|
---|
| 1131 | var s = indexList >= 0 ? invisibleTargetSeries[indexList] : new Series(series.Name) {
|
---|
| 1132 | Color = series.Color,
|
---|
| 1133 | ChartType = series.ChartType,
|
---|
| 1134 | BorderWidth = series.BorderWidth,
|
---|
| 1135 | BorderDashStyle = series.BorderDashStyle
|
---|
| 1136 | };
|
---|
| 1137 | if (indexList < 0) {
|
---|
| 1138 | // hide
|
---|
| 1139 | invisibleTargetSeries.Add(series);
|
---|
| 1140 | var shadeSeries = targetChart.Series.FirstOrDefault(x => x.Name == series.Name + "-range");
|
---|
| 1141 | if (shadeSeries != null) {
|
---|
| 1142 | if (targetChart.Series.Count == 1) targetChart.ChartAreas[0].AxisX.IsLogarithmic = false;
|
---|
| 1143 | targetChart.Series.Remove(shadeSeries);
|
---|
| 1144 | invisibleTargetSeries.Add(shadeSeries);
|
---|
| 1145 | indexChart--;
|
---|
| 1146 | }
|
---|
| 1147 | } else {
|
---|
| 1148 | // show
|
---|
| 1149 | invisibleTargetSeries.RemoveAt(indexList);
|
---|
| 1150 | var shadeSeries = invisibleTargetSeries.FirstOrDefault(x => x.Name == series.Name + "-range");
|
---|
| 1151 | if (shadeSeries != null) {
|
---|
| 1152 | invisibleTargetSeries.Remove(shadeSeries);
|
---|
| 1153 | InsertOrAddSeries(indexChart, shadeSeries);
|
---|
| 1154 | indexChart++;
|
---|
| 1155 | }
|
---|
| 1156 | }
|
---|
| 1157 | InsertOrAddSeries(indexChart, s);
|
---|
| 1158 | targetChart.ChartAreas[0].AxisX.IsLogarithmic = CanDisplayLogarithmic();
|
---|
| 1159 | }
|
---|
| 1160 |
|
---|
| 1161 | private bool CanDisplayLogarithmic() {
|
---|
| 1162 | return targetLogScalingCheckBox.Checked
|
---|
| 1163 | && targetChart.Series.Count > 0 // must have a series
|
---|
| 1164 | && targetChart.Series.Any(x => x.Points.Count > 0) // at least one series must have points
|
---|
| 1165 | && targetChart.Series.All(s => s.Points.All(p => p.XValue > 0)); // all points must be positive
|
---|
| 1166 | }
|
---|
| 1167 |
|
---|
| 1168 | private void InsertOrAddSeries(int index, Series s) {
|
---|
| 1169 | if (targetChart.Series.Count <= index)
|
---|
| 1170 | targetChart.Series.Add(s);
|
---|
| 1171 | else targetChart.Series.Insert(index, s);
|
---|
| 1172 | }
|
---|
| 1173 |
|
---|
[14751] | 1174 | private class ProblemInstance : INotifyPropertyChanged {
|
---|
[12841] | 1175 | private readonly bool matchAll;
|
---|
[14751] | 1176 | public static readonly ProblemInstance MatchAll = new ProblemInstance() {
|
---|
[12864] | 1177 | ProblemName = "All with Best-Known"
|
---|
| 1178 | };
|
---|
[12841] | 1179 |
|
---|
[14751] | 1180 | private ProblemInstance() {
|
---|
[12841] | 1181 | ProblemType = string.Empty;
|
---|
| 1182 | ProblemName = string.Empty;
|
---|
| 1183 | Evaluator = string.Empty;
|
---|
[13583] | 1184 | Maximization = string.Empty;
|
---|
[12841] | 1185 | DisplayProblemType = false;
|
---|
| 1186 | DisplayProblemName = false;
|
---|
| 1187 | DisplayEvaluator = false;
|
---|
[13583] | 1188 | DisplayMaximization = false;
|
---|
[12841] | 1189 | matchAll = true;
|
---|
[14751] | 1190 | BestKnownQuality = double.NaN;
|
---|
[12841] | 1191 | }
|
---|
| 1192 |
|
---|
[14751] | 1193 | public ProblemInstance(IRun run) {
|
---|
[12841] | 1194 | ProblemType = GetStringValueOrEmpty(run, "Problem Type");
|
---|
| 1195 | ProblemName = GetStringValueOrEmpty(run, "Problem Name");
|
---|
| 1196 | Evaluator = GetStringValueOrEmpty(run, "Evaluator");
|
---|
[13583] | 1197 | Maximization = GetMaximizationValueOrEmpty(run, "Maximization");
|
---|
[12841] | 1198 | DisplayProblemType = !string.IsNullOrEmpty(ProblemType);
|
---|
| 1199 | DisplayProblemName = !string.IsNullOrEmpty(ProblemName);
|
---|
| 1200 | DisplayEvaluator = !string.IsNullOrEmpty(Evaluator);
|
---|
[13583] | 1201 | DisplayMaximization = !string.IsNullOrEmpty(Maximization);
|
---|
[12841] | 1202 | matchAll = false;
|
---|
[14751] | 1203 | BestKnownQuality = GetDoubleValueOrNaN(run, "BestKnownQuality");
|
---|
[12841] | 1204 | }
|
---|
| 1205 |
|
---|
[14751] | 1206 | private bool displayProblemType;
|
---|
| 1207 | public bool DisplayProblemType {
|
---|
| 1208 | get { return displayProblemType; }
|
---|
| 1209 | set {
|
---|
| 1210 | if (displayProblemType == value) return;
|
---|
| 1211 | displayProblemType = value;
|
---|
| 1212 | OnPropertyChanged("DisplayProblemType");
|
---|
| 1213 | }
|
---|
| 1214 | }
|
---|
| 1215 | private string problemType;
|
---|
| 1216 | public string ProblemType {
|
---|
| 1217 | get { return problemType; }
|
---|
| 1218 | set {
|
---|
| 1219 | if (problemType == value) return;
|
---|
| 1220 | problemType = value;
|
---|
| 1221 | OnPropertyChanged("ProblemType");
|
---|
| 1222 | }
|
---|
| 1223 | }
|
---|
| 1224 | private bool displayProblemName;
|
---|
| 1225 | public bool DisplayProblemName {
|
---|
| 1226 | get { return displayProblemName; }
|
---|
| 1227 | set {
|
---|
| 1228 | if (displayProblemName == value) return;
|
---|
| 1229 | displayProblemName = value;
|
---|
| 1230 | OnPropertyChanged("DisplayProblemName");
|
---|
| 1231 | }
|
---|
| 1232 | }
|
---|
| 1233 | private string problemName;
|
---|
| 1234 | public string ProblemName {
|
---|
| 1235 | get { return problemName; }
|
---|
| 1236 | set {
|
---|
| 1237 | if (problemName == value) return;
|
---|
| 1238 | problemName = value;
|
---|
| 1239 | OnPropertyChanged("ProblemName");
|
---|
| 1240 | }
|
---|
| 1241 | }
|
---|
| 1242 | private bool displayEvaluator;
|
---|
| 1243 | public bool DisplayEvaluator {
|
---|
| 1244 | get { return displayEvaluator; }
|
---|
| 1245 | set {
|
---|
| 1246 | if (displayEvaluator == value) return;
|
---|
| 1247 | displayEvaluator = value;
|
---|
| 1248 | OnPropertyChanged("DisplayEvaluator");
|
---|
| 1249 | }
|
---|
| 1250 | }
|
---|
| 1251 | private string evaluator;
|
---|
| 1252 | public string Evaluator {
|
---|
| 1253 | get { return evaluator; }
|
---|
| 1254 | set {
|
---|
| 1255 | if (evaluator == value) return;
|
---|
| 1256 | evaluator = value;
|
---|
| 1257 | OnPropertyChanged("Evaluator");
|
---|
| 1258 | }
|
---|
| 1259 | }
|
---|
| 1260 | private bool displayMaximization;
|
---|
| 1261 | public bool DisplayMaximization {
|
---|
| 1262 | get { return displayMaximization; }
|
---|
| 1263 | set {
|
---|
| 1264 | if (displayMaximization == value) return;
|
---|
| 1265 | displayMaximization = value;
|
---|
| 1266 | OnPropertyChanged("DisplayMaximization");
|
---|
| 1267 | }
|
---|
| 1268 | }
|
---|
| 1269 | private string maximization;
|
---|
| 1270 | public string Maximization {
|
---|
| 1271 | get { return maximization; }
|
---|
| 1272 | set {
|
---|
| 1273 | if (maximization == value) return;
|
---|
| 1274 | maximization = value;
|
---|
| 1275 | OnPropertyChanged("Maximization");
|
---|
| 1276 | }
|
---|
| 1277 | }
|
---|
| 1278 | private double bestKnownQuality;
|
---|
| 1279 | public double BestKnownQuality {
|
---|
| 1280 | get { return bestKnownQuality; }
|
---|
| 1281 | set {
|
---|
| 1282 | if (bestKnownQuality == value) return;
|
---|
| 1283 | bestKnownQuality = value;
|
---|
| 1284 | OnPropertyChanged("BestKnownQuality");
|
---|
| 1285 | }
|
---|
| 1286 | }
|
---|
[12841] | 1287 |
|
---|
[13583] | 1288 | public bool IsMaximization() {
|
---|
| 1289 | return Maximization == "MAX";
|
---|
| 1290 | }
|
---|
| 1291 |
|
---|
[12841] | 1292 | public bool Match(IRun run) {
|
---|
| 1293 | return matchAll ||
|
---|
| 1294 | GetStringValueOrEmpty(run, "Problem Type") == ProblemType
|
---|
| 1295 | && GetStringValueOrEmpty(run, "Problem Name") == ProblemName
|
---|
[13583] | 1296 | && GetStringValueOrEmpty(run, "Evaluator") == Evaluator
|
---|
| 1297 | && GetMaximizationValueOrEmpty(run, "Maximization") == Maximization;
|
---|
[12841] | 1298 | }
|
---|
| 1299 |
|
---|
[14751] | 1300 | private double GetDoubleValueOrNaN(IRun run, string key) {
|
---|
| 1301 | IItem param;
|
---|
| 1302 | if (run.Parameters.TryGetValue(key, out param)) {
|
---|
| 1303 | var dv = param as DoubleValue;
|
---|
| 1304 | return dv != null ? dv.Value : double.NaN;
|
---|
| 1305 | }
|
---|
| 1306 | return double.NaN;
|
---|
| 1307 | }
|
---|
| 1308 |
|
---|
[12841] | 1309 | private string GetStringValueOrEmpty(IRun run, string key) {
|
---|
[14751] | 1310 | IItem param;
|
---|
| 1311 | if (run.Parameters.TryGetValue(key, out param)) {
|
---|
| 1312 | var sv = param as StringValue;
|
---|
| 1313 | return sv != null ? sv.Value : string.Empty;
|
---|
| 1314 | }
|
---|
| 1315 | return string.Empty;
|
---|
[12841] | 1316 | }
|
---|
| 1317 |
|
---|
[13583] | 1318 | private string GetMaximizationValueOrEmpty(IRun run, string key) {
|
---|
[14751] | 1319 | IItem param;
|
---|
| 1320 | if (run.Parameters.TryGetValue(key, out param)) {
|
---|
| 1321 | var bv = param as BoolValue;
|
---|
| 1322 | return bv != null ? (bv.Value ? "MAX" : "MIN") : string.Empty;
|
---|
| 1323 | }
|
---|
| 1324 | return string.Empty;
|
---|
[13583] | 1325 | }
|
---|
| 1326 |
|
---|
[12841] | 1327 | public override bool Equals(object obj) {
|
---|
[14751] | 1328 | var other = obj as ProblemInstance;
|
---|
[12841] | 1329 | if (other == null) return false;
|
---|
| 1330 | return ProblemType == other.ProblemType
|
---|
| 1331 | && ProblemName == other.ProblemName
|
---|
[13583] | 1332 | && Evaluator == other.Evaluator
|
---|
| 1333 | && Maximization == other.Maximization;
|
---|
[12841] | 1334 | }
|
---|
| 1335 |
|
---|
| 1336 | public override int GetHashCode() {
|
---|
[13583] | 1337 | return ProblemType.GetHashCode() ^ ProblemName.GetHashCode() ^ Evaluator.GetHashCode() ^ Maximization.GetHashCode();
|
---|
[12841] | 1338 | }
|
---|
| 1339 |
|
---|
| 1340 | public override string ToString() {
|
---|
| 1341 | return string.Join(" -- ", new[] {
|
---|
| 1342 | (DisplayProblemType ? ProblemType : string.Empty),
|
---|
| 1343 | (DisplayProblemName ? ProblemName : string.Empty),
|
---|
[13583] | 1344 | (DisplayEvaluator ? Evaluator : string.Empty),
|
---|
[14751] | 1345 | (DisplayMaximization ? Maximization : string.Empty),
|
---|
| 1346 | !double.IsNaN(BestKnownQuality) ? BestKnownQuality.ToString(CultureInfo.CurrentCulture.NumberFormat) : string.Empty }.Where(x => !string.IsNullOrEmpty(x)));
|
---|
[12841] | 1347 | }
|
---|
[14751] | 1348 |
|
---|
| 1349 | public event PropertyChangedEventHandler PropertyChanged;
|
---|
| 1350 | protected virtual void OnPropertyChanged(string propertyName = null) {
|
---|
| 1351 | var handler = PropertyChanged;
|
---|
| 1352 | if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
|
---|
| 1353 | }
|
---|
[12841] | 1354 | }
|
---|
[7980] | 1355 | }
|
---|
| 1356 | }
|
---|