- Timestamp:
- 07/28/15 14:41:03 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.Analysis/3.3/Optimizers/IRRestarter.cs
r12804 r12808 33 33 34 34 namespace HeuristicLab.Analysis { 35 public enum TerminationCriterium { OnlyByTime, OnlyByEvaluations, OnlyByTarget, ByTargetAndTime, ByTargetAndEvaluations, WhicheverHitsFirst, WhicheverHitsLast }35 public enum TerminationCriterium { OnlyByTime, OnlyByEvaluations, OnlyByTarget, ByTargetAndTime, ByTargetAndEvaluations, ByTimeAndEvaluations, WhicheverHitsFirst, WhicheverHitsLast } 36 36 /// <summary> 37 37 /// A run in which an algorithm is executed for a certain maximum time only. … … 43 43 private const string ExecutionTimeResultName = "Execution Time"; 44 44 private const string BestQualityResultName = "BestQuality"; 45 private const string RandomRestartsResultName = "RandomRestarts"; 45 46 46 47 public string Filename { get; set; } … … 153 154 } 154 155 155 private int lastAlgorithmEvaluatedSolutions;156 private int lastAlgorithmEvaluatedMoves;157 156 [Storable] 158 157 private double evaluations; … … 239 238 return timeHit && evalHit && targetHit 240 239 || timeHit && (TerminationCriterium == TerminationCriterium.OnlyByTime 240 || TerminationCriterium == TerminationCriterium.WhicheverHitsFirst 241 241 || TerminationCriterium == TerminationCriterium.ByTargetAndTime 242 || TerminationCriterium == TerminationCriterium. WhicheverHitsFirst)242 || TerminationCriterium == TerminationCriterium.ByTimeAndEvaluations) 243 243 || evalHit && (TerminationCriterium == TerminationCriterium.OnlyByEvaluations 244 || TerminationCriterium == TerminationCriterium.WhicheverHitsFirst 244 245 || TerminationCriterium == TerminationCriterium.ByTargetAndEvaluations 245 || TerminationCriterium == TerminationCriterium. WhicheverHitsFirst)246 || TerminationCriterium == TerminationCriterium.ByTimeAndEvaluations) 246 247 || targetHit && (TerminationCriterium == TerminationCriterium.OnlyByTarget 247 248 || TerminationCriterium == TerminationCriterium.WhicheverHitsFirst … … 267 268 bestSoFar = original.bestSoFar; 268 269 lastAlgorithmExecutionTime = original.lastAlgorithmExecutionTime; 269 lastAlgorithmEvaluatedSolutions = original.lastAlgorithmEvaluatedSolutions;270 lastAlgorithmEvaluatedMoves = original.lastAlgorithmEvaluatedMoves;271 270 272 271 perClockAnalyzer = cloner.Clone(original.perClockAnalyzer); … … 294 293 bestSoFar = double.NaN; 295 294 lastAlgorithmExecutionTime = TimeSpan.Zero; 296 lastAlgorithmEvaluatedSolutions = 0;297 lastAlgorithmEvaluatedMoves = 0;298 295 299 296 perClockAnalyzer = new QualityPerClockAnalyzer(); … … 316 313 bestSoFar = double.NaN; 317 314 lastAlgorithmExecutionTime = TimeSpan.Zero; 318 lastAlgorithmEvaluatedSolutions = 0;319 lastAlgorithmEvaluatedMoves = 0;320 315 321 316 perClockAnalyzer = new QualityPerClockAnalyzer(); … … 337 332 bestSoFar = double.NaN; 338 333 lastAlgorithmExecutionTime = TimeSpan.Zero; 339 lastAlgorithmEvaluatedSolutions = 0;340 lastAlgorithmEvaluatedMoves = 0;341 334 342 335 perClockAnalyzer = new QualityPerClockAnalyzer(); … … 366 359 BestSoFar = double.NaN; 367 360 lastAlgorithmExecutionTime = TimeSpan.Zero; 368 lastAlgorithmEvaluatedSolutions = 0;369 lastAlgorithmEvaluatedMoves = 0;370 361 371 362 CurrentRun = null; … … 399 390 CurrentRun.Results.Add(perEvaluationsAnalyzer.EvaluatedMovesParameter.ActualName, new IntValue(0)); 400 391 CurrentRun.Results.Add(BestQualityResultName, new DoubleValue(Maximization ? double.MinValue : double.MaxValue)); 392 CurrentRun.Results.Add(RandomRestartsResultName, new IntValue(0)); 401 393 } 402 394 Algorithm.Start(); … … 492 484 algorithm.ExceptionOccurred += Algorithm_ExceptionOccurred; 493 485 algorithm.ExecutionTimeChanged += Algorithm_ExecutionTimeChanged; 494 algorithm.ExecutionStateChanged += Algorithm_ExecutionStateChanged;495 486 algorithm.Paused += Algorithm_Paused; 496 487 algorithm.Prepared += Algorithm_Prepared; 497 algorithm.Started += Algorithm_Started;498 488 algorithm.Stopped += Algorithm_Stopped; 499 489 algorithm.ProblemChanged += Algorithm_ProblemChanged; … … 503 493 algorithm.ExceptionOccurred -= Algorithm_ExceptionOccurred; 504 494 algorithm.ExecutionTimeChanged -= Algorithm_ExecutionTimeChanged; 505 algorithm.ExecutionStateChanged -= Algorithm_ExecutionStateChanged;506 495 algorithm.Paused -= Algorithm_Paused; 507 496 algorithm.Prepared -= Algorithm_Prepared; 508 algorithm.Started -= Algorithm_Started;509 497 algorithm.Stopped -= Algorithm_Stopped; 510 498 algorithm.ProblemChanged -= Algorithm_ProblemChanged; … … 514 502 } 515 503 private void Algorithm_ExecutionTimeChanged(object sender, EventArgs e) { 516 if (Algorithm.ExecutionState != ExecutionState.Started) return; 517 518 if (ExecutionState == ExecutionState.Started) 519 UpdateAlgorithmResults(); 520 521 if (IsFinished && ExecutionState != ExecutionState.Stopped) { 522 Algorithm.Stop(); 523 } 524 OnExecutionTimeChanged(); 525 } 526 527 private void Algorithm_ExecutionStateChanged(object sender, EventArgs e) { 528 //OnExecutionStateChanged(); 504 ExecutionTime += Algorithm.ExecutionTime - lastAlgorithmExecutionTime; 505 lastAlgorithmExecutionTime = Algorithm.ExecutionTime; 529 506 } 530 507 private void Algorithm_Paused(object sender, EventArgs e) { 531 UpdateAlgorithmResults(); 508 ExecutionTime += Algorithm.ExecutionTime - lastAlgorithmExecutionTime; 509 lastAlgorithmExecutionTime = Algorithm.ExecutionTime; 532 510 OnPaused(); 533 511 } 534 512 private void Algorithm_Prepared(object sender, EventArgs e) { 535 lastAlgorithmEvaluatedSolutions = 0;536 lastAlgorithmEvaluatedMoves = 0;537 513 lastAlgorithmExecutionTime = TimeSpan.Zero; 538 }539 private void Algorithm_Started(object sender, EventArgs e) {540 //OnStarted();541 514 } 542 515 private void Algorithm_Stopped(object sender, EventArgs e) { 543 516 var bestQuality = UpdateAlgorithmResults(); 544 517 545 var execTime = ((TimeSpanValue) currentRun.Results[ExecutionTimeResultName]).Value;518 var execTime = ((TimeSpanValue)CurrentRun.Results[ExecutionTimeResultName]).Value; 546 519 foreach (var result in Algorithm.Results) { 547 520 if (result.Name == perClockAnalyzer.QualityPerClockParameter.ResultName) { 548 if (! currentRun.Results.ContainsKey(result.Name))549 currentRun.Results.Add(result.Name, (IItem)result.Value.Clone());521 if (!CurrentRun.Results.ContainsKey(result.Name)) 522 CurrentRun.Results.Add(result.Name, (IItem)result.Value.Clone()); 550 523 else { 551 var dt = (IndexedDataTable<double>) currentRun.Results[result.Name];524 var dt = (IndexedDataTable<double>)CurrentRun.Results[result.Name]; 552 525 var best = dt.Rows.First().Values.Last().Item2; 553 526 var resultDt = (IndexedDataTable<double>)result.Value; … … 560 533 } 561 534 } else if (result.Name == perEvaluationsAnalyzer.QualityPerEvaluationsParameter.ResultName) { 562 if (! currentRun.Results.ContainsKey(result.Name))563 currentRun.Results.Add(result.Name, (IItem)result.Value.Clone());535 if (!CurrentRun.Results.ContainsKey(result.Name)) 536 CurrentRun.Results.Add(result.Name, (IItem)result.Value.Clone()); 564 537 else { 565 var dt = (IndexedDataTable<double>) currentRun.Results[result.Name];566 var evalSols = ((IntValue) currentRun.Results[perEvaluationsAnalyzer.EvaluatedSolutionsParameter.ActualName]).Value;567 var evalMoves = ((IntValue) currentRun.Results[perEvaluationsAnalyzer.EvaluatedMovesParameter.ActualName]).Value;538 var dt = (IndexedDataTable<double>)CurrentRun.Results[result.Name]; 539 var evalSols = ((IntValue)CurrentRun.Results[perEvaluationsAnalyzer.EvaluatedSolutionsParameter.ActualName]).Value; 540 var evalMoves = ((IntValue)CurrentRun.Results[perEvaluationsAnalyzer.EvaluatedMovesParameter.ActualName]).Value; 568 541 var best = dt.Rows.First().Values.Last().Item2; 569 542 var resultDt = (IndexedDataTable<double>)result.Value; … … 576 549 } 577 550 } else if (result.Name == perEvaluationsAnalyzer.EvaluatedSolutionsParameter.ActualName) { 578 var evalSols = ((IntValue) currentRun.Results[perEvaluationsAnalyzer.EvaluatedSolutionsParameter.ActualName]);579 evalSols.Value += ((IntValue)result.Value).Value;551 var evalSols = ((IntValue)CurrentRun.Results[perEvaluationsAnalyzer.EvaluatedSolutionsParameter.ActualName]).Value; 552 CurrentRun.Results[perEvaluationsAnalyzer.EvaluatedSolutionsParameter.ActualName] = new IntValue(evalSols + ((IntValue)result.Value).Value); 580 553 } else if (result.Name == perEvaluationsAnalyzer.EvaluatedMovesParameter.ActualName) { 581 var evalMoves = ((IntValue) currentRun.Results[perEvaluationsAnalyzer.EvaluatedMovesParameter.ActualName]);582 evalMoves.Value += ((IntValue)result.Value).Value;554 var evalMoves = ((IntValue)CurrentRun.Results[perEvaluationsAnalyzer.EvaluatedMovesParameter.ActualName]).Value; 555 CurrentRun.Results[perEvaluationsAnalyzer.EvaluatedMovesParameter.ActualName] = new IntValue(evalMoves + ((IntValue)result.Value).Value); 583 556 } else if (result.Name == perEvaluationsAnalyzer.BestQualityParameter.ActualName) { 584 var best = ((DoubleValue) currentRun.Results[BestQualityResultName]).Value;557 var best = ((DoubleValue)CurrentRun.Results[BestQualityResultName]).Value; 585 558 if (Maximization && best < bestQuality || !Maximization && best > bestQuality) 586 currentRun.Results[BestQualityResultName] = new DoubleValue(bestQuality);559 CurrentRun.Results[BestQualityResultName] = new DoubleValue(bestQuality); 587 560 } else if (result.Name.ToLower().EndsWith("solution") && BestSoFar == bestQuality) { 588 if ( currentRun.Results.ContainsKey(result.Name))589 currentRun.Results[result.Name] = (IItem)result.Value.Clone();590 else currentRun.Results.Add(result.Name, (IItem)result.Value.Clone());561 if (CurrentRun.Results.ContainsKey(result.Name)) 562 CurrentRun.Results[result.Name] = (IItem)result.Value.Clone(); 563 else CurrentRun.Results.Add(result.Name, (IItem)result.Value.Clone()); 591 564 } 592 565 } 593 currentRun.Results[ExecutionTimeResultName] = new TimeSpanValue(execTime + Algorithm.ExecutionTime);566 CurrentRun.Results[ExecutionTimeResultName] = new TimeSpanValue(execTime + Algorithm.ExecutionTime); 594 567 595 568 if (!forceStop && !IsFinished) { 569 CurrentRun.Results[RandomRestartsResultName] = new IntValue(1 + ((IntValue)CurrentRun.Results[RandomRestartsResultName]).Value); 596 570 Algorithm.Prepare(); 597 571 Algorithm.Start(); 598 572 } else { 599 573 forceStop = false; 600 Runs.Add(currentRun); 601 currentRun = null; 574 Runs.Add(CurrentRun); 602 575 Algorithm.Prepare(true); 603 576 ExecutionState = ExecutionState.Stopped; … … 613 586 if (Algorithm.Results.TryGetValue(perEvaluationsAnalyzer.EvaluatedSolutionsParameter.ActualName, out evaluationsResult)) { 614 587 var evals = ((IntValue)evaluationsResult.Value).Value; 615 Evaluations += evals - lastAlgorithmEvaluatedSolutions; 616 lastAlgorithmEvaluatedSolutions = evals; 588 Evaluations += evals; 617 589 } 618 590 if (Algorithm.Results.TryGetValue(perEvaluationsAnalyzer.EvaluatedMovesParameter.ActualName, out evaluationsResult)) { 619 591 var evals = ((IntValue)evaluationsResult.Value).Value; 620 Evaluations += moveCostPerSolution * (evals - lastAlgorithmEvaluatedMoves); 621 lastAlgorithmEvaluatedMoves = evals; 592 Evaluations += moveCostPerSolution * evals; 622 593 } 623 594 if (Algorithm.Results.TryGetValue(perEvaluationsAnalyzer.BestQualityParameter.ActualName, out evaluationsResult)) {
Note: See TracChangeset
for help on using the changeset viewer.