- Timestamp:
- 07/21/16 15:08:21 (8 years ago)
- Location:
- branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
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.