Changeset 14040
- Timestamp:
- 07/12/16 17:51:37 (8 years ago)
- Location:
- branches/HeuristicLab.BinPacking
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/BinPacking2D.cs
r14038 r14040 66 66 ExtremePoints.Add(new TwoDimensionalPacking(0, sourcePointX.X, sourcePointX.Y)); 67 67 } 68 69 70 71 68 72 69 //Find ExtremePoints beginning from sourcepointY -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.2D/3.3/RectangularIdenticalBinPackingProblem.cs
r14039 r14040 41 41 [StorableClass] 42 42 [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 300)] 43 public class RectangularIdenticalBinPackingProblem : RegularIdenticalBinPackingProblem<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> { 43 // TODO: only support 2d BPPData 44 public class RectangularIdenticalBinPackingProblem : BinPackingProblem<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>, IProblemInstanceConsumer<BPPData>, IProblemInstanceExporter<BPPData> { 44 45 45 46 #region Default Instance … … 104 105 105 106 #region Problem instance handling 106 public overridevoid Load(BPPData data) {107 public void Load(BPPData data) { 107 108 var realData = data as RealBPPData; 108 109 var binData = new RectangularPackingBin(data.BinMeasures[0], data.BinMeasures[1]); … … 131 132 132 133 133 public overrideBPPData Export() {134 public BPPData Export() { 134 135 var result = new BPPData { 135 136 Name = Name, -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/CuboidIdenticalBinPackingProblem.cs
r14039 r14040 41 41 [StorableClass] 42 42 [Creatable(CreatableAttribute.Categories.CombinatorialProblems, Priority = 310)] 43 public class CuboidIdenticalBinPackingProblem : RegularIdenticalBinPackingProblem<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> { 43 // TODO don't support generic BPPData but only 3d BPPData 44 public class CuboidIdenticalBinPackingProblem : BinPackingProblem<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>, IProblemInstanceConsumer<BPPData>, IProblemInstanceExporter<BPPData> { 45 44 46 45 47 #region Default Instance … … 109 111 110 112 111 public overridevoid Load(BPPData data) {113 public void Load(BPPData data) { 112 114 var realData = data as RealBPPData; 113 115 var binData = new CuboidPackingBin(data.BinMeasures[0], data.BinMeasures[1], data.BinMeasures[2]); … … 135 137 } 136 138 137 public overrideBPPData Export() {139 public BPPData Export() { 138 140 var result = new BPPData { 139 141 Name = Name, -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking.3D/3.3/HeuristicLab.Problems.BinPacking3D-3.3.csproj
r13611 r14040 172 172 <Compile Include="Decoders\EP\ExtremePointMultiComponentVectorDecoder3D.cs" /> 173 173 <Compile Include="Decoders\EP\ExtremePointPackingSequenceDecoder3D.cs" /> 174 <Compile Include="Decoders\EP\ISOContainerMultiComponentVectorDecoder3D.cs" />175 174 <Compile Include="I3DOperator.cs" /> 176 <Compile Include="ISOContainerBinPackingProblem.cs" />177 175 <Compile Include="MoveEvaluators\PackingMoveEvaluator3DGV.cs" /> 178 176 <Compile Include="MoveEvaluators\PackingMoveEvaluator3DMCV.cs" /> -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/BinPackingProblem.cs
r13608 r14040 29 29 using HeuristicLab.Encodings.PackingEncoding.PackingPlan; 30 30 using HeuristicLab.Data; 31 using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector; 32 using HeuristicLab.Problems.BinPacking.Decoders; 33 using HeuristicLab.PluginInfrastructure; 34 using System.Linq; 35 using HeuristicLab.Problems.BinPacking.Analyzers; 36 using System; 37 using HeuristicLab.Encodings.PackingEncoding.PackingSequence; 38 using HeuristicLab.Encodings.PackingEncoding.GroupingVector; 31 39 32 40 namespace HeuristicLab.Problems.BinPacking.Problem { … … 35 43 public abstract class BinPackingProblem<D, B, I> : SingleObjectiveHeuristicOptimizationProblem<IPackingPlanEvaluationAlgorithm, IPackingSolutionCreator> 36 44 where D : class, IPackingDimensions 37 where B : PackingShape<D>, IPackingBin, new()38 where I : PackingShape<D>, IPackingItem, new () {45 where B : PackingShape<D>, IPackingBin, IRegularPackingShape, new() 46 where I : PackingShape<D>, IPackingItem, IRegularPackingShape, new () { 39 47 40 48 … … 54 62 public ValueParameter<IPackingPlanEvaluator> PackingPlanEvaluatorParameter { 55 63 get { return (ValueParameter<IPackingPlanEvaluator>)Parameters["PackingPlanEvaluator"]; } 64 } 65 public IValueParameter<B> PackingBinMeasuresParameter { 66 get { return (IValueParameter<B>)Parameters["PackingBinMeasures"]; } 67 } 68 public IConstrainedValueParameter<IPackingSolutionDecoder> PackingSolutionDecoderParameter { 69 get { return (IConstrainedValueParameter<IPackingSolutionDecoder>)Parameters["PackingSolutionDecoder"]; } 56 70 } 57 71 #endregion … … 70 84 set { PackingPlanEvaluatorParameter.Value = value; } 71 85 } 86 public B PackingBinMeasures { 87 get { return PackingBinMeasuresParameter.Value; } 88 set { PackingBinMeasuresParameter.Value = value; } 89 } 90 public PackingSolutionDecoder<D, B, I> PackingSolutionDecoder { 91 get { return PackingSolutionDecoderParameter.Value as PackingSolutionDecoder<D, B, I>; } 92 set { PackingSolutionDecoderParameter.Value = value; } 93 } 72 94 #endregion 73 95 … … 77 99 protected BinPackingProblem(BinPackingProblem<D,B,I> original, Cloner cloner) 78 100 : base(original, cloner) { 79 } 101 InitializeEventHandlers(); 102 } 103 104 protected BinPackingProblem(IPackingPlanEvaluationAlgorithm e) : this(e, new MultiComponentVectorRandomCreator()) { } 105 80 106 protected BinPackingProblem(IPackingPlanEvaluationAlgorithm e, IPackingSolutionCreator c) : base (e, c){ 81 107 Parameters.Add(new OptionalValueParameter<PackingPlan<D, B, I>>("BestKnownSolution", "The best known solution of this bin-packing instance.")); … … 84 110 Parameters.Add(new FixedValueParameter<IntValue>("PackingItems", "The number of packing-items used in this bin packing instance.", new IntValue())); 85 111 Parameters.Add(new FixedValueParameter<IntValue>("LowerBound", "The lower possible number of bins needed to solve this problem (taken from Dell'Amico, Martello and Vigo; 2002)", new IntValue())); 86 } 87 88 protected abstract void InitializeDecoder(); 89 protected abstract void InitializeProblemInstance(); 90 protected abstract void InitializeOperators(); 91 protected abstract void InitializeEventHandlers(); 112 Parameters.Add(new ValueParameter<B>("PackingBinMeasures", "Packing-bin data defining the measures of the used bins.", new B())); 113 Parameters.Add(new ValueParameter<IPackingPlanEvaluator>("PackingPlanEvaluator", "The evaluator is used to determine the quality of a solution.", CreateDefaultEvaluator())); 114 Parameters.Add(new ConstrainedValueParameter<IPackingSolutionDecoder>("PackingSolutionDecoder", "The operator that decodes the representation and creates a packing plan.")); 115 this.Maximization.Value = true; 116 InitializeProblemInstance(); 117 InitializeOperators(); 118 InitializeEventHandlers(); 119 } 120 121 protected abstract void InitializeDecoder(); 122 protected virtual void InitializeProblemInstance() { 123 InitializeProblemData(); 124 ApplyHorizontalOrientation(); 125 SortItems(); 126 RemoveTooBigItems(); 127 PackingItemsParameter.Value.Value = PackingItemMeasures.Count; 128 LowerBoundParameter.Value.Value = CalculateLowerBound(); 129 } 130 protected virtual void InitializeOperators() { 131 Operators.Clear(); 132 Operators.Add(new BestBinPackingSolutionAnalyzer<D, B, I>()); 133 134 ApplyEncoding(); 135 ParameterizeOperators(); 136 } 137 protected virtual void InitializeEventHandlers() { 138 PackingPlanEvaluatorParameter.ValueChanged += PackingPlanEvaluatorParameter_ValueChanged; 139 PackingPlanEvaluator.QualityParameter.ActualNameChanged += PackingPlanEvaluator_QualityParameter_ActualNameChanged; 140 SolutionCreatorParameter.ValueChanged += SolutionCreatorParameter_ValueChanged; 141 SolutionCreator.EncodedSolutionParameter.ActualNameChanged += SolutionCreator_EncodedSolutionParameter_ActualNameChanged; 142 PackingSolutionDecoderParameter.ValueChanged += PackingSolutionDecoderParameter_ValueChanged; 143 if (PackingSolutionDecoder != null) PackingSolutionDecoder.PackingPlanParameter.ActualNameChanged += PackingSolutionDecoder_PackingPlanParameter_ActualNameChanged; 144 } 145 146 147 protected abstract void RemoveTooBigItems(); 148 protected abstract void InitializeProblemData(); 149 protected abstract IPackingPlanEvaluator CreateDefaultEvaluator(); 150 protected void ApplyHorizontalOrientation() { 151 PackingBinMeasures.ApplyHorizontalOrientation(); 152 foreach (IRegularPackingShape shape in PackingItemMeasures) { 153 shape.ApplyHorizontalOrientation(); 154 } 155 } 156 protected void SortItems() { 157 PackingItemMeasures.Sort((x, y) => y.CompareTo(x)); 158 } 159 protected int CalculateLowerBound() { 160 //This is the obvious continuous lower bound calculation; Martello and Vigo proposed a better way but it has not been implemented yet; 161 int items = PackingItemMeasures.Select(x => x.Volume).Sum(); 162 int bin = PackingBinMeasures.Volume; 163 return (items + bin - 1) / (bin); 164 } 165 166 private void ApplyEncoding() { 167 if (SolutionCreator.GetType() == typeof(PackingSequenceRandomCreator)) { 168 Operators.AddRange(ApplicationManager.Manager.GetInstances<IPackingSequenceOperator>()); 169 InitializeDecoder(); 170 } else if (SolutionCreator.GetType() == typeof(GroupingVectorRandomCreator)) { 171 Operators.AddRange(ApplicationManager.Manager.GetInstances<IGroupingVectorOperator>()); 172 InitializeDecoder(); 173 } else if (SolutionCreator.GetType() == typeof(MultiComponentVectorRandomCreator)) { 174 Operators.AddRange(ApplicationManager.Manager.GetInstances<IMultiComponentVectorOperator>()); 175 InitializeDecoder(); 176 } 177 } 178 private void ParameterizeOperators() { 179 foreach (var op in Operators.OfType<BestBinPackingSolutionAnalyzer<D, B, I>>()) { 180 op.QualityParameter.ActualName = PackingPlanEvaluator.QualityParameter.ActualName; 181 } 182 183 Evaluator.PackingSolutionDecoderParameter.ActualName = PackingSolutionDecoderParameter.Name; 184 Evaluator.PackingSolutionDecoderParameter.Hidden = true; 185 Evaluator.PackingPlanEvaluatorParameter.ActualName = PackingPlanEvaluatorParameter.Name; 186 Evaluator.PackingPlanEvaluatorParameter.Hidden = true; 187 Evaluator.QualityParameter.ActualName = PackingPlanEvaluator.QualityParameter.ActualName; 188 Evaluator.QualityParameter.Hidden = true; 189 190 if (PackingSolutionDecoder != null) 191 PackingSolutionDecoder.EncodedSolutionParameter.ActualName = SolutionCreator.EncodedSolutionParameter.ActualName; 192 193 if (PackingSolutionDecoder != null) { 194 PackingPlanEvaluator.PackingPlanParameter.ActualName = PackingSolutionDecoder.PackingPlanParameter.ActualName; 195 PackingPlanEvaluator.PackingPlanParameter.Hidden = true; 196 } else { 197 PackingPlanEvaluator.PackingPlanParameter.ActualName = PackingPlanEvaluator.PackingPlanParameter.Name; 198 PackingPlanEvaluator.PackingPlanParameter.Hidden = false; 199 } 200 201 foreach (var op in Operators.OfType<IPackingSolutionManipulator>()) { 202 op.EncodedSolutionParameter.ActualName = SolutionCreator.EncodedSolutionParameter.ActualName; 203 op.EncodedSolutionParameter.Hidden = true; 204 } 205 206 foreach (var op in Operators.OfType<IPackingSolutionCrossover>()) { 207 op.ChildParameter.ActualName = SolutionCreator.EncodedSolutionParameter.ActualName; 208 op.ChildParameter.Hidden = true; 209 op.ParentsParameter.ActualName = SolutionCreator.EncodedSolutionParameter.ActualName; 210 op.ParentsParameter.Hidden = true; 211 } 212 213 foreach (var op in Operators.OfType<BestBinPackingSolutionAnalyzer<D, B, I>>()) { 214 op.QualityParameter.ActualName = PackingPlanEvaluator.QualityParameter.ActualName; 215 if (PackingSolutionDecoder != null) { 216 op.PackingPlanParameter.ActualName = PackingSolutionDecoder.PackingPlanParameter.ActualName; 217 op.PackingPlanParameter.Hidden = true; 218 } else { 219 op.PackingPlanParameter.ActualName = op.PackingPlanParameter.Name; 220 op.PackingPlanParameter.Hidden = false; 221 } 222 } 223 224 } 225 226 #region Events 227 protected override void OnSolutionCreatorChanged() { 228 InitializeOperators(); 229 } 230 protected override void OnEvaluatorChanged() { 231 base.OnEvaluatorChanged(); 232 ParameterizeOperators(); 233 } 234 private void PackingPlanEvaluatorParameter_ValueChanged(object sender, EventArgs eventArgs) { 235 PackingPlanEvaluator.QualityParameter.ActualNameChanged += PackingPlanEvaluator_QualityParameter_ActualNameChanged; 236 ParameterizeOperators(); 237 } 238 private void PackingPlanEvaluator_QualityParameter_ActualNameChanged(object sender, EventArgs eventArgs) { 239 ParameterizeOperators(); 240 } 241 private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs eventArgs) { 242 SolutionCreator.EncodedSolutionParameter.ActualNameChanged += SolutionCreator_EncodedSolutionParameter_ActualNameChanged; 243 ParameterizeOperators(); 244 } 245 private void SolutionCreator_EncodedSolutionParameter_ActualNameChanged(object sender, EventArgs eventArgs) { 246 ParameterizeOperators(); 247 } 248 private void PackingSolutionDecoderParameter_ValueChanged(object sender, EventArgs eventArgs) { 249 if (PackingSolutionDecoder != null) PackingSolutionDecoder.PackingPlanParameter.ActualNameChanged += PackingSolutionDecoder_PackingPlanParameter_ActualNameChanged; 250 ParameterizeOperators(); 251 } 252 private void PackingSolutionDecoder_PackingPlanParameter_ActualNameChanged(object sender, EventArgs eventArgs) { 253 ParameterizeOperators(); 254 } 255 #endregion 92 256 } 93 257 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/HeuristicLab.Problems.BinPacking-3.3.csproj
r13613 r14040 290 290 <Compile Include="Plugin.cs" /> 291 291 <Compile Include="Properties\AssemblyInfo.cs" /> 292 <Compile Include="RegularIdenticalBinPackingProblem.cs" />293 292 </ItemGroup> 294 293 <ItemGroup> -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/RegularIdenticalBinPackingProblem.cs
r14039 r14040 47 47 48 48 #region Parameter Properties 49 public IValueParameter<B> PackingBinMeasuresParameter { 50 get { return (IValueParameter<B>)Parameters["PackingBinMeasures"]; } 51 } 52 public IConstrainedValueParameter<IPackingSolutionDecoder> PackingSolutionDecoderParameter { 53 get { return (IConstrainedValueParameter<IPackingSolutionDecoder>)Parameters["PackingSolutionDecoder"]; } 54 } 49 55 50 #endregion 56 51 57 52 #region Properties 58 public B PackingBinMeasures { 59 get { return PackingBinMeasuresParameter.Value; } 60 set { PackingBinMeasuresParameter.Value = value; } 61 } 62 public PackingSolutionDecoder<D, B, I> PackingSolutionDecoder { 63 get { return PackingSolutionDecoderParameter.Value as PackingSolutionDecoder<D, B, I>; } 64 set { PackingSolutionDecoderParameter.Value = value; } 65 } 53 66 54 #endregion 67 55
Note: See TracChangeset
for help on using the changeset viewer.