Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Operators/Crossovers/DoubleValue/DiscreteDoubleValueCrossover.cs @ 16574

Last change on this file since 16574 was 16574, checked in by gkronber, 5 years ago

#2520: changed HeuristicLab.MetaOptimization addon to compile with new HL.Persistence

File size: 1.5 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 HEAL.Attic;
13
14namespace 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}
Note: See TracBrowser for help on using the repository browser.