Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Operators/Crossovers/DoubleValue/NormalDoubleValueCrossover.cs @ 9596

Last change on this file since 9596 was 6421, checked in by cneumuel, 14 years ago

#1215

  • small fixes
File size: 1.7 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 NormalDoubleValueCrossover : SingleSuccessorOperator, IDoubleValueCrossover, IStochasticOperator {
14    public ILookupParameter<IRandom> RandomParameter {
15      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
16    }
17
18    public NormalDoubleValueCrossover()
19      : base() {
20    }
21    [StorableConstructor]
22    protected NormalDoubleValueCrossover(bool deserializing) : base(deserializing) { }
23    protected NormalDoubleValueCrossover(NormalDoubleValueCrossover original, Cloner cloner)
24      : base(original, cloner) {
25    }
26    public override IDeepCloneable Clone(Cloner cloner) {
27      return new NormalDoubleValueCrossover(this, cloner);
28    }
29
30    public void Apply(IRandom random, DoubleValue value, DoubleValue other, DoubleValueRange range) {
31      value.Value = ApplyStatic(random, value, other, range).Value;
32    }
33
34    public static DoubleValue ApplyStatic(IRandom random, DoubleValue better, DoubleValue worse, DoubleValueRange range) {
35      NormalDistributedRandom N = new NormalDistributedRandom(random, better.Value, Math.Abs(better.Value - worse.Value) / 3);
36      var offspring = new DoubleValue();
37      do {
38        offspring.Value = N.NextDouble();
39        offspring.Value = range.ApplyStepSize(offspring.Value);
40      } while (!range.IsInRange(offspring.Value));
41
42      return offspring;
43    }
44  }
45}
Note: See TracBrowser for help on using the repository browser.