Changeset 13751 for branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views/UnderstandingProblemInstanceView.cs
- Timestamp:
- 04/11/16 17:34:50 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views/UnderstandingProblemInstanceView.cs
r13722 r13751 20 20 #endregion 21 21 22 using HeuristicLab.Core; 22 23 using HeuristicLab.MainForm; 23 24 using HeuristicLab.OptimizationExpertSystem.Common; … … 31 32 [View("Understanding Problem Instance")] 32 33 [Content(typeof(KnowledgeCenter), IsDefaultView = false)] 33 public partial class UnderstandingProblemInstanceView : KnowledgeCenterViewBase { 34 public sealed partial class UnderstandingProblemInstanceView : KnowledgeCenterViewBase { 35 private bool SuppressEvents { get; set; } 36 34 37 public UnderstandingProblemInstanceView() { 35 38 InitializeComponent(); … … 45 48 problemInstancesView.Content = Content.ProblemInstances; 46 49 UpdateProjectionComboBox(); 50 UpdateSizeComboBox(); 47 51 } 48 52 } … … 58 62 if (Content.ProblemInstances.UpdateOfRunsInProgress) return; 59 63 UpdateProjectionComboBox(); 64 UpdateSizeComboBox(); 65 UpdateProjection(); 66 } 67 #endregion 68 69 private void UpdateProjectionComboBox() { 70 try { 71 SuppressEvents = true; 72 var selected = projectionComboBox.SelectedIndex >= 0 ? (string)projectionComboBox.SelectedItem : null; 73 projectionComboBox.Items.Clear(); 74 foreach (var str in GetProjections()) { 75 projectionComboBox.Items.Add(str); 76 if (selected == str) projectionComboBox.SelectedItem = str; 77 } 78 if (selected == null && projectionComboBox.Items.Count > 0) 79 projectionComboBox.SelectedIndex = 0; 80 } finally { SuppressEvents = false; } 60 81 } 61 82 62 protected override void OnDownloadEnded() { 63 base.OnDownloadEnded(); 64 UpdateProjectionComboBox(); 83 private void UpdateSizeComboBox() { 84 try { 85 SuppressEvents = true; 86 var selected = sizeComboBox.SelectedIndex >= 0 ? (string)sizeComboBox.SelectedItem : null; 87 sizeComboBox.Items.Clear(); 88 sizeComboBox.Items.Add(string.Empty); 89 foreach (var str in Content.ProblemInstances.ResultNames.Where(x => !(x.StartsWith("Projection.") && (x.EndsWith(".X") || x.EndsWith(".Y"))))) { 90 sizeComboBox.Items.Add(str); 91 if (selected == str) sizeComboBox.SelectedItem = str; 92 } 93 if (selected == null && sizeComboBox.Items.Count > 0) 94 sizeComboBox.SelectedIndex = 0; 95 } finally { SuppressEvents = false; } 65 96 } 66 #endregion67 97 68 p ublicIEnumerable<string> GetProjections() {98 private IEnumerable<string> GetProjections() { 69 99 return Content.ProblemInstances 70 100 .SelectMany(x => x.Results.Where(y => Regex.IsMatch(y.Key, "^Projection[.].*[.][XY]$"))) … … 73 103 } 74 104 75 public void ProjectProblemInstances(Series instancesSeries, Series currentInstanceSeries, string projection) { 105 private void UpdateProjection() { 106 if (InvokeRequired) { Invoke((Action)UpdateProjection); return; } 107 108 var instancesSeries = instanceMapChart.Series["InstancesSeries"]; 109 var currentInstanceSeries = instanceMapChart.Series["CurrentInstanceSeries"]; 110 111 if (projectionComboBox.SelectedIndex < 0) { 112 instancesSeries.Points.Clear(); 113 currentInstanceSeries.Points.Clear(); 114 return; 115 } 116 117 var projection = (string)projectionComboBox.SelectedItem; 118 var size = sizeComboBox.SelectedIndex >= 0 ? (string)sizeComboBox.SelectedItem : string.Empty; 119 120 DoProjectProblemInstances(instancesSeries, currentInstanceSeries, projection, size, invPropCheckBox.Checked); 121 } 122 123 private void DoProjectProblemInstances(Series instancesSeries, Series currentInstanceSeries, string projection, string size, bool invProp) { 76 124 instancesSeries.Points.Clear(); 77 125 currentInstanceSeries.Points.Clear(); 78 126 127 double maxSize = 0, minSize = 0; 128 if (!string.IsNullOrEmpty(size)) { 129 var sizes = Content.ProblemInstances.Where(x => x.Results.ContainsKey(size)).Select(x => x.Results[size]).OfType<Data.DoubleValue>().Where(x => !double.IsNaN(x.Value)).ToList(); 130 if (sizes.Count > 0) { 131 maxSize = sizes.Max(x => x.Value); 132 minSize = sizes.Min(x => x.Value); 133 } 134 } 79 135 foreach (var run in Content.ProblemInstances) { 80 136 var xKey = "Projection." + projection + ".X"; … … 85 141 var y = ((Data.DoubleValue)run.Results[yKey]).Value; 86 142 var dataPoint = new DataPoint(x, y) { 87 Label = run.Name 143 Label = run.Name, 88 144 }; 89 instancesSeries.Points.Add(dataPoint); 90 } 145 IItem item; 146 if (maxSize > minSize && run.Results.TryGetValue(size, out item)) { 147 var dItem = item as Data.DoubleValue; 148 if (dItem != null) { 149 if (double.IsNaN(dItem.Value)) 150 dataPoint.MarkerSize = 1; 151 else { 152 if (invProp) dataPoint.MarkerSize = (int)Math.Round(5 + 15 * (maxSize - dItem.Value) / (maxSize - minSize)); 153 else dataPoint.MarkerSize = (int)Math.Round(5 + 15 * (dItem.Value - minSize) / (maxSize - minSize)); 154 } 155 } 156 } else if (maxSize == minSize) { 157 dataPoint.MarkerSize = instancesSeries.MarkerSize; 158 } else dataPoint.MarkerSize = 1; 91 159 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); 160 if (Content.IsCurrentInstance(run)) currentInstanceSeries.Points.Add(dataPoint); 161 else instancesSeries.Points.Add(dataPoint); 98 162 } 99 163 } 100 164 165 #region Control Event Handlers 101 166 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); 167 UpdateProjection(); 109 168 } 110 169 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; 170 private void SizeComboBoxOnSelectedIndexChanged(object sender, EventArgs e) { 171 UpdateProjection(); 118 172 } 173 174 private void InvPropCheckBoxOnCheckedChanged(object sender, EventArgs e) { 175 UpdateProjection(); 176 } 177 #endregion 119 178 } 120 179 }
Note: See TracChangeset
for help on using the changeset viewer.