Changeset 12288 for branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Crossovers/LowestIndexFirstCrossover.cs
- Timestamp:
- 04/06/15 22:41:24 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/LinearLinkage/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/Crossovers/LowestIndexFirstCrossover.cs
r12285 r12288 42 42 public static LinearLinkage Apply(IRandom random, ItemArray<LinearLinkage> parents) { 43 43 var len = parents[0].Length; 44 var p = random.Next(parents.Length); 44 45 var child = new LinearLinkage(len); 45 var childGroup = new List<HashSet<int>>(); 46 var currentParent = random.Next(parents.Length); 47 var remaining = new HashSet<int>(Enumerable.Range(0, len)); 46 var remaining = new SortedSet<int>(Enumerable.Range(0, len)); 48 47 do { 49 var i = remaining.Min(); 50 var group = new HashSet<int>(parents[currentParent].GetGroupForward(i)); 51 group.IntersectWith(remaining); 52 childGroup.Add(group); 53 remaining.ExceptWith(group); 54 currentParent = (currentParent + 1) % parents.Length; 48 var i = remaining.Min; 49 foreach (var g in parents[p].GetGroupForward(i)) { 50 if (!remaining.Contains(g)) continue; 51 child[i] = g; 52 i = g; 53 remaining.Remove(g); 54 } 55 child[i] = i; 56 remaining.Remove(i); 57 58 p = (p + 1) % parents.Length; 55 59 } while (remaining.Count > 0); 56 60 57 child.SetGroups(childGroup);58 61 return child; 59 62 }
Note: See TracChangeset
for help on using the changeset viewer.