Changeset 15770
- Timestamp:
- 02/13/18 16:45:01 (7 years ago)
- Location:
- branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/BinPacking3D.cs
r15731 r15770 38 38 [Storable] 39 39 public IDictionary<PackingPosition, IEnumerable<ResidualSpace>> ExtremePoints { get; protected set; } 40 40 41 41 [Storable] 42 42 public IDirectedGraph WeightDistirbution { get; protected set; } … … 64 64 } 65 65 66 // todo clone WeightDistirbution graph66 WeightDistirbution = original.WeightDistirbution.Clone() as IDirectedGraph; 67 67 } 68 68 … … 88 88 89 89 90 #region Graph for the calculating the weight distirbution 90 #region Graph for the calculating the weight distirbution 91 /// <summary> 92 /// The given item is added to the graph as the source vertex. 93 /// Its items below are the target vertices. 94 /// </summary> 95 /// <param name="itemId"></param> 96 /// <param name="item"></param> 97 /// <param name="position"></param> 91 98 private void AddToGraph(int itemId, PackingItem item, PackingPosition position) { 92 99 var sourceVertex = new VertexWithItemId(itemId); … … 356 363 357 364 #region Weight supported 365 358 366 //old implementation 359 367 /// <summary> … … 367 375 return true; 368 376 } 369 IEnumerable<Tuple<PackingPosition, PackingItem>> itemsP1; 370 IEnumerable<Tuple<PackingPosition, PackingItem>> itemsP2; 371 IEnumerable<Tuple<PackingPosition, PackingItem>> itemsP3; 372 IEnumerable<Tuple<PackingPosition, PackingItem>> itemsP4; 373 374 GetItemsUnderItemWithContact(item, position, out itemsP1, out itemsP2, out itemsP3, out itemsP4); 375 376 return itemsP1.Where(x => x.Item2.SupportsStacking(item)).Any() && 377 itemsP2.Where(x => x.Item2.SupportsStacking(item)).Any() && 378 itemsP3.Where(x => x.Item2.SupportsStacking(item)).Any() && 379 itemsP4.Where(x => x.Item2.SupportsStacking(item)).Any(); 380 } 377 378 var itemsBelow = Items.Where(x => Positions[x.Key].Y + x.Value.Height == position.Y) 379 .Select(x => new { 380 ItemId = x.Key, 381 Item = Tuple.Create<PackingPosition, PackingItem>(Positions[x.Key], x.Value), 382 Overlay = CalculateOverlay(Tuple.Create<PackingPosition, PackingItem>(Positions[x.Key], x.Value), 383 Tuple.Create<PackingPosition, PackingItem>(position, item)) 384 }) 385 .Where(x=> x.Overlay > 0); 386 387 var area = item.Width * item.Depth; 388 foreach (var itemBelow in itemsBelow) { 389 var factor = itemBelow.Overlay / area; 390 if (itemBelow.Item.Item2.SupportedWeightPerSquareMeter < item.Weight / area) { 391 return false; 392 } 393 394 if (!IsWeightSupportedRec(itemBelow.Item.Item2, itemBelow.ItemId, item.Weight, factor)) { 395 return false; 396 } 397 } 398 return true; 399 } 400 401 private bool IsWeightSupportedRec(PackingItem item, int itemId, double weigth, double factor) { 402 var stackedWeight = GetStackedWeightForItemId(itemId); 403 if (!item.SupportWeight(weigth * factor + stackedWeight)) { 404 return false; 405 } 406 407 var arcs = WeightDistirbution.Arcs.Where(x => ((VertexWithItemId)x.Source).ItemId == itemId); 408 foreach (var arc in arcs) { 409 var targetItemId = ((VertexWithItemId)arc.Target).ItemId; 410 var targetItem = Items[targetItemId]; 411 if (!IsWeightSupportedRec(targetItem, targetItemId, weigth, factor * arc.Weight)) { 412 return false; 413 } 414 } 415 416 return true; 417 } 418 419 381 420 382 421 private double CalculateOverlay(Tuple<PackingPosition, PackingItem> item1, Tuple<PackingPosition, PackingItem> item2) { … … 452 491 } 453 492 493 public IEnumerable<PackingItem> GetItemsBelow(int itemId) { 494 var item = Items[itemId]; 495 var position = Positions[itemId]; 496 497 var itemsBelow = Items.Where(x => Positions[x.Key].Y + x.Value.Height == position.Y && 498 CalculateOverlay(Tuple.Create<PackingPosition, PackingItem>(Positions[x.Key], x.Value), 499 Tuple.Create<PackingPosition, PackingItem>(position, item)) > 0) 500 .Select(x => x.Value); 501 return itemsBelow; 502 } 503 454 504 #endregion 455 505 } -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/PackingItem.cs
r15731 r15770 60 60 } 61 61 62 #region Material 63 public IFixedValueParameter<EnumValue<MaterialType>> MaterialBottomParameter { 64 get { return (IFixedValueParameter<EnumValue<MaterialType>>)Parameters["MaterialBottom"]; } 65 } 66 public MaterialType MaterialBottom { 67 get { return MaterialBottomParameter.Value.Value; } 68 set { MaterialBottomParameter.Value.Value = value; } 69 } 62 #region Material 70 63 71 64 public IFixedValueParameter<EnumValue<MaterialType>> MaterialTopParameter { … … 84 77 get { return SupportedWeightParameter.Value.Value; } 85 78 set { SupportedWeightParameter.Value.Value = value; } 79 } 80 81 public double SupportedWeightPerSquareMeter { 82 get { 83 return SupportedWeight / (Width * Depth); 84 } 86 85 } 87 86 … … 297 296 return other.Layer <= this.Layer && SupportedWeight > 0; 298 297 } 298 299 public bool SupportWeight(double weigth) { 300 return SupportedWeight >= weigth; 301 } 299 302 #endregion 300 303 … … 314 317 315 318 Parameters.Add(new FixedValueParameter<EnumValue<MaterialType>>("MaterialTop")); 316 Parameters.Add(new FixedValueParameter<EnumValue<MaterialType>>("MaterialBottom"));317 319 318 320 Parameters.Add(new FixedValueParameter<DoubleValue>("SupportedWeight")); -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/PackingShape.cs
r15617 r15770 27 27 using HeuristicLab.Parameters; 28 28 using HeuristicLab.Problems.BinPacking; 29 using HeuristicLab.Problems.BinPacking3D.Material; 29 30 30 31 namespace HeuristicLab.Problems.BinPacking3D { … … 57 58 } 58 59 60 public IFixedValueParameter<EnumValue<MaterialType>> MaterialBottomParameter { 61 get { return (IFixedValueParameter<EnumValue<MaterialType>>)Parameters["MaterialBottom"]; } 62 } 63 public MaterialType MaterialBottom { 64 get { return MaterialBottomParameter.Value.Value; } 65 set { MaterialBottomParameter.Value.Value = value; } 66 } 67 59 68 [StorableConstructor] 60 69 protected PackingShape(bool deserializing) : base(deserializing) { } … … 68 77 Parameters.Add(new FixedValueParameter<IntValue>("Height")); 69 78 Parameters.Add(new FixedValueParameter<IntValue>("Depth")); 79 Parameters.Add(new FixedValueParameter<EnumValue<MaterialType>>("MaterialBottom")); 80 81 MaterialBottom = MaterialType.ScreenPrintingPlate; 70 82 71 83 RegisterEvents(); -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/ResidualSpaceCalculation/ResidualSpaceCalculator.cs
r15617 r15770 20 20 #endregion 21 21 22 using HeuristicLab.Core; 22 23 using HeuristicLab.Problems.BinPacking3D.Geometry; 23 24 using System; … … 26 27 using System.Text; 27 28 using System.Threading.Tasks; 29 using HeuristicLab.Common; 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 31 29 32 namespace HeuristicLab.Problems.BinPacking3D.ResidualSpaceCalculation { 30 internal class ResidualSpaceCalculator : I ResidualSpaceCalculator {33 internal class ResidualSpaceCalculator : Item, IResidualSpaceCalculator { 31 34 32 35 internal ResidualSpaceCalculator() {} 33 36 37 [StorableConstructor] 38 protected ResidualSpaceCalculator(bool deserializing) : base(deserializing) { } 39 40 protected ResidualSpaceCalculator(ResidualSpaceCalculator original, Cloner cloner) 41 : base(original, cloner) { 42 } 43 44 public override IDeepCloneable Clone(Cloner cloner) { 45 return new ResidualSpaceCalculator(this, cloner); 46 } 47 34 48 public IEnumerable<ResidualSpace> CalculateResidualSpaces(BinPacking3D binPacking, Vector3D point) { 35 49 IList<ResidualSpace> residualSpaces = new List<ResidualSpace>();
Note: See TracChangeset
for help on using the changeset viewer.