Changeset 17517 for branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid
- Timestamp:
- 04/20/20 17:31:31 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
r17382 r17517 46 46 private IRandom random; 47 47 48 private const string IterationsParameterName = "Iterations";49 private const string BestQualityResultName = "Best quality";50 private const string IterationsResultName = "Iterations";48 [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; } 51 51 52 52 public override Type ProblemType { … … 60 60 public override bool SupportsPause { get { return false; } } 61 61 62 public IFixedValueParameter<IntValue> IterationsParameter { 63 get { return (IFixedValueParameter<IntValue>)Parameters[IterationsParameterName]; } 62 public int MaximumIterations { 63 get { return MaximumIterationsParameter.Value.Value; } 64 set { MaximumIterationsParameter.Value.Value = value; } 64 65 } 65 66 public int Iterations {67 get { return IterationsParameter.Value.Value; }68 set { IterationsParameter.Value.Value = value; }69 }70 71 #region ResultsProperties72 private double ResultsBestQuality {73 get { return ((DoubleValue)Results[BestQualityResultName].Value).Value; }74 set { ((DoubleValue)Results[BestQualityResultName].Value).Value = value; }75 }76 private int ResultsIterations {77 get { return ((IntValue)Results[IterationsResultName].Value).Value; }78 set { ((IntValue)Results[IterationsResultName].Value).Value = value; }79 }80 #endregion81 66 82 67 [StorableConstructor] … … 84 69 protected HillClimber(HillClimber original, Cloner cloner) 85 70 : base(original, cloner) { 71 MaximumIterationsParameter = cloner.Clone(original.MaximumIterationsParameter); 72 BestQualityResultParameter = cloner.Clone(original.BestQualityResultParameter); 73 IterationsResultParameter = cloner.Clone(original.IterationsResultParameter); 86 74 } 87 75 public override IDeepCloneable Clone(Cloner cloner) { … … 92 80 : base() { 93 81 random = new MersenneTwister(); 94 Parameters.Add(new FixedValueParameter<IntValue>(IterationsParameterName, "", new IntValue(100))); 82 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))); 95 85 } 96 86 97 98 protected override void Initialize(CancellationToken cancellationToken) {99 Results.Add(new Result(BestQualityResultName, new DoubleValue(double.NaN)));100 Results.Add(new Result(IterationsResultName, new IntValue(0)));101 base.Initialize(cancellationToken);102 }103 87 protected override void Run(CancellationToken cancellationToken) { 104 while ( ResultsIterations <Iterations) {88 while (IterationsResultParameter.ActualValue.Value < MaximumIterations) { 105 89 cancellationToken.ThrowIfCancellationRequested(); 106 90 … … 114 98 115 99 fitness = ImproveToLocalOptimum(Problem, solution, fitness, random); 116 if (double.IsNaN(ResultsBestQuality) || Problem.IsBetter(fitness, ResultsBestQuality)) { 117 ResultsBestQuality = fitness; 100 var bestSoFar = BestQualityResultParameter.ActualValue.Value; 101 if (double.IsNaN(bestSoFar) || Problem.IsBetter(fitness, bestSoFar)) { 102 BestQualityResultParameter.ActualValue.Value = fitness; 118 103 } 119 104 120 ResultsIterations++;105 IterationsResultParameter.ActualValue.Value++; 121 106 } 122 107 }
Note: See TracChangeset
for help on using the changeset viewer.