Changeset 4068 for trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/AlbaEncoding.cs
- Timestamp:
- 07/22/10 00:44:01 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/AlbaEncoding.cs
r3938 r4068 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 25 using System.Text; 26 using HeuristicLab.Encodings.PermutationEncoding; 22 using HeuristicLab.Common; 27 23 using HeuristicLab.Core; 28 24 using HeuristicLab.Data; 25 using HeuristicLab.Encodings.PermutationEncoding; 29 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Common;31 27 32 28 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Alba { 33 29 [Item("AlbaEncoding", "Represents an alba encoding of VRP solutions.")] 34 30 [StorableClass] 35 class AlbaEncoding : Permutation, IVRPEncoding {31 class AlbaEncoding : Permutation, IVRPEncoding { 36 32 #region IVRPEncoding Members 37 33 [Storable] … … 46 42 } 47 43 48 public AlbaEncoding(Permutation permutation, int cities): base(PermutationTypes.RelativeDirected) { 44 public AlbaEncoding(Permutation permutation, int cities) 45 : base(PermutationTypes.RelativeDirected) { 49 46 this.array = new int[permutation.Length]; 50 47 for (int i = 0; i < array.Length; i++) … … 76 73 } else { 77 74 tour.Add(new IntValue(this.array[i] + 1)); 78 } 75 } 79 76 } 80 77 … … 95 92 96 93 public static AlbaEncoding ConvertFrom(IVRPEncoding encoding) { 97 94 ItemList<Tour> tours = encoding.Tours; 98 95 99 int cities = 0; 100 foreach (Tour tour in tours) { 101 cities += tour.Count; 96 int cities = 0; 97 foreach (Tour tour in tours) { 98 cities += tour.Count; 99 } 100 int[] array = new int[cities + tours.Count - 2]; 101 int delimiter = cities; 102 int arrayIndex = 0; 103 104 foreach (Tour tour in tours) { 105 foreach (IntValue city in tour) { 106 array[arrayIndex] = city.Value; 107 108 arrayIndex++; 102 109 } 103 int[] array = new int[cities + tours.Count - 2];104 int delimiter = cities;105 int arrayIndex = 0;106 110 107 foreach (Tour tour in tours) { 108 foreach(IntValue city in tour) { 109 array[arrayIndex] = city.Value; 110 111 arrayIndex++; 112 } 113 114 if (arrayIndex != array.Length) { 115 array[arrayIndex] = delimiter; 116 delimiter++; 117 arrayIndex++; 118 } 111 if (arrayIndex != array.Length) { 112 array[arrayIndex] = delimiter; 113 delimiter++; 114 arrayIndex++; 119 115 } 116 } 120 117 121 118 AlbaEncoding solution = new AlbaEncoding(new Permutation(PermutationTypes.RelativeUndirected), cities); … … 124 121 } 125 122 126 123 127 124 128 125 }
Note: See TracChangeset
for help on using the changeset viewer.