Changeset 9242 for branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Crossover
- Timestamp:
- 02/25/13 12:37:18 (12 years ago)
- Location:
- branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3
- Property svn:ignore
-
old new 1 1 obj 2 Plugin.cs
-
- Property svn:ignore
-
branches/LearningClassifierSystems/HeuristicLab.Encodings.VariableVector/3.3/Crossover/SinglePointCrossover.cs
r9226 r9242 54 54 55 55 if (parent1.Count != parent2.Count && parent1.VirtualLength != parent2.VirtualLength 56 && parent1Condition. Count != parent2Condition.Count && parent1Condition.VirtualLength != parent2Condition.VirtualLength57 && parent1Action. Count != parent2Action.Count && parent1Action.VirtualLength != parent2Action.VirtualLength)56 && parent1Condition.VariableDictionary.Count != parent2Condition.VariableDictionary.Count && parent1Condition.VirtualLength != parent2Condition.VirtualLength 57 && parent1Action.VariableDictionary.Count != parent2Action.VariableDictionary.Count && parent1Action.VirtualLength != parent2Action.VirtualLength) 58 58 throw new ArgumentException("SinglePointCrossover: The parents are of different length."); 59 59 60 60 int conditionLength = parent1Condition.VirtualLength; 61 61 int breakPoint = random.Next(1, conditionLength); 62 IList<IVariable> newCondition = new List<IVariable>(parent1Condition. Count);62 IList<IVariable> newCondition = new List<IVariable>(parent1Condition.VariableDictionary.Count); 63 63 64 64 var keyEnumerator = parent1Condition.Order.GetEnumerator(); 65 65 66 66 int index = 0; 67 IVariable curVariable ;67 IVariable curVariable = null; 68 68 while (index < breakPoint) { 69 keyEnumerator.MoveNext();70 curVariable = parent1Condition [keyEnumerator.Current];71 if ( curVariable.VirtualLength == 1 || index + curVariable.VirtualLength - 1 <breakPoint) {69 if (!keyEnumerator.MoveNext()) { throw new IndexOutOfRangeException("Enumerator has no next element!"); } 70 curVariable = parent1Condition.VariableDictionary[keyEnumerator.Current]; 71 if (index + curVariable.VirtualLength <= breakPoint) { 72 72 newCondition.Add(curVariable.GetSetCopy()); 73 index += curVariable.VirtualLength;74 73 } 74 index += curVariable.VirtualLength; 75 75 } 76 76 77 77 // breakpoint is in between a variable 78 78 if (index != breakPoint) { 79 newCondition.Add(parent1Condition [keyEnumerator.Current].CrossParentsAtPosition(parent2Condition[keyEnumerator.Current], breakPoint - index - 1));79 newCondition.Add(parent1Condition.VariableDictionary[keyEnumerator.Current].CrossParentsAtPosition(parent2Condition.VariableDictionary[keyEnumerator.Current], breakPoint - (index - curVariable.VirtualLength))); 80 80 } 81 81 82 82 while (index < conditionLength) { 83 83 keyEnumerator.MoveNext(); 84 curVariable = parent2Condition [keyEnumerator.Current];84 curVariable = parent2Condition.VariableDictionary[keyEnumerator.Current]; 85 85 newCondition.Add(curVariable.GetSetCopy()); 86 86 index += curVariable.VirtualLength; 87 87 } 88 88 89 var action = random.Next(2) == 1 ? parent1Action.Va lues.Select(x => x.GetSetCopy()) : parent2Action.Values.Select(x => x.GetSetCopy());89 var action = random.Next(2) == 1 ? parent1Action.VariableDictionary.Values.Select(x => x.GetSetCopy()) : parent2Action.VariableDictionary.Values.Select(x => x.GetSetCopy()); 90 90 91 91 return new VariableVector(newCondition, action);
Note: See TracChangeset
for help on using the changeset viewer.