Changeset 15585 for branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/ExtremePointCreation/LineProjectionBasedEPCreator.cs
- Timestamp:
- 01/09/18 15:46:53 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/ExtremePointCreation/LineProjectionBasedEPCreator.cs
r15554 r15585 23 23 GenerateNewExtremePointsForItem(binPacking, it, p); 24 24 } 25 } 26 27 /// <summary> 28 /// Adds a new extreme point an the related residual spaces to a given bin packing. 29 /// - The given position has to be valid. 30 /// - The extreme point does not exist in the bin packing. 31 /// - There must be at minimum one valid residual space. A residual space is invalid if the space is zero. 32 /// </summary> 33 /// <param name="binPacking"></param> 34 /// <param name="position"></param> 35 /// <returns>True = the given point and its related residual spaces were successfully added to the bin packing</returns> 36 protected override bool AddExtremePoint(BinPacking3D binPacking, PackingPosition position) { 37 if (position == null) { 38 return false; 39 } 40 41 if (PointIsInAnyItem(binPacking, new Vector3D(position))) { 42 return false; 43 } 44 45 if (binPacking.ExtremePoints.ContainsKey(position)) { 46 return false; 47 } 48 49 var rs = CalculateResidualSpace(binPacking, new Vector3D(position)); 50 51 if (rs.Count() <= 0) { 52 return false; 53 } 54 55 // todo 56 /* 57 ist der extrempunkt im residual space eines anderen muss ueberprueft werden: 58 - ist der andere ep in der luft, kann auch dieser hinzugefuegt werden. 59 - hat der andere ep ein item unterhalb, darf dieser nicht hinzugefuegt werden. 60 -> neu methode basierend auf IsWithinResidualSpaceOfAnotherExtremePoint, die den ep oder rs zurueck gibt, der einen anderen rs einschließt. 61 eventuell gehoert diese logik in den ResidualSpaceCreator. 62 if (LiesOnAnyItem(binPacking, position)) { 63 return false; 64 }*/ 65 66 binPacking.ExtremePoints.Add(position, rs); 67 return true; 68 } 69 25 26 // remove not needed extreme points. 27 foreach (var extremePoint in binPacking.ExtremePoints.ToList()) { 28 // check if a residual space can be removed 29 foreach (var rs in extremePoint.Value.ToList()) { 30 if (ResidualSpaceCanBeRemoved(binPacking, extremePoint.Key, rs)) { 31 ((IList<ResidualSpace>)extremePoint.Value).Remove(rs); 32 } 33 } 34 // if the current extreme point has no more residual spaces, it can be removed. 35 if (((IList<ResidualSpace>)extremePoint.Value).Count <= 0) { 36 binPacking.ExtremePoints.Remove(extremePoint); 37 } 38 } 39 } 40 41 /// <summary> 42 /// Returns true if a given residual space can be removed. 43 /// The given residual space can be removed if it is within another residual space and 44 /// - neither the position of the other residual space and the current extreme point have an item below or 45 /// - the current extreme point has an item below. 46 /// </summary> 47 /// <param name="binPacking"></param> 48 /// <param name="position"></param> 49 /// <param name="rs"></param> 50 /// <returns></returns> 51 private bool ResidualSpaceCanBeRemoved(BinPacking3D binPacking, PackingPosition position, ResidualSpace rs) { 52 foreach (var extremePoint in binPacking.ExtremePoints) { 53 if (position.Equals(extremePoint.Key)) { 54 continue; 55 } 56 if (IsWithinResidualSpaceOfAnotherExtremePoint(new Vector3D(position), rs, extremePoint.Key, extremePoint.Value)) { 57 var itemBelowEp = LiesOnAnyItem(binPacking, extremePoint.Key); 58 var itemBelowPos = LiesOnAnyItem(binPacking, position); 59 60 if (itemBelowEp || !itemBelowEp && !itemBelowPos) { 61 return true; 62 } 63 } 64 } 65 return false; 66 } 67 68 /// <summary> 69 /// Returns true if the given position lies on an item or an the ground. 70 /// </summary> 71 /// <param name="binPacking"></param> 72 /// <param name="position"></param> 73 /// <returns></returns> 70 74 private bool LiesOnAnyItem(BinPacking3D binPacking, PackingPosition position) { 71 75 if (position.Y == 0) { … … 85 89 86 90 return items.Count() > 0; 91 } 92 93 94 /// <summary> 95 /// Adds a new extreme point an the related residual spaces to a given bin packing. 96 /// - The given position has to be valid. 97 /// - The extreme point does not exist in the bin packing. 98 /// - There must be at minimum one valid residual space. A residual space is invalid if the space is zero. 99 /// </summary> 100 /// <param name="binPacking"></param> 101 /// <param name="position"></param> 102 /// <returns>True = the given point and its related residual spaces were successfully added to the bin packing</returns> 103 protected override bool AddExtremePoint(BinPacking3D binPacking, PackingPosition position) { 104 if (position == null) { 105 return false; 106 } 107 108 if (PointIsInAnyItem(binPacking, new Vector3D(position))) { 109 return false; 110 } 111 112 if (binPacking.ExtremePoints.ContainsKey(position)) { 113 return false; 114 } 115 116 var rs = CalculateResidualSpace(binPacking, new Vector3D(position)); 117 118 if (rs.Count() <= 0) { 119 return false; 120 } 121 122 binPacking.ExtremePoints.Add(position, rs); 123 return true; 87 124 } 88 125
Note: See TracChangeset
for help on using the changeset viewer.