Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Operators/Crossovers/IntValue/NormalIntValueCrossover.cs @ 6038

Last change on this file since 6038 was 6038, checked in by cneumuel, 13 years ago

#1215

  • reduced significance of NormalCrossovers
  • small fixes
File size: 1.6 KB
Line 
1using System;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Data;
5using HeuristicLab.Operators;
6using HeuristicLab.Optimization;
7using HeuristicLab.Parameters;
8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9using HeuristicLab.Random;
10
11namespace HeuristicLab.Problems.MetaOptimization {
12  [StorableClass]
13  public class NormalIntValueCrossover : SingleSuccessorOperator, IIntValueCrossover, IStochasticOperator {
14    public ILookupParameter<IRandom> RandomParameter {
15      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
16    }
17
18    public NormalIntValueCrossover() { }
19    [StorableConstructor]
20    protected NormalIntValueCrossover(bool deserializing) : base(deserializing) { }
21    protected NormalIntValueCrossover(NormalIntValueCrossover original, Cloner cloner)
22      : base(original, cloner) {
23    }
24    public override IDeepCloneable Clone(Cloner cloner) {
25      return new NormalIntValueCrossover(this, cloner);
26    }
27
28    public void Apply(IRandom random, IntValue value, IntValue other, IntValueRange range) {
29      value.Value = ApplyStatic(random, value, other, range).Value;
30    }
31
32    public static IntValue ApplyStatic(IRandom random, IntValue better, IntValue worse, IntValueRange range) {
33      NormalDistributedRandom N = new NormalDistributedRandom(random, better.Value, Math.Abs(better.Value - worse.Value) / 3);
34      var offspring = new IntValue();
35      do {
36        offspring.Value = (int)N.NextDouble();
37        offspring.Value = range.ApplyStepSize(offspring.Value);
38      } while (!range.IsInRange(offspring.Value));
39      return offspring;
40    }
41  }
42}
Note: See TracBrowser for help on using the repository browser.