1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Operators;
|
---|
6 | using HeuristicLab.Optimization;
|
---|
7 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
8 | using HeuristicLab.Core;
|
---|
9 | using HeuristicLab.Parameters;
|
---|
10 | using HeuristicLab.Common;
|
---|
11 | using HeuristicLab.Data;
|
---|
12 | using HEAL.Attic;
|
---|
13 |
|
---|
14 | namespace HeuristicLab.Problems.MetaOptimization {
|
---|
15 | [StorableType("42E25F0F-0DFF-4501-8930-4972D70955E0")]
|
---|
16 | public class DiscreteDoubleValueCrossover : SingleSuccessorOperator, IDoubleValueCrossover, IStochasticOperator {
|
---|
17 | public ILookupParameter<IRandom> RandomParameter {
|
---|
18 | get { return (LookupParameter<IRandom>)Parameters["Random"]; }
|
---|
19 | }
|
---|
20 |
|
---|
21 | public DiscreteDoubleValueCrossover() { }
|
---|
22 | [StorableConstructor]
|
---|
23 | protected DiscreteDoubleValueCrossover(StorableConstructorFlag _) : base(_) { }
|
---|
24 | protected DiscreteDoubleValueCrossover(DiscreteDoubleValueCrossover original, Cloner cloner)
|
---|
25 | : base(original, cloner) {
|
---|
26 | }
|
---|
27 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
28 | return new DiscreteDoubleValueCrossover(this, cloner);
|
---|
29 | }
|
---|
30 |
|
---|
31 | public void Apply(IRandom random, DoubleValue value, DoubleValue other, DoubleValueRange range) {
|
---|
32 | ApplyStatic(random, value, other, range);
|
---|
33 | }
|
---|
34 |
|
---|
35 | public static void ApplyStatic(IRandom random, DoubleValue value, DoubleValue other, DoubleValueRange range) {
|
---|
36 | if (random.NextDouble() > 0.5) {
|
---|
37 | value.Value = other.Value;
|
---|
38 | }
|
---|
39 | }
|
---|
40 | }
|
---|
41 | }
|
---|