Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2520 Update plugin dependencies and references for HL.MetaOptimization for new persistence

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.Random;
9using HEAL.Attic;
10
11namespace HeuristicLab.Problems.MetaOptimization {
12  [StorableType("09087C46-DE3F-43B2-A6B0-2B6A03671ACB")]
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(StorableConstructorFlag _) : base(_) { }
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.