- Timestamp:
- 03/03/16 15:54:48 (9 years ago)
- Location:
- branches/PerformanceComparison
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Views/3.3/ExpertSystemView.Designer.cs
r13561 r13649 211 211 this.suggestedInstancesComboBox.Size = new System.Drawing.Size(322, 21); 212 212 this.suggestedInstancesComboBox.TabIndex = 0; 213 this.suggestedInstancesComboBox.SelectedIndexChanged += new System.EventHandler(this.SuggestedInstancesComboBoxOnSelectedIndexChanged); 213 214 // 214 215 // runsTabPage -
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Views/3.3/ExpertSystemView.cs
r13569 r13649 20 20 #endregion 21 21 22 using HeuristicLab.Common.Resources; 23 using HeuristicLab.Core.Views; 24 using HeuristicLab.MainForm; 25 using HeuristicLab.Optimization; 26 using HeuristicLab.Optimization.Views; 22 27 using System; 23 28 using System.ComponentModel; … … 26 31 using System.Windows.Forms; 27 32 using System.Windows.Forms.DataVisualization.Charting; 28 using HeuristicLab.Common.Resources;29 using HeuristicLab.Core.Views;30 using HeuristicLab.MainForm;31 using HeuristicLab.Optimization;32 using HeuristicLab.Optimization.Views;33 33 34 34 namespace HeuristicLab.OptimizationExpertSystem.Views { … … 104 104 kbViewHost.Content = Content.KnowledgeBase; 105 105 problemInstancesView.Content = Content.ProblemInstances; 106 algorithmViewHost.Content = Content.CurrentResult; 106 107 } 107 108 } finally { SuppressEvents = false; } … … 161 162 break; 162 163 case "ProblemInstances": problemInstancesView.Content = Content.ProblemInstances; break; 164 case "CurrentResult": algorithmViewHost.Content = Content.CurrentResult; break; 163 165 } 164 166 } finally { SuppressEvents = false; } … … 231 233 232 234 private void AlgorithmStartButtonOnClick(object sender, EventArgs e) { 233 var selectedInstance = (IAlgorithm)suggestedInstancesComboBox.SelectedItem; 234 var clone = (IAlgorithm)selectedInstance.Clone(); 235 clone.Prepare(true); 236 clone.Start(); 237 algorithmViewHost.Content = clone.Results; 235 if (suggestedInstancesComboBox.SelectedIndex >= 0) 236 Content.StartAlgorithmAsync(suggestedInstancesComboBox.SelectedIndex); 238 237 } 239 238 … … 268 267 } 269 268 } 269 270 private void SuggestedInstancesComboBoxOnSelectedIndexChanged(object sender, EventArgs e) { 271 SetEnabledStateOfControls(); 272 } 270 273 } 271 274 } -
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Views/3.3/ExpertSystemView.resx
r13551 r13649 121 121 <value>17, 17</value> 122 122 </metadata> 123 <metadata name="errorProvider.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">124 <value>17, 17</value>125 </metadata>126 123 <metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 127 124 <value>140, 17</value> -
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/ExpertSystem.cs
r13561 r13649 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 using System.ComponentModel;25 using System.Drawing;26 using System.IO;27 using System.Linq;28 using System.Threading.Tasks;29 22 using HeuristicLab.Analysis; 30 23 using HeuristicLab.Collections; … … 37 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 38 31 using HeuristicLab.Persistence.Default.Xml; 32 using System; 33 using System.Collections.Generic; 34 using System.ComponentModel; 35 using System.Drawing; 36 using System.IO; 37 using System.Linq; 38 using System.Threading; 39 using System.Threading.Tasks; 39 40 using RunCreationClient = HeuristicLab.Clients.OKB.RunCreation.RunCreationClient; 40 41 using SingleObjectiveOKBProblem = HeuristicLab.Clients.OKB.RunCreation.SingleObjectiveOKBProblem; … … 108 109 problemInstances = value; 109 110 OnPropertyChanged("ProblemInstances"); 111 } 112 } 113 114 [Storable] 115 private ResultCollection currentResult; 116 public ResultCollection CurrentResult { 117 get { return currentResult; } 118 set { 119 if (currentResult == value) return; 120 currentResult = value; 121 OnPropertyChanged("CurrentResult"); 110 122 } 111 123 } … … 327 339 "QualityPerEvaluations", "Problem Name", "Problem Type", "Algorithm Name", "Algorithm Type", "Maximization", "BestKnownQuality" 328 340 }; 341 342 public async void StartAlgorithmAsync(int index) { 343 var selectedInstance = suggestedInstances[index]; 344 var algorithm = (IAlgorithm)selectedInstance.Clone(); 345 algorithm.Prepare(true); 346 IParameter stopParam; 347 var monitorStop = true; 348 if (algorithm.Parameters.TryGetValue("MaximumEvaluations", out stopParam)) { 349 var maxEvalParam = stopParam as IValueParameter<Data.IntValue>; 350 if (maxEvalParam != null) { 351 maxEvalParam.Value.Value = MaximumEvaluations; 352 monitorStop = false; 353 } 354 } 355 algorithm.ExecutionStateChanged += AlgorithmOnExecutionStateChanged; 356 algorithm.ExceptionOccurred += AlgorithmOnExceptionOccurred; 357 if (monitorStop) algorithm.ExecutionTimeChanged += AlgorithmOnExecutionTimeChanged; 358 359 algorithm.Start(); 360 } 361 362 public void StartAlgorithm(int index) { 363 var selectedInstance = suggestedInstances[index]; 364 var algorithm = (IAlgorithm)selectedInstance.Clone(); 365 algorithm.Prepare(true); 366 IParameter stopParam; 367 var monitorStop = true; 368 if (algorithm.Parameters.TryGetValue("MaximumEvaluations", out stopParam)) { 369 var maxEvalParam = stopParam as IValueParameter<Data.IntValue>; 370 if (maxEvalParam != null) { 371 maxEvalParam.Value.Value = MaximumEvaluations; 372 monitorStop = false; 373 } 374 } 375 algorithm.ExecutionStateChanged += AlgorithmOnExecutionStateChanged; 376 algorithm.ExceptionOccurred += AlgorithmOnExceptionOccurred; 377 if (monitorStop) algorithm.ExecutionTimeChanged += AlgorithmOnExecutionTimeChanged; 378 379 using (algWh = new AutoResetEvent(false)) { 380 algorithm.Start(); 381 algWh.WaitOne(); 382 } 383 algWh = null; 384 } 385 386 private AutoResetEvent algWh; 387 388 private void AlgorithmOnExecutionStateChanged(object sender, EventArgs eventArgs) { 389 var alg = sender as IAlgorithm; 390 if (alg == null) return; 391 if (alg.ExecutionState == ExecutionState.Started) { 392 CurrentResult = alg.Results; 393 } else if (alg.ExecutionState == ExecutionState.Stopped) { 394 alg.ExecutionStateChanged -= AlgorithmOnExecutionStateChanged; 395 alg.ExceptionOccurred -= AlgorithmOnExceptionOccurred; 396 alg.ExecutionTimeChanged -= AlgorithmOnExecutionTimeChanged; 397 if (algWh != null) algWh.Set(); 398 } 399 } 400 401 private void AlgorithmOnExceptionOccurred(object sender, EventArgs<Exception> eventArgs) { 402 var alg = sender as IAlgorithm; 403 if (alg == null) return; 404 alg.ExecutionStateChanged -= AlgorithmOnExecutionStateChanged; 405 alg.ExceptionOccurred -= AlgorithmOnExceptionOccurred; 406 alg.ExecutionTimeChanged -= AlgorithmOnExecutionTimeChanged; 407 if (algWh != null) algWh.Set(); 408 } 409 410 private void AlgorithmOnExecutionTimeChanged(object sender, EventArgs eventArgs) { 411 var alg = sender as IAlgorithm; 412 if (alg == null) return; 413 IResult evalSolResult; 414 if (!alg.Results.TryGetValue("EvaluatedSolutions", out evalSolResult) || !(evalSolResult.Value is Data.IntValue)) return; 415 var evalSols = ((Data.IntValue)evalSolResult.Value).Value; 416 if (evalSols >= MaximumEvaluations) alg.Stop(); 417 } 329 418 330 419 public async void UpdateKnowledgeBaseAsync(IProgress progress) { … … 372 461 var probRun = new Run() { Name = prob.Name }; 373 462 prob.CollectParameterValues(probRun.Parameters); 463 probRun.Parameters["Problem Name"] = new StringValue(prob.Name); 464 probRun.Parameters["Problem Type"] = new StringValue(prob.GetType().Name); 374 465 progress.Status += Environment.NewLine + "Downloading characteristics..."; 375 466 foreach (var v in RunCreationClient.GetCharacteristicValues(problInst.Id)) { … … 412 503 var count = queryClient.GetNumberOfRuns(problemClassFilter); 413 504 if (count == 0) return; 414 505 415 506 var runIds = queryClient.GetRunIds(problemClassFilter).ToList(); 416 507 var conversions = new List<Task>(); … … 445 536 446 537 var probInstanceName = ((StringValue)probNameParam).Value; 447 var bkQuality = ((DoubleValue)instance.Parameters["BestKnownQuality"]).Value;448 538 var maximization = ((BoolValue)instance.Parameters["Maximization"]).Value; 539 540 IItem bkParam; 541 if (!instance.Parameters.TryGetValue("BestKnownQuality", out bkParam) || !(bkParam is DoubleValue)) { 542 Dictionary<string, List<IRun>> algRuns; 543 if (!algInstRunDict.TryGetValue(probInstanceName, out algRuns)) continue; 544 var list = algRuns.SelectMany(x => x.Value) 545 .Where(x => x.Results.ContainsKey("QualityPerEvaluations")) 546 .Select(x => ((IndexedDataTable<double>)x.Results["QualityPerEvaluations"]).Rows.First().Values.Last().Item2); 547 bkParam = new DoubleValue(maximization ? list.Max() : list.Min()); 548 instance.Parameters["BestKnownQuality"] = bkParam; 549 } else bkParam = instance.Parameters["BestKnownQuality"]; 550 551 var bkQuality = ((DoubleValue)bkParam).Value; 449 552 450 553 if (!algInstRunDict.ContainsKey(probInstanceName)) continue; 451 554 foreach (var kvp in algInstRunDict[probInstanceName]) { 452 var algInstanceName = kvp.Key;453 555 // TODO: Things needs to be configurable here (table name, targets) 454 556 foreach (var target in new[] { 1, 1.01, 1.05, 1.1, 1.2, 1.5 }) { 455 557 var result = ExpectedRuntimeHelper.CalculateErt(kvp.Value, "QualityPerEvaluations", bkQuality * target, maximization); 456 var resultName = algInstanceName+ "@" + ((target - 1) * 100) + "%";558 var resultName = kvp.Key + "@" + ((target - 1) * 100) + "%"; 457 559 IItem item; 458 560 if (instance.Results.TryGetValue(resultName, out item)) { … … 469 571 if (Problem == null) return; 470 572 var instances = new SortedList<double, IAlgorithm>(); 471 foreach (var relevantRuns in knowledgeBase.GroupBy(x => x.Algorithm)) { 573 foreach (var relevantRuns in knowledgeBase.GroupBy(x => algorithmId2RunMapping.GetBySecond(x).Single())) { 574 var algorithm = algorithmId2AlgorithmInstanceMapping.GetByFirst(relevantRuns.Key); 472 575 var avgQuality = 0.0; 473 576 var counter = 0; 474 foreach (var run in relevantRuns) { 475 var performanceGraph = ((IndexedDataTable<double>)run.Results["QualityPerEvaluations"]); 476 try { 477 avgQuality += performanceGraph.Rows.First().Values.TakeWhile(x => x.Item1 < MaximumEvaluations).Last().Item2; 478 counter++; 479 } catch { continue; } 577 foreach (var problemRuns in relevantRuns.GroupBy(x => ((StringValue)x.Parameters["Problem Name"]).Value)) { 578 var probInstance = ProblemInstances.SingleOrDefault(x => x.Name == problemRuns.Key); 579 if (probInstance == null) continue; 580 var bkQuality = ((DoubleValue)probInstance.Parameters["BestKnownQuality"]).Value; 581 foreach (var run in problemRuns) { 582 var performanceGraph = ((IndexedDataTable<double>)run.Results["QualityPerEvaluations"]); 583 try { 584 avgQuality += performanceGraph.Rows.First().Values.TakeWhile(x => x.Item1 < MaximumEvaluations).Last().Item2 / bkQuality; 585 counter++; 586 } catch { 587 continue; 588 } 589 } 480 590 } 481 591 avgQuality /= counter; 482 instances.Add(avgQuality, relevantRuns.Key);592 instances.Add(avgQuality, algorithm); 483 593 } 484 594 485 595 suggestedInstances.Clear(); 486 var instanceLadder = instances.Select(x => (IAlgorithm)x.Value.Clone()); 487 suggestedInstances.AddRange(Maximization ? instanceLadder.Reverse() : instanceLadder); 596 var instanceLadder = instances.Select(x => (IAlgorithm)x.Value.Clone()).ToList(); 597 if (Maximization) instanceLadder.Reverse(); 598 suggestedInstances.AddRange(instanceLadder); 488 599 } 489 600
Note: See TracChangeset
for help on using the changeset viewer.