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

Last change on this file since 9392 was 9392, checked in by sforsten, 8 years ago

#1980:

  • several small bug fixes
  • added windowing technique ILAS to GAssist
  • GAssist and XCS work now with real-valued features
  • severely improved the performance of XCS
File size: 2.8 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) {
48      return Manipulate(random, input, child, random.Next(child.Condition.VirtualLength));
49    }
50
51    public static VariableVector Manipulate(IRandom random, VariableVectorInput input, VariableVector child, int index) {
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);
64      return child;
65    }
66  }
67}
Note: See TracBrowser for help on using the repository browser.