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