Changeset 9473 for branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorMoveGenerator.cs
- Timestamp:
- 05/09/13 15:03:41 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/ThreeWay/MultiComponentVectorMoveGenerator.cs
r9440 r9473 27 27 using HeuristicLab.Parameters; 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using HeuristicLab.Problems.BinPacking.Decoders; 29 30 using HeuristicLab.Problems.BinPacking.Interfaces; 31 using HeuristicLab.Problems.BinPacking.PackingBin; 32 using HeuristicLab.Problems.BinPacking.PackingItem; 30 33 31 34 namespace HeuristicLab.Encodings.PackingEncoding.MultiComponentVector { … … 44 47 protected ScopeParameter CurrentScopeParameter { 45 48 get { return (ScopeParameter)Parameters["CurrentScope"]; } 46 } 49 } 50 47 51 48 52 [StorableConstructor] … … 57 61 58 62 59 60 63 public static int NrOfRotationMoves(MultiComponentVectorEncoding mcv) { 64 return mcv.PackingInformations.Count; 65 } 61 66 public static IEnumerable<MultiComponentVectorMove> GenerateRotationMoves(MultiComponentVectorEncoding multiComponentVector) { 62 67 for (int i = 0; i < multiComponentVector.PackingInformations.Count; i++) … … 64 69 } 65 70 71 public static int NrOfSingleGroupingMoves(MultiComponentVectorEncoding mcv) { 72 int nrOfBins = 0; 73 foreach (var pi in mcv.PackingInformations) { 74 if (pi.AssignedBin > nrOfBins) 75 nrOfBins = pi.AssignedBin; 76 } 77 nrOfBins++; 78 return mcv.PackingInformations.Count * (nrOfBins - 1); 79 } 66 80 public static IEnumerable<MultiComponentVectorMove> GenerateSingleGroupingMoves(MultiComponentVectorEncoding multiComponentVector) { 67 81 int nrOfBins = 0; … … 78 92 } 79 93 80 public static IEnumerable<MultiComponentVectorMove> GenerateSwapSequenceMoves(MultiComponentVectorEncoding multiComponentVector) { 94 public static int NrOfSwapPositionMoves(MultiComponentVectorEncoding mcv) { 95 int nrOfBins = 0; 96 foreach (var pi in mcv.PackingInformations) { 97 if (pi.AssignedBin > nrOfBins) 98 nrOfBins = pi.AssignedBin; 99 } 100 nrOfBins++; 101 int[] itemsPerBin = new int[nrOfBins]; 102 foreach (var pi in mcv.PackingInformations) { 103 itemsPerBin[pi.AssignedBin]++; 104 } 105 int nrOfSwapPositionMoves = 0; 106 foreach (int items in itemsPerBin) { 107 nrOfSwapPositionMoves += (items * (items - 1)) / 2; 108 } 109 return nrOfSwapPositionMoves; 110 } 111 public static IEnumerable<MultiComponentVectorMove> GenerateSwapPositionMoves(MultiComponentVectorEncoding multiComponentVector) { 81 112 Dictionary<int, List<int>> indexesPerBin = new Dictionary<int, List<int>>(); 82 113 for (int i = 0; i < multiComponentVector.PackingInformations.Count; i++) { … … 89 120 for (int i = 0; i < entry.Value.Count - 1; i++) 90 121 for (int j = i + 1; j < entry.Value.Count; j++) 91 yield return new Swap SequenceMove(entry.Value[i], entry.Value[j], multiComponentVector);122 yield return new SwapPositionMove(entry.Value[i], entry.Value[j], multiComponentVector); 92 123 } 93 124 } 94 125 126 public static int NrOfChangePositionMoves(MultiComponentVectorEncoding mcv) { 127 int nrOfBins = 0; 128 foreach (var pi in mcv.PackingInformations) { 129 if (pi.AssignedBin > nrOfBins) 130 nrOfBins = pi.AssignedBin; 131 } 132 nrOfBins++; 133 int[] itemsPerBin = new int[nrOfBins]; 134 foreach (var pi in mcv.PackingInformations) { 135 itemsPerBin[pi.AssignedBin]++; 136 } 137 int nrOfSwapPositionMoves = 0; 138 foreach (int items in itemsPerBin) { 139 nrOfSwapPositionMoves += (items * (items - 1)) / 2; 140 } 141 return nrOfSwapPositionMoves; 142 } 143 public static IEnumerable<MultiComponentVectorMove> GenerateChangePositionMoves(MultiComponentVectorEncoding multiComponentVector) { 144 Dictionary<int, List<int>> indexesPerBin = new Dictionary<int, List<int>>(); 145 for (int i = 0; i < multiComponentVector.PackingInformations.Count; i++) { 146 int currentBin = multiComponentVector.PackingInformations[i].AssignedBin; 147 if (!indexesPerBin.ContainsKey(currentBin)) 148 indexesPerBin[currentBin] = new List<int>(); 149 indexesPerBin[currentBin].Add(i); 150 } 151 foreach (var entry in indexesPerBin) { 152 for (int i = 0; i < entry.Value.Count - 1; i++) 153 for (int j = i + 1; j < entry.Value.Count; j++) 154 yield return new ChangePositionMove(entry.Value[i], entry.Value[j], multiComponentVector); 155 } 156 } 95 157 96 158 public override IOperation Apply() {
Note: See TracChangeset
for help on using the changeset viewer.