1 | using System;
|
---|
2 | using HeuristicLab.Common;
|
---|
3 | using HeuristicLab.Core;
|
---|
4 | using HeuristicLab.Data;
|
---|
5 | using HeuristicLab.Operators;
|
---|
6 | using HeuristicLab.Optimization;
|
---|
7 | using HeuristicLab.Parameters;
|
---|
8 | using HeuristicLab.Random;
|
---|
9 | using HEAL.Attic;
|
---|
10 |
|
---|
11 | namespace 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 | }
|
---|