Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Operators/Crossovers/IntValue/NormalIntValueCrossover.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.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;
10using HEAL.Attic;
11
12namespace HeuristicLab.Problems.MetaOptimization {
13  [StorableType("39FB97FC-E6C1-4364-8E45-317ECAE9136D")]
14  public class NormalIntValueCrossover : SingleSuccessorOperator, IIntValueCrossover, IStochasticOperator {
15    public ILookupParameter<IRandom> RandomParameter {
16      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
17    }
18
19    public NormalIntValueCrossover() { }
20    [StorableConstructor]
21    protected NormalIntValueCrossover(StorableConstructorFlag _) : base(_) { }
22    protected NormalIntValueCrossover(NormalIntValueCrossover original, Cloner cloner)
23      : base(original, cloner) {
24    }
25    public override IDeepCloneable Clone(Cloner cloner) {
26      return new NormalIntValueCrossover(this, cloner);
27    }
28
29    public void Apply(IRandom random, IntValue value, IntValue other, IntValueRange range) {
30      value.Value = ApplyStatic(random, value, other, range).Value;
31    }
32
33    public static IntValue ApplyStatic(IRandom random, IntValue better, IntValue worse, IntValueRange range) {
34      NormalDistributedRandom N = new NormalDistributedRandom(random, better.Value, Math.Abs(better.Value - worse.Value) / 3);
35      var offspring = new IntValue();
36      do {
37        offspring.Value = (int)N.NextDouble();
38        offspring.Value = range.ApplyStepSize(offspring.Value);
39      } while (!range.IsInRange(offspring.Value));
40      return offspring;
41    }
42  }
43}
Note: See TracBrowser for help on using the repository browser.