Free cookie consent management tool by TermsFeed Policy Generator

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