Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views/UnderstandingProblemInstanceView.cs @ 13743

Last change on this file since 13743 was 13722, checked in by abeham, 8 years ago

#2457:

  • Renamed remaining files from ExpertSystem to KnowledgeCenter
  • Added ability to scatter plot to display a regression line
  • Allowed to execute multiple instances at once and displaying either only final result or tracking result
  • Split runs in seeded runs and instance runs
File size: 4.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.MainForm;
23using HeuristicLab.OptimizationExpertSystem.Common;
24using System;
25using System.Collections.Generic;
26using System.Linq;
27using System.Text.RegularExpressions;
28using System.Windows.Forms.DataVisualization.Charting;
29
30namespace HeuristicLab.OptimizationExpertSystem {
31  [View("Understanding Problem Instance")]
32  [Content(typeof(KnowledgeCenter), IsDefaultView = false)]
33  public partial class UnderstandingProblemInstanceView : KnowledgeCenterViewBase {
34    public UnderstandingProblemInstanceView() {
35      InitializeComponent();
36    }
37
38    protected override void OnContentChanged() {
39      base.OnContentChanged();
40      if (Content == null) {
41        problemInstancesView.Content = null;
42        instanceMapChart.Series["InstancesSeries"].Points.Clear();
43        instanceMapChart.Series["CurrentInstanceSeries"].Points.Clear();
44      } else {
45        problemInstancesView.Content = Content.ProblemInstances;
46        UpdateProjectionComboBox();
47      }
48    }
49
50    #region Content Event Handlers
51    protected override void OnProblemChanged() {
52      base.OnProblemChanged();
53      SetEnabledStateOfControls();
54    }
55
56    protected override void OnProblemInstancesChanged() {
57      base.OnProblemInstancesChanged();
58      if (Content.ProblemInstances.UpdateOfRunsInProgress) return;
59      UpdateProjectionComboBox();
60    }
61
62    protected override void OnDownloadEnded() {
63      base.OnDownloadEnded();
64      UpdateProjectionComboBox();
65    }
66    #endregion
67   
68    public IEnumerable<string> GetProjections() {
69      return Content.ProblemInstances
70        .SelectMany(x => x.Results.Where(y => Regex.IsMatch(y.Key, "^Projection[.].*[.][XY]$")))
71        .Select(x => Regex.Match(x.Key, "Projection[.](?<g>.*)[.][XY]").Groups["g"].Value)
72        .Distinct();
73    }
74
75    public void ProjectProblemInstances(Series instancesSeries, Series currentInstanceSeries, string projection) {
76      instancesSeries.Points.Clear();
77      currentInstanceSeries.Points.Clear();
78
79      foreach (var run in Content.ProblemInstances) {
80        var xKey = "Projection." + projection + ".X";
81        var yKey = "Projection." + projection + ".Y";
82        if (!run.Results.ContainsKey(xKey) || !run.Results.ContainsKey(yKey)
83            || !(run.Results[xKey] is Data.DoubleValue) || !(run.Results[yKey] is Data.DoubleValue)) continue;
84        var x = ((Data.DoubleValue)run.Results[xKey]).Value;
85        var y = ((Data.DoubleValue)run.Results[yKey]).Value;
86        var dataPoint = new DataPoint(x, y) {
87          Label = run.Name
88        };
89        instancesSeries.Points.Add(dataPoint);
90      }
91
92      var curPoint = Content.ProjectCurrentInstance(projection);
93      if (curPoint != null) {
94        var dp = new DataPoint(curPoint.Item1, curPoint.Item2) {
95          Label = Content.Problem.Problem.Name
96        };
97        currentInstanceSeries.Points.Add(dp);
98      }
99    }
100
101    private void ProjectionComboBoxOnSelectedIndexChanged(object sender, EventArgs e) {
102      if (InvokeRequired) { Invoke((Action<object, EventArgs>)ProjectionComboBoxOnSelectedIndexChanged, sender, e); return; }
103      if (projectionComboBox.SelectedIndex < 0) return;
104      var projection = (string)projectionComboBox.SelectedItem;
105      var instancesSeries = instanceMapChart.Series["InstancesSeries"];
106      var currentInstanceSeries = instanceMapChart.Series["CurrentInstanceSeries"];
107
108      ProjectProblemInstances(instancesSeries, currentInstanceSeries, projection);
109    }
110
111    private void UpdateProjectionComboBox() {
112      projectionComboBox.Items.Clear();
113      foreach (var str in GetProjections()) {
114        projectionComboBox.Items.Add(str);
115      }
116      if (projectionComboBox.Items.Count > 0)
117        projectionComboBox.SelectedIndex = 0;
118    }
119  }
120}
Note: See TracBrowser for help on using the repository browser.