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