Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 14517,14523,14527
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
r14186 r15061 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 } -
stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs
r14186 r15061 56 56 57 57 // Tracks all solutions in Pyramid for quick membership checks 58 private HashSet<BinaryVector> seen = new HashSet<BinaryVector>(new EnumerableBoolEqualityComparer());58 private readonly HashSet<BinaryVector> seen = new HashSet<BinaryVector>(new EnumerableBoolEqualityComparer()); 59 59 60 60 #region ParameterNames … … 152 152 } 153 153 #endregion 154 155 public override bool SupportsPause { get { return true; } } 154 156 155 157 [StorableConstructor] … … 213 215 } 214 216 215 protected override void Run(CancellationToken cancellationToken) {217 protected override void Initialize(CancellationToken cancellationToken) { 216 218 // Set up the algorithm 217 219 if (SetSeedRandomly) Seed = new System.Random().Next(); … … 242 244 Results.Add(new Result("Stored Solutions", table)); 243 245 246 base.Initialize(cancellationToken); 247 } 248 249 protected override void Run(CancellationToken cancellationToken) { 244 250 // Loop until iteration limit reached or canceled. 245 for (ResultsIterations = 0; ResultsIterations < MaximumIterations; ResultsIterations++) {251 while (ResultsIterations < MaximumIterations) { 246 252 double fitness = double.NaN; 247 253 248 254 try { 249 255 fitness = iterate(); 256 ResultsIterations++; 250 257 cancellationToken.ThrowIfCancellationRequested(); 251 258 } finally {
Note: See TracChangeset
for help on using the changeset viewer.