Changeset 14542 for branches/symbreg-factors-2650/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
- Timestamp:
- 01/04/17 16:33:37 (7 years ago)
- Location:
- branches/symbreg-factors-2650
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650
- Property svn:mergeinfo changed
/trunk/sources merged: 14504,14506-14509,14516-14517,14519,14522-14523,14527-14529,14531-14533
- Property svn:mergeinfo changed
-
branches/symbreg-factors-2650/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
r14185 r14542 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 { 52 54 get { return typeof(BinaryProblem); } 53 55 } 56 57 public override bool SupportsPause { get { return false; } } 58 54 59 public new BinaryProblem Problem { 55 60 get { return (BinaryProblem)base.Problem; } … … 65 70 set { IterationsParameter.Value.Value = value; } 66 71 } 72 73 #region ResultsProperties 74 private double ResultsBestQuality { 75 get { return ((DoubleValue)Results[BestQualityResultName].Value).Value; } 76 set { ((DoubleValue)Results[BestQualityResultName].Value).Value = value; } 77 } 78 private int ResultsIterations { 79 get { return ((IntValue)Results[IterationsResultName].Value).Value; } 80 set { ((IntValue)Results[IterationsResultName].Value).Value = value; } 81 } 82 #endregion 67 83 68 84 [StorableConstructor] … … 80 96 Parameters.Add(new FixedValueParameter<IntValue>(IterationsParameterName, "", new IntValue(100))); 81 97 } 98 99 100 protected override void Initialize(CancellationToken cancellationToken) { 101 Results.Add(new Result(BestQualityResultName, new DoubleValue(double.NaN))); 102 Results.Add(new Result(IterationsResultName, new IntValue(0))); 103 base.Initialize(cancellationToken); 104 } 82 105 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++) { 106 while (ResultsIterations < Iterations) { 107 cancellationToken.ThrowIfCancellationRequested(); 108 86 109 var solution = new BinaryVector(Problem.Length); 87 110 for (int i = 0; i < solution.Length; i++) { … … 92 115 93 116 fitness = ImproveToLocalOptimum(Problem, solution, fitness, random); 94 if (double.IsNaN( BestQuality.Value) || Problem.IsBetter(fitness, BestQuality.Value)) {95 BestQuality.Value= fitness;117 if (double.IsNaN(ResultsBestQuality) || Problem.IsBetter(fitness, ResultsBestQuality)) { 118 ResultsBestQuality = fitness; 96 119 } 120 121 ResultsIterations++; 97 122 } 98 123 }
Note: See TracChangeset
for help on using the changeset viewer.