- Timestamp:
- 07/12/16 20:35:19 (8 years ago)
- Location:
- branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3
- Files:
-
- 11 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Analyzers/BestBinPackingSolutionAnalyzer.cs
r14048 r14050 93 93 } 94 94 string binUtilKey = "Overall Bin Utilization"; 95 DoubleValue binUtil = BinUtilization RegularIdenticalBinEvaluator<D, B, I>.CalculateBinUtilization(bestSolution);95 DoubleValue binUtil = BinUtilizationEvaluator<D, B, I>.CalculateBinUtilization(bestSolution); 96 96 if (!results.ContainsKey(binUtilKey)) 97 97 results.Add(new Result(binUtilKey, binUtil)); -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/PackingPlan.cs
r14048 r14050 37 37 [Item("PackingPlan", "Represents a concrete solution for a bin-packing problem.")] 38 38 [StorableClass] 39 public abstract class PackingPlan<D, B, I> : Item, IPackingPlan39 public abstract class PackingPlan<D, B, I> : Item, IPackingPlan 40 40 where D : class, IPackingPosition 41 41 where B : PackingShape<D> … … 77 77 78 78 protected PackingPlan(B binMeasures, bool useExtremePoints, bool stackingConstraints) 79 : base() {80 81 82 83 79 : base() { 80 BinMeasures = (B)binMeasures.Clone(); 81 StackingConstraints = stackingConstraints; 82 UseExtremePoints = useExtremePoints; 83 BinPackings = new ObservableList<BinPacking<D, B, I>>(); 84 84 } 85 85 86 86 [StorableConstructor] 87 87 protected PackingPlan(bool deserializing) : base(deserializing) { } 88 protected PackingPlan(PackingPlan<D, B,I> original, Cloner cloner)88 protected PackingPlan(PackingPlan<D, B, I> original, Cloner cloner) 89 89 : base(original, cloner) { 90 91 } 92 90 this.BinPackings = new ObservableList<BinPacking<D, B, I>>(original.BinPackings); 91 } 92 93 93 94 94 public abstract BinPacking<D, B, I> NewBinPacking(); 95 95 public void UpdateBinPackings() { 96 96 BinPackings.RemoveAll(x => x.ItemPositions.Count == 0); 97 BinPackings = new ObservableList<BinPacking<D, B, I>>(BinPackings.OrderByDescending 97 BinPackings = new ObservableList<BinPacking<D, B, I>>(BinPackings.OrderByDescending(bp => bp.PackingDensity)); 98 98 } 99 99 … … 139 139 UpdateBinPackings(); 140 140 141 var newSolution = new ObservableDictionary<int, ItemList<PackingInformation>>();141 var newSolution = new ObservableDictionary<int, ItemList<PackingInformation>>(); 142 142 foreach (var bp in BinPackings) { 143 143 int binIndex = newSolution.Count; 144 144 newSolution[binIndex] = new ItemList<PackingInformation>(); 145 145 foreach (var entry in bp.ItemPositions) 146 newSolution[binIndex].Add(new PackingInformation 146 newSolution[binIndex].Add(new PackingInformation(entry.Key, entry.Value.Rotated)); 147 147 } 148 148 solution.PackingInformations = newSolution; … … 167 167 var temp = new List<int>(remainingIDs); 168 168 foreach (int id in temp) { 169 foreach (var bp in BinPackings) { 170 var position = UseExtremePoints ? bp.FindExtremePointForItem 169 foreach (var bp in BinPackings) { 170 var position = UseExtremePoints ? bp.FindExtremePointForItem(itemMeasures[id], false, StackingConstraints) : bp.FindPositionBySliding(itemMeasures[id], false); 171 171 if (position != null) { 172 172 bp.PackItem(id, itemMeasures[id], position); … … 195 195 binIndex++; 196 196 } 197 solution.GroupingVector = new IntegerVector 197 solution.GroupingVector = new IntegerVector(newSolution); 198 198 } 199 199 public void Pack(PackingSequenceEncoding solution, ItemList<I> itemMeasures) { -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Evaluators/BinUtilizationRegularIdenticalBinEvaluator.cs
r14048 r14050 28 28 29 29 namespace HeuristicLab.Problems.BinPacking { 30 [Item("Bin-Utilization Regular Identical-Bin Evaluator", "<Description missing> Found in Lee:2010")]30 [Item("Bin-Utilization Evaluator", "<Description missing> Found in Lee:2010")] // TODO 31 31 [StorableClass] 32 public abstract class BinUtilization RegularIdenticalBinEvaluator<D, B, I> : RegularSimpleRotationIdenticalBinPackingPlanEvaluator<D, B, I>32 public abstract class BinUtilizationEvaluator<D, B, I> : EvaluatorBase<D, B, I> 33 33 where D : class, IPackingPosition 34 34 where B : PackingShape<D> … … 36 36 37 37 [StorableConstructor] 38 protected BinUtilization RegularIdenticalBinEvaluator(bool deserializing) : base(deserializing) { }39 protected BinUtilization RegularIdenticalBinEvaluator(BinUtilizationRegularIdenticalBinEvaluator<D, B, I> original, Cloner cloner)38 protected BinUtilizationEvaluator(bool deserializing) : base(deserializing) { } 39 protected BinUtilizationEvaluator(BinUtilizationEvaluator<D, B, I> original, Cloner cloner) 40 40 : base(original, cloner) { 41 41 } 42 public BinUtilization RegularIdenticalBinEvaluator() : base() { }42 public BinUtilizationEvaluator() : base() { } 43 43 44 44 protected override DoubleValue Evaluate() { … … 49 49 ItemList<I> itemMeasures = PackingItemMeasuresParameter.ActualValue; 50 50 51 // TODO: check and remove code 51 52 52 53 //Check if data is valid -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Evaluators/PackingPlanEvaluationAlgorithm.cs
r14048 r14050 44 44 get { return PackingSolutionDecoderParameter; } 45 45 } 46 public IValueLookupParameter<I PackingPlanEvaluator> PackingPlanEvaluatorParameter {47 get { return (IValueLookupParameter<I PackingPlanEvaluator>)Parameters["PackingPlanEvaluator"]; }46 public IValueLookupParameter<IEvaluator> PackingPlanEvaluatorParameter { 47 get { return (IValueLookupParameter<IEvaluator>)Parameters["PackingPlanEvaluator"]; } 48 48 } 49 ILookupParameter<I PackingPlanEvaluator> IPackingPlanEvaluationAlgorithm.PackingPlanEvaluatorParameter {49 ILookupParameter<IEvaluator> IPackingPlanEvaluationAlgorithm.PackingPlanEvaluatorParameter { 50 50 get { return PackingPlanEvaluatorParameter; } 51 51 } … … 62 62 : base() { 63 63 Parameters.Add(new ValueLookupParameter<IPackingSolutionDecoder>("PackingSolutionDecoder", "The decoding operator that is used to calculate a packing plan from the used representation.")); 64 Parameters.Add(new ValueLookupParameter<I PackingPlanEvaluator>("PackingPlanEvaluator", "The actual packing plan evaluation operator."));64 Parameters.Add(new ValueLookupParameter<IEvaluator>("PackingPlanEvaluator", "The actual packing plan evaluation operator.")); 65 65 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality value aka fitness value of the solution.")); 66 66 QualityParameter.Hidden = true; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Evaluators/PackingPlanEvaluator.cs
r14048 r14050 27 27 using HeuristicLab.Parameters; 28 28 using HeuristicLab.Data; 29 29 using HeuristicLab.Collections; 30 30 31 31 namespace HeuristicLab.Problems.BinPacking { 32 32 [Item("Packingplan Evaluator", "Represents a evaluator class for standard bin-packing problems.")] 33 33 [StorableClass] 34 public abstract class PackingPlanEvaluator<D,B,I> : SingleSuccessorOperator, IPackingPlanEvaluator34 public abstract class EvaluatorBase<D,B,I> : SingleSuccessorOperator, IEvaluator 35 35 where D : class, IPackingPosition 36 36 where B : PackingShape<D> … … 52 52 get { return (ILookupParameter<IPackingPlan>)Parameters["PackingPlan"]; } 53 53 } 54 public ILookupParameter<ItemList<I>> PackingItemMeasuresParameter { 55 get { return (ILookupParameter<ItemList<I>>)Parameters["PackingItemMeasures"]; } 56 } 57 public ILookupParameter<B> PackingBinMeasuresParameter { 58 get { return (ILookupParameter<B>)Parameters["PackingBinMeasures"]; } 59 } 54 60 #endregion 55 61 56 62 [StorableConstructor] 57 protected PackingPlanEvaluator(bool deserializing) : base(deserializing) { }58 protected PackingPlanEvaluator(PackingPlanEvaluator<D,B,I> original, Cloner cloner)63 protected EvaluatorBase(bool deserializing) : base(deserializing) { } 64 protected EvaluatorBase(EvaluatorBase<D,B,I> original, Cloner cloner) 59 65 : base(original, cloner) { 60 66 } 61 public PackingPlanEvaluator()67 public EvaluatorBase() 62 68 : base() { 63 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality value aka fitness valueof the solution."));69 Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality value of the solution.")); 64 70 Parameters.Add(new LookupParameter<IPackingPlan>("PackingPlan", "The decoded bin-packing solution represented as generalized packing-plan.")); 65 71 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator.")); 72 Parameters.Add(new LookupParameter<ItemList<I>>("PackingItemMeasures", "Packing-item data taken from the bin-packing problem-instance.")); 73 Parameters.Add(new LookupParameter<B>("PackingBinMeasures", "Packing-bin data taken from the bin-packing problem-instance.")); 74 66 75 } 67 68 76 69 77 protected abstract DoubleValue Evaluate(); … … 73 81 } 74 82 83 protected bool HasOverlappingOrNotContainedItems(ObservableDictionary<int, D> positions, B binMeasure, ItemList<I> itemMeasures, int nrOfBins) { 84 //TODO: Optimize performance by removing unnecessary allocations.. 85 for (int i = 0; i < itemMeasures.Count; i++) { 86 I packingItem = itemMeasures[i]; 87 D currentPosition = positions[i]; 88 if (!binMeasure.Encloses(currentPosition, packingItem)) 89 return true; 90 91 for (int j = 0; j < itemMeasures.Count; j++) { 92 D checkedPosition = positions[j]; 93 if (i != j && currentPosition.AssignedBin == checkedPosition.AssignedBin) { 94 I checkedItem = itemMeasures[j]; 95 if (packingItem.Overlaps(currentPosition, checkedPosition, checkedItem)) 96 return true; 97 } 98 } 99 } 100 return false; 101 } 75 102 } 76 103 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Evaluators/PackingRatioEvaluator.cs
r14049 r14050 28 28 29 29 namespace HeuristicLab.Problems.BinPacking { 30 [Item("Packing-Ratio Regular Identical-Bin Evaluator", "Represents an evaluation-algorithm for regular-shaped bin-packing problems with identical bins which calculates the ratio between packed and unpacked space. Found in Falkenauer:1996")]31 30 [StorableClass] 32 public abstract class PackingRatio RegularIdenticalBinEvaluator<D, B, I> : RegularSimpleRotationIdenticalBinPackingPlanEvaluator<D, B, I>31 public abstract class PackingRatioEvaluator<D, B, I> : EvaluatorBase<D, B, I> 33 32 where D : class, IPackingPosition 34 33 where B : PackingShape<D> … … 36 35 37 36 [StorableConstructor] 38 protected PackingRatio RegularIdenticalBinEvaluator(bool deserializing) : base(deserializing) { }39 protected PackingRatio RegularIdenticalBinEvaluator(PackingRatioRegularIdenticalBinEvaluator<D, B, I> original, Cloner cloner)37 protected PackingRatioEvaluator(bool deserializing) : base(deserializing) { } 38 protected PackingRatioEvaluator(PackingRatioEvaluator<D, B, I> original, Cloner cloner) 40 39 : base(original, cloner) { 41 40 } 42 public PackingRatio RegularIdenticalBinEvaluator() : base() { }41 public PackingRatioEvaluator() : base() { } 43 42 44 43 protected override DoubleValue Evaluate() { -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Evaluators/RegularSimpleRotationIdenticalBinPackingPlanEvaluator.cs
r14048 r14050 54 54 } 55 55 56 57 58 59 56 protected bool HasOverlappingOrNotContainedItems(ObservableDictionary<int, D> positions, B binMeasure, ItemList<I> itemMeasures, int nrOfBins) { 60 57 //TODO: Optimize performance by removing unnecessary allocations.. … … 73 70 } 74 71 } 75 76 72 } 77 78 73 return false; 79 74 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/HeuristicLab.Problems.BinPacking-3.3.csproj
r14049 r14050 254 254 <Compile Include="Evaluators\PackingPlanEvaluationAlgorithm.cs" /> 255 255 <Compile Include="Evaluators\PackingPlanEvaluator.cs" /> 256 <Compile Include="Evaluators\PackingRatioRegularIdenticalBinEvaluator.cs" /> 257 <Compile Include="Evaluators\RegularSimpleRotationIdenticalBinPackingPlanEvaluator.cs" /> 256 <Compile Include="Evaluators\PackingRatioEvaluator.cs" /> 258 257 <Compile Include="Instances\BPPData.cs" /> 259 258 <Compile Include="Instances\BPPInstanceProvider.cs" /> -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Interfaces/IPackingPlanEvaluationAlgorithm.cs
r14046 r14050 26 26 public interface IPackingPlanEvaluationAlgorithm : ISingleObjectiveEvaluator { 27 27 ILookupParameter<IPackingSolutionDecoder> PackingSolutionDecoderParameter { get; } 28 ILookupParameter<I PackingPlanEvaluator> PackingPlanEvaluatorParameter { get; }28 ILookupParameter<IEvaluator> PackingPlanEvaluatorParameter { get; } 29 29 } 30 30 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Interfaces/IPackingPlanEvaluator.cs
r14046 r14050 24 24 25 25 namespace HeuristicLab.Problems.BinPacking { 26 public interface I PackingPlanEvaluator : ISingleObjectiveEvaluator {26 public interface IEvaluator : ISingleObjectiveEvaluator { 27 27 ILookupParameter<IPackingPlan> PackingPlanParameter { get; } 28 28 } -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/PackingMoveEvaluator.cs
r14048 r14050 55 55 get { return (IValueLookupParameter<IPackingSolutionDecoder>)Parameters["PackingSolutionDecoder"]; } 56 56 } 57 public IValueLookupParameter<I PackingPlanEvaluator> PackingPlanEvaluatorParameter {58 get { return (IValueLookupParameter<I PackingPlanEvaluator>)Parameters["PackingPlanEvaluator"]; }57 public IValueLookupParameter<IEvaluator> PackingPlanEvaluatorParameter { 58 get { return (IValueLookupParameter<IEvaluator>)Parameters["PackingPlanEvaluator"]; } 59 59 } 60 60 protected ScopeParameter CurrentScopeParameter { … … 75 75 Parameters.Add(new LookupParameter<B>("PackingBinMeasures", "Packing-bin data taken from the bin-packing problem-instance.")); 76 76 Parameters.Add(new ValueLookupParameter<IPackingSolutionDecoder>("PackingSolutionDecoder", "The decoding operator that is used to calculate a packing plan from the used representation.")); 77 Parameters.Add(new ValueLookupParameter<I PackingPlanEvaluator>("PackingPlanEvaluator", "The actual packing plan evaluation operator."));77 Parameters.Add(new ValueLookupParameter<IEvaluator>("PackingPlanEvaluator", "The actual packing plan evaluation operator.")); 78 78 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope where the decoded solution should be added to.")); 79 79 Parameters.Add(new LookupParameter<IPackingMove>("PackingMove", "The move to evaluate.")); … … 93 93 CurrentScopeParameter.ActualValue.Variables.Add(new Variable("PackingPlanAfterMove", packingPlan)); 94 94 95 DoubleValue quality = PackingRatio RegularIdenticalBinEvaluator<D, B, I>.CalculatePackingRatio(packingPlan);95 DoubleValue quality = PackingRatioEvaluator<D, B, I>.CalculatePackingRatio(packingPlan); 96 96 97 97 double moveQuality = quality.Value; -
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Problem.cs
r14049 r14050 55 55 get { return (IFixedValueParameter<IntValue>)Parameters["LowerBound"]; } 56 56 } 57 public ValueParameter<I PackingPlanEvaluator> PackingPlanEvaluatorParameter {58 get { return (ValueParameter<I PackingPlanEvaluator>)Parameters["PackingPlanEvaluator"]; }57 public ValueParameter<IEvaluator> PackingPlanEvaluatorParameter { 58 get { return (ValueParameter<IEvaluator>)Parameters["PackingPlanEvaluator"]; } 59 59 } 60 60 public IValueParameter<B> PackingBinMeasuresParameter { … … 75 75 set { PackingItemMeasuresParameter.Value = value; } 76 76 } 77 public I PackingPlanEvaluator PackingPlanEvaluator {77 public IEvaluator PackingPlanEvaluator { 78 78 get { return PackingPlanEvaluatorParameter.Value; } 79 79 set { PackingPlanEvaluatorParameter.Value = value; } … … 106 106 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())); 107 107 Parameters.Add(new ValueParameter<B>("PackingBinMeasures", "Packing-bin data defining the measures of the used bins.", new B())); 108 Parameters.Add(new ValueParameter<I PackingPlanEvaluator>("PackingPlanEvaluator", "The evaluator is used to determine the quality of a solution.", CreateDefaultEvaluator()));108 Parameters.Add(new ValueParameter<IEvaluator>("PackingPlanEvaluator", "The evaluator is used to determine the quality of a solution.", CreateDefaultEvaluator())); 109 109 Parameters.Add(new ConstrainedValueParameter<IPackingSolutionDecoder>("PackingSolutionDecoder", "The operator that decodes the representation and creates a packing plan.")); 110 110 this.Maximization.Value = true; … … 142 142 protected abstract void RemoveTooBigItems(); 143 143 protected abstract void InitializeProblemData(); 144 protected abstract I PackingPlanEvaluator CreateDefaultEvaluator();144 protected abstract IEvaluator CreateDefaultEvaluator(); 145 145 protected void ApplyHorizontalOrientation() { 146 146 PackingBinMeasures.ApplyHorizontalOrientation();
Note: See TracChangeset
for help on using the changeset viewer.