Changeset 17612 for branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
- Timestamp:
- 06/19/20 16:38:33 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
r17594 r17612 45 45 public class HillClimber : BasicAlgorithm { 46 46 [Storable] 47 private IRandom random;47 private readonly IRandom random; 48 48 49 49 [Storable] public IFixedValueParameter<IntValue> MaximumIterationsParameter { get; private set; } … … 65 65 get { return MaximumIterationsParameter.Value.Value; } 66 66 set { MaximumIterationsParameter.Value.Value = value; } 67 } 68 69 private int Iterations { 70 get => IterationsResult.Value.Value; 71 set => IterationsResult.Value.Value = value; 72 } 73 74 private double BestQuality { 75 get => BestQualityResult.Value.Value; 76 set => BestQualityResult.Value.Value = value; 67 77 } 68 78 … … 88 98 } 89 99 100 protected override void Initialize(CancellationToken cancellationToken) { 101 base.Initialize(cancellationToken); 102 103 IterationsResult.Value = new IntValue(); 104 BestQualityResult.Value = new DoubleValue(double.NaN); 105 } 106 90 107 91 108 92 109 protected override void Run(CancellationToken cancellationToken) { 93 IterationsResult.Value = new IntValue();94 BestQualityResult.Value = new DoubleValue(double.NaN);95 96 110 while (IterationsResult.Value.Value < MaximumIterations) { 97 111 cancellationToken.ThrowIfCancellationRequested(); … … 106 120 107 121 fitness = ImproveToLocalOptimum(Problem, solution, fitness, random); 108 var bestSoFar = BestQuality Result.Value.Value;122 var bestSoFar = BestQuality; 109 123 if (double.IsNaN(bestSoFar) || Problem.IsBetter(fitness, bestSoFar)) { 110 BestQuality Result.Value.Value= fitness;124 BestQuality = fitness; 111 125 } 112 126 113 Iterations Result.Value.Value++;127 Iterations++; 114 128 } 115 129 }
Note: See TracChangeset
for help on using the changeset viewer.