- Timestamp:
- 07/21/16 15:08:21 (8 years ago)
- Location:
- branches/HeuristicLab.BinPacking
- Files:
-
- 2 added
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/BinPacking2D.cs
r14151 r14154 32 32 public class BinPacking2D : BinPacking.BinPacking<PackingPosition, PackingShape, PackingItem> { 33 33 34 public BinPacking2D(PackingShape bin Measures)35 : base(bin Measures) {34 public BinPacking2D(PackingShape binShape) 35 : base(binShape) { 36 36 ExtremePoints = new SortedSet<PackingPosition>(new EPComparer2D()); 37 ExtremePoints.Add(binMeasures.Origin); 38 } 37 ExtremePoints.Add(binShape.Origin); 38 InitializeOccupationLayers(); 39 } 40 39 41 [StorableConstructor] 40 42 protected BinPacking2D(bool deserializing) : base(deserializing) { } 41 43 protected BinPacking2D(BinPacking2D original, Cloner cloner) 42 44 : base(original, cloner) { 43 this.ExtremePoints = new SortedSet<PackingPosition>(original.ExtremePoints , new EPComparer2D());45 this.ExtremePoints = new SortedSet<PackingPosition>(original.ExtremePoints.Select(p => cloner.Clone(p)), new EPComparer2D()); 44 46 } 45 47 public override IDeepCloneable Clone(Cloner cloner) { … … 54 56 //Find ExtremePoints beginning from sourcepointX 55 57 var sourcePointX = new PackingPosition(0, position.X + newWidth, position.Y); 56 if (sourcePointX.X < Bin Measures.Width && sourcePointX.Y < BinMeasures.Height) {58 if (sourcePointX.X < BinShape.Width && sourcePointX.Y < BinShape.Height) { 57 59 //Traversing down the y-axis 58 60 var newPoint = new PackingPosition(0, sourcePointX.X, sourcePointX.Y - 1); … … 66 68 //Find ExtremePoints beginning from sourcepointY 67 69 var sourcePointY = new PackingPosition(0, position.X, position.Y + newHeight); 68 if (sourcePointY.X < Bin Measures.Width && sourcePointY.Y < BinMeasures.Height) {70 if (sourcePointY.X < BinShape.Width && sourcePointY.Y < BinShape.Height) { 69 71 //Traversing down the x-axis 70 72 var newPoint = new PackingPosition(0, sourcePointY.X - 1, sourcePointY.Y); … … 96 98 public override PackingPosition FindPositionBySliding(PackingItem item, bool rotated) { 97 99 PackingPosition currentPosition = new PackingPosition(0, 98 Bin Measures.Width - (rotated ? item.Height : item.Width),99 Bin Measures.Height - (rotated ? item.Width : item.Height), rotated);100 BinShape.Width - (rotated ? item.Height : item.Width), 101 BinShape.Height - (rotated ? item.Width : item.Height), rotated); 100 102 //Slide the item as far as possible to the left 101 103 while (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition)) … … 159 161 public override int ShortestPossibleSideFromPoint(PackingPosition position) { 160 162 int shortestSide = int.MaxValue; 161 int width = Bin Measures.Width;162 int height = Bin Measures.Height;163 int width = BinShape.Width; 164 int height = BinShape.Height; 163 165 164 166 if (position.X >= width || position.Y >= height) … … 182 184 } 183 185 184 185 186 protected override void InitializeOccupationLayers() { 186 for (int i = 0; i * 10 <= Bin Measures.Width; i += 1) {187 for (int i = 0; i * 10 <= BinShape.Width; i += 1) { 187 188 OccupationLayers[i] = new List<int>(); 188 189 } 189 190 } 190 protected override void AddNewItemToOccupationLayers(int itemID, PackingItem measures, PackingPosition position) { 191 192 protected override void AddNewItemToOccupationLayers(int itemID, PackingItem item, PackingPosition position) { 191 193 int x1 = position.X / 10; 192 int x2 = (position.X + (position.Rotated ? measures.Height : measures.Width)) / 10;194 int x2 = (position.X + (position.Rotated ? item.Height : item.Width)) / 10; 193 195 194 196 for (int i = x1; i <= x2; i++) … … 198 200 return OccupationLayers[position.X / 10]; 199 201 } 200 protected override List<int> GetLayerItemIDs(PackingItem measures, PackingPosition position) {202 protected override List<int> GetLayerItemIDs(PackingItem item, PackingPosition position) { 201 203 List<int> result = new List<int>(); 202 204 int x1 = position.X / 10; 203 int x2 = (position.X + (position.Rotated ? measures.Height : measures.Width)) / 10;205 int x2 = (position.X + (position.Rotated ? item.Height : item.Width)) / 10; 204 206 205 207 for (int i = x1; i <= x2; i++) -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/Evaluators/BinUtilizationEvaluator.cs
r14148 r14154 53 53 54 54 for (int i = 0; i < nrOfBins; i++) { 55 totalUsableSpace += solution.BinPackings[i].Bin Measures.Volume;56 totalUsedSpace += solution.BinPackings[i].Item Measures.Sum(kvp => kvp.Value.Volume);55 totalUsableSpace += solution.BinPackings[i].BinShape.Volume; 56 totalUsedSpace += solution.BinPackings[i].Items.Sum(kvp => kvp.Value.Volume); 57 57 } 58 58 -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/Evaluators/PackingRatioEvaluator.cs
r14151 r14154 60 60 const double k = 2; 61 61 for (int i = 0; i < nrOfBins; i++) { 62 double f = solution.BinPackings[i].Item Measures.Sum(kvp => kvp.Value.Volume);63 double c = solution.BinPackings[i].Bin Measures.Volume;62 double f = solution.BinPackings[i].Items.Sum(kvp => kvp.Value.Volume); 63 double c = solution.BinPackings[i].BinShape.Volume; 64 64 result += Math.Pow(f / c, k); 65 65 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/HeuristicLab.Problems.BinPacking2D-3.3.csproj
r14151 r14154 172 172 <Compile Include="IntegerVectorEncoding\ExtremePointIntegerVectorDecoder.cs" /> 173 173 <Compile Include="IntegerVectorEncoding\IntegerVectorProblem.cs" /> 174 <Compile Include="Interfaces\IOperator.cs" /> 174 175 <Compile Include="Interfaces\IDecoder.cs" /> 175 176 <Compile Include="Interfaces\IEvaluator.cs" /> -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/MoveEvaluatorBase.cs
r14153 r14154 31 31 [StorableClass] 32 32 public abstract class MoveEvaluatorBase<TSol, TMove> : SingleSuccessorOperator, 33 ISingleObjectiveMoveEvaluator, ISingleObjectiveMoveOperator 33 ISingleObjectiveMoveEvaluator, ISingleObjectiveMoveOperator, IOperator<TSol> 34 34 where TSol : class, IItem 35 35 where TMove : class, IItem { … … 43 43 get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; } 44 44 } 45 public ILookupParameter<ReadOnlyItemList<PackingItem>> PackingItemMeasuresParameter {45 public ILookupParameter<ReadOnlyItemList<PackingItem>> ItemsParameter { 46 46 get { return (LookupParameter<ReadOnlyItemList<PackingItem>>)Parameters["Items"]; } 47 47 } 48 public ILookupParameter<PackingShape> PackingBinMeasuresParameter {48 public ILookupParameter<PackingShape> BinShapeParameter { 49 49 get { return (LookupParameter<PackingShape>)Parameters["BinShape"]; } 50 50 } 51 public ILookupParameter<IDecoder<TSol>> PackingSolutionDecoderParameter {51 public ILookupParameter<IDecoder<TSol>> DecoderParameter { 52 52 get { return (ILookupParameter<IDecoder<TSol>>)Parameters["Decoder"]; } 53 53 } 54 public ILookupParameter<IEvaluator> PackingPlanEvaluatorParameter {54 public ILookupParameter<IEvaluator> SolutionEvaluatorParameter { 55 55 get { return (ILookupParameter<IEvaluator>)Parameters["SolutionEvaluator"]; } 56 56 } … … 78 78 var move = MoveParameter.ActualValue; 79 79 var encSolCandidate = EncodedSolutionParameter.ActualValue; 80 var binShape = PackingBinMeasuresParameter.ActualValue;81 var items = PackingItemMeasuresParameter.ActualValue;80 var binShape = BinShapeParameter.ActualValue; 81 var items = ItemsParameter.ActualValue; 82 82 83 83 -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/PermutationEncoding/PermutationProblem.cs
r14153 r14154 23 23 24 24 using System.Linq; 25 using System.Windows.Forms; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 72 73 Encoding.ConfigureOperators(Operators.OfType<IOperator>()); 73 74 74 // TODO: configure the move evaluators (add interface for my move evaluators) 75 foreach (var op in Operators.OfType<IOperator<Permutation>>()) { 76 op.BinShapeParameter.ActualName = BinShapeParameter.Name; 77 op.ItemsParameter.ActualName = ItemsParameter.Name; 78 op.SolutionEvaluatorParameter.ActualName = SolutionEvaluatorParameter.Name; 79 op.DecoderParameter.ActualName = DecoderParameter.Name; 80 } 75 81 } 76 82 -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/PermutationEncoding/Swap2MoveEvaluator.cs
r14149 r14154 50 50 // uses full evaluation 51 51 Swap2Manipulator.Apply(permutation, move.Index1, move.Index2); 52 var solution = PackingSolutionDecoderParameter.ActualValue.Decode(permutation, binShape, items);52 var solution = DecoderParameter.ActualValue.Decode(permutation, binShape, items); 53 53 54 return PackingPlanEvaluatorParameter.ActualValue.Evaluate(solution);54 return SolutionEvaluatorParameter.ActualValue.Evaluate(solution); 55 55 } 56 56 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/PermutationEncoding/TranslocationMoveEvaluator.cs
r14149 r14154 51 51 // uses full evaluation 52 52 TranslocationManipulator.Apply(permutation, move.Index1, move.Index2, move.Index3); 53 var solution = PackingSolutionDecoderParameter.ActualValue.Decode(permutation, binShape, items);53 var solution = DecoderParameter.ActualValue.Decode(permutation, binShape, items); 54 54 55 return PackingPlanEvaluatorParameter.ActualValue.Evaluate(solution);55 return SolutionEvaluatorParameter.ActualValue.Evaluate(solution); 56 56 } 57 57 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/BinPacking3D.cs
r14153 r14154 32 32 public class BinPacking3D : BinPacking<PackingPosition, PackingShape, PackingItem> { 33 33 34 public BinPacking3D(PackingShape bin Measures)35 : base(bin Measures) {34 public BinPacking3D(PackingShape binShape) 35 : base(binShape) { 36 36 ExtremePoints = new SortedSet<PackingPosition>(new EPComparer3D()); 37 ExtremePoints.Add(binMeasures.Origin); 37 ExtremePoints.Add(binShape.Origin); 38 InitializeOccupationLayers(); 38 39 } 39 40 [StorableConstructor] … … 41 42 protected BinPacking3D(BinPacking3D original, Cloner cloner) 42 43 : base(original, cloner) { 43 this.ExtremePoints = new SortedSet<PackingPosition>(original.ExtremePoints , new EPComparer3D());44 this.ExtremePoints = new SortedSet<PackingPosition>(original.ExtremePoints.Select(p => cloner.Clone(p)), new EPComparer3D()); 44 45 } 45 46 public override IDeepCloneable Clone(Cloner cloner) { … … 53 54 //Find ExtremePoints beginning from sourcepointX 54 55 var sourcePointX = new PackingPosition(0, position.X + newWidth, position.Y, position.Z); 55 if (sourcePointX.X < Bin Measures.Width && sourcePointX.Y < BinMeasures.Height && sourcePointX.Z < BinMeasures.Depth) {56 if (sourcePointX.X < BinShape.Width && sourcePointX.Y < BinShape.Height && sourcePointX.Z < BinShape.Depth) { 56 57 //Traversing down the y-axis 57 58 PackingPosition current = new PackingPosition(0, sourcePointX.X, sourcePointX.Y, sourcePointX.Z); … … 79 80 //Find ExtremePoints beginning from sourcepointY 80 81 var sourcePointY = new PackingPosition(0, position.X, position.Y + newItem.Height, position.Z); 81 if (sourcePointY.X < Bin Measures.Width && sourcePointY.Y < BinMeasures.Height && sourcePointY.Z < BinMeasures.Depth) {82 if (sourcePointY.X < BinShape.Width && sourcePointY.Y < BinShape.Height && sourcePointY.Z < BinShape.Depth) { 82 83 //Traversing down the x-axis 83 84 PackingPosition current = new PackingPosition(0, sourcePointY.X, sourcePointY.Y, sourcePointY.Z); … … 105 106 //Find ExtremePoints beginning from sourcepointZ 106 107 var sourcePointZ = new PackingPosition(0, position.X, position.Y, position.Z + newDepth); 107 if (sourcePointZ.X < Bin Measures.Width && sourcePointZ.Y < BinMeasures.Height && sourcePointZ.Z < BinMeasures.Depth) {108 if (sourcePointZ.X < BinShape.Width && sourcePointZ.Y < BinShape.Height && sourcePointZ.Z < BinShape.Depth) { 108 109 //Traversing down the x-axis 109 110 PackingPosition current = new PackingPosition(0, sourcePointZ.X, sourcePointZ.Y, sourcePointZ.Z); … … 130 131 } 131 132 132 public override PackingPosition FindExtremePointForItem(PackingItem measures, bool rotated, bool stackingConstraints) {133 134 PackingItem item = new PackingItem(135 rotated ? measures.Depth : measures.Width,136 measures.Height,137 rotated ? measures.Width : measures.Depth,138 measures.TargetBin);133 public override PackingPosition FindExtremePointForItem(PackingItem item, bool rotated, bool stackingConstraints) { 134 135 PackingItem newItem = new PackingItem( 136 rotated ? item.Depth : item.Width, 137 item.Height, 138 rotated ? item.Width : item.Depth, 139 item.TargetBin); 139 140 140 141 int epIndex = 0; 141 142 while (epIndex < ExtremePoints.Count && ( 142 !IsPositionFeasible( item, ExtremePoints.ElementAt(epIndex))143 || !IsSupportedByAtLeastOnePoint( item, ExtremePoints.ElementAt(epIndex))144 || (stackingConstraints && !IsStaticStable( item, ExtremePoints.ElementAt(epIndex)))145 || (stackingConstraints && !IsWeightSupported( item, ExtremePoints.ElementAt(epIndex)))143 !IsPositionFeasible(newItem, ExtremePoints.ElementAt(epIndex)) 144 || !IsSupportedByAtLeastOnePoint(newItem, ExtremePoints.ElementAt(epIndex)) 145 || (stackingConstraints && !IsStaticStable(newItem, ExtremePoints.ElementAt(epIndex))) 146 || (stackingConstraints && !IsWeightSupported(newItem, ExtremePoints.ElementAt(epIndex))) 146 147 )) { epIndex++; } 147 148 … … 154 155 } 155 156 156 public override PackingPosition FindPositionBySliding(PackingItem measures, bool rotated) {157 public override PackingPosition FindPositionBySliding(PackingItem item, bool rotated) { 157 158 //TODO: does not support stacking constraints yet 158 159 //Starting-position at upper right corner (=left bottom point of item-rectangle is at position item.width,item.height) 159 160 PackingPosition currentPosition = new PackingPosition(0, 160 Bin Measures.Width - (rotated ? measures.Depth : measures.Width),161 Bin Measures.Height - measures.Height,162 Bin Measures.Depth - (rotated ? measures.Width : measures.Depth), rotated);161 BinShape.Width - (rotated ? item.Depth : item.Width), 162 BinShape.Height - item.Height, 163 BinShape.Depth - (rotated ? item.Width : item.Depth), rotated); 163 164 //Slide the item as far as possible to the bottom 164 while (IsPositionFeasible( measures, PackingPosition.MoveDown(currentPosition))165 || IsPositionFeasible( measures, PackingPosition.MoveLeft(currentPosition))166 || IsPositionFeasible( measures, PackingPosition.MoveBack(currentPosition))) {165 while (IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition)) 166 || IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition)) 167 || IsPositionFeasible(item, PackingPosition.MoveBack(currentPosition))) { 167 168 //Slide the item as far as possible to the left 168 while (IsPositionFeasible( measures, PackingPosition.MoveLeft(currentPosition))169 || IsPositionFeasible( measures, PackingPosition.MoveBack(currentPosition))) {169 while (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition)) 170 || IsPositionFeasible(item, PackingPosition.MoveBack(currentPosition))) { 170 171 //Slide the item as far as possible to the back 171 while (IsPositionFeasible( measures, PackingPosition.MoveBack(currentPosition))) {172 while (IsPositionFeasible(item, PackingPosition.MoveBack(currentPosition))) { 172 173 currentPosition = PackingPosition.MoveBack(currentPosition); 173 174 } 174 if (IsPositionFeasible( measures, PackingPosition.MoveLeft(currentPosition)))175 if (IsPositionFeasible(item, PackingPosition.MoveLeft(currentPosition))) 175 176 currentPosition = PackingPosition.MoveLeft(currentPosition); 176 177 } 177 if (IsPositionFeasible( measures, PackingPosition.MoveDown(currentPosition)))178 if (IsPositionFeasible(item, PackingPosition.MoveDown(currentPosition))) 178 179 currentPosition = PackingPosition.MoveDown(currentPosition); 179 180 } 180 181 181 return IsPositionFeasible( measures, currentPosition) ? currentPosition : null;182 } 183 184 public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> item Measures) {182 return IsPositionFeasible(item, currentPosition) ? currentPosition : null; 183 } 184 185 public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items) { 185 186 var temp = new List<int>(sequence); 186 187 for (int i = 0; i < temp.Count; i++) { 187 var item = item Measures[temp[i]];188 var item = items[temp[i]]; 188 189 var position = FindPositionBySliding(item, false); 189 190 if (position != null) { … … 193 194 } 194 195 } 195 public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> item Measures, Dictionary<int, bool> rotationArray) {196 public override void SlidingBasedPacking(ref IList<int> sequence, IList<PackingItem> items, Dictionary<int, bool> rotationArray) { 196 197 var temp = new List<int>(sequence); 197 198 for (int i = 0; i < temp.Count; i++) { 198 var item = item Measures[temp[i]];199 var item = items[temp[i]]; 199 200 var position = FindPositionBySliding(item, rotationArray[i]); 200 201 if (position != null) { … … 204 205 } 205 206 } 206 public override void ExtremePointBasedPacking(ref IList<int> sequence, IList<PackingItem> item Measures, bool stackingConstraints) {207 public override void ExtremePointBasedPacking(ref IList<int> sequence, IList<PackingItem> items, bool stackingConstraints) { 207 208 var temp = new List<int>(sequence); 208 209 foreach (int itemID in temp) { 209 var item = item Measures[itemID];210 var item = items[itemID]; 210 211 var positionFound = FindExtremePointForItem(item, false, stackingConstraints); 211 212 if (positionFound != null) { … … 215 216 } 216 217 } 217 public override void ExtremePointBasedPacking(ref IList<int> sequence, IList<PackingItem> item Measures, bool stackingConstraints, Dictionary<int, bool> rotationArray) {218 public override void ExtremePointBasedPacking(ref IList<int> sequence, IList<PackingItem> items, bool stackingConstraints, Dictionary<int, bool> rotationArray) { 218 219 var temp = new List<int>(sequence); 219 220 foreach (int itemID in temp) { 220 var item = item Measures[itemID];221 var item = items[itemID]; 221 222 var positionFound = FindExtremePointForItem(item, rotationArray[itemID], stackingConstraints); 222 223 if (positionFound != null) { … … 230 231 231 232 int shortestSide = int.MaxValue; 232 int width = Bin Measures.Width;233 int height = Bin Measures.Height;234 int depth = Bin Measures.Depth;233 int width = BinShape.Width; 234 int height = BinShape.Height; 235 int depth = BinShape.Depth; 235 236 236 237 if (position.X >= width || position.Y >= height || position.Z >= depth) … … 287 288 return true; 288 289 289 if (Item Measures[PointOccupation(new PackingPosition(0, ep.X, ep.Y - 1, ep.Z))].SupportsStacking(item)290 && Item Measures[PointOccupation(new PackingPosition(0, ep.X + item.Width - 1, ep.Y - 1, ep.Z))].SupportsStacking(item)291 && Item Measures[PointOccupation(new PackingPosition(0, ep.X, ep.Y - 1, ep.Z + item.Depth - 1))].SupportsStacking(item)292 && Item Measures[PointOccupation(new PackingPosition(0, ep.X + item.Width - 1, ep.Y - 1, ep.Z + item.Depth - 1))].SupportsStacking(item))290 if (Items[PointOccupation(new PackingPosition(0, ep.X, ep.Y - 1, ep.Z))].SupportsStacking(item) 291 && Items[PointOccupation(new PackingPosition(0, ep.X + item.Width - 1, ep.Y - 1, ep.Z))].SupportsStacking(item) 292 && Items[PointOccupation(new PackingPosition(0, ep.X, ep.Y - 1, ep.Z + item.Depth - 1))].SupportsStacking(item) 293 && Items[PointOccupation(new PackingPosition(0, ep.X + item.Width - 1, ep.Y - 1, ep.Z + item.Depth - 1))].SupportsStacking(item)) 293 294 return true; 294 295 … … 298 299 299 300 protected override void InitializeOccupationLayers() { 300 for (int i = 0; i * 10 <= Bin Measures.Depth; i += 1) {301 for (int i = 0; i * 10 <= BinShape.Depth; i += 1) { 301 302 OccupationLayers[i] = new List<int>(); 302 303 } 303 304 } 304 protected override void AddNewItemToOccupationLayers(int itemID, PackingItem measures, PackingPosition position) {305 protected override void AddNewItemToOccupationLayers(int itemID, PackingItem item, PackingPosition position) { 305 306 int z1 = position.Z / 10; 306 int z2 = (position.Z + (position.Rotated ? measures.Width : measures.Depth)) / 10;307 int z2 = (position.Z + (position.Rotated ? item.Width : item.Depth)) / 10; 307 308 308 309 for (int i = z1; i <= z2; i++) … … 312 313 return OccupationLayers[position.Z / 10]; 313 314 } 314 protected override List<int> GetLayerItemIDs(PackingItem measures, PackingPosition position) {315 protected override List<int> GetLayerItemIDs(PackingItem item, PackingPosition position) { 315 316 List<int> result = new List<int>(); 316 317 int z1 = position.Z / 10; 317 int z2 = (position.Z + (position.Rotated ? measures.Width : measures.Depth)) / 10;318 int z2 = (position.Z + (position.Rotated ? item.Width : item.Depth)) / 10; 318 319 319 320 for (int i = z1; i <= z2; i++) -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/Evaluators/BinUtilizationEvaluator.cs
r14153 r14154 54 54 55 55 for (int i = 0; i < nrOfBins; i++) { 56 totalUsableSpace += solution.BinPackings[i].Bin Measures.Volume;57 totalUsedSpace += solution.BinPackings[i].Item Measures.Sum(kvp => kvp.Value.Volume);56 totalUsableSpace += solution.BinPackings[i].BinShape.Volume; 57 totalUsedSpace += solution.BinPackings[i].Items.Sum(kvp => kvp.Value.Volume); 58 58 } 59 59 -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/Evaluators/PackingRatioEvaluator.cs
r14153 r14154 61 61 const double k = 2; 62 62 for (int i = 0; i < nrOfBins; i++) { 63 double f = solution.BinPackings[i].Item Measures.Sum(kvp => kvp.Value.Volume);64 double c = solution.BinPackings[i].Bin Measures.Volume;63 double f = solution.BinPackings[i].Items.Sum(kvp => kvp.Value.Volume); 64 double c = solution.BinPackings[i].BinShape.Volume; 65 65 result += Math.Pow(f / c, k); 66 66 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/HeuristicLab.Problems.BinPacking3D-3.3.csproj
r14153 r14154 174 174 <Compile Include="Interfaces\IDecoder.cs" /> 175 175 <Compile Include="Interfaces\IEvaluator.cs" /> 176 <Compile Include="Interfaces\IOperator.cs" /> 176 177 <Compile Include="MoveEvaluatorBase.cs" /> 177 178 <Compile Include="PackingItem.cs" /> -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/MoveEvaluatorBase.cs
r14153 r14154 31 31 [StorableClass] 32 32 public abstract class MoveEvaluatorBase<TSol, TMove> : SingleSuccessorOperator, 33 ISingleObjectiveMoveEvaluator, ISingleObjectiveMoveOperator 33 ISingleObjectiveMoveEvaluator, ISingleObjectiveMoveOperator, IOperator<TSol> 34 34 where TSol : class, IItem 35 35 where TMove : class, IItem { … … 43 43 get { return (ILookupParameter<DoubleValue>)Parameters["MoveQuality"]; } 44 44 } 45 public ILookupParameter<ReadOnlyItemList<PackingItem>> PackingItemMeasuresParameter {45 public ILookupParameter<ReadOnlyItemList<PackingItem>> ItemsParameter { 46 46 get { return (LookupParameter<ReadOnlyItemList<PackingItem>>)Parameters["Items"]; } 47 47 } 48 public ILookupParameter<PackingShape> PackingBinMeasuresParameter {48 public ILookupParameter<PackingShape> BinShapeParameter { 49 49 get { return (LookupParameter<PackingShape>)Parameters["BinShape"]; } 50 50 } 51 public ILookupParameter<IDecoder<TSol>> PackingSolutionDecoderParameter {51 public ILookupParameter<IDecoder<TSol>> DecoderParameter { 52 52 get { return (ILookupParameter<IDecoder<TSol>>)Parameters["Decoder"]; } 53 53 } 54 public ILookupParameter<IEvaluator> PackingPlanEvaluatorParameter {54 public ILookupParameter<IEvaluator> SolutionEvaluatorParameter { 55 55 get { return (ILookupParameter<IEvaluator>)Parameters["SolutionEvaluator"]; } 56 56 } … … 82 82 var move = MoveParameter.ActualValue; 83 83 var encSolCandidate = EncodedSolutionParameter.ActualValue; 84 var binShape = PackingBinMeasuresParameter.ActualValue;85 var items = PackingItemMeasuresParameter.ActualValue;84 var binShape = BinShapeParameter.ActualValue; 85 var items = ItemsParameter.ActualValue; 86 86 87 87 -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/PermutationEncoding/PermutationProblem.cs
r14153 r14154 70 70 Operators.RemoveAll(x => x is SingleObjectiveMoveEvaluator); 71 71 72 Encoding.ConfigureOperators(Operators.OfType<IOperator>()); 72 Encoding.ConfigureOperators(Operators.OfType<IOperator>()); 73 73 74 // TODO: configure my move evaluators (introduce interface) 74 foreach (var op in Operators.OfType<IOperator<Permutation>>()) { 75 op.BinShapeParameter.ActualName = BinShapeParameter.Name; 76 op.ItemsParameter.ActualName = ItemsParameter.Name; 77 op.SolutionEvaluatorParameter.ActualName = SolutionEvaluatorParameter.Name; 78 op.DecoderParameter.ActualName = DecoderParameter.Name; 79 op.UseStackingConstraintsParameter.ActualName = UseStackingConstraintsParameter.Name; 80 } 75 81 } 76 82 -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/PermutationEncoding/Swap2MoveEvaluator.cs
r14153 r14154 50 50 // uses full evaluation 51 51 Swap2Manipulator.Apply(permutation, move.Index1, move.Index2); 52 var solution = PackingSolutionDecoderParameter.ActualValue.Decode(permutation, binShape, items, useStackingConstraints);52 var solution = DecoderParameter.ActualValue.Decode(permutation, binShape, items, useStackingConstraints); 53 53 54 return PackingPlanEvaluatorParameter.ActualValue.Evaluate(solution);54 return SolutionEvaluatorParameter.ActualValue.Evaluate(solution); 55 55 } 56 56 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/PermutationEncoding/TranslocationMoveEvaluator.cs
r14153 r14154 51 51 // uses full evaluation 52 52 TranslocationManipulator.Apply(permutation, move.Index1, move.Index2, move.Index3); 53 var solution = PackingSolutionDecoderParameter.ActualValue.Decode(permutation, binShape, items, useStackingConstraints);53 var solution = DecoderParameter.ActualValue.Decode(permutation, binShape, items, useStackingConstraints); 54 54 55 return PackingPlanEvaluatorParameter.ActualValue.Evaluate(solution);55 return SolutionEvaluatorParameter.ActualValue.Evaluate(solution); 56 56 } 57 57 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3/Container2DView.xaml.cs
r14151 r14154 71 71 if (packing == null) return; 72 72 // the container should fill the whole size 73 var scalingX = renderSize.Width / Packing.Bin Measures.Width;74 var scalingY = renderSize.Height / Packing.Bin Measures.Width;73 var scalingX = renderSize.Width / Packing.BinShape.Width; 74 var scalingY = renderSize.Height / Packing.BinShape.Width; 75 75 // draw container 76 76 drawingContext.DrawRectangle(Brushes.LightGray, new Pen(Brushes.Black, 1), new Rect(new Point(0, 0), renderSize)); … … 79 79 var unselectedBrush = selectedItemKey < 0 ? selectedBrush : Brushes.DarkGray; 80 80 81 foreach (var t in Packing.Item Measures) {81 foreach (var t in Packing.Items) { 82 82 var key = t.Key; 83 83 var item = t.Value; 84 var pos = Packing. ItemPositions[key];84 var pos = Packing.Positions[key]; 85 85 86 86 var scaledPos = new Point(pos.X * scalingX, pos.Y * scalingY); -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml
r14153 r14154 128 128 </RotateTransform3D> 129 129 <TranslateTransform3D OffsetX="0.5" OffsetY="0.5" OffsetZ="0.5" /> 130 <ScaleTransform3D x:Name="scaleZoom" CenterX="0.5" CenterY="0.5" CenterZ="0.5" ScaleX=" 0.6" ScaleY="0.6" ScaleZ="0.6"/>130 <ScaleTransform3D x:Name="scaleZoom" CenterX="0.5" CenterY="0.5" CenterZ="0.5" ScaleX="1" ScaleY="1" ScaleZ="1"/> 131 131 </Transform3DGroup> 132 132 </ModelVisual3D.Transform> -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3/Container3DView.xaml.cs
r14151 r14154 47 47 public Container3DView() { 48 48 InitializeComponent(); 49 camMain.Position = new Point3D(0.5, 2, 2); // for design time we use a different camera position49 camMain.Position = new Point3D(0.5, 3, 3); // for design time we use a different camera position 50 50 Clear(); 51 51 } … … 80 80 // - from rotation and Z-ordering 81 81 82 foreach (var item in packing.Item Measures.OrderBy(i => packing.ItemPositions[i.Key].Z)) {83 var position = packing. ItemPositions[item.Key];82 foreach (var item in packing.Items.OrderBy(i => packing.Positions[i.Key].Z)) { 83 var position = packing.Positions[item.Key]; 84 84 85 85 var w = position.Rotated ? item.Value.Depth : item.Value.Width; … … 98 98 } 99 99 100 var container = packing.Bin Measures;100 var container = packing.BinShape; 101 101 // draw a transparent container 102 102 AddCube(meshTransparent, container.Origin.X, container.Origin.Y, container.Origin.Z, container.Width, container.Height, container.Depth, addInsideTriangles: true); -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.Views/3.3/PackingPlan3DView.cs
r14151 r14154 67 67 int currentBin = (binSelection != null) ? (int)(binSelection.SelectedIndex) : 0; 68 68 var packing = Content.BinPackings[currentBin]; 69 foreach (var item in packing.Item Measures) {69 foreach (var item in packing.Items) { 70 70 itemSelection.Items.Add(item.Key); 71 71 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/BinPacking.cs
r14151 r14154 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 30 31 [Item("BinPacking", "Represents a single-bin packing for a bin-packing problem.")] 31 32 [StorableClass] 32 public abstract class BinPacking< D, B, I> : Item33 where D: class, IPackingPosition34 where B : PackingShape<D>35 where I : PackingShape<D> {33 public abstract class BinPacking<TPos, TBin, TItem> : Item 34 where TPos : class, IPackingPosition 35 where TBin : PackingShape<TPos> 36 where TItem : PackingShape<TPos> { 36 37 #region Properties 37 38 [Storable] 38 public ObservableDictionary<int, D> ItemPositions { get; private set; }39 public ObservableDictionary<int, TPos> Positions { get; private set; } 39 40 40 41 [Storable] 41 public ObservableDictionary<int, I> ItemMeasures { get; private set; } // TODO: rename to items42 public ObservableDictionary<int, TItem> Items { get; private set; } 42 43 43 44 [Storable] 44 public B BinMeasures{ get; private set; }45 public TBin BinShape { get; private set; } 45 46 46 47 [Storable] 47 public SortedSet< D> ExtremePoints { get; protected set; }48 public SortedSet<TPos> ExtremePoints { get; protected set; } 48 49 49 50 [Storable] … … 52 53 #endregion Properties 53 54 54 protected BinPacking( B binMeasures)55 protected BinPacking(TBin binShape) 55 56 : base() { 56 ItemPositions = new ObservableDictionary<int, D>();57 Item Measures = new ObservableDictionary<int, I>();58 Bin Measures = (B)binMeasures.Clone();57 Positions = new ObservableDictionary<int, TPos>(); 58 Items = new ObservableDictionary<int, TItem>(); 59 BinShape = (TBin)binShape.Clone(); 59 60 OccupationLayers = new Dictionary<int, List<int>>(); 60 InitializeOccupationLayers(); // TODO61 61 } 62 62 … … 64 64 [StorableConstructor] 65 65 protected BinPacking(bool deserializing) : base(deserializing) { } 66 protected BinPacking(BinPacking< D, B, I> original, Cloner cloner)66 protected BinPacking(BinPacking<TPos, TBin, TItem> original, Cloner cloner) 67 67 : base(original, cloner) { 68 this.ItemPositions = new ObservableDictionary<int, D>(original.ItemPositions); 69 this.ItemMeasures = new ObservableDictionary<int, I>(original.ItemMeasures); 70 this.BinMeasures = (B)original.BinMeasures.Clone(cloner); 71 this.OccupationLayers = new Dictionary<int, List<int>>(original.OccupationLayers); 68 this.Positions = new ObservableDictionary<int, TPos>(); 69 foreach (var kvp in original.Positions) { 70 Positions.Add(kvp.Key, cloner.Clone(kvp.Value)); 71 } 72 this.Items = new ObservableDictionary<int, TItem>(); 73 foreach (var kvp in original.Items) { 74 Items.Add(kvp.Key, cloner.Clone(kvp.Value)); 75 } 76 this.BinShape = (TBin)original.BinShape.Clone(cloner); 77 this.OccupationLayers = new Dictionary<int, List<int>>(); 78 foreach (var kvp in original.OccupationLayers) { 79 OccupationLayers.Add(kvp.Key, new List<int>(kvp.Value)); 80 } 72 81 } 73 82 74 protected abstract void GenerateNewExtremePointsForNewItem( I measures, Dposition);83 protected abstract void GenerateNewExtremePointsForNewItem(TItem item, TPos position); 75 84 76 public abstract D FindExtremePointForItem(I measures, bool rotated, bool stackingConstraints);77 public abstract D FindPositionBySliding(I measures, bool rotated);85 public abstract TPos FindExtremePointForItem(TItem item, bool rotated, bool stackingConstraints); 86 public abstract TPos FindPositionBySliding(TItem item, bool rotated); 78 87 79 public abstract void SlidingBasedPacking(ref IList<int> sequence, IList< I> itemMeasures);80 public abstract void SlidingBasedPacking(ref IList<int> sequence, IList< I> itemMeasures, Dictionary<int, bool> rotationArray);81 public abstract void ExtremePointBasedPacking(ref IList<int> sequence, IList< I> itemMeasures, bool stackingConstraints);82 public abstract void ExtremePointBasedPacking(ref IList<int> sequence, IList< I> itemMeasures, bool stackingConstraints, Dictionary<int, bool> rotationArray);88 public abstract void SlidingBasedPacking(ref IList<int> sequence, IList<TItem> items); 89 public abstract void SlidingBasedPacking(ref IList<int> sequence, IList<TItem> items, Dictionary<int, bool> rotationArray); 90 public abstract void ExtremePointBasedPacking(ref IList<int> sequence, IList<TItem> items, bool stackingConstraints); 91 public abstract void ExtremePointBasedPacking(ref IList<int> sequence, IList<TItem> items, bool stackingConstraints, Dictionary<int, bool> rotationArray); 83 92 84 public void PackItem(int itemID, I measures, Dposition) {85 Item Measures[itemID] = measures;86 ItemPositions[itemID] = position;93 public void PackItem(int itemID, TItem item, TPos position) { 94 Items[itemID] = item; 95 Positions[itemID] = position; 87 96 ExtremePoints.Remove(position); 88 foreach (int id in Item Measures.Select(x => x.Key))89 GenerateNewExtremePointsForNewItem(Item Measures[id], ItemPositions[id]);97 foreach (int id in Items.Select(x => x.Key)) 98 GenerateNewExtremePointsForNewItem(Items[id], Positions[id]); 90 99 91 AddNewItemToOccupationLayers(itemID, measures, position);100 AddNewItemToOccupationLayers(itemID, item, position); 92 101 } 93 102 … … 95 104 get { 96 105 double result = 0; 97 foreach (var entry in Item Measures)106 foreach (var entry in Items) 98 107 result += entry.Value.Volume; 99 result /= Bin Measures.Volume;108 result /= BinShape.Volume; 100 109 return result; 101 110 } … … 103 112 104 113 105 public int PointOccupation( Dposition) {114 public int PointOccupation(TPos position) { 106 115 foreach (var id in GetLayerItemIDs(position)) { 107 if (Item Measures[id].EnclosesPoint(ItemPositions[id], position))116 if (Items[id].EnclosesPoint(Positions[id], position)) 108 117 return id; 109 118 } … … 111 120 } 112 121 113 public bool IsPointOccupied( Dposition) {122 public bool IsPointOccupied(TPos position) { 114 123 foreach (var id in GetLayerItemIDs(position)) { 115 if (Item Measures[id].EnclosesPoint(ItemPositions[id], position))124 if (Items[id].EnclosesPoint(Positions[id], position)) 116 125 return true; 117 126 } 118 127 return false; 119 128 } 120 public bool IsPositionFeasible( I measures, Dposition) {129 public bool IsPositionFeasible(TItem item, TPos position) { 121 130 //In this case feasability is defined as following: 1. the item fits into the bin-borders; 2. the point is supported by something; 3. the item does not collide with another already packed item 122 if (!Bin Measures.Encloses(position, measures))131 if (!BinShape.Encloses(position, item)) 123 132 return false; 124 133 125 foreach (var id in GetLayerItemIDs( measures, position)) {126 if (Item Measures[id].Overlaps(ItemPositions[id], position, measures))134 foreach (var id in GetLayerItemIDs(item, position)) { 135 if (Items[id].Overlaps(Positions[id], position, item)) 127 136 return false; 128 137 } … … 130 139 return true; 131 140 } 132 public abstract int ShortestPossibleSideFromPoint( Dposition);133 public abstract bool IsStaticStable( I measures, Dposition);141 public abstract int ShortestPossibleSideFromPoint(TPos position); 142 public abstract bool IsStaticStable(TItem measures, TPos position); 134 143 135 144 136 145 protected abstract void InitializeOccupationLayers(); 137 protected abstract void AddNewItemToOccupationLayers(int itemID, I measures, Dposition);138 protected abstract List<int> GetLayerItemIDs( Dposition);139 protected abstract List<int> GetLayerItemIDs( I measures, Dposition);146 protected abstract void AddNewItemToOccupationLayers(int itemID, TItem item, TPos position); 147 protected abstract List<int> GetLayerItemIDs(TPos position); 148 protected abstract List<int> GetLayerItemIDs(TItem item, TPos position); 140 149 } 141 150 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/PackingPlan.cs
r14153 r14154 86 86 87 87 public void UpdateBinPackings() { 88 BinPackings.RemoveAll(x => x. ItemPositions.Count == 0);88 BinPackings.RemoveAll(x => x.Positions.Count == 0); 89 89 BinPackings = new ObservableList<BinPacking<D, B, I>>(BinPackings.OrderByDescending(bp => bp.PackingDensity)); 90 90 }
Note: See TracChangeset
for help on using the changeset viewer.