source: branches/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Operators/Mutation/BoundaryToggleRealVectorMutator.cs @ 13069

Last change on this file since 13069 was 13069, checked in by gkronber, 7 years ago

#2499: imported source code for HeuristicLab.BioBoost from private repository with some changes

File size: 1.6 KB
Line 
1using HeuristicLab.BioBoost.ProblemDescription;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Data;
5using HeuristicLab.Encodings.IntegerVectorEncoding;
6using HeuristicLab.Encodings.RealVectorEncoding;
7using HeuristicLab.Parameters;
8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9using System;
10using System.Linq;
11
12namespace 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}
Note: See TracBrowser for help on using the repository browser.