Changeset 13378 for branches/PausableBasicAlgorithm/HeuristicLab.Algorithms.ParameterlessPopulationPyramid
- Timestamp:
- 11/24/15 17:46:18 (9 years ago)
- Location:
- branches/PausableBasicAlgorithm/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PausableBasicAlgorithm/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
r13173 r13378 48 48 49 49 private const string IterationsParameterName = "Iterations"; 50 private const string BestQualityResultName = "Best quality"; 51 private const string IterationsResultName = "Iterations"; 52 53 public override bool Pausable { get { return true; } } 50 54 51 55 public override Type ProblemType { … … 66 70 } 67 71 72 #region ResultsProperties 73 private double ResultsBestQuality { 74 get { return ((DoubleValue)Results[BestQualityResultName].Value).Value; } 75 set { ((DoubleValue)Results[BestQualityResultName].Value).Value = value; } 76 } 77 private int ResultsIterations { 78 get { return ((IntValue)Results[IterationsResultName].Value).Value; } 79 set { ((IntValue)Results[IterationsResultName].Value).Value = value; } 80 } 81 #endregion 82 68 83 [StorableConstructor] 69 84 protected HillClimber(bool deserializing) : base(deserializing) { } … … 80 95 Parameters.Add(new FixedValueParameter<IntValue>(IterationsParameterName, "", new IntValue(100))); 81 96 } 97 protected override void Initialize(CancellationToken cancellationToken) { 98 Results.Add(new Result(BestQualityResultName, new DoubleValue(double.NaN))); 99 Results.Add(new Result(IterationsResultName, new IntValue(0))); 100 base.Initialize(cancellationToken); 101 } 82 102 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++) { 103 while (ResultsIterations < Iterations) { 104 cancellationToken.ThrowIfCancellationRequested(); 105 86 106 var solution = new BinaryVector(Problem.Length); 87 107 for (int i = 0; i < solution.Length; i++) { … … 92 112 93 113 fitness = ImproveToLocalOptimum(Problem, solution, fitness, random); 94 if (double.IsNaN( BestQuality.Value) || Problem.IsBetter(fitness, BestQuality.Value)) {95 BestQuality.Value= fitness;114 if (double.IsNaN(ResultsBestQuality) || Problem.IsBetter(fitness, ResultsBestQuality)) { 115 ResultsBestQuality = fitness; 96 116 } 117 118 ResultsIterations++; 97 119 } 98 120 } -
branches/PausableBasicAlgorithm/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs
r13173 r13378 213 213 } 214 214 215 protected override void Run(CancellationToken cancellationToken) {215 protected override void Initialize(CancellationToken cancellationToken) { 216 216 // Set up the algorithm 217 217 if (SetSeedRandomly) Seed = new System.Random().Next(); … … 242 242 Results.Add(new Result("Stored Solutions", table)); 243 243 244 base.Initialize(cancellationToken); 245 } 246 247 protected override void Run(CancellationToken cancellationToken) { 244 248 // Loop until iteration limit reached or canceled. 245 for (ResultsIterations = 0; ResultsIterations < MaximumIterations; ResultsIterations++) { 246 double fitness = double.NaN; 247 248 try { 249 fitness = iterate(); 250 cancellationToken.ThrowIfCancellationRequested(); 251 } finally { 252 ResultsEvaluations = tracker.Evaluations; 253 ResultsBestSolution = new BinaryVector(tracker.BestSolution); 254 ResultsBestQuality = tracker.BestQuality; 255 ResultsBestFoundOnEvaluation = tracker.BestFoundOnEvaluation; 256 ResultsQualitiesBest.Values.Add(tracker.BestQuality); 257 ResultsQualitiesIteration.Values.Add(fitness); 258 ResultsLevels.Values.Add(pyramid.Count); 259 ResultsSolutions.Values.Add(seen.Count); 260 } 249 while (ResultsIterations < MaximumIterations) { 250 cancellationToken.ThrowIfCancellationRequested(); 251 double fitness = iterate(); 252 253 ResultsEvaluations = tracker.Evaluations; 254 ResultsBestSolution = new BinaryVector(tracker.BestSolution); 255 ResultsBestQuality = tracker.BestQuality; 256 ResultsBestFoundOnEvaluation = tracker.BestFoundOnEvaluation; 257 ResultsQualitiesBest.Values.Add(tracker.BestQuality); 258 ResultsQualitiesIteration.Values.Add(fitness); 259 ResultsLevels.Values.Add(pyramid.Count); 260 ResultsSolutions.Values.Add(seen.Count); 261 262 ResultsIterations++; 261 263 } 262 264 }
Note: See TracChangeset
for help on using the changeset viewer.