Changeset 3750
- Timestamp:
- 05/10/10 17:19:34 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 1 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.EvolutionStrategy/3.3/EvolutionStrategyMainLoop.cs
r3715 r3750 154 154 ConditionalBranch conditionalBranch = new ConditionalBranch(); 155 155 156 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); 156 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Class EvolutionStrategy expects this to be called Generations 157 157 158 158 resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Generations")); -
trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/GeneticAlgorithm.cs
r3680 r3750 213 213 ParameterizeSelectors(); 214 214 ParameterizeAnalyzers(); 215 ParameterizeIterationBasedOperators(); 215 216 UpdateCrossovers(); 216 217 UpdateMutators(); … … 236 237 protected override void Problem_OperatorsChanged(object sender, EventArgs e) { 237 238 foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op); 239 ParameterizeIterationBasedOperators(); 238 240 UpdateCrossovers(); 239 241 UpdateMutators(); … … 307 309 qualityAnalyzer.QualityParameter.Depth = 1; 308 310 qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name; 311 } 312 } 313 private void ParameterizeIterationBasedOperators() { 314 if (Problem != null) { 315 foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) { 316 op.IterationsParameter.ActualName = "Generations"; 317 op.MaximumIterationsParameter.ActualName = "MaximumGenerations"; 318 } 309 319 } 310 320 } -
trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/GeneticAlgorithmMainLoop.cs
r3715 r3750 130 130 ConditionalBranch conditionalBranch = new ConditionalBranch(); 131 131 132 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); 132 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Class GeneticAlgorithm expects this to be called Generations 133 133 134 134 resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Generations")); -
trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/IslandGeneticAlgorithm.cs
r3704 r3750 304 304 ParameterizeSelectors(); 305 305 ParameterizeAnalyzers(); 306 ParameterizeIterationBasedOperators(); 306 307 UpdateCrossovers(); 307 308 UpdateMutators(); … … 327 328 protected override void Problem_OperatorsChanged(object sender, EventArgs e) { 328 329 foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op); 330 ParameterizeIterationBasedOperators(); 329 331 UpdateCrossovers(); 330 332 UpdateMutators(); … … 431 433 } 432 434 } 435 private void ParameterizeIterationBasedOperators() { 436 if (Problem != null) { 437 foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) { 438 op.IterationsParameter.ActualName = "Generations"; 439 op.MaximumIterationsParameter.ActualName = "MaximumGenerations"; 440 } 441 } 442 } 433 443 private void UpdateCrossovers() { 434 444 ICrossover oldCrossover = CrossoverParameter.Value; -
trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/IslandGeneticAlgorithmMainLoop.cs
r3715 r3750 177 177 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Migrations", new IntValue(0))); 178 178 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("GenerationsSinceLastMigration", new IntValue(0))); 179 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); 179 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Class IslandGeneticAlgorithm expects this to be called Generations 180 180 181 181 islandVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>("Results", new ResultCollection())); -
trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearch.cs
r3689 r3750 197 197 ParameterizeSolutionsCreator(); 198 198 ParameterizeMainLoop(); 199 ParameterizeMoveEvaluators();200 ParameterizeMoveMakers();201 ParameterizeAnalyzers();202 199 UpdateMoveGenerator(); 203 200 UpdateMoveParameters(); 204 201 UpdateAnalyzers(); 202 ParameterizeMoveEvaluators(); 203 ParameterizeMoveMakers(); 204 ParameterizeAnalyzers(); 205 ParameterizeIterationBasedOperators(); 205 206 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 206 207 base.OnProblemChanged(); … … 236 237 ParameterizeMoveMakers(); 237 238 ParameterizeAnalyzers(); 239 ParameterizeIterationBasedOperators(); 238 240 base.Problem_OperatorsChanged(sender, e); 239 241 } … … 366 368 } 367 369 } 370 private void ParameterizeIterationBasedOperators() { 371 if (Problem != null) { 372 foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) { 373 op.IterationsParameter.ActualName = "Iterations"; 374 op.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name; 375 } 376 } 377 } 368 378 #endregion 369 379 } -
trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearchMainLoop.cs
r3715 r3750 137 137 ConditionalBranch iterationsTermination = new ConditionalBranch(); 138 138 139 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0))); 139 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0))); // Class LocalSearch expects this to be called Iterations 140 140 variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("BestQuality", new DoubleValue(0))); 141 141 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedMoves", new IntValue(0))); -
trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/IslandOffspringSelectionGeneticAlgorithm.cs
r3744 r3750 373 373 ParameterizeSelectors(); 374 374 ParameterizeAnalyzers(); 375 ParameterizeIterationBasedOperators(); 375 376 UpdateCrossovers(); 376 377 UpdateMutators(); … … 396 397 protected override void Problem_OperatorsChanged(object sender, EventArgs e) { 397 398 foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op); 399 ParameterizeIterationBasedOperators(); 398 400 UpdateCrossovers(); 399 401 UpdateMutators(); … … 542 544 } 543 545 } 546 private void ParameterizeIterationBasedOperators() { 547 if (Problem != null) { 548 foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) { 549 op.IterationsParameter.ActualName = "Generations"; 550 op.MaximumIterationsParameter.ActualName = MaximumGenerationsParameter.Name; 551 } 552 } 553 } 544 554 private void UpdateCrossovers() { 545 555 ICrossover oldCrossover = CrossoverParameter.Value; -
trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/IslandOffspringSelectionGeneticAlgorithmMainLoop.cs
r3744 r3750 210 210 211 211 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Migrations", new IntValue(0))); 212 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); 212 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Class IslandOffspringSelectionGeneticAlgorithm expects this to be called Generations 213 213 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("GenerationsSinceLastMigration", new IntValue(0))); 214 214 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("TerminatedIslands", new IntValue(0))); -
trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithm.cs
r3744 r3750 284 284 ParameterizeSelectors(); 285 285 ParameterizeAnalyzers(); 286 ParameterizeIterationBasedOperators(); 286 287 UpdateCrossovers(); 287 288 UpdateMutators(); … … 307 308 protected override void Problem_OperatorsChanged(object sender, EventArgs e) { 308 309 foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op); 310 ParameterizeIterationBasedOperators(); 309 311 UpdateCrossovers(); 310 312 UpdateMutators(); … … 394 396 } 395 397 } 398 private void ParameterizeIterationBasedOperators() { 399 if (Problem != null) { 400 foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) { 401 op.IterationsParameter.ActualName = "Generations"; 402 op.MaximumIterationsParameter.ActualName = MaximumGenerationsParameter.Name; 403 } 404 } 405 } 396 406 private void UpdateCrossovers() { 397 407 ICrossover oldCrossover = CrossoverParameter.Value; -
trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithmMainLoop.cs
r3744 r3750 139 139 ConditionalBranch conditionalBranch2 = new ConditionalBranch(); 140 140 141 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); 141 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Class OffspringSelectionGeneticAlgorithm expects this to be called Generations 142 142 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedSolutions", new IntValue(0))); 143 143 variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("SelectionPressure", new DoubleValue(0))); -
trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/SASEGASA.cs
r3744 r3750 332 332 ParameterizeSelectors(); 333 333 ParameterizeAnalyzers(); 334 ParameterizeIterationBasedOperators(); 334 335 UpdateCrossovers(); 335 336 UpdateMutators(); … … 355 356 protected override void Problem_OperatorsChanged(object sender, EventArgs e) { 356 357 foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op); 358 ParameterizeIterationBasedOperators(); 357 359 UpdateCrossovers(); 358 360 UpdateMutators(); … … 480 482 } 481 483 } 484 private void ParameterizeIterationBasedOperators() { 485 if (Problem != null) { 486 foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) { 487 op.IterationsParameter.ActualName = "Generations"; 488 op.MaximumIterationsParameter.ActualName = MaximumGenerationsParameter.Name; 489 } 490 } 491 } 482 492 private void UpdateCrossovers() { 483 493 ICrossover oldCrossover = CrossoverParameter.Value; -
trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/SASEGASAMainLoop.cs
r3744 r3750 191 191 192 192 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Reunifications", new IntValue(0))); 193 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); 193 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); // Class SASEGASA expects this to be called Generations 194 194 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("GenerationsSinceLastReunification", new IntValue(0))); 195 195 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedSolutions", new IntValue(0))); -
trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealing.cs
r3689 r3750 217 217 UpdateMoveGenerator(); 218 218 UpdateMoveParameters(); 219 UpdateAnalyzers(); 219 220 ParameterizeMoveEvaluators(); 220 221 ParameterizeMoveMakers(); 221 222 ParameterizeMoveGenerators(); 222 223 ParameterizeAnalyzers(); 223 UpdateAnalyzers();224 ParameterizeIterationBasedOperators(); 224 225 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 225 226 base.OnProblemChanged(); … … 255 256 ParameterizeMoveMakers(); 256 257 ParameterizeMoveGenerators(); 258 ParameterizeIterationBasedOperators(); 257 259 base.Problem_OperatorsChanged(sender, e); 258 260 } … … 388 390 } 389 391 } 392 private void ParameterizeIterationBasedOperators() { 393 if (Problem != null) { 394 foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) { 395 op.IterationsParameter.ActualName = "Iterations"; 396 op.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name; 397 } 398 } 399 } 390 400 private void UpdateAnalyzers() { 391 401 Analyzer.Operators.Clear(); -
trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealingMainLoop.cs
r3715 r3750 135 135 Placeholder analyzer2 = new Placeholder(); 136 136 ConditionalBranch iterationsTermination = new ConditionalBranch(); 137 138 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0))); 137 138 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0))); // Class SimulatedAnnealing expects this to be called Iterations 139 139 variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("Temperature", new DoubleValue(double.MaxValue))); 140 140 -
trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearch.cs
r3689 r3750 236 236 ParameterizeTabuChecker(); 237 237 ParameterizeAnalyzers(); 238 ParameterizeIterationBasedOperators(); 238 239 Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged); 239 240 base.OnProblemChanged(); … … 278 279 ParameterizeTabuChecker(); 279 280 ParameterizeAnalyzers(); 281 ParameterizeIterationBasedOperators(); 280 282 base.Problem_OperatorsChanged(sender, e); 281 283 } … … 470 472 } 471 473 } 474 private void ParameterizeIterationBasedOperators() { 475 if (Problem != null) { 476 foreach (IIterationBasedOperator op in Problem.Operators.OfType<IIterationBasedOperator>()) { 477 op.IterationsParameter.ActualName = "Iterations"; 478 op.MaximumIterationsParameter.ActualName = MaximumIterationsParameter.Name; 479 } 480 } 481 } 472 482 #endregion 473 483 } -
trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearchMainLoop.cs
r3715 r3750 148 148 ConditionalBranch iterationsTermination = new ConditionalBranch(); 149 149 150 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0))); 150 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Iterations", new IntValue(0))); // Class TabuSearch expects this to be called Iterations 151 151 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedMoves", new IntValue(0))); 152 152 variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("EmptyNeighborhood", new BoolValue(false))); -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/MichalewiczNonUniformAllPositionsManipulator.cs
r3677 r3750 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Data; 26 using HeuristicLab.Optimization; 26 27 using HeuristicLab.Parameters; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 37 38 [Item("MichalewiczNonUniformAllPositionsManipulator", "It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.")] 38 39 [StorableClass] 39 public class MichalewiczNonUniformAllPositionsManipulator : RealVectorManipulator {40 public class MichalewiczNonUniformAllPositionsManipulator : RealVectorManipulator, IIterationBasedOperator { 40 41 /// <summary> 41 /// The current generation.42 /// The current iteration. 42 43 /// </summary> 43 public LookupParameter<IntValue> GenerationParameter {44 get { return ( LookupParameter<IntValue>)Parameters["Generations"]; }44 public ILookupParameter<IntValue> IterationsParameter { 45 get { return (ILookupParameter<IntValue>)Parameters["Iterations"]; } 45 46 } 46 47 /// <summary> 47 /// The maximum generation.48 /// The maximum iteration. 48 49 /// </summary> 49 public LookupParameter<IntValue> MaximumGenerationsParameter {50 get { return ( LookupParameter<IntValue>)Parameters["MaximumGenerations"]; }50 public IValueLookupParameter<IntValue> MaximumIterationsParameter { 51 get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; } 51 52 } 52 53 /// <summary> 53 /// The parameter describing how much the mutation should depend on the progress towards the maximum generation.54 /// The parameter describing how much the mutation should depend on the progress towards the maximum iteration. 54 55 /// </summary> 55 public ValueLookupParameter<DoubleValue> GenerationDependencyParameter {56 get { return (ValueLookupParameter<DoubleValue>)Parameters[" GenerationDependency"]; }56 public ValueLookupParameter<DoubleValue> IterationDependencyParameter { 57 get { return (ValueLookupParameter<DoubleValue>)Parameters["IterationDependency"]; } 57 58 } 58 59 59 60 /// <summary> 60 /// Initializes a new instance of <see cref="MichalewiczNonUniformAllPositionsManipulator"/> with 61 /// four parameters (<c>Bounds</c>, <c>CurrentGeneration</c>, 62 /// <c>MaximumGenerations</c> and <c>GenerationDependency</c>). 61 /// Initializes a new instance of <see cref="MichalewiczNonUniformAllPositionsManipulator"/> with three 62 /// parameters (<c>Iterations</c>, <c>MaximumIterations</c> and <c>IterationDependency</c>). 63 63 /// </summary> 64 64 public MichalewiczNonUniformAllPositionsManipulator() 65 65 : base() { 66 Parameters.Add(new LookupParameter<IntValue>(" Generations", "Current generation of the algorithm"));67 Parameters.Add(new LookupParameter<IntValue>("MaximumGenerations", "Maximum number of generations"));68 Parameters.Add(new ValueLookupParameter<DoubleValue>(" GenerationDependency", "Specifies the degree of dependency on the number of generations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum generations will be taken into account by sampling closer around the current position. Value must be >= 0.", new DoubleValue(5)));66 Parameters.Add(new LookupParameter<IntValue>("Iterations", "Current iteration of the algorithm")); 67 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "Maximum number of iterations")); 68 Parameters.Add(new ValueLookupParameter<DoubleValue>("IterationDependency", "Specifies the degree of dependency on the number of iterations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum iterations will be taken into account by sampling closer around the current position. Value must be >= 0.", new DoubleValue(5))); 69 69 } 70 70 71 71 /// <summary> 72 /// Performs a non uniformly distributed all position manipulation on the given73 /// real <paramref name="vector"/>. The probability of stronger mutations reduces the more <see cref="current Generation"/> approaches <see cref="maximumGenerations"/>.72 /// Performs a non uniformly distributed all positions manipulation on the given 73 /// real <paramref name="vector"/>. The probability of stronger mutations reduces the more <see cref="currentIteration"/> approaches <see cref="maximumIterations"/>. 74 74 /// </summary> 75 /// <exception cref="ArgumentException">Thrown when <paramref name="current Generation"/> is greater than <paramref name="maximumGenerations"/>.</exception>75 /// <exception cref="ArgumentException">Thrown when <paramref name="currentIteration"/> is greater than <paramref name="maximumIterations"/>.</exception> 76 76 /// <param name="random">The random number generator.</param> 77 77 /// <param name="vector">The real vector to manipulate.</param> 78 78 /// <param name="bounds">The lower and upper bound (1st and 2nd column) of the positions in the vector. If there are less rows than dimensions, the rows are cycled.</param> 79 /// <param name="current Generation">The current generation of the algorithm.</param>80 /// <param name="maximum Generations">Maximum number of generations.</param>81 /// <param name=" generationsDependency">Specifies the degree of dependency on the number of generations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum generations will be taken into account by sampling closer around the current position. Value must be >= 0.</param>79 /// <param name="currentIteration">The current iteration of the algorithm.</param> 80 /// <param name="maximumIterations">Maximum number of iterations.</param> 81 /// <param name="iterationDependency">Specifies the degree of dependency on the number of iterations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum iterations will be taken into account by sampling closer around the current position. Value must be >= 0.</param> 82 82 /// <returns>The manipulated real vector.</returns> 83 public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, IntValue current Generation, IntValue maximumGenerations, DoubleValue generationsDependency) {84 if (current Generation.Value > maximumGenerations.Value) throw new ArgumentException("MichalewiczNonUniformAllPositionManipulator: CurrentGeneration must be smaller or equal than MaximumGeneration", "currentGeneration");85 if ( generationsDependency.Value < 0) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: GenerationsDependency must be >= 0.");83 public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, IntValue currentIteration, IntValue maximumIterations, DoubleValue iterationDependency) { 84 if (currentIteration.Value > maximumIterations.Value) throw new ArgumentException("MichalewiczNonUniformAllPositionsManipulator: CurrentIteration must be smaller or equal than MaximumIterations", "currentIteration"); 85 if (iterationDependency.Value < 0) throw new ArgumentException("MichalewiczNonUniformAllPositionsManipulator: iterationDependency must be >= 0.", "iterationDependency"); 86 86 int length = vector.Length; 87 87 88 double prob = Math.Pow(1 - current Generation.Value / maximumGenerations.Value, generationsDependency.Value);88 double prob = Math.Pow(1 - currentIteration.Value / maximumIterations.Value, iterationDependency.Value); 89 89 90 90 for (int i = 0; i < length; i++) { … … 106 106 protected override void Manipulate(IRandom random, RealVector realVector) { 107 107 if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + BoundsParameter.ActualName + " could not be found."); 108 if ( GenerationParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + GenerationParameter.ActualName + " could not be found.");109 if (Maximum GenerationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + MaximumGenerationsParameter.ActualName + " could not be found.");110 if ( GenerationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + GenerationDependencyParameter.ActualName + " could not be found.");111 Apply(random, realVector, BoundsParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue);108 if (IterationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + IterationsParameter.ActualName + " could not be found."); 109 if (MaximumIterationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + MaximumIterationsParameter.ActualName + " could not be found."); 110 if (IterationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformAllPositionManipulator: Parameter " + IterationDependencyParameter.ActualName + " could not be found."); 111 Apply(random, realVector, BoundsParameter.ActualValue, IterationsParameter.ActualValue, MaximumIterationsParameter.ActualValue, IterationDependencyParameter.ActualValue); 112 112 } 113 113 } -
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/MichalewiczNonUniformOnePositionManipulator.cs
r3677 r3750 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Data; 26 using HeuristicLab.Optimization; 26 27 using HeuristicLab.Parameters; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 37 38 [Item("MichalewiczNonUniformOnePositionManipulator", "It is implemented as described in Michalewicz, Z. 1999. Genetic Algorithms + Data Structures = Evolution Programs. Third, Revised and Extended Edition, Spring-Verlag Berlin Heidelberg.")] 38 39 [StorableClass] 39 public class MichalewiczNonUniformOnePositionManipulator : RealVectorManipulator {40 public class MichalewiczNonUniformOnePositionManipulator : RealVectorManipulator, IIterationBasedOperator { 40 41 /// <summary> 41 /// The current generation.42 /// The current iteration. 42 43 /// </summary> 43 public LookupParameter<IntValue> GenerationParameter {44 get { return ( LookupParameter<IntValue>)Parameters["Generations"]; }44 public ILookupParameter<IntValue> IterationsParameter { 45 get { return (ILookupParameter<IntValue>)Parameters["Iterations"]; } 45 46 } 46 47 /// <summary> 47 /// The maximum generation.48 /// The maximum iteration. 48 49 /// </summary> 49 public LookupParameter<IntValue> MaximumGenerationsParameter {50 get { return ( LookupParameter<IntValue>)Parameters["MaximumGenerations"]; }50 public IValueLookupParameter<IntValue> MaximumIterationsParameter { 51 get { return (IValueLookupParameter<IntValue>)Parameters["MaximumIterations"]; } 51 52 } 52 53 /// <summary> 53 /// The parameter describing how much the mutation should depend on the progress towards the maximum generation.54 /// The parameter describing how much the mutation should depend on the progress towards the maximum iterations. 54 55 /// </summary> 55 public ValueLookupParameter<DoubleValue> GenerationDependencyParameter {56 get { return (ValueLookupParameter<DoubleValue>)Parameters[" GenerationDependency"]; }56 public ValueLookupParameter<DoubleValue> IterationDependencyParameter { 57 get { return (ValueLookupParameter<DoubleValue>)Parameters["IterationDependency"]; } 57 58 } 58 59 59 60 /// <summary> 60 /// Initializes a new instance of <see cref="MichalewiczNonUniformOnePositionManipulator"/> with four 61 /// parameters (<c>Bounds</c>, <c>CurrentGeneration</c>, <c>MaximumGenerations</c> 62 /// and <c>GenerationDependency</c>). 61 /// Initializes a new instance of <see cref="MichalewiczNonUniformOnePositionManipulator"/> with three 62 /// parameters (<c>Iterations</c>, <c>MaximumIterations</c> and <c>IterationDependency</c>). 63 63 /// </summary> 64 64 public MichalewiczNonUniformOnePositionManipulator() 65 65 : base() { 66 Parameters.Add(new LookupParameter<IntValue>(" Generations", "Current generation of the algorithm"));67 Parameters.Add(new LookupParameter<IntValue>("MaximumGenerations", "Maximum number of generations"));68 Parameters.Add(new ValueLookupParameter<DoubleValue>(" GenerationDependency", "Specifies the degree of dependency on the number of generations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum generations will be taken into account by sampling closer around the current position. Value must be >= 0.", new DoubleValue(5)));66 Parameters.Add(new LookupParameter<IntValue>("Iterations", "Current iteration of the algorithm.")); 67 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumIterations", "Maximum number of iterations.")); 68 Parameters.Add(new ValueLookupParameter<DoubleValue>("IterationDependency", "Specifies the degree of dependency on the number of iterations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum iterations will be taken into account by sampling closer around the current position. Value must be >= 0.", new DoubleValue(5))); 69 69 } 70 70 71 71 /// <summary> 72 72 /// Performs a non uniformly distributed one position manipulation on the given 73 /// real <paramref name="vector"/>. The probability of stronger mutations reduces the more <see cref="current Generation"/> approaches <see cref="maximumGenerations"/>.73 /// real <paramref name="vector"/>. The probability of stronger mutations reduces the more <see cref="currentIteration"/> approaches <see cref="maximumIterations"/>. 74 74 /// </summary> 75 /// <exception cref="ArgumentException">Thrown when <paramref name="current Generation"/> is greater than <paramref name="maximumGenerations"/>.</exception>75 /// <exception cref="ArgumentException">Thrown when <paramref name="currentIteration"/> is greater than <paramref name="maximumIterations"/>.</exception> 76 76 /// <param name="random">The random number generator.</param> 77 77 /// <param name="vector">The real vector to manipulate.</param> 78 78 /// <param name="bounds">The lower and upper bound (1st and 2nd column) of the positions in the vector. If there are less rows than dimensions, the rows are cycled.</param> 79 /// <param name="current Generation">The current generation of the algorithm.</param>80 /// <param name="maximum Generations">Maximum number of generations.</param>81 /// <param name=" generationsDependency">Specifies the degree of dependency on the number of generations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum generations will be taken into account by sampling closer around the current position. Value must be >= 0.</param>79 /// <param name="currentIteration">The current iteration of the algorithm.</param> 80 /// <param name="maximumIterations">Maximum number of iterations.</param> 81 /// <param name="iterationDependency">Specifies the degree of dependency on the number of iterations. A value of 0 means no dependency and the higher the value the stronger the progress towards maximum iterations will be taken into account by sampling closer around the current position. Value must be >= 0.</param> 82 82 /// <returns>The manipulated real vector.</returns> 83 public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, IntValue current Generation, IntValue maximumGenerations, DoubleValue generationsDependency) {84 if (current Generation.Value > maximumGenerations.Value) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: CurrentGeneration must be smaller or equal than MaximumGeneration", "currentGeneration");85 if ( generationsDependency.Value < 0) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: GenerationsDependency must be >= 0.");83 public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, IntValue currentIteration, IntValue maximumIterations, DoubleValue iterationDependency) { 84 if (currentIteration.Value > maximumIterations.Value) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: CurrentIteration must be smaller or equal than MaximumIterations", "currentIteration"); 85 if (iterationDependency.Value < 0) throw new ArgumentException("MichalewiczNonUniformOnePositionManipulator: iterationDependency must be >= 0.", "iterationDependency"); 86 86 int length = vector.Length; 87 87 int index = random.Next(length); 88 88 89 double prob = (1 - Math.Pow(random.NextDouble(), Math.Pow(1 - current Generation.Value / maximumGenerations.Value, generationsDependency.Value)));89 double prob = (1 - Math.Pow(random.NextDouble(), Math.Pow(1 - currentIteration.Value / maximumIterations.Value, iterationDependency.Value))); 90 90 91 91 double min = bounds[index % bounds.Rows, 0]; … … 106 106 protected override void Manipulate(IRandom random, RealVector realVector) { 107 107 if (BoundsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + BoundsParameter.ActualName + " could not be found."); 108 if ( GenerationParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + GenerationParameter.ActualName + " could not be found.");109 if (Maximum GenerationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MaximumGenerationsParameter.ActualName + " could not be found.");110 if ( GenerationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + GenerationDependencyParameter.ActualName + " could not be found.");111 Apply(random, realVector, BoundsParameter.ActualValue, GenerationParameter.ActualValue, MaximumGenerationsParameter.ActualValue, GenerationDependencyParameter.ActualValue);108 if (IterationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + IterationsParameter.ActualName + " could not be found."); 109 if (MaximumIterationsParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + MaximumIterationsParameter.ActualName + " could not be found."); 110 if (IterationDependencyParameter.ActualValue == null) throw new InvalidOperationException("MichalewiczNonUniformOnePositionManipulator: Parameter " + IterationDependencyParameter.ActualName + " could not be found."); 111 Apply(random, realVector, BoundsParameter.ActualValue, IterationsParameter.ActualValue, MaximumIterationsParameter.ActualValue, IterationDependencyParameter.ActualValue); 112 112 } 113 113 } -
trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj
r3717 r3750 87 87 <Compile Include="Algorithm.cs" /> 88 88 <Compile Include="BatchRun.cs" /> 89 <Compile Include="Interfaces\IIterationBasedOperator.cs" /> 89 90 <Compile Include="Interfaces\IRealVectorDecoder.cs" /> 90 91 <Compile Include="Interfaces\IRealVectorEncoder.cs" />
Note: See TracChangeset
for help on using the changeset viewer.