Changeset 14039
- Timestamp:
- 07/12/16 17:12:15 (8 years ago)
- Location:
- branches/HeuristicLab.BinPacking
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/RectangularIdenticalBinPackingProblem.cs
r13611 r14039 34 34 using HeuristicLab.Problems.Instances; 35 35 using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector; 36 using HeuristicLab.Data; 37 using System; 36 38 37 39 namespace HeuristicLab.Problems.BinPacking.Problem { … … 101 103 } 102 104 105 #region Problem instance handling 106 public override void Load(BPPData data) { 107 var realData = data as RealBPPData; 108 var binData = new RectangularPackingBin(data.BinMeasures[0], data.BinMeasures[1]); 109 110 var itemData = new ItemList<RectangularPackingItem>(data.Items); 111 for (int j = 0; j < data.Items; j++) { 112 var bin = new RectangularPackingBin(data.BinMeasures[0], data.BinMeasures[1]); 113 var item = new RectangularPackingItem(data.ItemMeasures[j][0], data.ItemMeasures[j][1], bin); 114 if (realData != null) { 115 item.Weight = realData.ItemWeights[j]; 116 item.Material = realData.ItemMaterials[j]; 117 } 118 itemData.Add(item); 119 } 120 121 BestKnownQuality = data.BestKnownQuality.HasValue ? new DoubleValue(data.BestKnownQuality.Value) : null; 122 123 PackingBinMeasures = binData; 124 PackingItemMeasures = itemData; 125 126 ApplyHorizontalOrientation(); 127 SortItems(); 128 PackingItemsParameter.Value.Value = PackingItemMeasures.Count; 129 LowerBoundParameter.Value.Value = CalculateLowerBound(); 130 } 131 132 133 public override BPPData Export() { 134 var result = new BPPData { 135 Name = Name, 136 Description = Description, 137 Items = PackingItemsParameter.Value.Value, 138 BinMeasures = new int[] { PackingBinMeasures.Width, PackingBinMeasures.Height } 139 }; 140 141 var itemMeasures = new int[result.Items][]; 142 int i = 0; 143 foreach (var item in PackingItemMeasures) { 144 itemMeasures[i] = new int[] { item.Width, item.Height }; 145 i++; 146 } 147 result.ItemMeasures = itemMeasures; 148 return result; 149 } 150 #endregion 103 151 104 152 #region Helpers … … 107 155 108 156 PackingSolutionDecoderParameter.ValidValues.Clear(); 109 if (SolutionCreator is PackingSequenceRandomCreator) { 157 if (SolutionCreator is PackingSequenceRandomCreator) { 110 158 PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I2DPSDecoder>()); 111 } else if (SolutionCreator is GroupingVectorRandomCreator) { 159 } else if (SolutionCreator is GroupingVectorRandomCreator) { 112 160 PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I2DGVDecoder>()); 113 } else if (SolutionCreator is MultiComponentVectorRandomCreator) { 161 } else if (SolutionCreator is MultiComponentVectorRandomCreator) { 114 162 PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I2DMCVDecoder>()); 115 163 } else { … … 120 168 121 169 protected override IPackingPlanEvaluator CreateDefaultEvaluator() { 122 return new PackingRatioRectangularIdenticalBinEvaluator 170 return new PackingRatioRectangularIdenticalBinEvaluator(); 123 171 } 124 172 -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/RectangularPackingItem.cs
r13606 r14039 69 69 public RectangularPackingItem(int width, int height, RectangularPackingBin targetBin) 70 70 : this() { 71 this.W eight= width;71 this.Width = width; 72 72 this.Height = height; 73 73 this.TargetBin = (RectangularPackingBin)targetBin.Clone(); -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/CuboidIdenticalBinPackingProblem.cs
r13608 r14039 34 34 using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector; 35 35 using HeuristicLab.PluginInfrastructure; 36 using System; 37 using HeuristicLab.Data; 36 38 37 39 namespace HeuristicLab.Problems.BinPacking.Problem { … … 42 44 43 45 #region Default Instance 44 private static readonly BPPData DefaultInstance = new BPPData() { 45 Name = "3D BPP Default Instance", 46 private static readonly BPPData DefaultInstance = new BPPData() { 47 Name = "3D BPP Default Instance", 46 48 Description = "The default instance for 3D Bin Packing.", 47 BinMeasures = new int[] { 25,25,35},49 BinMeasures = new int[] { 25, 25, 35 }, 48 50 ItemMeasures = new int[][] { 49 51 new int[] {12,5,10}, … … 92 94 }; 93 95 #endregion 94 96 95 97 [StorableConstructor] 96 98 protected CuboidIdenticalBinPackingProblem(bool deserializing) : base(deserializing) { } … … 107 109 108 110 111 public override void Load(BPPData data) { 112 var realData = data as RealBPPData; 113 var binData = new CuboidPackingBin(data.BinMeasures[0], data.BinMeasures[1], data.BinMeasures[2]); 114 115 var itemData = new ItemList<CuboidPackingItem>(data.Items); 116 for (int j = 0; j < data.Items; j++) { 117 var bin = new CuboidPackingBin(data.BinMeasures[0], data.BinMeasures[1], data.BinMeasures[2]); 118 var item = new CuboidPackingItem(data.ItemMeasures[j][0], data.ItemMeasures[j][1], data.ItemMeasures[j][2], bin); 119 if (realData != null) { 120 item.Weight = realData.ItemWeights[j]; 121 item.Material = realData.ItemMaterials[j]; 122 } 123 itemData.Add(item); 124 } 125 126 BestKnownQuality = data.BestKnownQuality.HasValue ? new DoubleValue(data.BestKnownQuality.Value) : null; 127 128 PackingBinMeasures = binData; 129 PackingItemMeasures = itemData; 130 131 ApplyHorizontalOrientation(); 132 SortItems(); 133 PackingItemsParameter.Value.Value = PackingItemMeasures.Count; 134 LowerBoundParameter.Value.Value = CalculateLowerBound(); 135 } 136 137 public override BPPData Export() { 138 var result = new BPPData { 139 Name = Name, 140 Description = Description, 141 Items = PackingItemsParameter.Value.Value, 142 BinMeasures = new int[] { PackingBinMeasures.Width, PackingBinMeasures.Height, PackingBinMeasures.Depth } 143 }; 144 145 var itemMeasures = new int[result.Items][]; 146 int i = 0; 147 foreach (var item in PackingItemMeasures) { 148 itemMeasures[i] = new int[] { item.Width, item.Height, item.Depth }; 149 i++; 150 } 151 result.ItemMeasures = itemMeasures; 152 return result; 153 } 154 109 155 #region Helpers 110 156 protected override void InitializeDecoder() { … … 112 158 113 159 PackingSolutionDecoderParameter.ValidValues.Clear(); 114 if (SolutionCreator is PackingSequenceRandomCreator) { 160 if (SolutionCreator is PackingSequenceRandomCreator) { 115 161 PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I3DPSDecoder>()); 116 } else if (SolutionCreator is GroupingVectorRandomCreator) { 162 } else if (SolutionCreator is GroupingVectorRandomCreator) { 117 163 PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I3DGVDecoder>()); 118 } else if (SolutionCreator is MultiComponentVectorRandomCreator) { 164 } else if (SolutionCreator is MultiComponentVectorRandomCreator) { 119 165 PackingSolutionDecoderParameter.ValidValues.UnionWith(ApplicationManager.Manager.GetInstances<I3DMCVDecoder>()); 120 166 } else { … … 133 179 134 180 protected override void RemoveTooBigItems() { 135 PackingItemMeasures.RemoveAll(pi => 136 !PackingBinMeasures.Encloses 181 PackingItemMeasures.RemoveAll(pi => 182 !PackingBinMeasures.Encloses(new ThreeDimensionalPacking(0, 0, 0, 0, false), pi) && 137 183 !PackingBinMeasures.Encloses(new ThreeDimensionalPacking(0, 0, 0, 0, true), pi)); 138 184 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/RegularIdenticalBinPackingProblem.cs
r13608 r14039 41 41 [Item("RegularIdenticalBinPackingProblem", "Represents a bin-packing problem-instance using only bins with identical measures and bins/items with regular shapes (e.g. rectangle, cuboid).")] 42 42 [StorableClass] 43 public abstract class RegularIdenticalBinPackingProblem<D, B, I> : BinPackingProblem<D, B, I>, IProblemInstanceConsumer<BPPData>, IProblemInstanceExporter<BPPData>43 public abstract class RegularIdenticalBinPackingProblem<D, B, I> : BinPackingProblem<D, B, I>, IProblemInstanceConsumer<BPPData>, IProblemInstanceExporter<BPPData> 44 44 where D : class, IPackingDimensions 45 45 where B : PackingShape<D>, IPackingBin, IRegularPackingShape, new() 46 where I : PackingShape<D>, IPackingItem, IRegularPackingShape, new() { 46 where I : PackingShape<D>, IPackingItem, IRegularPackingShape, new() { 47 47 48 48 #region Parameter Properties … … 58 58 public B PackingBinMeasures { 59 59 get { return PackingBinMeasuresParameter.Value; } 60 set { PackingBinMeasuresParameter.Value = value; } 61 } 62 public PackingSolutionDecoder<D, B,I> PackingSolutionDecoder {60 set { PackingBinMeasuresParameter.Value = value; } 61 } 62 public PackingSolutionDecoder<D, B, I> PackingSolutionDecoder { 63 63 get { return PackingSolutionDecoderParameter.Value as PackingSolutionDecoder<D, B, I>; } 64 64 set { PackingSolutionDecoderParameter.Value = value; } … … 69 69 [StorableConstructor] 70 70 protected RegularIdenticalBinPackingProblem(bool deserializing) : base(deserializing) { } 71 protected RegularIdenticalBinPackingProblem(RegularIdenticalBinPackingProblem<D, B,I> original, Cloner cloner)71 protected RegularIdenticalBinPackingProblem(RegularIdenticalBinPackingProblem<D, B, I> original, Cloner cloner) 72 72 : base(original, cloner) { 73 73 InitializeEventHandlers(); … … 86 86 } 87 87 88 88 89 89 90 90 … … 101 101 protected abstract void InitializeProblemData(); 102 102 protected abstract IPackingPlanEvaluator CreateDefaultEvaluator(); 103 pr ivatevoid ApplyHorizontalOrientation() {103 protected void ApplyHorizontalOrientation() { 104 104 PackingBinMeasures.ApplyHorizontalOrientation(); 105 105 foreach (IRegularPackingShape shape in PackingItemMeasures) { … … 107 107 } 108 108 } 109 pr ivatevoid SortItems() {109 protected void SortItems() { 110 110 PackingItemMeasures.Sort((x, y) => y.CompareTo(x)); 111 111 } 112 pr ivateint CalculateLowerBound() {112 protected int CalculateLowerBound() { 113 113 //This is the obvious continuous lower bound calculation; Martello and Vigo proposed a better way but it has not been implemented yet; 114 114 int items = PackingItemMeasures.Select(x => x.Volume).Sum(); 115 115 int bin = PackingBinMeasures.Volume; 116 return (items + bin - 1) /(bin);116 return (items + bin - 1) / (bin); 117 117 } 118 118 119 119 protected override void InitializeOperators() { 120 Operators.Clear(); 120 Operators.Clear(); 121 121 Operators.Add(new BestBinPackingSolutionAnalyzer<D, B, I>()); 122 122 … … 134 134 Operators.AddRange(ApplicationManager.Manager.GetInstances<IMultiComponentVectorOperator>()); 135 135 InitializeDecoder(); 136 } 137 } 138 private void ParameterizeOperators() { 136 } 137 } 138 private void ParameterizeOperators() { 139 139 foreach (var op in Operators.OfType<BestBinPackingSolutionAnalyzer<D, B, I>>()) { 140 140 op.QualityParameter.ActualName = PackingPlanEvaluator.QualityParameter.ActualName; … … 224 224 ParameterizeOperators(); 225 225 } 226 #endregion 227 228 229 #region Problem instance handling 230 public virtual void Load(BPPData data) { 231 // var realData = data as RealBPPData; 232 // var binData = new B(); 233 // binData.InitializeFromMeasures (data.BinMeasures); 234 // 235 // var itemData = new ItemList<I>(data.Items); 236 // for (int j = 0; j < data.Items; j++) { 237 // var item = new I(); 238 // item.InitializeFromMeasures(data.ItemMeasures[j]); 239 // item.AddTargetBinMeasures(data.BinMeasures); 240 // if (realData != null) { 241 // item.Weight = realData.ItemWeights[j]; 242 // item.Material = realData.ItemMaterials[j]; 243 // } 244 // itemData.Add(item); 245 // } 246 // 247 // BestKnownQuality = data.BestKnownQuality.HasValue ? new DoubleValue(data.BestKnownQuality.Value) : null; 248 // 249 // PackingBinMeasures = binData; 250 // PackingItemMeasures = itemData; 251 // 252 // ApplyHorizontalOrientation(); 253 // SortItems(); 254 // PackingItemsParameter.Value.Value = PackingItemMeasures.Count; 255 // LowerBoundParameter.Value.Value = CalculateLowerBound(); 256 257 throw new NotImplementedException(); 258 } 259 260 public BPPData Export() { 261 // var result = new BPPData{ 262 // Name = Name, 263 // Description = Description, 264 // Items = PackingItemsParameter.Value.Value, 265 // BinMeasures = PackingBinMeasures.ToArray() // TODO: split functionality of class in 2d and 3d code 266 // }; 267 // 268 // var itemMeasures = new int[result.Items][]; 269 // int i = 0; 270 // foreach (var item in PackingItemMeasures) { 271 // itemMeasures[i] = item.ToArray(); 272 // i++; 273 // } 274 // result.ItemMeasures = itemMeasures; 275 // return result; 276 277 throw new NotImplementedException(); 278 } 279 #endregion 226 227 public abstract void Load(BPPData data); 228 229 public abstract BPPData Export(); 230 #endregion 231 280 232 } 281 233 }
Note: See TracChangeset
for help on using the changeset viewer.