Changeset 9599 for branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/BinPacking.cs
- Timestamp:
- 06/09/13 12:58:39 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/BinPacking.cs
r9598 r9599 54 54 55 55 [Storable] 56 public HashSet<D> ExtremePoints { get; protected set; } 56 //public HashSet<D> ExtremePoints { get; protected set; } 57 public SortedSet<D> ExtremePoints { get; protected set; } 57 58 58 //[Storable] 59 //public OccupiedPoints<D, B, I> OccupiedPoints { get; protected set; } 59 [Storable] 60 protected Dictionary<int, List<int>> OccupationLayers { get; set; } 61 60 62 #endregion Properties 61 63 … … 64 66 ItemMeasures = new ObservableDictionary<int, I>(); 65 67 BinMeasures = (B)binMeasures.Clone(); 66 ExtremePoints = new HashSet<D>();67 ExtremePoints.Add(binMeasures.Origin);68 OccupationLayers = new Dictionary<int, List<int>>(); 69 InitializeOccupationLayers(); 68 70 } 71 69 72 70 73 [StorableConstructor] … … 75 78 this.ItemMeasures = new ObservableDictionary<int, I>(original.ItemMeasures); 76 79 this.BinMeasures = (B)original.BinMeasures.Clone(cloner); 80 this.OccupationLayers = new Dictionary<int, List<int>>(original.OccupationLayers); 77 81 } 78 82 … … 91 95 ItemPositions[itemID] = position; 92 96 ExtremePoints.Remove(position); 93 GenerateNewExtremePointsForNewItem(measures, position); 97 foreach (int id in ItemMeasures.Select(x => x.Key)) 98 GenerateNewExtremePointsForNewItem(ItemMeasures[id], ItemPositions[id]); 99 100 101 //GenerateNewExtremePointsForNewItem(measures, position); 94 102 //OccupiedPoints.OccupyPoints(measures, position, itemID); 103 104 AddNewItemToOccupationLayers(itemID, measures, position); 95 105 } 96 106 … … 107 117 108 118 public int PointOccupation(D position) { 109 foreach (var ipEntry in ItemPositions) { 110 if (ItemMeasures[ipEntry.Key].EnclosesPoint(ipEntry.Value, position)) 111 return ipEntry.Key; 119 //foreach (var ipEntry in ItemPositions) { 120 // if (ItemMeasures[ipEntry.Key].EnclosesPoint(ipEntry.Value, position)) 121 // return ipEntry.Key; 122 //} 123 foreach (var id in GetLayerItemIDs(position)) { 124 if (ItemMeasures[id].EnclosesPoint(ItemPositions[id], position)) 125 return id; 112 126 } 113 127 return -1; 114 128 } 129 115 130 public bool IsPointOccupied(D position) { 116 foreach (var ipEntry in ItemPositions) { 117 if (ItemMeasures[ipEntry.Key].EnclosesPoint(ipEntry.Value, position)) 131 //foreach (var ipEntry in ItemPositions) { 132 // if (ItemMeasures[ipEntry.Key].EnclosesPoint(ipEntry.Value, position)) 133 // return true; 134 //} 135 foreach (var id in GetLayerItemIDs(position)) { 136 if (ItemMeasures[id].EnclosesPoint(ItemPositions[id], position)) 118 137 return true; 119 138 } 120 139 return false; 121 140 } 122 public bool IsPositionFeasible(I currentItem, D position) {141 public bool IsPositionFeasible(I measures, D position) { 123 142 //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 124 if (!BinMeasures.Encloses(position, currentItem))143 if (!BinMeasures.Encloses(position, measures)) 125 144 return false; 126 145 127 foreach (var ipEntry in ItemPositions) { 128 if (ItemMeasures[ipEntry.Key].Overlaps(ipEntry.Value, position, currentItem)) 146 //foreach (var ipEntry in ItemPositions) { 147 // if (ItemMeasures[ipEntry.Key].Overlaps(ipEntry.Value, position, measures)) 148 // return false; 149 //} 150 foreach (var id in GetLayerItemIDs(measures, position)) { 151 if (ItemMeasures[id].Overlaps(ItemPositions[id], position, measures)) 129 152 return false; 130 153 } … … 133 156 } 134 157 public abstract int ShortestPossibleSideFromPoint (D position); 135 public abstract bool IsStaticStable (I item, D position); 158 public abstract bool IsStaticStable (I measures, D position); 159 160 161 protected abstract void InitializeOccupationLayers(); 162 protected abstract void AddNewItemToOccupationLayers(int itemID, I measures, D position); 163 protected abstract List<int> GetLayerItemIDs(D position); 164 protected abstract List<int> GetLayerItemIDs(I measures, D position); 136 165 } 137 166 }
Note: See TracChangeset
for help on using the changeset viewer.