Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.Problems.BioBoost/HeuristicLab.Problems.BioBoost/3.3/Operators/Mutation/BoundaryToggleRealVectorMutator.cs @ 16575

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

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

File size: 2.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Encodings.RealVectorEncoding;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26using System;
27using HEAL.Attic;
28
29namespace HeuristicLab.BioBoost.Operators.Mutation {
30  [StorableType("CC8C60CC-E58C-4FD6-95CA-F310064221AD")]
31  public class BoundaryToggleRealVectorMutator : RealVectorManipulator {
32
33    #region Construction & Cloning
34    [StorableConstructor]
35    protected BoundaryToggleRealVectorMutator(StorableConstructorFlag _) : base(_) { }
36    protected BoundaryToggleRealVectorMutator(BoundaryToggleRealVectorMutator orig, Cloner cloner) : base(orig, cloner) { }
37    public BoundaryToggleRealVectorMutator() { }
38    public override IDeepCloneable Clone(Cloner cloner) {
39      return new BoundaryToggleRealVectorMutator(this, cloner);
40    }
41    #endregion
42
43    protected override void Manipulate(IRandom random, RealVector realVector) {
44      var bounds = BoundsParameter.ActualValue;
45      var idx = random.Next(realVector.Length);
46      var value = realVector[idx];
47      var lowerBound = bounds[idx % bounds.Rows, 0];
48      var upperBound = bounds[idx % bounds.Rows, 1];
49      if (value <= lowerBound || value >= upperBound) {
50        value = random.Next()*Math.Abs(upperBound - lowerBound) + Math.Min(lowerBound, upperBound);
51      } else {
52        value = random.NextDouble() <= 0.5 ? lowerBound : upperBound;
53      }
54      realVector[idx] = value;
55    }
56  }
57}
Note: See TracBrowser for help on using the repository browser.