Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Operators/Crossovers/DoubleValue/NormalDoubleValueCrossover.cs @ 16574

Last change on this file since 16574 was 16574, checked in by gkronber, 5 years ago

#2520: changed HeuristicLab.MetaOptimization addon to compile with new HL.Persistence

File size: 1.8 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;
10using HEAL.Attic;
11
12namespace HeuristicLab.Problems.MetaOptimization {
13  [StorableType("09087C46-DE3F-43B2-A6B0-2B6A03671ACB")]
14  public class NormalDoubleValueCrossover : SingleSuccessorOperator, IDoubleValueCrossover, IStochasticOperator {
15    public ILookupParameter<IRandom> RandomParameter {
16      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
17    }
18
19    public NormalDoubleValueCrossover()
20      : base() {
21    }
22    [StorableConstructor]
23    protected NormalDoubleValueCrossover(StorableConstructorFlag _) : base(_) { }
24    protected NormalDoubleValueCrossover(NormalDoubleValueCrossover original, Cloner cloner)
25      : base(original, cloner) {
26    }
27    public override IDeepCloneable Clone(Cloner cloner) {
28      return new NormalDoubleValueCrossover(this, cloner);
29    }
30
31    public void Apply(IRandom random, DoubleValue value, DoubleValue other, DoubleValueRange range) {
32      value.Value = ApplyStatic(random, value, other, range).Value;
33    }
34
35    public static DoubleValue ApplyStatic(IRandom random, DoubleValue better, DoubleValue worse, DoubleValueRange range) {
36      NormalDistributedRandom N = new NormalDistributedRandom(random, better.Value, Math.Abs(better.Value - worse.Value) / 3);
37      var offspring = new DoubleValue();
38      do {
39        offspring.Value = N.NextDouble();
40        offspring.Value = range.ApplyStepSize(offspring.Value);
41      } while (!range.IsInRange(offspring.Value));
42
43      return offspring;
44    }
45  }
46}
Note: See TracBrowser for help on using the repository browser.