Changeset 13540 for trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBProblemView.cs
- Timestamp:
- 01/18/16 15:03:52 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Clients.OKB.Views/3.3/RunCreation/Views/OKBProblemView.cs
r13534 r13540 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Globalization; 24 25 using System.Linq; 25 26 using System.Windows.Forms; … … 28 29 using HeuristicLab.Data; 29 30 using HeuristicLab.MainForm; 31 using HeuristicLab.Optimization; 32 using HeuristicLab.PluginInfrastructure; 30 33 31 34 namespace HeuristicLab.Clients.OKB.RunCreation { … … 41 44 public OKBProblemView() { 42 45 InitializeComponent(); 46 refreshButton.Text = string.Empty; 47 refreshButton.Image = VSImageLibrary.Refresh; 48 cloneProblemButton.Text = string.Empty; 49 cloneProblemButton.Image = VSImageLibrary.Clone; 43 50 downloadCharacteristicsButton.Text = string.Empty; 44 51 downloadCharacteristicsButton.Image = VSImageLibrary.Refresh; … … 72 79 parameterCollectionView.Content = Content.Parameters; 73 80 } 81 UpdateCharacteristicCalculators(); 74 82 } 75 83 … … 92 100 } 93 101 102 private void UpdateCharacteristicCalculators() { 103 calculatorListView.Items.Clear(); 104 calculatorListView.Groups.Clear(); 105 if (Content == null || Content.ProblemId == -1) return; 106 var problem = Content.CloneProblem(); 107 var calculators = ApplicationManager.Manager.GetInstances<ICharacteristicCalculator>().Where(x => x.CanCalculate(problem)).ToList(); 108 try { 109 calculatorListView.BeginUpdate(); 110 foreach (var calc in calculators) { 111 var group = calculatorListView.Groups.Add(calc.Name, calc.Name); 112 group.Tag = calc; 113 foreach (var c in calc.Characteristics) { 114 var item = calculatorListView.Items.Add(c, c); 115 item.Group = group; 116 } 117 } 118 } finally { calculatorListView.EndUpdate(); } 119 } 120 94 121 private void RunCreationClient_Refreshing(object sender, EventArgs e) { 95 122 if (InvokeRequired) { … … 161 188 } catch (Exception ex) { PluginInfrastructure.ErrorHandling.ShowErrorDialog(ex); } 162 189 } 190 private void calculateButton_Click(object sender, EventArgs e) { 191 var problem = Content.CloneProblem(); 192 var characteristics = calculatorListView.CheckedItems.OfType<ListViewItem>().GroupBy(x => x.Group); 193 var results = new Dictionary<string, double>(); 194 foreach (var c in characteristics) { 195 var calc = (ICharacteristicCalculator)c.Key.Tag; 196 foreach (var result in calc.Calculate(problem, c.Select(x => x.Text).ToArray())) 197 results[result.Key] = result.Value; 198 } 199 var matrix = characteristicsMatrixView.Content as StringMatrix; 200 if (matrix == null) matrix = new StringMatrix(results.Count, 3); 201 for (var i = 0; i < matrix.Rows; i++) { 202 double r; 203 if (results.TryGetValue(matrix[i, 0], out r)) { 204 matrix[i, 1] = r.ToString(CultureInfo.CurrentCulture.NumberFormat); 205 matrix[i, 2] = "DoubleValue"; 206 results.Remove(matrix[i, 0]); 207 } 208 } 209 if (results.Count == 0) return; 210 var resultsList = results.ToList(); 211 var counter = resultsList.Count - 1; 212 for (var i = 0; i < matrix.Rows; i++) { 213 if (string.IsNullOrEmpty(matrix[i, 0])) { 214 matrix[i, 0] = resultsList[counter].Key; 215 matrix[i, 1] = resultsList[counter].Value.ToString(CultureInfo.CurrentCulture.NumberFormat); 216 matrix[i, 2] = "DoubleValue"; 217 resultsList.RemoveAt(counter); 218 counter--; 219 if (counter < 0) return; 220 } 221 } 222 if (counter >= 0) { 223 ((IStringConvertibleMatrix)matrix).Rows += counter + 1; 224 for (var i = matrix.Rows - 1; counter >= 0; i--) { 225 matrix[i, 0] = resultsList[0].Key; 226 matrix[i, 1] = resultsList[0].Value.ToString(CultureInfo.CurrentCulture.NumberFormat); 227 matrix[i, 2] = "DoubleValue"; 228 counter--; 229 } 230 } 231 } 163 232 #endregion 164 233
Note: See TracChangeset
for help on using the changeset viewer.