Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3750


Ignore:
Timestamp:
05/10/10 17:19:34 (14 years ago)
Author:
abeham
Message:

#893

  • Fixed wiring of iteration based operators like the michalewicz manipulators for real vector encoding
Location:
trunk/sources
Files:
1 added
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.EvolutionStrategy/3.3/EvolutionStrategyMainLoop.cs

    r3715 r3750  
    154154      ConditionalBranch conditionalBranch = new ConditionalBranch();
    155155
    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
    157157
    158158      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
  • trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/GeneticAlgorithm.cs

    r3680 r3750  
    213213      ParameterizeSelectors();
    214214      ParameterizeAnalyzers();
     215      ParameterizeIterationBasedOperators();
    215216      UpdateCrossovers();
    216217      UpdateMutators();
     
    236237    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
    237238      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
     239      ParameterizeIterationBasedOperators();
    238240      UpdateCrossovers();
    239241      UpdateMutators();
     
    307309        qualityAnalyzer.QualityParameter.Depth = 1;
    308310        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        }
    309319      }
    310320    }
  • trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/GeneticAlgorithmMainLoop.cs

    r3715 r3750  
    130130      ConditionalBranch conditionalBranch = new ConditionalBranch();
    131131
    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
    133133
    134134      resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
  • trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/IslandGeneticAlgorithm.cs

    r3704 r3750  
    304304      ParameterizeSelectors();
    305305      ParameterizeAnalyzers();
     306      ParameterizeIterationBasedOperators();
    306307      UpdateCrossovers();
    307308      UpdateMutators();
     
    327328    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
    328329      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
     330      ParameterizeIterationBasedOperators();
    329331      UpdateCrossovers();
    330332      UpdateMutators();
     
    431433      }
    432434    }
     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    }
    433443    private void UpdateCrossovers() {
    434444      ICrossover oldCrossover = CrossoverParameter.Value;
  • trunk/sources/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/IslandGeneticAlgorithmMainLoop.cs

    r3715 r3750  
    177177      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Migrations", new IntValue(0)));
    178178      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
    180180
    181181      islandVariableCreator.CollectedValues.Add(new ValueParameter<ResultCollection>("Results", new ResultCollection()));
  • trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearch.cs

    r3689 r3750  
    197197      ParameterizeSolutionsCreator();
    198198      ParameterizeMainLoop();
    199       ParameterizeMoveEvaluators();
    200       ParameterizeMoveMakers();
    201       ParameterizeAnalyzers();
    202199      UpdateMoveGenerator();
    203200      UpdateMoveParameters();
    204201      UpdateAnalyzers();
     202      ParameterizeMoveEvaluators();
     203      ParameterizeMoveMakers();
     204      ParameterizeAnalyzers();
     205      ParameterizeIterationBasedOperators();
    205206      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    206207      base.OnProblemChanged();
     
    236237      ParameterizeMoveMakers();
    237238      ParameterizeAnalyzers();
     239      ParameterizeIterationBasedOperators();
    238240      base.Problem_OperatorsChanged(sender, e);
    239241    }
     
    366368      }
    367369    }
     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    }
    368378    #endregion
    369379  }
  • trunk/sources/HeuristicLab.Algorithms.LocalSearch/3.3/LocalSearchMainLoop.cs

    r3715 r3750  
    137137      ConditionalBranch iterationsTermination = new ConditionalBranch();
    138138
    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
    140140      variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("BestQuality", new DoubleValue(0)));
    141141      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedMoves", new IntValue(0)));
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/IslandOffspringSelectionGeneticAlgorithm.cs

    r3744 r3750  
    373373      ParameterizeSelectors();
    374374      ParameterizeAnalyzers();
     375      ParameterizeIterationBasedOperators();
    375376      UpdateCrossovers();
    376377      UpdateMutators();
     
    396397    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
    397398      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
     399      ParameterizeIterationBasedOperators();
    398400      UpdateCrossovers();
    399401      UpdateMutators();
     
    542544      }
    543545    }
     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    }
    544554    private void UpdateCrossovers() {
    545555      ICrossover oldCrossover = CrossoverParameter.Value;
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/IslandOffspringSelectionGeneticAlgorithmMainLoop.cs

    r3744 r3750  
    210210
    211211      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
    213213      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("GenerationsSinceLastMigration", new IntValue(0)));
    214214      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("TerminatedIslands", new IntValue(0)));
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithm.cs

    r3744 r3750  
    284284      ParameterizeSelectors();
    285285      ParameterizeAnalyzers();
     286      ParameterizeIterationBasedOperators();
    286287      UpdateCrossovers();
    287288      UpdateMutators();
     
    307308    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
    308309      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
     310      ParameterizeIterationBasedOperators();
    309311      UpdateCrossovers();
    310312      UpdateMutators();
     
    394396      }
    395397    }
     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    }
    396406    private void UpdateCrossovers() {
    397407      ICrossover oldCrossover = CrossoverParameter.Value;
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/OffspringSelectionGeneticAlgorithmMainLoop.cs

    r3744 r3750  
    139139      ConditionalBranch conditionalBranch2 = new ConditionalBranch();
    140140
    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
    142142      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedSolutions", new IntValue(0)));
    143143      variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("SelectionPressure", new DoubleValue(0)));
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/SASEGASA.cs

    r3744 r3750  
    332332      ParameterizeSelectors();
    333333      ParameterizeAnalyzers();
     334      ParameterizeIterationBasedOperators();
    334335      UpdateCrossovers();
    335336      UpdateMutators();
     
    355356    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
    356357      foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op);
     358      ParameterizeIterationBasedOperators();
    357359      UpdateCrossovers();
    358360      UpdateMutators();
     
    480482      }
    481483    }
     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    }
    482492    private void UpdateCrossovers() {
    483493      ICrossover oldCrossover = CrossoverParameter.Value;
  • trunk/sources/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/SASEGASAMainLoop.cs

    r3744 r3750  
    191191
    192192      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
    194194      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("GenerationsSinceLastReunification", new IntValue(0)));
    195195      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedSolutions", new IntValue(0)));
  • trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealing.cs

    r3689 r3750  
    217217      UpdateMoveGenerator();
    218218      UpdateMoveParameters();
     219      UpdateAnalyzers();
    219220      ParameterizeMoveEvaluators();
    220221      ParameterizeMoveMakers();
    221222      ParameterizeMoveGenerators();
    222223      ParameterizeAnalyzers();
    223       UpdateAnalyzers();
     224      ParameterizeIterationBasedOperators();
    224225      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    225226      base.OnProblemChanged();
     
    255256      ParameterizeMoveMakers();
    256257      ParameterizeMoveGenerators();
     258      ParameterizeIterationBasedOperators();
    257259      base.Problem_OperatorsChanged(sender, e);
    258260    }
     
    388390      }
    389391    }
     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    }
    390400    private void UpdateAnalyzers() {
    391401      Analyzer.Operators.Clear();
  • trunk/sources/HeuristicLab.Algorithms.SimulatedAnnealing/3.3/SimulatedAnnealingMainLoop.cs

    r3715 r3750  
    135135      Placeholder analyzer2 = new Placeholder();
    136136      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
    139139      variableCreator.CollectedValues.Add(new ValueParameter<DoubleValue>("Temperature", new DoubleValue(double.MaxValue)));
    140140
  • trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearch.cs

    r3689 r3750  
    236236      ParameterizeTabuChecker();
    237237      ParameterizeAnalyzers();
     238      ParameterizeIterationBasedOperators();
    238239      Problem.Evaluator.QualityParameter.ActualNameChanged += new EventHandler(Evaluator_QualityParameter_ActualNameChanged);
    239240      base.OnProblemChanged();
     
    278279      ParameterizeTabuChecker();
    279280      ParameterizeAnalyzers();
     281      ParameterizeIterationBasedOperators();
    280282      base.Problem_OperatorsChanged(sender, e);
    281283    }
     
    470472      }
    471473    }
     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    }
    472482    #endregion
    473483  }
  • trunk/sources/HeuristicLab.Algorithms.TabuSearch/3.3/TabuSearchMainLoop.cs

    r3715 r3750  
    148148      ConditionalBranch iterationsTermination = new ConditionalBranch();
    149149
    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
    151151      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("EvaluatedMoves", new IntValue(0)));
    152152      variableCreator.CollectedValues.Add(new ValueParameter<BoolValue>("EmptyNeighborhood", new BoolValue(false)));
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/MichalewiczNonUniformAllPositionsManipulator.cs

    r3677 r3750  
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Data;
     26using HeuristicLab.Optimization;
    2627using HeuristicLab.Parameters;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3738  [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.")]
    3839  [StorableClass]
    39   public class MichalewiczNonUniformAllPositionsManipulator : RealVectorManipulator {
     40  public class MichalewiczNonUniformAllPositionsManipulator : RealVectorManipulator, IIterationBasedOperator {
    4041    /// <summary>
    41     /// The current generation.
     42    /// The current iteration.
    4243    /// </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"]; }
    4546    }
    4647    /// <summary>
    47     /// The maximum generation.
     48    /// The maximum iteration.
    4849    /// </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"]; }
    5152    }
    5253    /// <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.
    5455    /// </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"]; }
    5758    }
    5859
    5960    /// <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>).
    6363    /// </summary>
    6464    public MichalewiczNonUniformAllPositionsManipulator()
    6565      : 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)));
    6969    }
    7070
    7171    /// <summary>
    72     /// Performs a non uniformly distributed all position manipulation on the given
    73     /// real <paramref name="vector"/>. The probability of stronger mutations reduces the more <see cref="currentGeneration"/> 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"/>.
    7474    /// </summary>
    75     /// <exception cref="ArgumentException">Thrown when <paramref name="currentGeneration"/> is greater than <paramref name="maximumGenerations"/>.</exception>
     75    /// <exception cref="ArgumentException">Thrown when <paramref name="currentIteration"/> is greater than <paramref name="maximumIterations"/>.</exception>
    7676    /// <param name="random">The random number generator.</param>
    7777    /// <param name="vector">The real vector to manipulate.</param>
    7878    /// <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="currentGeneration">The current generation of the algorithm.</param>
    80     /// <param name="maximumGenerations">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>
    8282    /// <returns>The manipulated real vector.</returns>
    83     public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, IntValue currentGeneration, IntValue maximumGenerations, DoubleValue generationsDependency) {
    84       if (currentGeneration.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");
    8686      int length = vector.Length;
    8787
    88       double prob = Math.Pow(1 - currentGeneration.Value / maximumGenerations.Value, generationsDependency.Value);
     88      double prob = Math.Pow(1 - currentIteration.Value / maximumIterations.Value, iterationDependency.Value);
    8989
    9090      for (int i = 0; i < length; i++) {
     
    106106    protected override void Manipulate(IRandom random, RealVector realVector) {
    107107      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 (MaximumGenerationsParameter.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);
    112112    }
    113113  }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Manipulators/MichalewiczNonUniformOnePositionManipulator.cs

    r3677 r3750  
    2424using HeuristicLab.Core;
    2525using HeuristicLab.Data;
     26using HeuristicLab.Optimization;
    2627using HeuristicLab.Parameters;
    2728using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3738  [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.")]
    3839  [StorableClass]
    39   public class MichalewiczNonUniformOnePositionManipulator : RealVectorManipulator {
     40  public class MichalewiczNonUniformOnePositionManipulator : RealVectorManipulator, IIterationBasedOperator {
    4041    /// <summary>
    41     /// The current generation.
     42    /// The current iteration.
    4243    /// </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"]; }
    4546    }
    4647    /// <summary>
    47     /// The maximum generation.
     48    /// The maximum iteration.
    4849    /// </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"]; }
    5152    }
    5253    /// <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.
    5455    /// </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"]; }
    5758    }
    5859
    5960    /// <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>).
    6363    /// </summary>
    6464    public MichalewiczNonUniformOnePositionManipulator()
    6565      : 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)));
    6969    }
    7070
    7171    /// <summary>
    7272    /// 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="currentGeneration"/> approaches <see cref="maximumGenerations"/>.
     73    /// real <paramref name="vector"/>. The probability of stronger mutations reduces the more <see cref="currentIteration"/> approaches <see cref="maximumIterations"/>.
    7474    /// </summary>
    75     /// <exception cref="ArgumentException">Thrown when <paramref name="currentGeneration"/> is greater than <paramref name="maximumGenerations"/>.</exception>
     75    /// <exception cref="ArgumentException">Thrown when <paramref name="currentIteration"/> is greater than <paramref name="maximumIterations"/>.</exception>
    7676    /// <param name="random">The random number generator.</param>
    7777    /// <param name="vector">The real vector to manipulate.</param>
    7878    /// <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="currentGeneration">The current generation of the algorithm.</param>
    80     /// <param name="maximumGenerations">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>
    8282    /// <returns>The manipulated real vector.</returns>
    83     public static void Apply(IRandom random, RealVector vector, DoubleMatrix bounds, IntValue currentGeneration, IntValue maximumGenerations, DoubleValue generationsDependency) {
    84       if (currentGeneration.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");
    8686      int length = vector.Length;
    8787      int index = random.Next(length);
    8888
    89       double prob = (1 - Math.Pow(random.NextDouble(), Math.Pow(1 - currentGeneration.Value / maximumGenerations.Value, generationsDependency.Value)));
     89      double prob = (1 - Math.Pow(random.NextDouble(), Math.Pow(1 - currentIteration.Value / maximumIterations.Value, iterationDependency.Value)));
    9090
    9191      double min = bounds[index % bounds.Rows, 0];
     
    106106    protected override void Manipulate(IRandom random, RealVector realVector) {
    107107      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 (MaximumGenerationsParameter.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);
    112112    }
    113113  }
  • trunk/sources/HeuristicLab.Optimization/3.3/HeuristicLab.Optimization-3.3.csproj

    r3717 r3750  
    8787    <Compile Include="Algorithm.cs" />
    8888    <Compile Include="BatchRun.cs" />
     89    <Compile Include="Interfaces\IIterationBasedOperator.cs" />
    8990    <Compile Include="Interfaces\IRealVectorDecoder.cs" />
    9091    <Compile Include="Interfaces\IRealVectorEncoder.cs" />
Note: See TracChangeset for help on using the changeset viewer.