- Timestamp:
- 03/18/19 17:24:30 (6 years ago)
- Location:
- branches/2521_ProblemRefactoring
- Files:
-
- 1 deleted
- 37 edited
- 6 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring
- Property svn:ignore
-
old new 24 24 protoc.exe 25 25 obj 26 .vs
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Creators/ExactGroupsLinearLinkageCreator.cs
r12650 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 56 56 57 57 public static LinearLinkage Apply(IRandom random, int length, int groups) { 58 var solution = new LinearLinkage(length);59 58 var groupNumbers = Enumerable.Range(0, length).Select(x => x % groups).Shuffle(random); 60 59 var grouping = Enumerable.Range(0, groups).Select(x => new List<int>()).ToList(); … … 63 62 grouping[g].Add(idx++); 64 63 65 solution.SetGroups(grouping); 66 return solution; 64 return LinearLinkage.FromGroups(length, grouping); 67 65 } 68 66 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Creators/MaxGroupsLinearLinkageCreator.cs
r12650 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 55 55 56 56 public static LinearLinkage Apply(IRandom random, int length, int maxGroups) { 57 var solution = new LinearLinkage(length);58 57 var groups = Enumerable.Range(0, length).Select(x => Tuple.Create(x, random.Next(maxGroups))) 59 58 .GroupBy(x => x.Item2) 60 59 .Select(x => x.Select(y => y.Item1).ToList()); 61 solution.SetGroups(groups); 62 return solution; 60 return LinearLinkage.FromGroups(length, groups); 63 61 } 64 62 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Creators/RandomLinearLinkageCreator.cs
r12650 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 41 41 42 42 public static LinearLinkage Apply(IRandom random, int length) { 43 var solution = new LinearLinkage(length);44 43 var groups = Enumerable.Range(0, length).Select(x => Tuple.Create(x, random.Next(length))) 45 44 .GroupBy(x => x.Item2) 46 45 .Select(x => x.Select(y => y.Item1).ToList()); 47 solution.SetGroups(groups); 48 return solution; 46 return LinearLinkage.FromGroups(length, groups); 49 47 } 50 48 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Crossovers/GreedyPartitionCrossover.cs
r12285 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 44 44 public static LinearLinkage Apply(IRandom random, ItemArray<LinearLinkage> parents) { 45 45 var len = parents[0].Length; 46 47 var child = new LinearLinkage(len);48 46 var childGroup = new List<HashSet<int>>(); 49 47 var currentParent = random.Next(parents.Length); … … 69 67 } while (remaining); 70 68 71 child.SetGroups(childGroup); 72 return child; 69 return LinearLinkage.FromGroups(len, childGroup); 73 70 } 74 71 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Crossovers/GroupCrossover.cs
r12650 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 39 39 return new GroupCrossover(this, cloner); 40 40 } 41 41 42 42 public static LinearLinkage Apply(IRandom random, LinearLinkage p1, LinearLinkage p2) { 43 43 var length = p1.Length; 44 var child = new LinearLinkage(length); 45 var endNodes = new HashSet<int>(); 46 for (var i = 0; i < length; i++) { 47 if ((p1[i] == i && p2[i] == i) 48 || ((p1[i] == i || p2[i] == i) && random.NextDouble() < 0.5)) { 49 child[i] = i; 50 endNodes.Add(i); 44 var lleeP1 = p1.ToEndLinks(); 45 var lleeP2 = p2.ToEndLinks(); 46 var lleeChild = new int[length]; 47 var isTransfered = new bool[length]; 48 49 for (var i = p1.Length - 1; i >= 0; i--) { 50 lleeChild[i] = i; 51 52 // Step 1 53 var isEndP1 = p1[i] == i; 54 var isEndP2 = p2[i] == i; 55 if (isEndP1 & isEndP2 || (isEndP1 | isEndP2 && random.NextDouble() < 0.5)) { 56 isTransfered[i] = true; 57 continue; 58 } 59 60 // Step 2 61 var end1 = lleeP1[i]; 62 var end2 = lleeP2[i]; 63 64 if (isTransfered[end1] & isTransfered[end2]) { 65 var end = random.NextDouble() < 0.5 ? end1 : end2; 66 lleeChild[i] = end; 67 } else if (isTransfered[end1]) { 68 lleeChild[i] = end1; 69 } else if (isTransfered[end2]) { 70 lleeChild[i] = end2; 71 } else { 72 var next = random.NextDouble() < 0.5 ? p1[i] : p2[i]; 73 var end = lleeChild[next]; 74 lleeChild[i] = end; 51 75 } 52 76 } 53 for (var i = 0; i < length; i++) { 54 if (endNodes.Contains(i)) continue; 55 var p1End = endNodes.Contains(p1[i]); 56 var p2End = endNodes.Contains(p2[i]); 57 if ((p1End && p2End) || (!p1End && !p2End)) { 58 child[i] = random.NextDouble() < 0.5 ? p1[i] : p2[i]; 59 } else if (p1End) { 60 child[i] = p1[i]; 61 } else { 62 child[i] = p2[i]; 63 } 64 } 65 child.LinearizeTreeStructures(); 66 return child; 77 return LinearLinkage.FromEndLinks(lleeChild); 67 78 } 68 79 -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Crossovers/LowestIndexFirstCrossover.cs
r12288 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 43 43 var len = parents[0].Length; 44 44 var p = random.Next(parents.Length); 45 var child = new LinearLinkage(len);45 var child = LinearLinkage.SingleElementGroups(len); 46 46 var remaining = new SortedSet<int>(Enumerable.Range(0, len)); 47 47 do { -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Crossovers/LowestIndexMaxCrossover.cs
r12288 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 44 44 public static LinearLinkage Apply(IRandom random, ItemArray<LinearLinkage> parents) { 45 45 var len = parents[0].Length; 46 var child = new LinearLinkage(len);46 var child = LinearLinkage.SingleElementGroups(len); 47 47 var remaining = new SortedSet<int>(Enumerable.Range(0, len)); 48 48 do { -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Crossovers/MultiLLECrossover.cs
r12701 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Crossovers/SinglePointCrossover.cs
r12650 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 41 41 public static LinearLinkage Apply(IRandom random, LinearLinkage p1, LinearLinkage p2) { 42 42 var length = p1.Length; 43 var child = new LinearLinkage(length);43 var child = LinearLinkage.SingleElementGroups(length); 44 44 var bp = random.Next(length - 1); 45 45 for (var i = 0; i <= bp; i++) child[i] = p1[i]; -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Interfaces/ILinearLinkageCreator.cs
r13372 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Interfaces/ILinearLinkageCrossover.cs
r12650 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Interfaces/ILinearLinkageManipulator.cs
r12650 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Interfaces/ILinearLinkageMoveOperator.cs
r12650 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Interfaces/ILinearLinkageOperator.cs
r12650 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Interfaces/ILinearLinkageShakingOperator.cs
r12650 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Interfaces/ILinearLinkageSwap2MoveOperator.cs
r12650 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/LinearLinkage.cs
r13372 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 38 38 private LinearLinkage(LinearLinkage original, Cloner cloner) : base(original, cloner) { } 39 39 public LinearLinkage() { } 40 public LinearLinkage(int length) : base(length) { } 41 public LinearLinkage(int[] elements) : base(elements) { } 40 41 private LinearLinkage(int length) : base(length) { } 42 private LinearLinkage(int[] elements) : base(elements) { } 43 44 /// <summary> 45 /// Create a new LinearLinkage object where every element is in a seperate group. 46 /// </summary> 47 public static LinearLinkage SingleElementGroups(int length) { 48 var elements = new int[length]; 49 for (var i = 0; i < length; i++) { 50 elements[i] = i; 51 } 52 return new LinearLinkage(elements); 53 } 54 55 /// <summary> 56 /// Create a new LinearLinkage object from an int[] in LLE 57 /// </summary> 58 /// <remarks> 59 /// This operation checks if the argument is a well formed LLE 60 /// and throws an ArgumentException otherwise. 61 /// </remarks> 62 /// <exception cref="ArgumentException">If <paramref name="lle"/> does not represent a valid LLE array.</exception> 63 /// <param name="lle">The LLE representation</param> 64 /// <returns>The linear linkage encoding in LLE format (with forward-links).</returns> 65 public static LinearLinkage FromForwardLinks(int[] lle) { 66 if (!Validate(lle)) 67 throw new ArgumentException("Array is malformed and does not represent a valid LLE forward encoding.", "elements"); 68 return new LinearLinkage(lle); 69 } 70 71 /// <summary> 72 /// Create a new LinearLinkage object by parsing a LLE-b representation 73 /// and modifing the underlying array so that it is in LLE representation. 74 /// </summary> 75 /// <remarks> 76 /// This operation runs in O(n) time, the parameter <paramref name="lleb"/> is not modified. 77 /// </remarks> 78 /// <exception cref="ArgumentException">If <paramref name="lleb"/> does not represent a valid LLE-b array.</exception> 79 /// <param name="lleb">The LLE-b representation (LLE with back-links)</param> 80 /// <returns>The linear linkage encoding in LLE format (with forward-links).</returns> 81 public static LinearLinkage FromBackLinks(int[] lleb) { 82 var result = new LinearLinkage(lleb.Length); 83 for (var i = lleb.Length - 1; i > 0; i--) { 84 if (lleb[i] == i) { 85 if (result[i] == 0) result[i] = i; 86 continue; 87 } 88 result[lleb[i]] = i; 89 if (result[i] == 0) result[i] = i; 90 } 91 if (!Validate(result.array)) 92 throw new ArgumentException("Array is malformed and does not represent a valid LLE-b encoding (with back-links).", "lleb"); 93 return result; 94 } 95 96 /// <summary> 97 /// Create a new LinearLinkage object by parsing an LLE-e representation 98 /// and modifing the underlying array so that it is in LLE representation. 99 /// </summary> 100 /// <remarks> 101 /// This operation runs in O(n) time, but requires additional memory 102 /// in form of a int[]. 103 /// </remarks> 104 /// <param name="llee">The LLE-e representation</param> 105 /// <returns>The linear linkage encoding in LLE format (with forward-links).</returns> 106 public static LinearLinkage FromEndLinks(int[] llee) { 107 var result = new LinearLinkage(llee.Length); 108 result.SetEndLinks(llee); 109 return result; 110 } 111 112 /// <summary> 113 /// Create a new LinearLinkage object by translating 114 /// an enumeration of groups into the underlying array representation. 115 /// </summary> 116 /// <remarks> 117 /// Throws an ArgumentException when there is an element assigned to 118 /// multiple groups or elements that are not assigned to any group. 119 /// </remarks> 120 /// <param name="grouping">The grouping of the elements, each element must 121 /// be part of exactly one group.</param> 122 public static LinearLinkage FromGroups(int length, IEnumerable<IEnumerable<int>> grouping) { 123 var result = new LinearLinkage(length); 124 result.SetGroups(grouping); 125 return result; 126 } 42 127 43 128 public override IDeepCloneable Clone(Cloner cloner) { … … 53 138 /// array. 54 139 /// </remarks> 140 /// <exception cref="InvalidOperationException">If this object is not vaild LLE.</exception> 55 141 /// <returns>An enumeration of all groups.</returns> 56 142 public IEnumerable<List<int>> GetGroups() { 57 143 var len = array.Length; 58 var remaining = new HashSet<int>(Enumerable.Range(0, len)); 59 // iterate from lowest to highest index 144 var used = new bool[len]; 60 145 for (var i = 0; i < len; i++) { 61 if (!remaining.Contains(i)) continue; 62 var group = new List<int> { i }; 63 remaining.Remove(i); 64 var next = array[i]; 65 if (next != i) { 66 int prev; 67 do { 68 group.Add(next); 69 if (!remaining.Remove(next)) 70 throw new ArgumentException("Array is malformed and does not represent a valid LLE forward encoding."); 71 prev = next; 72 next = array[next]; 73 } while (next != prev); 74 } 146 if (used[i]) continue; 147 var curr = i; 148 var next = array[curr]; 149 var group = new List<int> { curr }; 150 while (next > curr && next < len && !used[next]) { 151 used[curr] = true; 152 curr = next; 153 next = array[next]; 154 group.Add(curr); 155 } 156 if (curr != next) throw new InvalidOperationException("Array is malformed and does not represent a valid LLE forward encoding."); 157 used[curr] = true; 75 158 yield return group; 76 159 } … … 150 233 /// <param name="grouping">The grouping of the elements, each element must 151 234 /// be part of exactly one group.</param> 235 /// <exception cref="ArgumentException">If <paramref name="grouping"/> cannot be converted 236 /// to a valid LLE representation. For instance, because elements are too big or too small, 237 /// or they're contained in multiple groups, or there are elements not assigned to any group. 238 /// </exception> 152 239 public void SetGroups(IEnumerable<IEnumerable<int>> grouping) { 153 240 var len = array.Length; 154 var remaining = new HashSet<int>(Enumerable.Range(0, len));241 var used = new bool[len]; 155 242 foreach (var group in grouping) { 156 243 var prev = -1; 157 244 foreach (var g in group.OrderBy(x => x)) { 245 if (g < prev || g >= len) throw new ArgumentException(string.Format("Element {0} is bigger than {1} or smaller than 0.", g, len - 1), "grouping"); 158 246 if (prev >= 0) array[prev] = g; 159 247 prev = g; 160 if ( !remaining.Remove(prev))248 if (used[prev]) { 161 249 throw new ArgumentException(string.Format("Element {0} is contained at least twice.", prev), "grouping"); 162 } 163 if (prev >= 0) array[prev] = prev; 164 } 165 if (remaining.Count > 0) 166 throw new ArgumentException(string.Format("Elements are not assigned a group: {0}", string.Join(", ", remaining))); 250 } 251 used[prev] = true; 252 } 253 array[prev] = prev; 254 } 255 if (!used.All(x => x)) 256 throw new ArgumentException(string.Format("Elements are not assigned a group: {0}", string.Join(", ", used.Select((x, i) => new { x, i }).Where(x => !x.x).Select(x => x.i)))); 167 257 } 168 258 … … 176 266 /// <returns>True if the encoding is valid.</returns> 177 267 public bool Validate() { 268 return Validate(array); 269 } 270 271 private static bool Validate(int[] array) { 178 272 var len = array.Length; 179 var remaining = new HashSet<int>(Enumerable.Range(0, len));273 var used = new bool[len]; 180 274 for (var i = 0; i < len; i++) { 181 if (!remaining.Contains(i)) continue; 182 remaining.Remove(i); 183 var next = array[i]; 184 if (next == i) continue; 185 int prev; 186 do { 187 if (!remaining.Remove(next)) return false; 188 prev = next; 275 if (used[i]) continue; 276 var curr = i; 277 var next = array[curr]; 278 while (next > curr && next < len && !used[next]) { 279 used[curr] = true; 280 curr = next; 189 281 next = array[next]; 190 } while (next != prev); 191 } 192 return remaining.Count == 0; 282 } 283 if (curr != next) return false; 284 used[curr] = true; 285 } 286 return true; 193 287 } 194 288 … … 197 291 /// These tree structures may be created by e.g. merging two groups by 198 292 /// linking one end node to the end node of another. 199 /// Consider following 1-based index array: 6, 6, 7, 5, 5, 8, 8, 8, 9.200 /// This results in the following tree structure for group 8:201 /// 8293 /// Consider following array: 5, 5, 6, 4, 4, 7, 7, 7, 8. 294 /// This results in the following tree structure for group 7: 295 /// 7 202 296 /// / \ 203 /// 6 7297 /// 5 6 204 298 /// / \ | 205 /// 1 2 3206 /// After this operation the array will be 2, 3, 6, 5, 5, 7, 8, 8, 9.207 /// Representing a tree with one branch: 1 -> 2 -> 3 -> 6 -> 7 -> 8299 /// 0 1 2 300 /// After this operation the array will be 1, 2, 5, 4, 4, 6, 7, 7, 8. 301 /// Representing a tree with one branch: 0 -> 1 -> 2 -> 5 -> 6 -> 7. 208 302 /// </summary> 209 303 /// <remarks> 210 304 /// The method first converts the array to LLE-e format and then 211 305 /// linearizes the links. This requires two passes of the whole array 212 /// as well as a dictionary to hold the smallest index of each group.306 /// as well as another copy of the underlying array. 213 307 /// The runtime complexity is O(n). 214 308 /// … … 217 311 public void LinearizeTreeStructures() { 218 312 // Step 1: Convert the array into LLE-e 219 To LLEeInplace(array);313 ToEndLinksInplace(array); 220 314 // Step 2: For all groups linearize the links 221 FromLLEe(array);315 SetEndLinks(array); 222 316 } 223 317 … … 228 322 /// LLE-e is a special format where each element points to the 229 323 /// ending item of a group. 230 /// The LLE representation 2, 3, 5, 6, 5, 7, 8, 8would become231 /// 5, 5, 5, 8, 5, 8, 8, 8in LLE-e.324 /// The LLE representation 1, 2, 4, 5, 4, 6, 7, 7 would become 325 /// 4, 4, 4, 7, 4, 7, 7, 7 in LLE-e. 232 326 /// 233 327 /// This operation runs in O(n) time. 234 328 /// </remarks> 329 /// <exception cref="ArgumentException">In case, this object does not 330 /// represent a valid LLE encoding. 331 /// </exception> 235 332 /// <returns>An integer array in LLE-e representation</returns> 236 public int[] To LLEe() {333 public int[] ToEndLinks() { 237 334 var result = (int[])array.Clone(); 238 To LLEeInplace(result);335 ToEndLinksInplace(result); 239 336 return result; 240 337 } 241 338 242 private void ToLLEeInplace(int[] a) {243 var length = a .Length;339 private static void ToEndLinksInplace(int[] array) { 340 var length = array.Length; 244 341 for (var i = length - 1; i >= 0; i--) { 245 if (array[i] == i) a[i] = i; 246 else a[i] = a[a[i]]; 342 var next = array[i]; 343 if (next > i) { 344 array[i] = array[next]; 345 } else if (next < i) { 346 throw new ArgumentException("Array is malformed and does not represent a valid LLE encoding.", "array"); 347 } 247 348 } 248 349 } … … 254 355 /// <remarks> 255 356 /// This operation runs in O(n) time, but requires additional memory 256 /// in form of a dictionary.357 /// in form of a int[]. 257 358 /// </remarks> 258 359 /// <param name="llee">The LLE-e representation</param> 259 public void FromLLEe(int[] llee) { 360 /// <exception cref="ArgumentException"> 361 /// If <paramref name="llee"/> does not contain a valid LLE-e representation or 362 /// has a different length to the given instance. 363 /// </exception> 364 public void SetEndLinks(int[] llee) { 260 365 var length = array.Length; 261 var groups = new Dictionary<int, int>(); 366 if (length != llee.Length) { 367 throw new ArgumentException(string.Format("Expected length {0} but length was {1}", length, llee.Length), "llee"); 368 } 369 // If we are ok with mutating llee we can avoid this clone 370 var lookup = (int[])llee.Clone(); 262 371 for (var i = length - 1; i >= 0; i--) { 263 if (llee[i] == i) { 264 array[i] = i; 265 groups[i] = i; 372 var end = llee[i]; 373 if (end == i) { 374 array[i] = end; 375 } else if (end > i && end < length) { 376 array[i] = lookup[end]; 377 lookup[end] = i; 266 378 } else { 267 var g = llee[i]; 268 array[i] = groups[g]; 269 groups[g] = i; 270 } 271 } 379 throw new ArgumentException("Array is malformed and does not represent a valid LLE-e end encoding.", "llee"); 380 } 381 } 382 } 383 384 /// <summary> 385 /// Creates a copy of the underlying array and turns it into LLE-b. 386 /// </summary> 387 /// <remarks> 388 /// LLE-b is a special format where each element points to the 389 /// predecessor instead of the successor. 390 /// The LLE representation 1, 2, 4, 5, 4, 6, 7, 7 391 /// would become 0, 0, 1, 3, 2, 3, 5, 6 in LLE-b. 392 /// 393 /// This operation runs in O(n) time. 394 /// </remarks> 395 /// <returns>An integer array in LLE-b representation</returns> 396 public int[] ToBackLinks() { 397 var result = new int[array.Length]; 398 var zeroLink = array[0]; 399 for (var i = 0; i < array.Length; i++) { 400 if (array[i] == i) { 401 if (result[i] == 0 && i != zeroLink) result[i] = i; 402 continue; 403 } 404 result[array[i]] = i; 405 if (result[i] == 0 && i != zeroLink) result[i] = i; 406 } 407 return result; 272 408 } 273 409 } -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/LinearLinkageCreator.cs
r12288 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/LinearLinkageCrossover.cs
r12285 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/LinearLinkageEncoding.cs
r13396 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/LinearLinkageManipulator.cs
r12288 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Manipulators/GraftManipulator.cs
r12396 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Manipulators/MergeGroupManipulator.cs
r12396 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Manipulators/MoveItemManipulator.cs
r12396 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Manipulators/MultiLLEManipulator.cs
r12743 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Manipulators/SplitGroupManipulator.cs
r12396 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Manipulators/SwapItemManipulator.cs
r12396 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Moves/Swap/ExhaustiveSwap2MoveGenerator.cs
r12643 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 29 29 30 30 namespace HeuristicLab.Encodings.LinearLinkageEncoding { 31 [Item("ExhaustiveSwap2MoveGenerator", "Generates all possible swap-2 moves from a given permutation.")]31 [Item("ExhaustiveSwap2MoveGenerator", "Generates all possible swap-2 moves from a given lle grouping.")] 32 32 [StorableClass] 33 33 public class ExhaustiveSwap2MoveGenerator : Swap2MoveGenerator, IExhaustiveMoveGenerator { -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Moves/Swap/StochasticSwap2MultiMoveGenerator.cs
r12643 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Moves/Swap/StochasticSwap2SingleMoveGenerator.cs
r12643 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 29 29 30 30 namespace HeuristicLab.Encodings.LinearLinkageEncoding { 31 [Item("StochasticSwap2SingleMoveGenerator", "Randomly samples a single from all possible swap-2 moves from a given grouping.")]31 [Item("StochasticSwap2SingleMoveGenerator", "Randomly samples a single from all possible swap-2 moves from a given lle grouping.")] 32 32 [StorableClass] 33 33 public class StochasticSwap2SingleMoveGenerator : Swap2MoveGenerator, IStochasticOperator, ISingleMoveGenerator { -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Moves/Swap/Swap2Move.cs
r12643 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Moves/Swap/Swap2MoveGenerator.cs
r12643 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Moves/Swap/Swap2MoveMaker.cs
r12643 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Plugin.cs.frame
r13321 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 23 23 24 24 namespace HeuristicLab.Encodings.LinearLinkageEncoding { 25 [Plugin("HeuristicLab.Encodings.LinearLinkageEncoding", "Provides data structures and operators for the linear linkage encoding (LLE).", "3. 3.13.$WCREV$")]26 [PluginFile("HeuristicLab.Encodings.LinearLinkageEncoding-3. 3.dll", PluginFileType.Assembly)]25 [Plugin("HeuristicLab.Encodings.LinearLinkageEncoding", "Provides data structures and operators for the linear linkage encoding (LLE).", "3.4.14.$WCREV$")] 26 [PluginFile("HeuristicLab.Encodings.LinearLinkageEncoding-3.4.dll", PluginFileType.Assembly)] 27 27 [PluginDependency("HeuristicLab.Collections", "3.3")] 28 28 [PluginDependency("HeuristicLab.Common", "3.3")] -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/Properties/AssemblyInfo.cs.frame
r13321 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 31 31 [assembly: AssemblyCompany("HEAL")] 32 32 [assembly: AssemblyProduct("HeuristicLab")] 33 [assembly: AssemblyCopyright("(c) 2002-201 5HEAL")]33 [assembly: AssemblyCopyright("(c) 2002-2018 HEAL")] 34 34 [assembly: AssemblyTrademark("")] 35 35 [assembly: AssemblyCulture("")] … … 53 53 // by using the '*' as shown below: 54 54 // [assembly: AssemblyVersion("1.0.*")] 55 [assembly: AssemblyVersion("3. 3.0.0")]56 [assembly: AssemblyFileVersion("3. 3.13.$WCREV$")]55 [assembly: AssemblyVersion("3.4.0.0")] 56 [assembly: AssemblyFileVersion("3.4.14.$WCREV$")] -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.LinearLinkageEncoding/3.4/ShakingOperators/LLEShakingOperator.cs
r12650 r16692 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 5Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab.
Note: See TracChangeset
for help on using the changeset viewer.