Changeset 17594 for branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
- Timestamp:
- 06/10/20 12:15:23 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
r17517 r17594 31 31 using HeuristicLab.Encodings.BinaryVectorEncoding; 32 32 using HeuristicLab.Optimization; 33 33 34 using HeuristicLab.Parameters; 34 35 using HeuristicLab.Random; … … 47 48 48 49 [Storable] public IFixedValueParameter<IntValue> MaximumIterationsParameter { get; private set; } 49 [Storable] public IResultParameter<DoubleValue> BestQualityResultParameter { get; private set; } 50 [Storable] public IResultParameter<IntValue> IterationsResultParameter { get; private set; } 50 51 [Storable] public IResult<DoubleValue> BestQualityResult { get; private set; } 52 [Storable] public IResult<IntValue> IterationsResult { get; private set; } 51 53 52 54 public override Type ProblemType { … … 70 72 : base(original, cloner) { 71 73 MaximumIterationsParameter = cloner.Clone(original.MaximumIterationsParameter); 72 BestQualityResult Parameter = cloner.Clone(original.BestQualityResultParameter);73 IterationsResult Parameter = cloner.Clone(original.IterationsResultParameter);74 BestQualityResult = cloner.Clone(original.BestQualityResult); 75 IterationsResult = cloner.Clone(original.IterationsResult); 74 76 } 75 77 public override IDeepCloneable Clone(Cloner cloner) { … … 81 83 random = new MersenneTwister(); 82 84 Parameters.Add(MaximumIterationsParameter = new FixedValueParameter<IntValue>("Maximum Iterations", "", new IntValue(100))); 83 Parameters.Add(BestQualityResultParameter = new ResultParameter<DoubleValue>("Best Quality", "", "Results", new DoubleValue(double.NaN))); 84 Parameters.Add(IterationsResultParameter = new ResultParameter<IntValue>("Iterations", "", "Results", new IntValue(0))); 85 86 Results.Add(BestQualityResult = new Result<DoubleValue>("Best Quality")); 87 Results.Add(IterationsResult = new Result<IntValue>("Iterations")); 85 88 } 86 89 90 91 87 92 protected override void Run(CancellationToken cancellationToken) { 88 while (IterationsResultParameter.ActualValue.Value < MaximumIterations) { 93 IterationsResult.Value = new IntValue(); 94 BestQualityResult.Value = new DoubleValue(double.NaN); 95 96 while (IterationsResult.Value.Value < MaximumIterations) { 89 97 cancellationToken.ThrowIfCancellationRequested(); 90 98 … … 98 106 99 107 fitness = ImproveToLocalOptimum(Problem, solution, fitness, random); 100 var bestSoFar = BestQualityResult Parameter.ActualValue.Value;108 var bestSoFar = BestQualityResult.Value.Value; 101 109 if (double.IsNaN(bestSoFar) || Problem.IsBetter(fitness, bestSoFar)) { 102 BestQualityResult Parameter.ActualValue.Value = fitness;110 BestQualityResult.Value.Value = fitness; 103 111 } 104 112 105 IterationsResult Parameter.ActualValue.Value++;113 IterationsResult.Value.Value++; 106 114 } 107 115 }
Note: See TracChangeset
for help on using the changeset viewer.