Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1215

  • fixed import of existing algorithm
  • moved operators in subfolders
  • extended tests for SymbolicExpressionGrammar
File size: 1.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Operators;
6using HeuristicLab.Optimization;
7using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8using HeuristicLab.Core;
9using HeuristicLab.Parameters;
10using HeuristicLab.Common;
11using HeuristicLab.Data;
12using HeuristicLab.Random;
13
14namespace HeuristicLab.Problems.MetaOptimization {
15  [StorableClass]
16  public class NormalDoubleValueCrossover : SingleSuccessorOperator, IDoubleValueCrossover, IStochasticOperator {
17    public ILookupParameter<IRandom> RandomParameter {
18      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
19    }
20
21    public NormalDoubleValueCrossover() : base() {
22    }
23    [StorableConstructor]
24    protected NormalDoubleValueCrossover(bool deserializing) : base(deserializing) { }
25    protected NormalDoubleValueCrossover(NormalDoubleValueCrossover original, Cloner cloner)
26      : base(original, cloner) {
27    }
28    public override IDeepCloneable Clone(Cloner cloner) {
29      return new NormalDoubleValueCrossover(this, cloner);
30    }
31
32    public void Apply(IRandom random, DoubleValue value, DoubleValue other, DoubleValueRange range) {
33      value.Value = ApplyStatic(random, value, other, range).Value;
34    }
35
36    public static DoubleValue ApplyStatic(IRandom random, DoubleValue better, DoubleValue worse, DoubleValueRange range) {
37      NormalDistributedRandom N = new NormalDistributedRandom(random, better.Value, Math.Abs(better.Value - worse.Value));
38      var offspring = new DoubleValue();
39      do {
40        offspring.Value = N.NextDouble();
41        offspring.Value = range.ApplyStepSize(offspring.Value);
42      } while (!range.IsInRange(offspring.Value));
43      return offspring;
44    }
45  }
46}
Note: See TracBrowser for help on using the repository browser.