1 | using HeuristicLab.BioBoost.ProblemDescription;
|
---|
2 | using HeuristicLab.Common;
|
---|
3 | using HeuristicLab.Core;
|
---|
4 | using HeuristicLab.Data;
|
---|
5 | using HeuristicLab.Encodings.IntegerVectorEncoding;
|
---|
6 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
7 | using HeuristicLab.Parameters;
|
---|
8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
9 | using System;
|
---|
10 | using System.Linq;
|
---|
11 |
|
---|
12 | namespace HeuristicLab.BioBoost.Operators.Mutation {
|
---|
13 | [StorableClass]
|
---|
14 | public class BoundaryToggleRealVectorMutator : RealVectorManipulator {
|
---|
15 |
|
---|
16 | #region Construction & Cloning
|
---|
17 | [StorableConstructor]
|
---|
18 | protected BoundaryToggleRealVectorMutator(bool isDeserializing) : base(isDeserializing) { }
|
---|
19 | protected BoundaryToggleRealVectorMutator(BoundaryToggleRealVectorMutator orig, Cloner cloner) : base(orig, cloner) { }
|
---|
20 | public BoundaryToggleRealVectorMutator() { }
|
---|
21 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
22 | return new BoundaryToggleRealVectorMutator(this, cloner);
|
---|
23 | }
|
---|
24 | #endregion
|
---|
25 |
|
---|
26 | protected override void Manipulate(IRandom random, RealVector realVector) {
|
---|
27 | var bounds = BoundsParameter.ActualValue;
|
---|
28 | var idx = random.Next(realVector.Length);
|
---|
29 | var value = realVector[idx];
|
---|
30 | var lowerBound = bounds[idx % bounds.Rows, 0];
|
---|
31 | var upperBound = bounds[idx % bounds.Rows, 1];
|
---|
32 | if (value <= lowerBound || value >= upperBound) {
|
---|
33 | value = random.Next()*Math.Abs(upperBound - lowerBound) + Math.Min(lowerBound, upperBound);
|
---|
34 | } else {
|
---|
35 | value = random.NextDouble() <= 0.5 ? lowerBound : upperBound;
|
---|
36 | }
|
---|
37 | realVector[idx] = value;
|
---|
38 | }
|
---|
39 | }
|
---|
40 | }
|
---|