Changeset 14517 for trunk/sources/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
- Timestamp:
- 12/22/16 10:07:46 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
r14185 r14517 48 48 49 49 private const string IterationsParameterName = "Iterations"; 50 private const string BestQualityResultName = "Best quality"; 51 private const string IterationsResultName = "Iterations"; 50 52 51 53 public override Type ProblemType { … … 66 68 } 67 69 70 #region ResultsProperties 71 private double ResultsBestQuality { 72 get { return ((DoubleValue)Results[BestQualityResultName].Value).Value; } 73 set { ((DoubleValue)Results[BestQualityResultName].Value).Value = value; } 74 } 75 private int ResultsIterations { 76 get { return ((IntValue)Results[IterationsResultName].Value).Value; } 77 set { ((IntValue)Results[IterationsResultName].Value).Value = value; } 78 } 79 #endregion 80 68 81 [StorableConstructor] 69 82 protected HillClimber(bool deserializing) : base(deserializing) { } … … 77 90 public HillClimber() 78 91 : base() { 92 pausable = true; 79 93 random = new MersenneTwister(); 80 94 Parameters.Add(new FixedValueParameter<IntValue>(IterationsParameterName, "", new IntValue(100))); 81 95 } 96 97 [StorableHook(HookType.AfterDeserialization)] 98 private void AfterDeserialization() { 99 // BackwardsCompatibility3.3 100 #region Backwards compatible code, remove with 3.4 101 pausable = true; 102 #endregion 103 } 104 105 protected override void Initialize(CancellationToken cancellationToken) { 106 Results.Add(new Result(BestQualityResultName, new DoubleValue(double.NaN))); 107 Results.Add(new Result(IterationsResultName, new IntValue(0))); 108 base.Initialize(cancellationToken); 109 } 82 110 protected override void Run(CancellationToken cancellationToken) { 83 var BestQuality = new DoubleValue(double.NaN);84 Results.Add(new Result("Best quality", BestQuality));85 for (int iteration = 0; iteration < Iterations; iteration++) { 111 while (ResultsIterations < Iterations) { 112 cancellationToken.ThrowIfCancellationRequested(); 113 86 114 var solution = new BinaryVector(Problem.Length); 87 115 for (int i = 0; i < solution.Length; i++) { … … 92 120 93 121 fitness = ImproveToLocalOptimum(Problem, solution, fitness, random); 94 if (double.IsNaN( BestQuality.Value) || Problem.IsBetter(fitness, BestQuality.Value)) {95 BestQuality.Value= fitness;122 if (double.IsNaN(ResultsBestQuality) || Problem.IsBetter(fitness, ResultsBestQuality)) { 123 ResultsBestQuality = fitness; 96 124 } 125 126 ResultsIterations++; 97 127 } 98 128 }
Note: See TracChangeset
for help on using the changeset viewer.