Changeset 14825 for branches/symbreg-factors-2650/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionRLDView.cs
- Timestamp:
- 04/04/17 16:57:45 (7 years ago)
- Location:
- branches/symbreg-factors-2650
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650
- Property svn:mergeinfo changed
/trunk/sources merged: 14769-14770,14772-14775,14779-14781,14786,14789-14791,14793,14805,14809-14810,14817,14819-14820
- Property svn:mergeinfo changed
-
branches/symbreg-factors-2650/HeuristicLab.Optimization.Views
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Optimization.Views merged: 14775,14791,14793
- Property svn:mergeinfo changed
-
branches/symbreg-factors-2650/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionRLDView.cs
r14751 r14825 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2017 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 42 42 private List<Series> invisibleTargetSeries; 43 43 44 private const string All Runs = "All Runs";44 private const string AllInstances = "All Instances"; 45 45 46 46 private static readonly Color[] colors = new[] { … … 223 223 var groupings = Content.ParameterNames.OrderBy(x => x).ToArray(); 224 224 groupComboBox.Items.Clear(); 225 groupComboBox.Items.Add(All Runs);225 groupComboBox.Items.Add(AllInstances); 226 226 groupComboBox.Items.AddRange(groupings); 227 227 if (selectedGroupItem != null && groupComboBox.Items.Contains(selectedGroupItem)) { … … 241 241 242 242 var selectedProblemItem = (ProblemInstance)problemComboBox.SelectedItem; 243 problemComboBox.DataSource = null; 244 problemComboBox.Items.Clear(); 243 245 problems.Clear(); 244 246 problems.Add(ProblemInstance.MatchAll); 247 problemComboBox.DataSource = new BindingSource() { DataSource = problems }; 248 problemComboBox.DataBindings.DefaultDataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged; 245 249 if (problems[0].Equals(selectedProblemItem)) problemComboBox.SelectedItem = problems[0]; 246 250 foreach (var p in problemDict.ToList()) { … … 282 286 } 283 287 284 private Dictionary<string, Dictionary<ProblemInstance, List<IRun>>> GroupRuns() { 285 var groupedRuns = new Dictionary<string, Dictionary<ProblemInstance, List<IRun>>>(); 286 288 private IEnumerable<AlgorithmInstance> GroupRuns() { 287 289 var table = (string)dataTableComboBox.SelectedItem; 288 if (string.IsNullOrEmpty(table)) return groupedRuns;290 if (string.IsNullOrEmpty(table)) yield break; 289 291 290 292 var selectedGroup = (string)groupComboBox.SelectedItem; 291 if (string.IsNullOrEmpty(selectedGroup)) return groupedRuns;293 if (string.IsNullOrEmpty(selectedGroup)) yield break; 292 294 293 295 var selectedProblem = (ProblemInstance)problemComboBox.SelectedItem; 294 if (selectedProblem == null) return groupedRuns;296 if (selectedProblem == null) yield break; 295 297 296 298 foreach (var x in (from r in Content 297 where (selectedGroup == All Runs || r.Parameters.ContainsKey(selectedGroup))299 where (selectedGroup == AllInstances || r.Parameters.ContainsKey(selectedGroup)) 298 300 && selectedProblem.Match(r) 299 301 && r.Results.ContainsKey(table) 300 302 && r.Visible 301 let key = selectedGroup == All Runs ? AllRuns : r.Parameters[selectedGroup].ToString()303 let key = selectedGroup == AllInstances ? AllInstances : r.Parameters[selectedGroup].ToString() 302 304 group r by key into g 303 select Tuple.Create(g.Key, g.ToList()))) { 304 var pDict = problems.ToDictionary(r => r, _ => new List<IRun>()); 305 foreach (var y in x.Item2) { 306 var pd = new ProblemInstance(y); 307 List<IRun> l; 308 if (pDict.TryGetValue(pd, out l)) l.Add(y); 309 } 310 groupedRuns[x.Item1] = pDict.Where(a => a.Value.Count > 0).ToDictionary(a => a.Key, a => a.Value); 311 } 312 313 return groupedRuns; 305 select new AlgorithmInstance(g.Key, g, problems))) { 306 yield return x; 307 } 314 308 } 315 309 … … 326 320 if (targets == null) GenerateDefaultTargets(); 327 321 328 var groupedRuns = GroupRuns();329 if ( groupedRuns.Count == 0) return;322 var algInstances = GroupRuns().ToList(); 323 if (algInstances.Count == 0) return; 330 324 331 325 var xAxisTitles = new HashSet<string>(); … … 337 331 // how many targets have been left open at the point when the run ended 338 332 var misses = new Dictionary<string, SortedList<double, int>>(); 333 var totalRuns = new Dictionary<string, int>(); 339 334 340 335 var aggregate = aggregateTargetsCheckBox.Checked; 341 336 double minEff = double.MaxValue, maxEff = double.MinValue; 342 var noRuns = 0;343 foreach (var group in groupedRuns) {337 foreach (var alg in algInstances) { 338 var noRuns = 0; 344 339 SortedList<double, int> epdfHits = null, epdfMisses = null; 345 340 if (aggregate) { 346 hits[ group.Key] = epdfHits = new SortedList<double, int>();347 misses[ group.Key] = epdfMisses = new SortedList<double, int>();348 } 349 foreach (var problem in group.Value) {350 var max = problem. Key.IsMaximization();351 var absTargets = GetAbsoluteTargets(problem .Key).ToArray();352 foreach (var run in problem.Value) {341 hits[alg.Name] = epdfHits = new SortedList<double, int>(); 342 misses[alg.Name] = epdfMisses = new SortedList<double, int>(); 343 } 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)) { 353 348 noRuns++; 354 349 var resultsTable = (IndexedDataTable<double>)run.Results[table]; … … 361 356 var e = efforts[idx]; 362 357 if (!aggregate) { 363 var key = group.Key+ "@" + (targetsAreRelative364 ? (targets[idx] * 100).ToString(CultureInfo.CurrentCulture.NumberFormat) + "%"365 : targets[idx].ToString(CultureInfo.CurrentCulture.NumberFormat));358 var key = alg.Name + "@" + (targetsAreRelative 359 ? (targets[idx] * 100).ToString(CultureInfo.CurrentCulture.NumberFormat) + "%" 360 : targets[idx].ToString(CultureInfo.CurrentCulture.NumberFormat)); 366 361 if (!hits.TryGetValue(key, out epdfHits)) 367 362 hits[key] = epdfHits = new SortedList<double, int>(); 368 363 if (!misses.TryGetValue(key, out epdfMisses)) 369 364 misses[key] = epdfMisses = new SortedList<double, int>(); 370 } 365 totalRuns[key] = noRuns; 366 }; 371 367 var list = e.Item1 ? epdfHits : epdfMisses; 372 368 int v; … … 377 373 } 378 374 } 375 if (aggregate) totalRuns[alg.Name] = noRuns; 379 376 } 380 377 381 378 UpdateTargetChartAxisXBounds(minEff, maxEff); 382 379 383 DrawTargetsEcdf(hits, misses, noRuns);380 DrawTargetsEcdf(hits, misses, totalRuns); 384 381 385 382 if (targets.Length == 1) { … … 392 389 targetChart.ChartAreas[0].CursorY.Interval = 0.05; 393 390 394 UpdateErtTables( groupedRuns);395 } 396 397 private void DrawTargetsEcdf(Dictionary<string, SortedList<double, int>> hits, Dictionary<string, SortedList<double, int>> misses, intnoRuns) {391 UpdateErtTables(algInstances); 392 } 393 394 private void DrawTargetsEcdf(Dictionary<string, SortedList<double, int>> hits, Dictionary<string, SortedList<double, int>> misses, Dictionary<string, int> noRuns) { 398 395 var colorCount = 0; 399 396 var lineStyleCount = 0; … … 418 415 var iter = misses[list.Key].GetEnumerator(); 419 416 var moreMisses = iter.MoveNext(); 420 var totalTargets = noRuns ;417 var totalTargets = noRuns[list.Key]; 421 418 if (aggregateTargetsCheckBox.Checked) totalTargets *= targets.Length; 422 419 var movingTargets = totalTargets; … … 594 591 } 595 592 596 private void UpdateErtTables( Dictionary<string, Dictionary<ProblemInstance, List<IRun>>> groupedRuns) {593 private void UpdateErtTables(List<AlgorithmInstance> algorithmInstances) { 597 594 ertTableView.Content = null; 598 595 var columns = 1 + targets.Length + 1; 599 var matrix = new string[ groupedRuns.Count * groupedRuns.Max(x => x.Value.Count) + groupedRuns.Max(x => x.Value.Count), columns];596 var matrix = new string[algorithmInstances.Count * algorithmInstances.Max(x => x.GetNumberOfProblemInstances()) + algorithmInstances.Max(x => x.GetNumberOfProblemInstances()), columns]; 600 597 var rowCount = 0; 601 598 … … 603 600 if (string.IsNullOrEmpty(tableName)) return; 604 601 605 var problems = groupedRuns.SelectMany(x => x.Value.Keys).Distinct().ToList();602 var problems = algorithmInstances.SelectMany(x => x.GetProblemInstances()).Distinct().ToList(); 606 603 607 604 foreach (var problem in problems) { … … 615 612 rowCount++; 616 613 617 foreach (var group in groupedRuns) { 618 matrix[rowCount, 0] = group.Key; 619 if (!group.Value.ContainsKey(problem)) { 614 foreach (var alg in algorithmInstances) { 615 matrix[rowCount, 0] = alg.Name; 616 var runs = alg.GetRuns(problem).ToList(); 617 if (runs.Count == 0) { 620 618 matrix[rowCount, columns - 1] = "N/A"; 621 619 rowCount++; 622 620 continue; 623 621 } 624 var runs = group.Value[problem];625 622 var result = default(ErtCalculationResult); 626 623 for (var i = 0; i < absTargets.Length; i++) { … … 648 645 if (budgets == null) GenerateDefaultBudgets(table); 649 646 650 var groupedRuns = GroupRuns();651 if ( groupedRuns.Count == 0) return;647 var algInstances = GroupRuns().ToList(); 648 if (algInstances.Count == 0) return; 652 649 653 650 var colorCount = 0; 654 651 var lineStyleCount = 0; 655 652 656 foreach (var group in groupedRuns) {653 foreach (var alg in algInstances) { 657 654 var hits = new Dictionary<string, SortedList<double, double>>(); 658 655 659 foreach (var problem in group.Value) {660 foreach (var run in problem.Value) {656 foreach (var problem in alg.GetProblemInstances()) { 657 foreach (var run in alg.GetRuns(problem)) { 661 658 var resultsTable = (IndexedDataTable<double>)run.Results[table]; 662 659 663 660 if (aggregateBudgetsCheckBox.Checked) { 664 CalculateHitsForAllBudgets(hits, resultsTable.Rows.First(), group.Value.Count, problem.Key, group.Key, problem.Value.Count);661 CalculateHitsForAllBudgets(hits, resultsTable.Rows.First(), alg.GetNumberOfProblemInstances(), problem, alg.Name, alg.GetNumberOfRuns(problem)); 665 662 } else { 666 CalculateHitsForEachBudget(hits, resultsTable.Rows.First(), group.Value.Count, problem.Key, group.Key, problem.Value.Count);663 CalculateHitsForEachBudget(hits, resultsTable.Rows.First(), alg.GetNumberOfProblemInstances(), problem, alg.Name, alg.GetNumberOfRuns(problem)); 667 664 } 668 665 } … … 697 694 698 695 private void GenerateDefaultBudgets(string table) { 699 var runs = GroupRuns().SelectMany(x => x.Value.Values).SelectMany(x => x).ToList();696 var runs = Content; 700 697 var min = runs.Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Select(y => y.Item1).Min()).Min(); 701 698 var max = runs.Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Select(y => y.Item1).Max()).Max(); … … 1172 1169 } 1173 1170 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 1174 1239 private class ProblemInstance : INotifyPropertyChanged { 1175 1240 private readonly bool matchAll;
Note: See TracChangeset
for help on using the changeset viewer.