Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/06/13 03:12:42 (12 years ago)
Author:
jhelm
Message:

#1966: Applied some heavy refactoring on the decoder-classes and cleaned up the code a bit;

Location:
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3
Files:
8 added
2 deleted
31 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Analyzers/BestBinPackingSolutionAnalyzer.cs

    r9563 r9593  
    9393          !max && bestSolution.Quality.Value > qualities[i].Value) {
    9494          bestSolution.Quality.Value = qualities[i].Value;
    95           bestSolution.PackingItemPositions = new ObservableDictionary<int, D> (solutions[i].PackingItemPositions);
    96           bestSolution.PackingBinMeasures = new ObservableDictionary<int, B>(solutions[i].PackingBinMeasures);
     95          //bestSolution.PackingItemPositions = new ObservableDictionary<int, D> (solutions[i].PackingItemPositions);
     96          //bestSolution.PackingBinMeasures = new ObservableDictionary<int, B>(solutions[i].PackingBinMeasures);
     97          bestSolution.BinPackings = new ObservableList<BinPacking<D, B, I>>(solutions[i].BinPackings);
    9798        }
    9899      }
    99100      string binUtilKey = "Overall Bin Utilization";
    100101      DoubleValue binUtil = BinUtilizationRegularIdenticalBinEvaluator<D, B, I>.CalculateBinUtilization(bestSolution);
    101       if (!results.ContainsKey("Overall Bin Utilization"))
     102      if (!results.ContainsKey(binUtilKey))
    102103        results.Add(new Result(binUtilKey, binUtil));
    103104      else
    104105        results[binUtilKey].Value = binUtil;
     106
     107
     108      string nocKey = "Nr Of Containers";
     109      if (!results.ContainsKey(nocKey))
     110        results.Add(new Result(nocKey, new IntValue (bestSolution.NrOfBins)));
     111      else
     112        results[nocKey].Value = new IntValue (bestSolution.NrOfBins);
    105113
    106114      return base.Apply();
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/BL/BottomLeftFunctions.cs

    r9563 r9593  
    77using HeuristicLab.Encodings.PackingEncoding.GroupingVector;
    88using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
     9using HeuristicLab.Encodings.PackingEncoding.PackingPlan;
    910using HeuristicLab.Encodings.PackingEncoding.PackingSequence;
    1011using HeuristicLab.Encodings.PermutationEncoding;
     
    1819  public static class BottomLeftFunctions {
    1920
    20 
    21     public static ObservableDictionary<int, TwoDimensionalPacking> BottomLeftPacking(
     21    /*
     22    public static ObservableList<BinPacking<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> BottomLeftPacking(
    2223      MultiComponentVectorEncoding solution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
    2324      int nrOfBins = solution.NrOfBins;
     
    3031      }
    3132
    32       ObservableDictionary<int, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>();
     33      ObservableDictionary<int, TwoDimensionalPacking> itemPositions = new ObservableDictionary<int, TwoDimensionalPacking>();
    3334      var remainingItems = new List<PackingInformation>();
    3435
     
    4243          TwoDimensionalPacking position = null;
    4344
    44           position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures, unpackedItems[i].Rotated);
     45          position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, itemPositions, itemMeasures, unpackedItems[i].Rotated);
    4546
    4647          if (position == null) {
    47             position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures, !unpackedItems[i].Rotated);
    48           }
    49           if (position == null) {
    50             remainingItems.Add(unpackedItems[i]);
     48            position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, itemPositions, itemMeasures, !unpackedItems[i].Rotated);
     49          }
     50          if (position == null) { 
     51            remainingItems.Add(unpackedItems[i]);     
     52            solution.PackingInformations[binNr].Remove(unpackedItems[i]);
    5153          } else {
    52             packingPositions[itemIndex] = position;
    53             solution.PackingInformations[binNr].Remove(unpackedItems[i]);
     54            itemPositions[itemIndex] = position;
    5455            solution.PackingInformations[binNr].Find(pi => pi.ItemID == itemIndex).Rotated = position.Rotated;
    5556          }
     
    6768
    6869          //Look for space in current bin
    69           position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures, unpackedItems[i].Rotated);
     70          position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, itemPositions, itemMeasures, unpackedItems[i].Rotated);
    7071
    7172          if (position == null) {
    72             position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures, !unpackedItems[i].Rotated);
     73            position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, itemPositions, itemMeasures, !unpackedItems[i].Rotated);
    7374          }
    7475          if (position != null) {
    75             packingPositions[itemIndex] = position;
     76            itemPositions[itemIndex] = position;
    7677            remainingItems.Remove(unpackedItems[i]);
    7778            solution.PackingInformations[binNr].Add(unpackedItems[i]);
     
    8586      }
    8687
    87       return packingPositions;
    88     }
    89 
    90     public static ObservableDictionary<int, TwoDimensionalPacking> BottomLeftPacking(
     88      return BinPacking<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>.GetBinPackings(itemPositions, binMeasures, itemMeasures, nrOfBins);
     89    }
     90
     91    public static ObservableList<BinPacking<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> BottomLeftPacking(
    9192      GroupingVectorEncoding solution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
    9293
     
    104105      }
    105106
    106       ObservableDictionary<int, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>();
     107      ObservableDictionary<int, TwoDimensionalPacking> itemPositions = new ObservableDictionary<int, TwoDimensionalPacking>();
    107108      var remainingItems = new List<int>();
    108109
     
    117118
    118119          //Look for space in current bin
    119           position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures);
     120          position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, itemPositions, itemMeasures);
    120121
    121122          //Did not find enough space in current bin
     
    123124            remainingItems.Add(itemIndex);
    124125          } else
    125             packingPositions[itemIndex] = position;
     126            itemPositions[itemIndex] = position;
    126127        }
    127128      }
     
    137138
    138139          //Look for space in current bin
    139           position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures);
     140          position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, itemPositions, itemMeasures);
    140141
    141142          if (position != null) {
    142             packingPositions[itemIndex] = position;
     143            itemPositions[itemIndex] = position;
    143144            remainingItems.Remove(itemIndex);
    144145            solution.GroupingVector[itemIndex] = binNr;
     
    150151      }
    151152
    152       return packingPositions;
    153     }
    154 
    155     public static ObservableDictionary<int, TwoDimensionalPacking> BottomLeftPacking(
     153      return BinPacking<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>.GetBinPackings(itemPositions, binMeasures, itemMeasures, nrOfBins);
     154    }
     155
     156    public static ObservableList<BinPacking<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> BottomLeftPacking(
    156157      PackingSequenceEncoding solution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
    157158
    158       ObservableDictionary<int, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>();
     159      ObservableDictionary<int, TwoDimensionalPacking> itemPositions = new ObservableDictionary<int, TwoDimensionalPacking>();
    159160      int nrOfBins = 1;
    160161      for (int i = 0; i < solution.PackingSequence.Length; i++) {
     
    163164        //Look for space in existing bins
    164165        for (int binNr = 0; binNr < nrOfBins; binNr++) {
    165           position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures);
     166          position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, itemPositions, itemMeasures);
    166167          if (position != null)
    167168            break;
     
    170171        if (position == null) {
    171172          nrOfBins++;
    172           position = BottomLeftFunctions.BottomLeftPosition(binMeasures, nrOfBins - 1, item, packingPositions, itemMeasures);
     173          position = BottomLeftFunctions.BottomLeftPosition(binMeasures, nrOfBins - 1, item, itemPositions, itemMeasures);
    173174        }
    174175
     
    176177          position = new TwoDimensionalPacking(-1, 0, 0);
    177178
    178         packingPositions[solution.PackingSequence[i]] = position;
    179       }
    180 
    181       return packingPositions;
    182     }
    183 
    184     private static TwoDimensionalPacking BottomLeftPosition(RectangularPackingBin binMeasures, int binNr, RectangularPackingItem currentItem, ObservableDictionary<int, TwoDimensionalPacking> itemPositions, ItemList<RectangularPackingItem> itemMeasures) {
     179        itemPositions[solution.PackingSequence[i]] = position;
     180      }
     181
     182      return BinPacking<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>.GetBinPackings(itemPositions, binMeasures, itemMeasures, nrOfBins);
     183    }
     184
     185    */
     186    public static TwoDimensionalPacking BottomLeftPosition(RectangularPackingBin binMeasures, int binNr, RectangularPackingItem currentItem, ObservableDictionary<int, TwoDimensionalPacking> itemPositions, ItemList<RectangularPackingItem> itemMeasures) {
    185187      return BottomLeftPosition(binMeasures, binNr, currentItem, itemPositions, itemMeasures, false);
    186188    }
    187     private static TwoDimensionalPacking BottomLeftPosition(RectangularPackingBin binMeasures, int binNr, RectangularPackingItem currentItem, ObservableDictionary<int, TwoDimensionalPacking> itemPositions, ItemList<RectangularPackingItem> itemMeasures, bool rotated) {     
     189    public static TwoDimensionalPacking BottomLeftPosition(RectangularPackingBin binMeasures, int binNr, RectangularPackingItem currentItem, ObservableDictionary<int, TwoDimensionalPacking> itemPositions, ItemList<RectangularPackingItem> itemMeasures, bool rotated) {     
    188190      TwoDimensionalPacking currentPosition = new TwoDimensionalPacking(binNr,
    189191        binMeasures.Width - (rotated ? currentItem.Height : currentItem.Width),
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/BL/BottomLeftGroupingVectorDecoder.cs

    r9563 r9593  
    6666
    6767      PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> result =
    68         new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(binMeasures, itemMeasures);
     68        new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(binMeasures);
    6969
    70       result.PackingItemPositions = BottomLeftFunctions.BottomLeftPacking(solution, binMeasures, itemMeasures);
     70      result.BinPackings = TwoDimensionalPackingFunctions.BottomLeftPacking(solution, binMeasures, itemMeasures); //BottomLeftFunctions.BottomLeftPacking(solution, binMeasures, itemMeasures);
    7171      return result;
    7272    }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/BL/BottomLeftMultiComponentVectorDecoder.cs

    r9563 r9593  
    6666
    6767      PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> result =
    68         new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(binMeasures, itemMeasures);
    69      
    70       result.PackingItemPositions = BottomLeftFunctions.BottomLeftPacking(solution, binMeasures, itemMeasures);
     68        new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(binMeasures);
     69
     70      result.BinPackings = TwoDimensionalPackingFunctions.BottomLeftPacking(solution, binMeasures, itemMeasures); //BottomLeftFunctions.BottomLeftPacking(solution, binMeasures, itemMeasures);
    7171
    7272      return result;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/BL/BottomLeftPackingSequenceDecoder.cs

    r9563 r9593  
    6565
    6666      PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> result =
    67         new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(binMeasures, itemMeasures);
     67        new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(binMeasures);
    6868
    69       result.PackingItemPositions = BottomLeftFunctions.BottomLeftPacking (solution, binMeasures, itemMeasures);
     69      result.BinPackings = TwoDimensionalPackingFunctions.BottomLeftPacking(solution, binMeasures, itemMeasures); //BottomLeftFunctions.BottomLeftPacking(solution, binMeasures, itemMeasures);
    7070
    7171      return result;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/EP/ExtremePointGroupingVectorDecoder2D.cs

    r9563 r9593  
    6060    public static PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> Decode(GroupingVectorEncoding solution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
    6161      PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> result =
    62         new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(binMeasures, itemMeasures);
     62        new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(binMeasures);
    6363
    64       result.PackingItemPositions = ExtremPointsFunctions2D.ExtremePointBasedPacking(solution, itemMeasures, binMeasures);
     64      result.BinPackings = TwoDimensionalPackingFunctions.ExtremePointBasedPacking(solution, itemMeasures, binMeasures);//ExtremPointsFunctions2D.ExtremePointBasedPacking(solution, itemMeasures, binMeasures);
    6565
    6666      return result;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/EP/ExtremePointMultiComponentVectorDecoder2D.cs

    r9563 r9593  
    6161    public static PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> Decode(MultiComponentVectorEncoding solution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
    6262      PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> result =
    63         new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(binMeasures, itemMeasures);
     63        new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(binMeasures);
    6464
    65       result.PackingItemPositions = ExtremPointsFunctions2D.ExtremePointBasedPacking(solution, itemMeasures, binMeasures);
     65      result.BinPackings = TwoDimensionalPackingFunctions.ExtremePointBasedPacking(solution, itemMeasures, binMeasures);//ExtremPointsFunctions2D.ExtremePointBasedPacking(solution, itemMeasures, binMeasures);
    6666
    6767      return result;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/EP/ExtremePointPackingSequenceDecoder2D.cs

    r9563 r9593  
    6464
    6565      PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> result =
    66         new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(binMeasures, itemMeasures);
     66        new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(binMeasures);
    6767
    68       result.PackingItemPositions = ExtremPointsFunctions2D.ExtremePointBasedPacking(solution, itemMeasures, binMeasures);
     68      result.BinPackings = TwoDimensionalPackingFunctions.ExtremePointBasedPacking(solution, itemMeasures, binMeasures);//ExtremPointsFunctions2D.ExtremePointBasedPacking(solution, itemMeasures, binMeasures);
    6969
    7070      return result;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/EP/ExtremePointsFunctions2D.cs

    r9563 r9593  
    77using HeuristicLab.Encodings.PackingEncoding.GroupingVector;
    88using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
     9using HeuristicLab.Encodings.PackingEncoding.PackingPlan;
    910using HeuristicLab.Encodings.PackingEncoding.PackingSequence;
    1011using HeuristicLab.Encodings.PermutationEncoding;
     
    2122
    2223
    23     public static ObservableDictionary<int, TwoDimensionalPacking> ExtremePointBasedPacking(MultiComponentVectorEncoding solution,
     24    public static ObservableList<BinPacking<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> ExtremePointBasedPacking(MultiComponentVectorEncoding solution,
    2425        ItemList<RectangularPackingItem> itemMeasures, RectangularPackingBin binMeasures) {
    2526
     
    9899      }
    99100
    100       return itemPositions;
    101     }
    102 
    103 
    104     public static ObservableDictionary<int, TwoDimensionalPacking> ExtremePointBasedPacking(GroupingVectorEncoding solution,
     101      return BinPacking<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>.GetBinPackings(itemPositions, binMeasures, itemMeasures, nrOfBins);
     102    }
     103
     104
     105    public static ObservableList<BinPacking<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> ExtremePointBasedPacking(GroupingVectorEncoding solution,
    105106        ItemList<RectangularPackingItem> itemMeasures, RectangularPackingBin binMeasures) {
    106107
     
    180181      }
    181182
    182       return itemPositions;
    183     }
    184 
    185 
    186     public static ObservableDictionary<int, TwoDimensionalPacking> ExtremePointBasedPacking(PackingSequenceEncoding solution,
     183      return BinPacking<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>.GetBinPackings(itemPositions, binMeasures, itemMeasures, nrOfBins);
     184    }
     185
     186
     187    public static ObservableList<BinPacking<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> ExtremePointBasedPacking(PackingSequenceEncoding solution,
    187188        ItemList<RectangularPackingItem> itemMeasures, RectangularPackingBin binMeasures) {
    188189
     
    215216      }
    216217
    217       return itemPositions;
    218     }
    219 
    220 
    221     private static TwoDimensionalPacking FindExtremePointForItem(int itemIndex, ItemList<RectangularPackingItem> itemMeasures, RectangularPackingBin binMeasures,
     218      return BinPacking<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>.GetBinPackings(itemPositions, binMeasures, itemMeasures, nrOfBins);
     219    }
     220
     221
     222    public static TwoDimensionalPacking FindExtremePointForItem(int itemIndex, ItemList<RectangularPackingItem> itemMeasures, RectangularPackingBin binMeasures,
    222223        HashSet<TwoDimensionalPacking> extremePoints, List<int[,]> occupiedPoints, ObservableDictionary<int, TwoDimensionalPacking> itemPositions) {
    223224          return FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePoints, occupiedPoints, itemPositions, false);
    224225    }
    225     private static TwoDimensionalPacking FindExtremePointForItem(int itemIndex, ItemList<RectangularPackingItem> itemMeasures, RectangularPackingBin binMeasures,
     226    public static TwoDimensionalPacking FindExtremePointForItem(int itemIndex, ItemList<RectangularPackingItem> itemMeasures, RectangularPackingBin binMeasures,
    226227        HashSet<TwoDimensionalPacking> extremePoints, List<int[,]> occupiedPoints, ObservableDictionary<int, TwoDimensionalPacking> itemPositions, bool rotated) {
    227228
     
    233234
    234235      int epIndex = 0;
    235       while (epIndex < extremePoints.Count &&
     236      while (epIndex < extremePoints.Count &&       
     237        //(!IsPositionFeasible(binMeasures, item, extremePoints.ElementAt(epIndex), occupiedPoints)))
    236238        (!BottomLeftFunctions.IsPositionFeasible(binMeasures, extremePoints.ElementAt(epIndex).AssignedBin, item, extremePoints.ElementAt(epIndex), itemPositions, itemMeasures)))
    237239      { epIndex++; }
     
    244246      return null;
    245247    }
    246     private static List<int[,]> IncreaseBinCountForOccupiedPoints(List<int[,]> occupiedPoints, RectangularPackingBin binMeasures) {
     248    public static List<int[,]> IncreaseBinCountForOccupiedPoints(List<int[,]> occupiedPoints, RectangularPackingBin binMeasures) {
    247249      occupiedPoints.Add(new int[binMeasures.Width, binMeasures.Height]);
    248250      int lastIndex = occupiedPoints.Count - 1;
     
    254256      return occupiedPoints;
    255257    }
    256     private static List<int[,]>  OccupyPointsForNewItem(List<int[,]> occupiedPoints, RectangularPackingItem newItem, TwoDimensionalPacking position, int itemIndex) {
     258    public static List<int[,]>  OccupyPointsForNewItem(List<int[,]> occupiedPoints, RectangularPackingItem newItem, TwoDimensionalPacking position, int itemIndex) {
    257259      int width = position.Rotated ? newItem.Height : newItem.Width;
    258260      int height = position.Rotated ? newItem.Width : newItem.Height;
     
    264266      return occupiedPoints;
    265267    }
    266     private static HashSet<TwoDimensionalPacking> GenerateNewExtremePointsForNewItem(HashSet<TwoDimensionalPacking> extremePoints, List<int[,]> occupiedPoints,
     268    public static HashSet<TwoDimensionalPacking> GenerateNewExtremePointsForNewItem(HashSet<TwoDimensionalPacking> extremePoints, List<int[,]> occupiedPoints,
    267269        RectangularPackingItem newItem, TwoDimensionalPacking position, RectangularPackingBin binMeasures) {
    268270      int currentBin = position.AssignedBin;
     
    321323      return shortestSide;
    322324    }
     325
     326   
    323327  }
    324328}
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/DBL/DeepestBottomLeftFunctions.cs

    r9563 r9593  
    77using HeuristicLab.Encodings.PackingEncoding.GroupingVector;
    88using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
     9using HeuristicLab.Encodings.PackingEncoding.PackingPlan;
    910using HeuristicLab.Encodings.PackingEncoding.PackingSequence;
    1011using HeuristicLab.Encodings.PermutationEncoding;
     
    1819  public static class DeepestBottomLeftFunctions {
    1920
    20     public static ObservableDictionary<int, ThreeDimensionalPacking> DeepestLeftBottomPacking(MultiComponentVectorEncoding solution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) {
     21    public static ObservableList<BinPacking<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>> DeepestLeftBottomPacking(MultiComponentVectorEncoding solution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) {
    2122      int nrOfBins = solution.NrOfBins;
    2223
     
    2829      }
    2930
    30       ObservableDictionary<int, ThreeDimensionalPacking> packingPositions = new ObservableDictionary<int, ThreeDimensionalPacking>();
     31      ObservableDictionary<int, ThreeDimensionalPacking> itemPositions = new ObservableDictionary<int, ThreeDimensionalPacking>();
    3132      var remainingItems = new List<PackingInformation>();
    3233
     
    4041          ThreeDimensionalPacking position = null;
    4142
    42           position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, packingPositions, itemMeasures, unpackedItems[i].Rotated);
    43 
    44           if (position == null) {
    45             position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, packingPositions, itemMeasures, !unpackedItems[i].Rotated);
     43          position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, itemPositions, itemMeasures, unpackedItems[i].Rotated);
     44
     45          if (position == null) {
     46            position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, itemPositions, itemMeasures, !unpackedItems[i].Rotated);
    4647          }
    4748          if (position == null) {
     
    4950            solution.PackingInformations[binNr].Remove(unpackedItems[i]);
    5051          } else {
    51             packingPositions[itemIndex] = position;
     52            itemPositions[itemIndex] = position;
    5253            solution.PackingInformations[binNr].Find(pi => pi.ItemID == itemIndex).Rotated = position.Rotated;
    5354          }
     
    6566
    6667          //Look for space in current bin
    67           position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, packingPositions, itemMeasures, unpackedItems[i].Rotated);
    68 
    69           if (position == null) {
    70             position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, packingPositions, itemMeasures, !unpackedItems[i].Rotated);
     68          position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, itemPositions, itemMeasures, unpackedItems[i].Rotated);
     69
     70          if (position == null) {
     71            position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, itemPositions, itemMeasures, !unpackedItems[i].Rotated);
    7172          }
    7273          if (position != null) {
    73             packingPositions[itemIndex] = position;
     74            itemPositions[itemIndex] = position;
    7475            remainingItems.Remove(unpackedItems[i]);
    7576            solution.PackingInformations[binNr].Add(unpackedItems[i]);
     
    8384      }
    8485
    85       return packingPositions;
    86     }
    87 
    88     public static ObservableDictionary<int, ThreeDimensionalPacking> DeepestLeftBottomPacking(GroupingVectorEncoding solution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) {
     86      return BinPacking<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>.GetBinPackings(itemPositions, binMeasures, itemMeasures, nrOfBins);
     87    }
     88
     89    public static ObservableList<BinPacking<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>> DeepestLeftBottomPacking(GroupingVectorEncoding solution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) {
    8990      int nrOfBins = solution.GroupingVector.Max() + 1;
    9091
     
    100101      }
    101102
    102       ObservableDictionary<int, ThreeDimensionalPacking> packingPositions = new ObservableDictionary<int, ThreeDimensionalPacking>();
     103      ObservableDictionary<int, ThreeDimensionalPacking> itemPositions = new ObservableDictionary<int, ThreeDimensionalPacking>();
    103104      var remainingItems = new List<int>();
    104105
     
    112113          ThreeDimensionalPacking position = null;
    113114
    114           position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, packingPositions, itemMeasures);
     115          position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, itemPositions, itemMeasures);
    115116
    116117          if (position == null) {
    117118            remainingItems.Add(itemIndex);
    118119          } else
    119             packingPositions[itemIndex] = position;
     120            itemPositions[itemIndex] = position;
    120121        }
    121122      }
     
    131132
    132133          //Look for space in current bin
    133           position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, packingPositions, itemMeasures);
     134          position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, itemPositions, itemMeasures);
    134135
    135136          if (position != null) {
    136             packingPositions[itemIndex] = position;
     137            itemPositions[itemIndex] = position;
    137138            remainingItems.Remove(itemIndex);
    138139            //solution.GroupingVector[itemIndex] = binNr;
     
    144145      }
    145146
    146       return packingPositions;
    147     }
    148 
    149     public static ObservableDictionary<int, ThreeDimensionalPacking> DeepestLeftBottomPacking(PackingSequenceEncoding solution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) {
    150       ObservableDictionary<int, ThreeDimensionalPacking> packingPositions = new ObservableDictionary<int, ThreeDimensionalPacking>();
     147      return BinPacking<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>.GetBinPackings(itemPositions, binMeasures, itemMeasures, nrOfBins);
     148    }
     149
     150    public static ObservableList<BinPacking<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>> DeepestLeftBottomPacking(PackingSequenceEncoding solution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) {
     151      ObservableDictionary<int, ThreeDimensionalPacking> itemPositions = new ObservableDictionary<int, ThreeDimensionalPacking>();
    151152      int nrOfBins = 1;
    152153      for (int i = 0; i < solution.PackingSequence.Length; i++) {
     
    155156        //Look for space in existing bins
    156157        for (int binNr = 0; binNr < nrOfBins; binNr++) {
    157           position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, packingPositions, itemMeasures);
     158          position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, binNr, item, itemPositions, itemMeasures);
    158159          if (position != null)
    159160            break;
     
    162163        if (position == null) {
    163164          nrOfBins++;
    164           position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, nrOfBins - 1, item, packingPositions, itemMeasures);
     165          position = DeepestBottomLeftFunctions.DeepestLeftBottomPosition(binMeasures, nrOfBins - 1, item, itemPositions, itemMeasures);
    165166        }
    166167
     
    168169          position = new ThreeDimensionalPacking(-1, 0, 0, 0);
    169170
    170         packingPositions[solution.PackingSequence[i]] = position;
    171       }
    172 
    173       return packingPositions;
     171        itemPositions[solution.PackingSequence[i]] = position;
     172      }
     173
     174      return BinPacking<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>.GetBinPackings(itemPositions, binMeasures, itemMeasures, nrOfBins);
    174175    }
    175176
     
    204205    }
    205206
     207   
     208
    206209    public static bool IsPositionFeasible(CuboidPackingBin binMeasures, int binNr, CuboidPackingItem currentItem,
    207210      ThreeDimensionalPacking currentPosition, ObservableDictionary<int, ThreeDimensionalPacking> itemPositions, ItemList<CuboidPackingItem> itemMeasures) {
     
    233236    }
    234237
    235 
    236  
    237238  }
    238239}
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/DBL/DeepestBottomLeftGroupingVectorDecoder.cs

    r9563 r9593  
    6464      if (solution == null) throw new InvalidOperationException("Encoding is not of type GroupingVector");
    6565
    66       PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> result = new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>(
    67         binMeasures, itemMeasures);
     66      PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> result = new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>(binMeasures);
    6867
    69       ObservableDictionary<int, ThreeDimensionalPacking> packingPositions = DeepestBottomLeftFunctions.DeepestLeftBottomPacking(
    70         solution,
    71         binMeasures,
    72         itemMeasures);
    73 
    74 
    75       result.PackingItemPositions = packingPositions;
     68      result.BinPackings = ThreeDimensionalPackingFunctions.DeepestLeftBottomPacking(solution, binMeasures, itemMeasures);
    7669
    7770      return result;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/DBL/DeepestBottomLeftMultiComponentVectorDecoder.cs

    r9563 r9593  
    6666
    6767      PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> result =
    68         new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>(binMeasures, itemMeasures);
    69      
    70       result.PackingItemPositions = DeepestBottomLeftFunctions.DeepestLeftBottomPacking (solution, binMeasures, itemMeasures);
     68        new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>(binMeasures);
     69
     70      result.BinPackings = ThreeDimensionalPackingFunctions.DeepestLeftBottomPacking(solution, binMeasures, itemMeasures);
    7171
    7272      return result;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/DBL/DeepestBottomLeftPackingSequenceDecoder.cs

    r9563 r9593  
    6565
    6666      PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> result =
    67         new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>(binMeasures, itemMeasures);
     67        new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>(binMeasures);
    6868
    69       result.PackingItemPositions = DeepestBottomLeftFunctions.DeepestLeftBottomPacking (solution, binMeasures, itemMeasures);
     69      result.BinPackings = ThreeDimensionalPackingFunctions.DeepestLeftBottomPacking(solution, binMeasures, itemMeasures);
    7070
    7171      return result;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/EP/ExtremePointGroupingVectorDecoder3D.cs

    r9563 r9593  
    3737using HeuristicLab.Problems.BinPacking.Interfaces;
    3838using HeuristicLab.Encodings.PackingEncoding.GroupingVector;
     39using HeuristicLab.Parameters;
    3940
    4041namespace HeuristicLab.Problems.BinPacking.Decoders {
     
    4647      CuboidPackingItem>, I3DGVDecoder {
    4748
     49    public ValueParameter<BoolValue> StackingConstraintsParameter {
     50      get { return (ValueParameter<BoolValue>)Parameters["StackingConstraint"]; }
     51    }
     52
    4853    public ExtremePointGroupingVectorDecoder3D ()
    4954      : base() {
     55      Parameters.Add(new ValueParameter<BoolValue>("StackingConstraint", "A flag determining whether stackingconstraints should be enforced or not."));
    5056    }
    5157    [StorableConstructor]
     
    5864    }
    5965
    60     public static PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> Decode(GroupingVectorEncoding solution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) {
     66    public static PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> Decode(GroupingVectorEncoding solution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures, bool stackingConstraints) {
    6167      PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> result =
    62         new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>(binMeasures, itemMeasures);
     68        new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>(binMeasures);
    6369
    64       result.PackingItemPositions = ExtremePointsFunctions3D.ExtremePointBasedPacking(solution, itemMeasures, binMeasures);
     70      result.BinPackings = ThreeDimensionalPackingFunctions.ExtremePointBasedPacking(solution, itemMeasures, binMeasures, stackingConstraints);
    6571
    6672      return result;
     
    7278      if (solution == null) throw new InvalidOperationException("Encoding is not of type GroupingVector");
    7379
    74       return Decode(solution, binMeasures, itemMeasures);
     80      return Decode(solution, binMeasures, itemMeasures, StackingConstraintsParameter.Value.Value);
    7581    }
    7682  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/EP/ExtremePointMultiComponentVectorDecoder3D.cs

    r9563 r9593  
    3838using HeuristicLab.Encodings.PackingEncoding.GroupingVector;
    3939using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
     40using HeuristicLab.Parameters;
    4041
    4142namespace HeuristicLab.Problems.BinPacking.Decoders {
     
    4748      CuboidPackingItem>, I3DMCVDecoder {
    4849
     50    public ValueParameter<BoolValue> StackingConstraintsParameter {
     51      get { return (ValueParameter<BoolValue>)Parameters["StackingConstraint"]; }
     52    }
     53
    4954    public ExtremePointMultiComponentVectorDecoder3D ()
    5055      : base() {
     56      Parameters.Add(new ValueParameter<BoolValue>("StackingConstraint", "A flag determining whether stackingconstraints should be enforced or not."));
    5157    }
    5258    [StorableConstructor]
     
    5965    }
    6066
    61     public static PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> Decode(MultiComponentVectorEncoding solution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures) {
     67    public static PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> Decode(MultiComponentVectorEncoding solution, CuboidPackingBin binMeasures, ItemList<CuboidPackingItem> itemMeasures, bool stackingConstraints) {
    6268      PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> result =
    63         new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>(binMeasures, itemMeasures);
     69        new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>(binMeasures);
    6470
    65       result.PackingItemPositions = ExtremePointsFunctions3D.ExtremePointBasedPacking(ref solution, itemMeasures, binMeasures);
     71      result.BinPackings = ThreeDimensionalPackingFunctions.ExtremePointBasedPacking(solution, itemMeasures, binMeasures, stackingConstraints);
    6672
    6773      return result;
     
    7379      if (solution == null) throw new InvalidOperationException("Encoding is not of type MultiComponentVector");
    7480
    75       return Decode(solution, binMeasures, itemMeasures);
     81      return Decode(solution, binMeasures, itemMeasures, StackingConstraintsParameter.Value.Value);
    7682    }
    7783  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/EP/ExtremePointPackingSequenceDecoder3D.cs

    r9563 r9593  
    3636using HeuristicLab.Encodings.PackingEncoding.PackingSequence;
    3737using HeuristicLab.Problems.BinPacking.Interfaces;
     38using HeuristicLab.Parameters;
    3839
    3940namespace HeuristicLab.Problems.BinPacking.Decoders {
     
    4546      CuboidPackingItem>, I3DPSDecoder {
    4647
     48    public ValueParameter<BoolValue> StackingConstraintsParameter {
     49      get { return (ValueParameter<BoolValue>)Parameters["StackingConstraint"]; }
     50    }
     51
    4752    public ExtremePointPackingSequenceDecoder3D ()
    4853      : base() {
     54        Parameters.Add(new ValueParameter<BoolValue>("StackingConstraint", "A flag determining whether stackingconstraints should be enforced or not."));
    4955    }
    5056    [StorableConstructor]
     
    6470
    6571      PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> result =
    66         new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>(binMeasures, itemMeasures);
     72        new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>(binMeasures);
    6773
    68       result.PackingItemPositions = ExtremePointsFunctions3D.ExtremePointBasedPacking(solution, itemMeasures, binMeasures);
     74      result.BinPackings = ThreeDimensionalPackingFunctions.ExtremePointBasedPacking(solution, itemMeasures, binMeasures, StackingConstraintsParameter.Value.Value);
    6975
    7076      return result;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/EP/ExtremePointsFunctions3D.cs

    r9563 r9593  
    88using HeuristicLab.Encodings.PackingEncoding.GroupingVector;
    99using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
     10using HeuristicLab.Encodings.PackingEncoding.PackingPlan;
    1011using HeuristicLab.Encodings.PackingEncoding.PackingSequence;
    1112using HeuristicLab.Encodings.PermutationEncoding;
     
    2021
    2122
    22     public static ObservableDictionary<int, ThreeDimensionalPacking> ExtremePointBasedPacking(ref MultiComponentVectorEncoding solution,
    23         ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures) {
     23    public static ObservableList<BinPacking<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>> ExtremePointBasedPacking(ref MultiComponentVectorEncoding solution,
     24        ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures, bool stackingConstraints) {
    2425
    2526      #region Preperations
     
    9798      }
    9899
    99       return itemPositions;
    100     }
    101 
    102 
    103     public static ObservableDictionary<int, ThreeDimensionalPacking> ExtremePointBasedPacking(GroupingVectorEncoding solution,
    104         ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures) {
     100      return BinPacking<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>.GetBinPackings(itemPositions, binMeasures, itemMeasures, nrOfBins);
     101    }
     102
     103
     104    public static ObservableList<BinPacking<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>> ExtremePointBasedPacking(GroupingVectorEncoding solution,
     105        ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures, bool stackingConstraints) {
    105106
    106107      #region Preperations
     
    139140
    140141          extremePointsForBin[binNr] = OrderExtremePoints(extremePointsForBin[binNr], occupiedPoints, binMeasures);
    141           var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePointsForBin[binNr], occupiedPoints, itemPositions);
     142          var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePointsForBin[binNr], occupiedPoints, itemPositions, stackingConstraints);
    142143          if (positionFound != null) {
    143144            extremePointsForBin[binNr].Remove(positionFound);
     
    162163
    163164          extremePointsForBin[binNr] = OrderExtremePoints(extremePointsForBin[binNr], occupiedPoints, binMeasures);
    164           var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePointsForBin[binNr], occupiedPoints, itemPositions);
     165          var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePointsForBin[binNr], occupiedPoints, itemPositions, stackingConstraints);
    165166          if (positionFound != null) {
    166167            extremePointsForBin[binNr].Remove(positionFound);
     
    179180      }
    180181
    181       return itemPositions;
    182     }
    183 
    184 
    185     public static ObservableDictionary<int, ThreeDimensionalPacking> ExtremePointBasedPacking(PackingSequenceEncoding solution,
    186         ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures) {
     182      return BinPacking<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>.GetBinPackings(itemPositions, binMeasures, itemMeasures, nrOfBins);
     183    }
     184
     185
     186    public static ObservableList<BinPacking<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>> ExtremePointBasedPacking(PackingSequenceEncoding solution,
     187        ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures, bool stackingConstraints) {
    187188
    188189      #region Preperations
     
    200201        var item = itemMeasures[itemIndex];
    201202        extremePoints = OrderExtremePoints(extremePoints, occupiedPoints, binMeasures);
    202         var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePoints, occupiedPoints, itemPositions);
     203        var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePoints, occupiedPoints, itemPositions, stackingConstraints);
    203204        if (positionFound != null) {
    204205          extremePoints.Remove(positionFound);
     
    214215      }
    215216
    216       return itemPositions;
    217     }
     217      return BinPacking<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>.GetBinPackings(itemPositions, binMeasures, itemMeasures, nrOfBins);
     218    }
     219
     220
    218221
    219222
    220223    public static ThreeDimensionalPacking FindExtremePointForItem(int itemIndex, ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures,
    221         HashSet<ThreeDimensionalPacking> extremePoints, List<int[, ,]> occupiedPoints, ObservableDictionary<int, ThreeDimensionalPacking> itemPositions) {
    222           return FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePoints, occupiedPoints, itemPositions, false);
    223     }
     224        HashSet<ThreeDimensionalPacking> extremePoints, List<int[, ,]> occupiedPoints, ObservableDictionary<int, ThreeDimensionalPacking> itemPositions, bool stackingConstraints) {
     225          return FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePoints, occupiedPoints, itemPositions, stackingConstraints, false);
     226    }
     227    public static ThreeDimensionalPacking FindExtremePointForItem(int itemIndex, ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures,
     228        HashSet<ThreeDimensionalPacking> extremePoints, List<int[, ,]> occupiedPoints, ObservableDictionary<int, ThreeDimensionalPacking> itemPositions, bool stackingConstraints, bool rotated) {
     229
     230      var itemFromList = itemMeasures[itemIndex];
     231      CuboidPackingItem item = new CuboidPackingItem(
     232        rotated ? itemFromList.Depth : itemFromList.Width,
     233        itemFromList.Height,
     234        rotated ? itemFromList.Width : itemFromList.Depth,
     235        itemFromList.TargetBin);
     236
     237      int epIndex = 0;
     238      while (epIndex < extremePoints.Count &&   
     239        //(!IsPositionFeasible(binMeasures, item, extremePoints.ElementAt(epIndex), occupiedPoints) ||
     240        (!DeepestBottomLeftFunctions.IsPositionFeasible(binMeasures, extremePoints.ElementAt(epIndex).AssignedBin, item, extremePoints.ElementAt(epIndex), itemPositions, itemMeasures) ||
     241        (stackingConstraints && !IsStaticStable(occupiedPoints[extremePoints.ElementAt(epIndex).AssignedBin], item, extremePoints.ElementAt(epIndex)))))
     242      { epIndex++; }
     243
     244      if (epIndex < extremePoints.Count) {
     245        var result = extremePoints.ElementAt(epIndex);
     246        result.Rotated = rotated;
     247        return result;
     248      }
     249      return null;
     250    }
     251
     252
    224253    public static ThreeDimensionalPacking FindExtremePointForItemUsingMaterialAndWeightConstraint(int itemIndex, ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures,
    225254       HashSet<ThreeDimensionalPacking> extremePoints, List<int[, ,]> occupiedPoints, ObservableDictionary<int, ThreeDimensionalPacking> itemPositions, bool rotated) {
     
    234263      int epIndex = 0;
    235264      while (epIndex < extremePoints.Count &&
     265        //(!IsPositionFeasible(binMeasures, item, extremePoints.ElementAt(epIndex), occupiedPoints) || 
    236266        (!DeepestBottomLeftFunctions.IsPositionFeasible(binMeasures, extremePoints.ElementAt(epIndex).AssignedBin, item, extremePoints.ElementAt(epIndex), itemPositions, itemMeasures) ||
    237267        !IsStaticStable(occupiedPoints[extremePoints.ElementAt(epIndex).AssignedBin], item, extremePoints.ElementAt(epIndex)) ||
     
    243273        return result;
    244274      }
    245       return null;
    246     }
    247     public static ThreeDimensionalPacking FindExtremePointForItem(int itemIndex, ItemList<CuboidPackingItem> itemMeasures, CuboidPackingBin binMeasures,
    248         HashSet<ThreeDimensionalPacking> extremePoints, List<int[,,]> occupiedPoints, ObservableDictionary<int, ThreeDimensionalPacking> itemPositions, bool rotated) {
    249 
    250       var itemFromList = itemMeasures[itemIndex];
    251       CuboidPackingItem item = new CuboidPackingItem(
    252         rotated ? itemFromList.Depth : itemFromList.Width,
    253         itemFromList.Height,
    254         rotated ? itemFromList.Width : itemFromList.Depth,
    255         itemFromList.TargetBin);
    256 
    257       int epIndex = 0;
    258       while (epIndex < extremePoints.Count &&
    259         (!DeepestBottomLeftFunctions.IsPositionFeasible(binMeasures, extremePoints.ElementAt(epIndex).AssignedBin, item, extremePoints.ElementAt(epIndex), itemPositions, itemMeasures) ||
    260         !IsStaticStable(occupiedPoints[extremePoints.ElementAt(epIndex).AssignedBin], item, extremePoints.ElementAt(epIndex))))
    261       { epIndex++; }
    262 
    263       if (epIndex < extremePoints.Count) {
    264         var result = extremePoints.ElementAt(epIndex);
    265         result.Rotated = rotated;
    266         return result;
    267       }
    268275      return null;
    269276    }
     
    439446      return shortestSide;
    440447    }
     448
     449   
    441450  }
    442451}
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/3D/EP/ISOContainerMultiComponentVectorDecoder3D.cs

    r9563 r9593  
    6262     
    6363      PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> result =
    64         new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>(new ObservableDictionary<int, CuboidPackingBin>(), itemMeasures);
    65 
     64        new PackingPlan<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>();
     65                                                                   /*
    6666      #region Preperations
    6767      int nrOfBins = solution.NrOfBins;
     
    153153      }
    154154
    155       result.PackingItemPositions = itemPositions;
    156       result.PackingBinMeasures = resultingBinMeasures;
     155      result.BinPackings = BinPacking<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem>.GetBinPackings(itemPositions, resultingBinMeasures, itemMeasures, nrOfBins);   */
    157156      return result;
    158157    }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/GroupingVector/GroupingVectorRandomCreator.cs

    r9563 r9593  
    6464    public static GroupingVectorEncoding Apply(int items, int lowerBound, IRandom random) {
    6565      var solution = new GroupingVectorEncoding();
    66       solution.GroupingVector = new IntegerVector(items, random, 0, lowerBound + 1);
     66      solution.GroupingVector = new IntegerVector(items, random, 0, lowerBound + 1);
    6767      return solution;
    6868    }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/Moves/Triple/Moves/MCVTripleMove.cs

    r9563 r9593  
    102102            return true;
    103103        } else {
    104           if ((Index == actualAttribute.Index && TargetIndex == actualAttribute.TargetIndex)
     104          if ((Index == actualAttribute.Index || TargetIndex == actualAttribute.TargetIndex)
    105105                  && MultiComponentVector.PackingInformations[OldGroup][Index].ItemID == actualAttribute.ItemID
    106106                  //&& Rotation == actualAttribute.Rotation
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/MultiComponentVectorRandomCreator.cs

    r9563 r9593  
    7070      var solution = new MultiComponentVectorEncoding();
    7171      if (sortedSequence)
    72         solution.PackingInformations = PackingInformation.CreateDictionaryRandomlyWithSortedSequence(items, lowerBound, random);
     72        solution.PackingInformations = PackingInformation.CreateDictionaryRandomlyWithSortedSequence(items, /*lowerBound*/ 1, random);
    7373      else
    74         solution.PackingInformations = PackingInformation.CreateDictionaryRandomly(items, lowerBound, random);
     74        solution.PackingInformations = PackingInformation.CreateDictionaryRandomly(items, /*lowerBound*/ 1, random);
    7575      return solution;
    7676    }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/MultiComponentVector/SequenceBasedMultiComponentVectorCrossover.cs

    r9563 r9593  
    4444    public override MultiComponentVectorEncoding Cross(IRandom random, MultiComponentVectorEncoding parent1, MultiComponentVectorEncoding parent2) {
    4545      MultiComponentVectorEncoding child = new MultiComponentVectorEncoding ();
    46      
     46
     47      int nrOfItems = parent1.NrOfItems;
     48      bool[] itemAlreadyAssigned = new bool[nrOfItems];
     49      int nrOfBins = parent1.NrOfBins > parent2.NrOfBins ? parent2.NrOfBins : parent1.NrOfBins;
     50      int swappedBin = random.Next(nrOfBins);
     51
     52      for (int binNr = 0; binNr < nrOfBins; binNr++) {
     53
     54        var newBin = new ItemList<PackingInformation>();
     55        var currentParent = binNr == swappedBin ? parent1 : parent2;
     56
     57        int nrOfItemsInBin = currentParent.PackingInformations[binNr].Count;
     58        for (int i = 0; i < nrOfItemsInBin; i++) {
     59          PackingInformation pi = new PackingInformation(currentParent.PackingInformations[binNr][i]);
     60          if (!itemAlreadyAssigned[pi.ItemID]) {
     61            itemAlreadyAssigned[pi.ItemID] = true;
     62            newBin.Add(new PackingInformation(pi));
     63          }
     64        }
     65
     66        child.PackingInformations[binNr] = newBin;
     67      }
     68
     69      for (int itemID = 0; itemID < nrOfItems; itemID++) {
     70        if (!itemAlreadyAssigned[itemID])
     71          child.PackingInformations[0].Add(new PackingInformation(itemID, random.Next(2) == 0 ? true : false));
     72      }
    4773
    4874
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingPlans/PackingPlan.cs

    r9563 r9593  
    3333using HeuristicLab.Data;
    3434using HeuristicLab.Collections;
     35using HeuristicLab.Problems.BinPacking.Dimensions;
     36using HeuristicLab.Problems.BinPacking.PackingBin;
    3537
    3638namespace HeuristicLab.Encodings.PackingEncoding.PackingPlan {
     
    4547    public int NrOfBins {
    4648      get {
    47         if (PackingItemPositions != null)
    48           return PackingItemPositions.Select(p => p.Value.AssignedBin).Max() + 1;
     49        if (BinPackings != null)
     50          return BinPackings.Count;
    4951        else return 0;
    5052      }
     
    5254
    5355    [Storable]
    54     public ObservableDictionary<int, D> PackingItemPositions { get; set; }
    55     [Storable]
    56     public ObservableDictionary<int, B> PackingBinMeasures { get; set; }
    57 
    58     [Storable]
    59     public ItemList<I> PackingItemMeasures {
    60       get;
    61       set;
    62     }
     56    public ObservableList<BinPacking<D, B, I>> BinPackings { get; set; }
     57
    6358    [Storable]
    6459    private DoubleValue quality;
     
    7671    #endregion
    7772
    78     public PackingPlan(B binMeasures, ItemList<I> itemMeasures)
     73    public PackingPlan(B binMeasures)
     74      : this(){
     75      //this.BinPackings.Add(new BinPacking<D,B,I> ());
     76    }
     77    public PackingPlan()
    7978      : base() {
    80       this.PackingItemMeasures = new ItemList<I> (itemMeasures);
    81       this.PackingBinMeasures = new ObservableDictionary<int, B>();
    82       this.PackingBinMeasures[0] = binMeasures;
    83     }
    84     public PackingPlan(ObservableDictionary<int, B> binMeasures, ItemList<I> itemMeasures)
    85       : base() {
    86       this.PackingItemMeasures = itemMeasures;
    87       this.PackingBinMeasures = binMeasures;
     79      this.BinPackings = new ObservableList<BinPacking<D, B,I>>();
    8880    }
    8981
     
    9284    protected PackingPlan(PackingPlan<D,B,I> original, Cloner cloner)
    9385      : base(original, cloner) {
    94       PackingItemPositions = new ObservableDictionary<int, D>(original.PackingItemPositions);
    95       PackingBinMeasures = new ObservableDictionary<int, B>(original.PackingBinMeasures);
    96       PackingItemMeasures = original.PackingItemMeasures;
     86        this.BinPackings = new ObservableList<BinPacking<D, B, I>>(original.BinPackings);
    9787    }
    9888    public override IDeepCloneable Clone(Cloner cloner) {
    9989      return new PackingPlan<D,B,I>(this, cloner);
    10090    }
    101 
    102     public B GetPackingBinMeasuresForBinNr(int binNr) {
    103       if (PackingBinMeasures.ContainsKey(binNr))
    104         return PackingBinMeasures[binNr];
    105       else
    106         return PackingBinMeasures[0];
    107     }
    108 
     91         
    10992
    11093    #region Events
     
    125108    }
    126109
    127     public event EventHandler PackingItemPositionChanged;
    128     private void OnPackingItemPositionChanged() {
    129       var changed = PackingItemPositionChanged;
     110    public event EventHandler BinPackingsChanged;
     111    private void OnBinPackingsChanged() {
     112      var changed = BinPackingsChanged;
    130113      if (changed != null)
    131114        changed(this, EventArgs.Empty);
    132115    }
    133     private void RegisterPackingItemPositionEvents() {
    134       PackingItemPositions.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(PackingItemPosition_PropertyChanged);
    135     }
    136     private void DeregisterPackingItemPositionEvents() {
    137       PackingItemPositions.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(PackingItemPosition_PropertyChanged);
    138     }
    139     private void PackingItemPosition_PropertyChanged(object sender, EventArgs e) {
    140       OnPackingItemPositionChanged();
     116    private void RegisterBinPackingsEvents() {
     117      BinPackings.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(BinPackings_PropertyChanged);
     118    }
     119    private void DeregisterBinPackingsEvents() {
     120      BinPackings.PropertyChanged -= new System.ComponentModel.PropertyChangedEventHandler(BinPackings_PropertyChanged);
     121    }
     122    private void BinPackings_PropertyChanged(object sender, EventArgs e) {
     123      OnBinPackingsChanged();
    141124    }
    142125    #endregion
    143126  }
     127
     128  [Item("BinPacking", "Represents a single-bin packing for a bin-packing problem.")]
     129  [StorableClass]
     130  public abstract class BinPacking<D,B,I>  : Item
     131    where D : class, IPackingDimensions
     132    where B : PackingShape<D>, IPackingBin
     133    where I : PackingShape<D>, IPackingItem {
     134 
     135    [Storable]
     136    public ObservableDictionary<int, D> ItemPositions { get; private set; }
     137
     138    [Storable]
     139    public B BinMeasures { get; private set; }
     140
     141    [Storable]
     142    public ObservableDictionary<int, I> ItemMeasures { get; private set; }
     143
     144    [Storable]
     145    public HashSet<D> ExtremePoints { get; protected set; }
     146
     147    [Storable]
     148    public OccupiedPoints<D, I> OccupiedPoints { get; protected set; }
     149
     150    public BinPacking(B binMeasures) : base() {   
     151      ItemPositions = new ObservableDictionary<int, D>();
     152      ItemMeasures = new ObservableDictionary<int, I>();
     153      BinMeasures = (B)binMeasures.Clone();
     154      ExtremePoints = new HashSet<D>();
     155      ExtremePoints.Add(binMeasures.Origin);
     156    }
     157
     158    [StorableConstructor]
     159    protected BinPacking(bool deserializing) : base(deserializing) { }
     160    protected BinPacking(BinPacking<D,B,I> original, Cloner cloner)
     161      : base(original, cloner) {
     162      this.ItemPositions = new ObservableDictionary<int, D>(original.ItemPositions);
     163      this.ItemMeasures = new ObservableDictionary<int, I>(original.ItemMeasures);
     164        this.BinMeasures = (B)original.BinMeasures.Clone(cloner);
     165    }
     166   
     167
     168    protected abstract void GenerateNewExtremePointsForNewItem(I measures, D position);
     169    public abstract D FindExtremePointForItem(I measures, bool rotated, bool stackingConstraint);
     170    public abstract D FindPositionBySliding(I measures, bool rotated);
     171    public void PackItem(int itemID, I measures, D position) {
     172      ItemMeasures[itemID] = measures;
     173      ItemPositions[itemID] = position;
     174      ExtremePoints.Remove(position);
     175      GenerateNewExtremePointsForNewItem(measures, position);
     176      OccupiedPoints.OccupyPoints(measures, position, itemID);
     177    }
     178
     179
     180    public double PackingDensity {
     181      get {
     182        double result = 0;
     183        foreach (var entry in ItemMeasures)
     184          result += entry.Value.MultipliedMeasures;
     185        result /= BinMeasures.MultipliedMeasures;
     186        return result;
     187      }
     188    }
     189
     190    public bool IsPositionFeasible1(I currentItem, D currentPosition) {
     191      //In this case feasability is defined as following: 1. the item fits into the bin-borders; 2. the item does not collide with another already packed item
     192      if (!BinMeasures.Encloses(currentPosition, currentItem))
     193        return false;
     194
     195      foreach (var ipEntry in ItemPositions) {
     196        if (ItemMeasures[ipEntry.Key].Overlaps(ipEntry.Value, currentPosition, currentItem))
     197          return false;
     198      }
     199
     200      return true;
     201    }
     202    public bool IsPositionFeasible(I currentItem, D position) {
     203      if (!BinMeasures.Encloses(position, currentItem))
     204        return false;
     205
     206      return OccupiedPoints.IsPositionFeasible (currentItem, position);
     207    }
     208  }
     209
     210
     211
     212
     213
     214  [Item("BinPacking2D", "Represents a single-bin packing for a 2D bin-packing problem.")]
     215  [StorableClass]
     216  public class BinPacking2D : BinPacking<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> {
     217
     218    public BinPacking2D(RectangularPackingBin binMeasures) : base(binMeasures) {
     219      OccupiedPoints = new OccupiedPoints2D(binMeasures);
     220    }
     221    [StorableConstructor]
     222    protected BinPacking2D(bool deserializing) : base(deserializing) { }
     223    protected BinPacking2D(BinPacking2D original, Cloner cloner)
     224      : base(original, cloner) {
     225    }
     226    public override IDeepCloneable Clone(Cloner cloner) {
     227      return new BinPacking2D(this, cloner);
     228    }
     229                     
     230    protected override void GenerateNewExtremePointsForNewItem(RectangularPackingItem newItem, TwoDimensionalPacking position) {
     231
     232      int newWidth = position.Rotated ? newItem.Height : newItem.Width;
     233      int newHeight = position.Rotated ? newItem.Width : newItem.Height;
     234
     235      //Find ExtremePoints beginning from sourcepointX
     236      var sourcePointX = new TwoDimensionalPacking(0, position.X + newWidth, position.Y);
     237      if (sourcePointX.X < BinMeasures.Width && sourcePointX.Y < BinMeasures.Height) {
     238        //Traversing down the y-axis       
     239        while (sourcePointX.Y > 0 && !OccupiedPoints.IsPointOccupied(new TwoDimensionalPacking(0, sourcePointX.X, sourcePointX.Y - 1))) {
     240          sourcePointX.Y--;
     241        }
     242        ExtremePoints.Add(new TwoDimensionalPacking(0, sourcePointX.X, sourcePointX.Y));
     243      }
     244
     245
     246
     247
     248      //Find ExtremePoints beginning from sourcepointY
     249      var sourcePointY = new TwoDimensionalPacking(0, position.X, position.Y + newItem.Height);
     250      if (sourcePointY.X < BinMeasures.Width && sourcePointY.Y < BinMeasures.Height) {
     251        //Traversing down the x-axis 
     252        while (sourcePointY.X > 0 && !OccupiedPoints.IsPointOccupied(new TwoDimensionalPacking (0,sourcePointY.X - 1, sourcePointY.Y))) {
     253          sourcePointY.X--;
     254        }
     255        ExtremePoints.Add(new TwoDimensionalPacking(0, sourcePointY.X, sourcePointY.Y));
     256      }
     257
     258      ExtremePoints = new HashSet<TwoDimensionalPacking>(ExtremePoints.
     259        OrderBy(ep => ep.AssignedBin).
     260        ThenBy(ep => ep.X).
     261        ThenBy(ep => ep.Y).
     262        ThenBy(ep => OccupiedPoints.ShortestPossibleSideFromEP(ep)));
     263    }
     264
     265    public override TwoDimensionalPacking FindExtremePointForItem(RectangularPackingItem measures, bool rotated, bool stackingConstraint) {
     266      RectangularPackingItem item = new RectangularPackingItem(
     267        rotated ? measures.Height : measures.Width,
     268        rotated ? measures.Width : measures.Height,
     269        measures.TargetBin);
     270
     271      int epIndex = 0;
     272      while (epIndex < ExtremePoints.Count && (!IsPositionFeasible(item, ExtremePoints.ElementAt(epIndex)))) { epIndex++; }
     273
     274      if (epIndex < ExtremePoints.Count) {
     275        var result = ExtremePoints.ElementAt(epIndex);
     276        result.Rotated = rotated;
     277        return result;
     278      }
     279      return null;
     280    }
     281    public override TwoDimensionalPacking FindPositionBySliding(RectangularPackingItem measures, bool rotated) {
     282      TwoDimensionalPacking currentPosition = new TwoDimensionalPacking(0,
     283        BinMeasures.Width - (rotated ? measures.Height : measures.Width),
     284        BinMeasures.Height - (rotated ? measures.Width : measures.Height), rotated);
     285      //Slide the item as far as possible to the left
     286      while (IsPositionFeasible(measures, MoveLeft(currentPosition))
     287        || IsPositionFeasible(measures, MoveDown(currentPosition))) {
     288        //Slide the item as far as possible to the bottom
     289        while (IsPositionFeasible(measures, MoveDown(currentPosition))) {
     290          currentPosition = MoveDown(currentPosition);
     291        }
     292        if (IsPositionFeasible(measures, MoveLeft(currentPosition)))
     293          currentPosition = MoveLeft(currentPosition);
     294      }
     295
     296      return IsPositionFeasible(measures, currentPosition) ? currentPosition : null;
     297    }
     298    private static TwoDimensionalPacking MoveLeft(TwoDimensionalPacking original) {
     299      return new TwoDimensionalPacking(original.AssignedBin, original.X - 1, original.Y, original.Rotated);
     300    }
     301    private static TwoDimensionalPacking MoveDown(TwoDimensionalPacking original) {
     302      return new TwoDimensionalPacking(original.AssignedBin, original.X, original.Y - 1, original.Rotated);
     303    }
     304  }
     305
     306
     307
     308  [Item("BinPacking3D", "Represents a single-bin packing for a 3D bin-packing problem.")]
     309  [StorableClass]
     310  public class BinPacking3D : BinPacking<ThreeDimensionalPacking, CuboidPackingBin, CuboidPackingItem> {
     311
     312   
     313    public BinPacking3D(CuboidPackingBin binMeasures) : base(binMeasures) {
     314      OccupiedPoints = new OccupiedPoints3D(binMeasures);
     315    }
     316    [StorableConstructor]
     317    protected BinPacking3D(bool deserializing) : base(deserializing) { }
     318    protected BinPacking3D(BinPacking3D original, Cloner cloner)
     319      : base(original, cloner) {
     320    }
     321    public override IDeepCloneable Clone(Cloner cloner) {
     322      return new BinPacking3D(this, cloner);
     323    }
     324                                       
     325    protected override void GenerateNewExtremePointsForNewItem(CuboidPackingItem newItem, ThreeDimensionalPacking position) {
     326      int newWidth = position.Rotated ? newItem.Depth : newItem.Width;
     327      int newDepth = position.Rotated ? newItem.Width : newItem.Depth;
     328
     329      //Find ExtremePoints beginning from sourcepointX
     330      var sourcePointX = new ThreeDimensionalPacking(0, position.X + newWidth, position.Y, position.Z);
     331      if (sourcePointX.X < BinMeasures.Width && sourcePointX.Y < BinMeasures.Height && sourcePointX.Z < BinMeasures.Depth) {
     332        //Traversing down the y-axis                                                                           
     333        int currentYValue = sourcePointX.Y;
     334        while (currentYValue > 0 && !OccupiedPoints.IsPointOccupied(new ThreeDimensionalPacking (0, sourcePointX.X, currentYValue, sourcePointX.Z))) {
     335          currentYValue--;
     336        }
     337        ExtremePoints.Add(new ThreeDimensionalPacking(0, sourcePointX.X, currentYValue, sourcePointX.Z));
     338
     339        //Traversing down the z-axis
     340        int currentZValue = sourcePointX.Z;
     341        while (currentZValue > 0 && !OccupiedPoints.IsPointOccupied(new ThreeDimensionalPacking (0, sourcePointX.X, sourcePointX.Y, currentZValue - 1))) {
     342          currentZValue--;
     343        }
     344        ExtremePoints.Add(new ThreeDimensionalPacking(0, sourcePointX.X, sourcePointX.Y, currentZValue));
     345      }
     346
     347
     348
     349
     350      //Find ExtremePoints beginning from sourcepointY
     351      var sourcePointY = new ThreeDimensionalPacking(0, position.X, position.Y + newItem.Height, position.Z);
     352      if (sourcePointY.X < BinMeasures.Width && sourcePointY.Y < BinMeasures.Height && sourcePointY.Z < BinMeasures.Depth) {
     353        //Traversing down the x-axis 
     354        int currentXValue = sourcePointY.X;
     355        while (currentXValue > 0 && !OccupiedPoints.IsPointOccupied(new ThreeDimensionalPacking (0, currentXValue - 1, sourcePointY.Y, sourcePointY.Z))) {
     356          currentXValue--;
     357        }
     358        ExtremePoints.Add(new ThreeDimensionalPacking(0, currentXValue, sourcePointY.Y, sourcePointY.Z));
     359
     360        //Traversing down the z-axis
     361        int currentZValue = sourcePointY.Z;
     362        while (currentZValue > 0 && !OccupiedPoints.IsPointOccupied(new ThreeDimensionalPacking (0, sourcePointY.X, sourcePointY.Y, currentZValue - 1))) {
     363          currentZValue--;
     364        }
     365        ExtremePoints.Add(new ThreeDimensionalPacking(0, sourcePointY.X, sourcePointY.Y, currentZValue));
     366      }
     367
     368
     369
     370
     371
     372      //Find ExtremePoints beginning from sourcepointZ
     373      var sourcePointZ = new ThreeDimensionalPacking(0, position.X, position.Y, position.Z + newDepth);
     374      if (sourcePointZ.X < BinMeasures.Width && sourcePointZ.Y < BinMeasures.Height && sourcePointZ.Z < BinMeasures.Depth) {
     375        //Traversing down the x-axis 
     376        int currentXValue = sourcePointZ.X;
     377        while (currentXValue > 0 && !OccupiedPoints.IsPointOccupied(new ThreeDimensionalPacking (0, currentXValue - 1, sourcePointZ.Y, sourcePointZ.Z))) {
     378          currentXValue--;
     379        }
     380        ExtremePoints.Add(new ThreeDimensionalPacking(0, currentXValue, sourcePointZ.Y, sourcePointZ.Z));
     381
     382        //Traversing down the y-axis                                                                           
     383        int currentYValue = sourcePointZ.Y;
     384        while (currentYValue > 0 && !OccupiedPoints.IsPointOccupied(new ThreeDimensionalPacking (0, sourcePointZ.X, currentYValue, sourcePointZ.Z))) {
     385          currentYValue--;
     386        }
     387        ExtremePoints.Add(new ThreeDimensionalPacking(0, sourcePointZ.X, currentYValue, sourcePointZ.Z));
     388      }
     389
     390      ExtremePoints = new HashSet<ThreeDimensionalPacking>(ExtremePoints.
     391        OrderBy(ep => ep.AssignedBin).
     392        ThenBy(ep => ep.Z).
     393        ThenBy(ep => ep.X).
     394        ThenBy(ep => ep.Y).
     395        ThenBy(ep => OccupiedPoints.ShortestPossibleSideFromEP(ep)));
     396    }
     397
     398    public override ThreeDimensionalPacking FindExtremePointForItem(CuboidPackingItem measures, bool rotated, bool stackingConstraint) {
     399
     400      CuboidPackingItem item = new CuboidPackingItem(
     401        rotated ? measures.Depth : measures.Width,
     402        measures.Height,
     403        rotated ? measures.Width : measures.Depth,
     404        measures.TargetBin);
     405
     406      int epIndex = 0;
     407      while (epIndex < ExtremePoints.Count && (
     408        !IsPositionFeasible(item, ExtremePoints.ElementAt(epIndex)) || (stackingConstraint && !OccupiedPoints.IsStaticStable(item, ExtremePoints.ElementAt(epIndex)))
     409      )) { epIndex++; }
     410
     411      if (epIndex < ExtremePoints.Count) {
     412        var result = ExtremePoints.ElementAt(epIndex);
     413        result.Rotated = rotated;
     414        return result;
     415      }
     416      return null;
     417    }
     418    public override ThreeDimensionalPacking FindPositionBySliding(CuboidPackingItem measures, bool rotated) {
     419      //Starting-position at upper right corner (=left bottom point of item-rectangle is at position item.width,item.height)
     420      ThreeDimensionalPacking currentPosition = new ThreeDimensionalPacking(0,
     421        BinMeasures.Width - (rotated ? measures.Depth : measures.Width),
     422        BinMeasures.Height - measures.Height,
     423        BinMeasures.Depth - (rotated ? measures.Width : measures.Depth), rotated);
     424      //Slide the item as far as possible to the bottom
     425      while (IsPositionFeasible(measures, MoveDown(currentPosition))
     426        || IsPositionFeasible(measures, MoveLeft(currentPosition))
     427        || IsPositionFeasible(measures, MoveBack(currentPosition))) {
     428        //Slide the item as far as possible to the left
     429        while (IsPositionFeasible(measures, MoveLeft(currentPosition))
     430        || IsPositionFeasible(measures, MoveBack(currentPosition))) {
     431          //Slide the item as far as possible to the back
     432          while (IsPositionFeasible(measures, MoveBack(currentPosition))) {
     433            currentPosition = MoveBack(currentPosition);
     434          }
     435          if (IsPositionFeasible(measures, MoveLeft(currentPosition)))
     436            currentPosition = MoveLeft(currentPosition);
     437        }
     438        if (IsPositionFeasible(measures, MoveDown(currentPosition)))
     439          currentPosition = MoveDown(currentPosition);
     440      }
     441
     442      return IsPositionFeasible(measures, currentPosition) ? currentPosition : null;
     443    }
     444    private static ThreeDimensionalPacking MoveLeft(ThreeDimensionalPacking original) {
     445      return new ThreeDimensionalPacking(original.AssignedBin, original.X - 1, original.Y, original.Z, original.Rotated);
     446    }
     447    private static ThreeDimensionalPacking MoveDown(ThreeDimensionalPacking original) {
     448      return new ThreeDimensionalPacking(original.AssignedBin, original.X, original.Y - 1, original.Z, original.Rotated);
     449    }
     450    private static ThreeDimensionalPacking MoveBack(ThreeDimensionalPacking original) {
     451      return new ThreeDimensionalPacking(original.AssignedBin, original.X, original.Y, original.Z - 1, original.Rotated);
     452    }
     453  }
     454
     455
     456
    144457}
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Encodings/PackingSequence/PackingSequenceOrderCrossover.cs

    r9563 r9593  
    4343    public override PackingSequenceEncoding Cross(IRandom random, PackingSequenceEncoding parent1, PackingSequenceEncoding parent2)  {
    4444      PackingSequenceEncoding result = new PackingSequenceEncoding();
    45       result.PackingSequence = OrderCrossover2.Apply(random, parent1.PackingSequence, parent2.PackingSequence);
     45      result.PackingSequence = OrderCrossover.Apply(random, parent1.PackingSequence, parent2.PackingSequence);
    4646      return result;
    4747    }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Evaluators/Abstract/BinUtilizationRegularIdenticalBinEvaluator.cs

    r9563 r9593  
    9090
    9191      for (int i = 0; i < nrOfBins; i++) {
    92         double usableSpace = plan.GetPackingBinMeasuresForBinNr(i).MultipliedMeasures;
    93         var indexes = plan.PackingItemPositions.Select((Value, Index) => new { Value, Index }).Where(s => s.Value.Value.AssignedBin == i).Select(s => s.Index);
    94         var packedItemsInThisBin = plan.PackingItemMeasures.Select((Value, Index) => new { Value, Index }).Where(s => indexes.Contains(s.Index));
    95         double usedSpaceInThisBin = packedItemsInThisBin.Select(s => s.Value.MultipliedMeasures).Sum();
     92        double usableSpace = plan.BinPackings[i].BinMeasures.MultipliedMeasures;
     93        //var indexes = plan.PackingItemPositions.Select((Value, Index) => new { Value, Index }).Where(s => s.Value.Value.AssignedBin == i).Select(s => s.Index);
     94        //var packedItemsInThisBin = plan.PackingItemMeasures.Select((Value, Index) => new { Value, Index }).Where(s => indexes.Contains(s.Index));
     95        //double usedSpaceInThisBin = packedItemsInThisBin.Select(s => s.Value.MultipliedMeasures).Sum();
    9696        //result += (usedSpaceInThisBin / usableSpace);
    9797        totalUsableSpace += usableSpace;
    98         totalUsedSpace += usedSpaceInThisBin;
     98        //totalUsedSpace += usedSpaceInThisBin;
     99        totalUsedSpace += plan.BinPackings[i].PackingDensity * usableSpace;
    99100      }
    100101
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Evaluators/Abstract/PackingRatioRegularIdenticalBinEvaluator.cs

    r9563 r9593  
    8989      for (int i = 0; i < nrOfBins; i++) {
    9090        //C
    91         double usableSpace = plan.GetPackingBinMeasuresForBinNr(0).MultipliedMeasures;//plan.GetPackingBinMeasuresForBinNr(i).MultipliedMeasures;
    92         var indexes = plan.PackingItemPositions.Select((Value, Index) => new { Value, Index }).Where(s => s.Value.Value.AssignedBin == i).Select(s => s.Index);
    93         var packedItemsInThisBin = plan.PackingItemMeasures.Select((Value, Index) => new { Value, Index }).Where(s => indexes.Contains(s.Index));
     91        //double usableSpace = plan.GetPackingBinMeasuresForBinNr(0).MultipliedMeasures;//plan.GetPackingBinMeasuresForBinNr(i).MultipliedMeasures;
     92        //var indexes = plan.PackingItemPositions.Select((Value, Index) => new { Value, Index }).Where(s => s.Value.Value.AssignedBin == i).Select(s => s.Index);
     93        //var packedItemsInThisBin = plan.PackingItemMeasures.Select((Value, Index) => new { Value, Index }).Where(s => indexes.Contains(s.Index));
    9494        //Fi
    95         double usedSpaceInThisBin = packedItemsInThisBin.Select(s => s.Value.MultipliedMeasures).Sum();
     95        //double usedSpaceInThisBin = packedItemsInThisBin.Select(s => s.Value.MultipliedMeasures).Sum();
    9696        //k = 2 --> (Fi/C)*(Fi/C)
    97         result += (((usedSpaceInThisBin) / (usableSpace)) * ((usedSpaceInThisBin) / (usableSpace))) / (i*i + 1);
     97        //result += (((usedSpaceInThisBin) / (usableSpace)) * ((usedSpaceInThisBin) / (usableSpace))) / (i*i + 1);
     98        var PD = plan.BinPackings[i].PackingDensity;
     99        result += (PD * PD) / (i + 1);
    98100      }
    99101
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/HeuristicLab.Problems.BinPacking-3.3.csproj

    r9563 r9593  
    166166    <Compile Include="Analyzers\BinPackingAnalyzer.cs" />
    167167    <Compile Include="Decoders\2D\BL\BottomLeftMultiComponentVectorDecoder.cs" />
    168     <Compile Include="Decoders\2D\BL\BottomLeftFunctions.cs" />
     168    <Compile Include="Decoders\2D\TwoDimensionalPackingFunctions.cs" />
    169169    <Compile Include="Decoders\2D\EP\ExtremePointGroupingVectorDecoder2D.cs" />
    170170    <Compile Include="Decoders\2D\EP\ExtremePointMultiComponentVectorDecoder2D.cs" />
    171171    <Compile Include="Decoders\2D\EP\ExtremePointPackingSequenceDecoder2D.cs" />
    172     <Compile Include="Decoders\2D\EP\ExtremePointsFunctions2D.cs" />
     172    <Compile Include="Decoders\3D\ThreeDimensionalPackingFunctions.cs" />
    173173    <Compile Include="Decoders\3D\EP\ExtremePointMultiComponentVectorDecoder3D.cs" />
    174174    <Compile Include="Decoders\3D\EP\ExtremePointGroupingVectorDecoder3D.cs" />
    175175    <Compile Include="Decoders\3D\EP\ExtremePointPackingSequenceDecoder3D.cs" />
    176176    <Compile Include="Decoders\3D\DBL\DeepestBottomLeftMultiComponentVectorDecoder.cs" />
    177     <Compile Include="Decoders\3D\DBL\DeepestBottomLeftFunctions.cs" />
    178     <Compile Include="Decoders\3D\EP\ExtremePointsFunctions3D.cs" />
    179177    <Compile Include="Decoders\3D\DBL\DeepestBottomLeftGroupingVectorDecoder.cs" />
    180178    <Compile Include="Decoders\2D\BL\BottomLeftGroupingVectorDecoder.cs" />
     
    182180    <Compile Include="Decoders\2D\BL\BottomLeftPackingSequenceDecoder.cs" />
    183181    <Compile Include="Decoders\3D\EP\ISOContainerMultiComponentVectorDecoder3D.cs" />
     182    <Compile Include="Decoders\SequentialPackingFunctions.cs">
     183      <SubType>Code</SubType>
     184    </Compile>
    184185    <Compile Include="Decoders\PackingSolutionDecoder.cs" />
     186    <Compile Include="Dimensions\OccupiedPoints3D.cs" />
     187    <Compile Include="Dimensions\OccupiedPoints2D.cs" />
     188    <Compile Include="Dimensions\OccupiedPoints.cs" />
    185189    <Compile Include="Encodings\GroupingVector\GroupingVectorSwap2Manipulator.cs" />
    186190    <Compile Include="Encodings\GroupingVector\GroupingVectorSinglePointCrossover.cs" />
     
    243247    <Compile Include="Encodings\PackingSequence\Moves\Insertion\InsertionMoveAttribute.cs" />
    244248    <Compile Include="Encodings\PackingSequence\Moves\Insertion\InsertionMoveGenerator.cs" />
    245     <Compile Include="Encodings\PackingSequence\PackingSequenceInsertionManipulator.cs" />
    246     <Compile Include="Encodings\PackingSequence\PackingSequenceSwap2Manipulator.cs" />
     249    <Compile Include="Encodings\PackingSequence\PackingSequenceInversionManipulator.cs" />
    247250    <Compile Include="Encodings\PackingSequence\PackingSequencePartiallyMatchedCrossover.cs" />
    248251    <Compile Include="Encodings\PackingSequence\PackingSequenceOrderCrossover.cs" />
     
    268271    </Compile>
    269272    <Compile Include="Encodings\PackingSequence\PackingSequenceRandomCreator.cs" />
     273    <Compile Include="Encodings\PackingSequence\PackingSequenceScrambleManipulator.cs" />
    270274    <Compile Include="Encodings\PackingSolutionCreator.cs" />
    271275    <Compile Include="Encodings\PackingSolutionCrossover.cs" />
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Plugin.cs

    r9563 r9593  
    2626  /// Plugin class for HeuristicLab.Problems.BinPacking plugin.
    2727  /// </summary>
    28   [Plugin("HeuristicLab.Problems.BinPacking", "3.3.7.9495")]
     28  [Plugin("HeuristicLab.Problems.BinPacking", "3.3.7.9563")]
    2929  [PluginFile("HeuristicLab.Problems.BinPacking-3.3.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.Common", "3.3")]
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Shapes/CuboidPackingShape.cs

    r9563 r9593  
    5353
    5454    #region Helpers
    55     public int MultipliedMeasures { get { return Width * Height * Depth; } }
     55    public override ThreeDimensionalPacking Origin { get { return new ThreeDimensionalPacking(0, 0, 0, 0); } }
     56    public override int MultipliedMeasures { get { return Width * Height * Depth; } }
    5657   
    5758    public override bool Encloses(ThreeDimensionalPacking checkedPosition, PackingShape<ThreeDimensionalPacking> checkedShape) {
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Shapes/PackingShape.cs

    r9348 r9593  
    4343    public abstract void InitializeFromMeasures(int[] measures);
    4444    public abstract int[] ToArray();
     45    public abstract int MultipliedMeasures { get; }
     46    public abstract D Origin { get; }
    4547
    4648    public PackingShape(int[] measures) {
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Shapes/RectangularPackingShape.cs

    r9440 r9593  
    4848
    4949    #region Helpers
    50     public int MultipliedMeasures { get { return Height * Width; } }
     50    public override TwoDimensionalPacking Origin { get { return new TwoDimensionalPacking(0, 0, 0); } }
     51    public override int MultipliedMeasures { get { return Height * Width; } }
    5152
    5253    public override bool Encloses(TwoDimensionalPacking checkedPosition, PackingShape<TwoDimensionalPacking> checkedShape) {
Note: See TracChangeset for help on using the changeset viewer.