[5111] | 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 |
|
---|
| 13 | namespace 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 |
|
---|
[5277] | 30 | public void Apply(IRandom random, IntValue value, IntValue other, IntValueRange range) {
|
---|
| 31 | ApplyStatic(random, value, other, range);
|
---|
[5111] | 32 | }
|
---|
| 33 |
|
---|
[5277] | 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 | }
|
---|
[5111] | 38 | }
|
---|
| 39 | }
|
---|
| 40 | }
|
---|