Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Operators/Crossovers/DiscreteIntValueCrossover.cs @ 5277

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

#1215

  • implemented crossover and manipulator operators for int and double values
File size: 1.4 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;
12
13namespace HeuristicLab.Problems.MetaOptimization {
14  [StorableClass]
15  public class DiscreteIntValueCrossover : SingleSuccessorOperator, IIntValueCrossover, IStochasticOperator {
16    public ILookupParameter<IRandom> RandomParameter {
17      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
18    }
19
20    public DiscreteIntValueCrossover() { }
21    [StorableConstructor]
22    protected DiscreteIntValueCrossover(bool deserializing) : base(deserializing) { }
23    protected DiscreteIntValueCrossover(DiscreteIntValueCrossover original, Cloner cloner)
24      : base(original, cloner) {
25    }
26    public override IDeepCloneable Clone(Cloner cloner) {
27      return new DiscreteIntValueCrossover(this, cloner);
28    }
29
30    public void Apply(IRandom random, IntValue value, IntValue other, IntValueRange range) {
31      ApplyStatic(random, value, other, range);
32    }
33
34    public static void ApplyStatic(IRandom random, IntValue value, IntValue other, IntValueRange range) {
35      if (random.NextDouble() > 0.5) {
36        value.Value = other.Value;
37      }
38    }
39  }
40}
Note: See TracBrowser for help on using the repository browser.