Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Operators/Crossovers/NormalIntValueCrossover.cs @ 5955

Last change on this file since 5955 was 5337, checked in by cneumuel, 14 years ago

#1215

  • made all IAlgorithm types compatible to be loaded into MetaOptimization.
  • valid problem types are now automatically set
File size: 1.7 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 NormalIntValueCrossover : SingleSuccessorOperator, IIntValueCrossover, IStochasticOperator {
17    public ILookupParameter<IRandom> RandomParameter {
18      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
19    }
20
21    public NormalIntValueCrossover() { }
22    [StorableConstructor]
23    protected NormalIntValueCrossover(bool deserializing) : base(deserializing) { }
24    protected NormalIntValueCrossover(NormalIntValueCrossover original, Cloner cloner)
25      : base(original, cloner) {
26    }
27    public override IDeepCloneable Clone(Cloner cloner) {
28      return new NormalIntValueCrossover(this, cloner);
29    }
30
31    public void Apply(IRandom random, IntValue value, IntValue other, IntValueRange range) {
32      value.Value = ApplyStatic(random, value, other, range).Value;
33    }
34
35    public static IntValue ApplyStatic(IRandom random, IntValue better, IntValue worse, IntValueRange range) {
36      NormalDistributedRandom N = new NormalDistributedRandom(random, better.Value, Math.Abs(better.Value - worse.Value));
37      var offspring = new IntValue();
38      do {
39        offspring.Value = (int)N.NextDouble();
40        offspring.Value = range.ApplyStepSize(offspring.Value);
41      } while (!range.IsInRange(offspring.Value));
42      return offspring;
43    }
44  }
45}
Note: See TracBrowser for help on using the repository browser.