Free cookie consent management tool by TermsFeed Policy Generator

source: branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Manipulator/UniformOnePositionInConditionManipulator.cs @ 10812

Last change on this file since 10812 was 9475, checked in by sforsten, 12 years ago

#1980: several small bug fixes

File size: 2.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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 System;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26
27namespace HeuristicLab.Encodings.VariableVector {
28  [Item("UniformOnePositionInConditionManipulator", "Description missing")]
29  [StorableClass]
30  public class UniformOnePositionInConditionManipulator : VariableVectorManipulator {
31
32    #region Parameter Properties
33    #endregion
34
35    [StorableConstructor]
36    protected UniformOnePositionInConditionManipulator(bool deserializing) : base(deserializing) { }
37    protected UniformOnePositionInConditionManipulator(UniformOnePositionInConditionManipulator original, Cloner cloner)
38      : base(original, cloner) {
39    }
40    public UniformOnePositionInConditionManipulator()
41      : base() {
42    }
43    public override IDeepCloneable Clone(Cloner cloner) {
44      return new UniformOnePositionInConditionManipulator(this, cloner);
45    }
46
47    protected override VariableVector Manipulate(IRandom random, VariableVectorInput input, VariableVector child, double spreadPercentage) {
48      return Manipulate(random, input, child, random.Next(child.Condition.VirtualLength), spreadPercentage);
49    }
50
51    public static VariableVector Manipulate(IRandom random, VariableVectorInput input, VariableVector child, int index, double spreadPercentage) {
52      VariableVectorCondition condition = child.Condition;
53      if (index >= condition.VirtualLength) {
54        throw new ArgumentOutOfRangeException();
55      }
56      var keyEnumerator = condition.VariableDictionary.Keys.GetEnumerator();
57      int count = 0;
58      keyEnumerator.MoveNext();
59      while (count < condition.VirtualLength && count < index && count + condition.VariableDictionary[keyEnumerator.Current].VirtualLength <= index) {
60        count += condition.VariableDictionary[keyEnumerator.Current].VirtualLength;
61        keyEnumerator.MoveNext();
62      }
63      condition.VariableDictionary[keyEnumerator.Current].Manipulate(random, input.InputDictionary[keyEnumerator.Current], index - count, spreadPercentage);
64      return child;
65    }
66  }
67}
Note: See TracBrowser for help on using the repository browser.