Changeset 14650
- Timestamp:
- 02/07/17 14:05:09 (8 years ago)
- Location:
- branches/PersistentDataStructures
- Files:
-
- 6 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PersistentDataStructures/HeuristicLab.Data/3.3/HeuristicLab.Data-3.3.csproj
r13979 r14650 146 146 <Compile Include="Interfaces\IStringConvertibleMatrix.cs" /> 147 147 <Compile Include="Interfaces\IStringConvertibleValue.cs" /> 148 <Compile Include="PersistentDataStructures\Adaptations\HistoryArray.cs" /> 149 <Compile Include="PersistentDataStructures\Adaptations\HistoryList.cs" /> 150 <Compile Include="PersistentDataStructures\Implementations\ArrayMappedTrie.cs" /> 148 151 <Compile Include="Plugin.cs" /> 149 152 <Compile Include="Properties\AssemblyInfo.cs" /> -
branches/PersistentDataStructures/HeuristicLab.Data/3.3/PercentArray.cs
r14186 r14650 45 45 StringBuilder sb = new StringBuilder(); 46 46 sb.Append("["); 47 if ( array.Length > 0) {48 sb.Append( array[0].ToString("#0.#################### %")); // percent format49 for (int i = 1; i < array.Length; i++)50 sb.Append(";").Append( array[i].ToString("#0.#################### %")); // percent format47 if (historyArray.Length > 0) { 48 sb.Append(historyArray[0].ToString("#0.#################### %")); // percent format 49 for (int i = 1; i < historyArray.Length; i++) 50 sb.Append(";").Append(historyArray[i].ToString("#0.#################### %")); // percent format 51 51 } 52 52 sb.Append("]"); -
branches/PersistentDataStructures/HeuristicLab.Data/3.3/ValueTypeArray.cs
r14186 r14650 28 28 using HeuristicLab.Common; 29 29 using HeuristicLab.Core; 30 using HeuristicLab.Data.PersistentDataStructures.Adaptations; 30 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 32 … … 40 41 } 41 42 42 [Storable] 43 protected T[] array; 43 [Storable(AllowOneWay = true, Name = "array")] 44 protected T[] oldArrayValuePersistence { set { historyArray = new HistoryArray<T>(value); } } 45 46 [Storable] 47 protected HistoryArray<T> historyArray; 44 48 45 49 [Storable] … … 60 64 61 65 public virtual int Length { 62 get { return array.Length; }66 get { return historyArray.Length; } 63 67 #region Mono Compatibility 64 68 // this setter should be protected, but the Mono compiler couldn't handle it … … 66 70 if (ReadOnly) throw new NotSupportedException("Length cannot be set. ValueTypeArray is read-only."); 67 71 if (value != Length) { 68 Array.Resize<T>(ref array,value);72 historyArray.Resize(value); 69 73 while (elementNames.Count > value) 70 74 elementNames.RemoveAt(elementNames.Count - 1); … … 90 94 91 95 public virtual T this[int index] { 92 get { return array[index]; }96 get { return historyArray[index]; } 93 97 set { 94 98 if (ReadOnly) throw new NotSupportedException("Item cannot be set. ValueTypeArray is read-only."); 95 if (!value.Equals( array[index])) {96 array[index] = value;99 if (!value.Equals(historyArray[index])) { 100 historyArray[index] = value; 97 101 OnItemChanged(index); 98 102 } … … 115 119 protected ValueTypeArray(ValueTypeArray<T> original, Cloner cloner) 116 120 : base(original, cloner) { 117 this. array = (T[])original.array.Clone();121 this.historyArray = (HistoryArray<T>)original.historyArray.Clone(); 118 122 this.readOnly = original.readOnly; 119 123 this.resizable = original.resizable; … … 121 125 } 122 126 protected ValueTypeArray() { 123 array = new T[0];127 historyArray = new HistoryArray<T>(0); 124 128 readOnly = false; 125 129 resizable = true; … … 127 131 } 128 132 protected ValueTypeArray(int length) { 129 array = new T[length];133 historyArray = new HistoryArray<T>(length); 130 134 readOnly = false; 131 135 resizable = true; … … 134 138 protected ValueTypeArray(T[] elements) { 135 139 if (elements == null) throw new ArgumentNullException(); 136 array = (T[])elements.Clone();140 historyArray = new HistoryArray<T>(elements); 137 141 readOnly = false; 138 142 resizable = true; … … 147 151 148 152 public T[] CloneAsArray() { 149 //mkommend: this works because T must be a value type (struct constraint); 150 return (T[])array.Clone(); 153 return historyArray.ToArray(); 151 154 } 152 155 153 156 public override string ToString() { 154 if ( array.Length == 0) return "[]";157 if (historyArray.Length == 0) return "[]"; 155 158 156 159 StringBuilder sb = new StringBuilder(); 157 160 sb.Append("["); 158 sb.Append( array[0].ToString());159 for (int i = 1; i < array.Length; i++) {160 sb.Append(";").Append( array[i].ToString());161 sb.Append(historyArray[0].ToString()); 162 for (int i = 1; i < historyArray.Length; i++) { 163 sb.Append(";").Append(historyArray[i].ToString()); 161 164 if (sb.Length > maximumToStringLength) { 162 165 sb.Append("..."); … … 169 172 170 173 public virtual IEnumerator<T> GetEnumerator() { 171 return array.Cast<T>().GetEnumerator();174 return historyArray.Cast<T>().GetEnumerator(); 172 175 } 173 176 -
branches/PersistentDataStructures/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/BinaryVector.cs
r14186 r14650 41 41 public BinaryVector(BoolArray elements) 42 42 : this(elements.Length) { 43 for (int i = 0; i < array.Length; i++)44 array[i] = elements[i];43 for (int i = 0; i < historyArray.Length; i++) 44 historyArray[i] = elements[i]; 45 45 } 46 46 … … 52 52 if (length > 0) { 53 53 for (int i = 0; i < length; i++) 54 array[startIndex + i] = random.Next(2) == 0;54 historyArray[startIndex + i] = random.Next(2) == 0; 55 55 OnReset(); 56 56 } -
branches/PersistentDataStructures/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/IntegerVector.cs
r14186 r14650 42 42 public IntegerVector(IntArray elements) 43 43 : this(elements.Length) { 44 for (int i = 0; i < array.Length; i++)45 array[i] = elements[i];44 for (int i = 0; i < historyArray.Length; i++) 45 historyArray[i] = elements[i]; 46 46 } 47 47 … … 54 54 int numbers = (int)Math.Floor((max - min) / (double)step); 55 55 for (int i = startIndex; i < startIndex + length; i++) { 56 array[i] = random.Next(numbers) * step + min;56 historyArray[i] = random.Next(numbers) * step + min; 57 57 } 58 58 OnReset(); … … 65 65 if (bounds.Columns > 2) step = bounds[i % bounds.Rows, 2]; 66 66 int numbers = (int)Math.Floor((max - min) / (double)step); 67 array[i] = random.Next(numbers) * step + min;67 historyArray[i] = random.Next(numbers) * step + min; 68 68 } 69 69 OnReset(); -
branches/PersistentDataStructures/HeuristicLab.Encodings.LinearLinkageEncoding/3.3/LinearLinkage.cs
r14186 r14650 54 54 /// <returns>An enumeration of all groups.</returns> 55 55 public IEnumerable<List<int>> GetGroups() { 56 var len = array.Length;56 var len = historyArray.Length; 57 57 var remaining = new HashSet<int>(Enumerable.Range(0, len)); 58 58 // iterate from lowest to highest index … … 61 61 var group = new List<int> { i }; 62 62 remaining.Remove(i); 63 var next = array[i];63 var next = historyArray[i]; 64 64 if (next != i) { 65 65 int prev; … … 69 69 throw new ArgumentException("Array is malformed and does not represent a valid LLE forward encoding."); 70 70 prev = next; 71 next = array[next];71 next = historyArray[next]; 72 72 } while (next != prev); 73 73 } … … 104 104 public IEnumerable<int> GetGroupForward(int index) { 105 105 yield return index; 106 var next = array[index];106 var next = historyArray[index]; 107 107 if (next == index) yield break; 108 108 int prev; … … 110 110 yield return next; 111 111 prev = next; 112 next = array[next];112 next = historyArray[next]; 113 113 } while (next != prev); 114 114 } … … 130 130 public IEnumerable<int> GetGroupBackward(int index) { 131 131 yield return index; 132 var next = array[index];132 var next = historyArray[index]; 133 133 // return preceding elements in group 134 134 for (var prev = index - 1; prev >= 0; prev--) { 135 if ( array[prev] != next) continue;135 if (historyArray[prev] != next) continue; 136 136 next = prev; 137 137 yield return next; … … 150 150 /// be part of exactly one group.</param> 151 151 public void SetGroups(IEnumerable<IEnumerable<int>> grouping) { 152 var len = array.Length;152 var len = historyArray.Length; 153 153 var remaining = new HashSet<int>(Enumerable.Range(0, len)); 154 154 foreach (var group in grouping) { 155 155 var prev = -1; 156 156 foreach (var g in group.OrderBy(x => x)) { 157 if (prev >= 0) array[prev] = g;157 if (prev >= 0) historyArray[prev] = g; 158 158 prev = g; 159 159 if (!remaining.Remove(prev)) 160 160 throw new ArgumentException(string.Format("Element {0} is contained at least twice.", prev), "grouping"); 161 161 } 162 if (prev >= 0) array[prev] = prev;162 if (prev >= 0) historyArray[prev] = prev; 163 163 } 164 164 if (remaining.Count > 0) … … 175 175 /// <returns>True if the encoding is valid.</returns> 176 176 public bool Validate() { 177 var len = array.Length;177 var len = historyArray.Length; 178 178 var remaining = new HashSet<int>(Enumerable.Range(0, len)); 179 179 for (var i = 0; i < len; i++) { 180 180 if (!remaining.Contains(i)) continue; 181 181 remaining.Remove(i); 182 var next = array[i];182 var next = historyArray[i]; 183 183 if (next == i) continue; 184 184 int prev; … … 186 186 if (!remaining.Remove(next)) return false; 187 187 prev = next; 188 next = array[next];188 next = historyArray[next]; 189 189 } while (next != prev); 190 190 } … … 216 216 public void LinearizeTreeStructures() { 217 217 // Step 1: Convert the array into LLE-e 218 ToLLEeInplace( array);218 ToLLEeInplace(historyArray.ToArray()); 219 219 // Step 2: For all groups linearize the links 220 FromLLEe( array);220 FromLLEe(historyArray.ToArray()); 221 221 } 222 222 … … 234 234 /// <returns>An integer array in LLE-e representation</returns> 235 235 public int[] ToLLEe() { 236 var result = (int[]) array.Clone();236 var result = (int[])historyArray.Clone(); 237 237 ToLLEeInplace(result); 238 238 return result; … … 242 242 var length = a.Length; 243 243 for (var i = length - 1; i >= 0; i--) { 244 if ( array[i] == i) a[i] = i;244 if (historyArray[i] == i) a[i] = i; 245 245 else a[i] = a[a[i]]; 246 246 } … … 257 257 /// <param name="llee">The LLE-e representation</param> 258 258 public void FromLLEe(int[] llee) { 259 var length = array.Length;259 var length = historyArray.Length; 260 260 var groups = new Dictionary<int, int>(); 261 261 for (var i = length - 1; i >= 0; i--) { 262 262 if (llee[i] == i) { 263 array[i] = i;263 historyArray[i] = i; 264 264 groups[i] = i; 265 265 } else { 266 266 var g = llee[i]; 267 array[i] = groups[g];267 historyArray[i] = groups[g]; 268 268 groups[g] = i; 269 269 } -
branches/PersistentDataStructures/HeuristicLab.Encodings.PermutationEncoding/3.3/Permutation.cs
r14186 r14650 71 71 public Permutation(PermutationTypes type, IntArray elements) 72 72 : this(type, elements.Length) { 73 for (int i = 0; i < array.Length; i++)74 array[i] = elements[i];73 for (int i = 0; i < historyArray.Length; i++) 74 historyArray[i] = elements[i]; 75 75 } 76 76 … … 103 103 index2 = startIndex + random.Next(i + 1); 104 104 if (index1 != index2) { 105 val = array[index1];106 array[index1] = array[index2];107 array[index2] = val;105 val = historyArray[index1]; 106 historyArray[index1] = historyArray[index2]; 107 historyArray[index2] = val; 108 108 } 109 109 } -
branches/PersistentDataStructures/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVector.cs
r14186 r14650 41 41 public RealVector(DoubleArray elements) 42 42 : this(elements.Length) { 43 for (int i = 0; i < array.Length; i++)44 array[i] = elements[i];43 for (int i = 0; i < historyArray.Length; i++) 44 historyArray[i] = elements[i]; 45 45 } 46 46 … … 53 53 if (length > 0) { 54 54 for (int i = 0; i < length; i++) 55 array[startIndex + i] = min + delta * random.NextDouble();55 historyArray[startIndex + i] = min + delta * random.NextDouble(); 56 56 OnReset(); 57 57 } … … 63 63 double min = bounds[i % bounds.Rows, 0]; 64 64 double max = bounds[i % bounds.Rows, 1]; 65 array[i] = min + (max - min) * random.NextDouble();65 historyArray[i] = min + (max - min) * random.NextDouble(); 66 66 } 67 67 OnReset(); -
branches/PersistentDataStructures/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/AlbaEncoding.cs
r14186 r14650 40 40 41 41 Tour tour = new Tour(); 42 for (int i = 0; i < this. array.Length; i++) {43 if (this. array[i] >= cities) {42 for (int i = 0; i < this.historyArray.Length; i++) { 43 if (this.historyArray[i] >= cities) { 44 44 if (tour.Stops.Count > 0) { 45 45 result.Add(tour); … … 48 48 } 49 49 } else { 50 tour.Stops.Add(this. array[i] + 1);50 tour.Stops.Add(this.historyArray[i] + 1); 51 51 } 52 52 } … … 72 72 73 73 while (vehicleAssignment == -1) { 74 if (this. array[i] >= ProblemInstance.Cities.Value) {75 vehicleAssignment = this. array[i] - ProblemInstance.Cities.Value;74 if (this.historyArray[i] >= ProblemInstance.Cities.Value) { 75 vehicleAssignment = this.historyArray[i] - ProblemInstance.Cities.Value; 76 76 } 77 77 -
branches/PersistentDataStructures/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/General/PermutationEncoding.cs
r14186 r14650 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Data.PersistentDataStructures.Adaptations; 26 27 using HeuristicLab.Encodings.PermutationEncoding; 27 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 69 70 public PermutationEncoding(Permutation permutation, IVRPProblemInstance problemInstance) 70 71 : base(PermutationTypes.RelativeUndirected) { 71 this. array = new int[permutation.Length];72 for (int i = 0; i < array.Length; i++)73 this. array[i] = permutation[i];72 this.historyArray = new HistoryArray<int>(permutation.Length); 73 for (int i = 0; i < historyArray.Length; i++) 74 this.historyArray[i] = permutation[i]; 74 75 75 76 this.ProblemInstance = problemInstance; … … 82 83 83 84 public int IndexOf(int city) { 84 return Array.IndexOf(this.array,city);85 return historyArray.IndexOf(city); 85 86 } 86 87 } -
branches/PersistentDataStructures/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Prins/PrinsEncoding.cs
r14186 r14650 102 102 103 103 //find predecessor / successor in permutation 104 int predecessorIndex = Array.IndexOf(this.array,tour.Stops[0] - 1) - 1;104 int predecessorIndex = historyArray.IndexOf(tour.Stops[0] - 1) - 1; 105 105 if (predecessorIndex >= 0) { 106 106 int predecessor = this[predecessorIndex] + 1; … … 114 114 } 115 115 } else { 116 int successorIndex = Array.IndexOf(this.array,116 int successorIndex = historyArray.IndexOf( 117 117 tour.Stops[tour.Stops.Count - 1] - 1) + 1; 118 118 int successor = this[successorIndex] + 1; -
branches/PersistentDataStructures/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Zhu/ZhuEncoding.cs
r14186 r14650 63 63 64 64 //find predecessor / successor in permutation 65 int predecessorIndex = Array.IndexOf(this.array,tour.Stops[0] - 1) - 1;65 int predecessorIndex = historyArray.IndexOf(tour.Stops[0] - 1) - 1; 66 66 if (predecessorIndex >= 0) { 67 67 int predecessor = this[predecessorIndex] + 1; … … 75 75 } 76 76 } else { 77 int successorIndex = Array.IndexOf(this.array,77 int successorIndex = historyArray.IndexOf( 78 78 tour.Stops[tour.Stops.Count - 1] - 1) + 1; 79 79 int successor = this[successorIndex] + 1;
Note: See TracChangeset
for help on using the changeset viewer.