Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/15/13 22:23:36 (12 years ago)
Author:
jhelm
Message:

#1966: Did some major refactoring in Decoder-classes; Added MoveEvaluator classes for different encodings and dimensions; Added new crossover-class for MCV encoding;

Location:
branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/BL/BottomLeftFunctions.cs

    r9440 r9495  
    55using HeuristicLab.Collections;
    66using HeuristicLab.Core;
     7using HeuristicLab.Encodings.PackingEncoding.GroupingVector;
     8using HeuristicLab.Encodings.PackingEncoding.MultiComponentVector;
    79using HeuristicLab.Encodings.PackingEncoding.PackingSequence;
    810using HeuristicLab.Problems.BinPacking.Dimensions;
     
    1416namespace HeuristicLab.Problems.BinPacking.Decoders {
    1517  public static class BottomLeftFunctions {
    16    
    17 
    18 
    19     public static TwoDimensionalPacking BottomLeftPosition(RectangularPackingBin binMeasures, int binNr, RectangularPackingItem currentItem, ObservableDictionary<int, TwoDimensionalPacking> itemPositions, ItemList<RectangularPackingItem> itemMeasures) {
     18
     19
     20    public static ObservableDictionary<int, TwoDimensionalPacking> BottomLeftPacking(
     21      MultiComponentVectorEncoding solution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
     22      int nrOfBins = solution.NrOfBins;
     23
     24      //Get all indexes of items for every bin according to grouping-vector
     25      Dictionary<int, List<PackingInformation>> unpackedItemIndexesPerBin = new Dictionary<int, List<PackingInformation>>();
     26
     27      for (int i = 0; i < nrOfBins; i++) {
     28        unpackedItemIndexesPerBin[i] = new List<PackingInformation>(solution.PackingInformations[i]);
     29      }
     30
     31      ObservableDictionary<int, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>();
     32      var remainingItems = new List<PackingInformation>();
     33
     34      //Iterate over all bin-lists
     35      for (int binNr = 0; binNr < nrOfBins; binNr++) {
     36        //Iterate over the current bin-item-list and find feasible positions in the current bin for each item
     37        var unpackedItems = unpackedItemIndexesPerBin[binNr];
     38        for (int i = 0; i < unpackedItems.Count; i++) {
     39          var itemIndex = unpackedItems[i].ItemID;
     40          var item = itemMeasures[itemIndex];
     41          TwoDimensionalPacking position = null;
     42
     43          position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures, unpackedItems[i].Rotated);
     44
     45          if (position == null) {
     46            position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures, !unpackedItems[i].Rotated);
     47          }
     48          if (position == null) {
     49            remainingItems.Add(unpackedItems[i]);
     50          } else {
     51            packingPositions[itemIndex] = position;
     52            solution.PackingInformations[binNr].Remove(unpackedItems[i]);
     53            solution.PackingInformations[binNr].Find(pi => pi.ItemID == itemIndex).Rotated = position.Rotated;
     54          }
     55        }
     56      }
     57
     58      //Packing of remaining items
     59      //Iterate over all bin-lists
     60      for (int binNr = 0; binNr < nrOfBins && remainingItems.Count > 0; binNr++) {
     61        var unpackedItems = new List<PackingInformation>(remainingItems);
     62        for (int i = 0; i < unpackedItems.Count; i++) {
     63          var itemIndex = unpackedItems[i].ItemID;
     64          var item = itemMeasures[itemIndex];
     65          TwoDimensionalPacking position = null;
     66
     67          //Look for space in current bin
     68          position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures, unpackedItems[i].Rotated);
     69
     70          if (position == null) {
     71            position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures, !unpackedItems[i].Rotated);
     72          }
     73          if (position != null) {
     74            packingPositions[itemIndex] = position;
     75            remainingItems.Remove(unpackedItems[i]);
     76            solution.PackingInformations[binNr].Add(unpackedItems[i]);
     77            solution.PackingInformations[binNr].Find(pi => pi.ItemID == itemIndex).Rotated = position.Rotated;
     78          }
     79        }
     80        if (remainingItems.Count > 0 && binNr + 1 >= nrOfBins) {
     81          solution.PackingInformations[nrOfBins] = new ItemList<PackingInformation>();
     82          nrOfBins++;
     83        }
     84      }
     85
     86      return packingPositions;
     87    }
     88
     89    public static ObservableDictionary<int, TwoDimensionalPacking> BottomLeftPacking(
     90      GroupingVectorEncoding solution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
     91
     92      int nrOfBins = solution.GroupingVector.Max() + 1;
     93
     94      //Get all indexes of items for every bin according to grouping-vector
     95      //It is assumed, that at this point the item-indexes are sorted according to their item-size!
     96      Dictionary<int, List<int>> unpackedItemIndexesPerBin = new Dictionary<int, List<int>>();
     97
     98      for (int i = 0; i < nrOfBins; i++) {
     99        unpackedItemIndexesPerBin[i] = solution.GroupingVector
     100          .Select((Value, Index) => new { Value, Index })
     101          .Where(temp => temp.Value == i)
     102          .Select(temp => temp.Index).ToList();
     103      }
     104
     105      ObservableDictionary<int, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>();
     106      var remainingItems = new List<int>();
     107
     108      //Iterate over all bin-lists
     109      for (int binNr = 0; binNr < nrOfBins; binNr++) {
     110        //Iterate over the current bin-item-list and find feasible positions in the current bin for each item
     111        var unpackedItems = unpackedItemIndexesPerBin[binNr];
     112        for (int i = 0; i < unpackedItems.Count; i++) {
     113          var itemIndex = unpackedItems[i];
     114          var item = itemMeasures[itemIndex];
     115          TwoDimensionalPacking position = null;
     116
     117          //Look for space in current bin
     118          position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures);
     119
     120          //Did not find enough space in current bin
     121          if (position == null) {
     122            remainingItems.Add(itemIndex);
     123          } else
     124            packingPositions[itemIndex] = position;
     125        }
     126      }
     127
     128      //Packing of remaining items
     129      //Iterate over all bin-lists
     130      for (int binNr = 0; binNr < nrOfBins && remainingItems.Count > 0; binNr++) {
     131        var unpackedItems = new List<int>(remainingItems);
     132        for (int i = 0; i < unpackedItems.Count; i++) {
     133          var itemIndex = unpackedItems[i];
     134          var item = itemMeasures[itemIndex];
     135          TwoDimensionalPacking position = null;
     136
     137          //Look for space in current bin
     138          position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures);
     139
     140          if (position != null) {
     141            packingPositions[itemIndex] = position;
     142            remainingItems.Remove(itemIndex);
     143            solution.GroupingVector[itemIndex] = binNr;
     144          }
     145        }
     146        if (remainingItems.Count > 0 && binNr + 1 >= nrOfBins) {
     147          nrOfBins++;
     148        }
     149      }
     150
     151      return packingPositions;
     152    }
     153
     154    public static ObservableDictionary<int, TwoDimensionalPacking> BottomLeftPacking(
     155      PackingSequenceEncoding solution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
     156
     157      ObservableDictionary<int, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>();
     158      int nrOfBins = 1;
     159      for (int i = 0; i < solution.PackingSequence.Length; i++) {
     160        var item = itemMeasures[solution.PackingSequence[i]];
     161        TwoDimensionalPacking position = null;
     162        //Look for space in existing bins
     163        for (int binNr = 0; binNr < nrOfBins; binNr++) {
     164          position = BottomLeftFunctions.BottomLeftPosition(binMeasures, binNr, item, packingPositions, itemMeasures);
     165          if (position != null)
     166            break;
     167        }
     168        //Did not find enough space in any of the existing bins => create new bin
     169        if (position == null) {
     170          nrOfBins++;
     171          position = BottomLeftFunctions.BottomLeftPosition(binMeasures, nrOfBins - 1, item, packingPositions, itemMeasures);
     172        }
     173
     174        if (position == null)
     175          position = new TwoDimensionalPacking(-1, 0, 0);
     176
     177        packingPositions[solution.PackingSequence[i]] = position;
     178      }
     179
     180      return packingPositions;
     181    }
     182
     183    private static TwoDimensionalPacking BottomLeftPosition(RectangularPackingBin binMeasures, int binNr, RectangularPackingItem currentItem, ObservableDictionary<int, TwoDimensionalPacking> itemPositions, ItemList<RectangularPackingItem> itemMeasures) {
    20184      return BottomLeftPosition(binMeasures, binNr, currentItem, itemPositions, itemMeasures, false);
    21185    }
    22     public static TwoDimensionalPacking BottomLeftPosition(RectangularPackingBin binMeasures, int binNr, RectangularPackingItem currentItem, ObservableDictionary<int, TwoDimensionalPacking> itemPositions, ItemList<RectangularPackingItem> itemMeasures, bool rotated) {     
     186    private static TwoDimensionalPacking BottomLeftPosition(RectangularPackingBin binMeasures, int binNr, RectangularPackingItem currentItem, ObservableDictionary<int, TwoDimensionalPacking> itemPositions, ItemList<RectangularPackingItem> itemMeasures, bool rotated) {     
    23187      TwoDimensionalPacking currentPosition = new TwoDimensionalPacking(binNr,
    24188        binMeasures.Width - (rotated ? currentItem.Height : currentItem.Width),
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/BL/BottomLeftGroupingVectorDecoder.cs

    r9440 r9495  
    4141  [Item("Identical bin two dimensional grouping vector decoder", "<Description missing...>")]
    4242  [StorableClass]
    43   public class BottomLeftGroupingVectorDecoder : IdenticalBinPackingSolutionDecoder<
     43  public class BottomLeftGroupingVectorDecoder : PackingSolutionDecoder<
    4444      TwoDimensionalPacking,
    4545      RectangularPackingBin,
    46       RectangularPackingItem,
    47       PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> {
     46      RectangularPackingItem> {
    4847
    4948    public BottomLeftGroupingVectorDecoder()
     
    6160
    6261
    63     protected override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {
     62    public override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
    6463
    6564      var solution = encodedSolution as GroupingVectorEncoding;
     
    6968        new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
    7069
    71       int nrOfBins = solution.GroupingVector.Max() + 1;
    72 
    73       //Get all indexes of items for every bin according to grouping-vector
    74       //It is assumed, that at this point the item-indexes are sorted according to their item-size!
    75       Dictionary<int, List<int>> unpackedItemIndexesPerBin = new Dictionary<int, List<int>>();
    76 
    77       for (int i = 0; i < nrOfBins; i++) {
    78         unpackedItemIndexesPerBin[i] = solution.GroupingVector
    79           .Select((Value, Index) => new { Value, Index })
    80           .Where(temp => temp.Value == i)
    81           .Select(temp => temp.Index).ToList();
    82       }
    83 
    84       ObservableDictionary<int, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>();
    85       var remainingItems = new List<int>();
    86 
    87       //Iterate over all bin-lists
    88       for (int binNr = 0; binNr < nrOfBins; binNr++ ) {
    89         //Iterate over the current bin-item-list and find feasible positions in the current bin for each item
    90         var unpackedItems = unpackedItemIndexesPerBin [binNr];
    91         for (int i = 0; i < unpackedItems.Count; i++ ) {
    92           var itemIndex = unpackedItems[i];
    93           var item = PackingItemMeasuresParameter.ActualValue[itemIndex];
    94           TwoDimensionalPacking position = null;
    95 
    96           //Look for space in current bin
    97           position = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue);
    98 
    99           //Did not find enough space in current bin
    100           if (position == null) {
    101             remainingItems.Add(itemIndex);
    102             //if (binNr + 1 >= nrOfBins) {
    103             //  nrOfBins++;
    104             //  unpackedItemIndexesPerBin[binNr + 1] = new List<int>();
    105             //  unpackedItemIndexesPerBin[binNr + 1].Add(itemIndex);
    106             //  unpackedItemIndexesPerBin[binNr].Remove(itemIndex);
    107             //} else {
    108             //  unpackedItemIndexesPerBin[binNr + 1].Add(itemIndex);
    109             //  unpackedItemIndexesPerBin[binNr + 1].Sort();
    110             //}
    111             //solution.GroupingVector[itemIndex] = binNr + 1;
    112           } else
    113             packingPositions[itemIndex] = position;
    114         }
    115       }
    116 
    117       //Packing of remaining items
    118       //Iterate over all bin-lists
    119       for (int binNr = 0; binNr < nrOfBins && remainingItems.Count > 0; binNr++) {
    120         var unpackedItems = new List<int>(remainingItems);
    121         for (int i = 0; i < unpackedItems.Count; i++) {
    122           var itemIndex = unpackedItems[i];
    123           var item = PackingItemMeasuresParameter.ActualValue[itemIndex];
    124           TwoDimensionalPacking position = null;
    125 
    126           //Look for space in current bin
    127           position = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue);
    128 
    129           if (position != null) {
    130             packingPositions[itemIndex] = position;
    131             remainingItems.Remove(itemIndex);
    132             solution.GroupingVector[itemIndex] = binNr;
    133           }
    134         }
    135         if (remainingItems.Count > 0 && binNr + 1 >= nrOfBins) {
    136           nrOfBins++;
    137         }
    138       }
    139 
    140       result.PackingItemPositions = packingPositions;
    141 
    142 
     70      result.PackingItemPositions = BottomLeftFunctions.BottomLeftPacking(solution, binMeasures, itemMeasures);
    14371      return result;
    14472    }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/BL/BottomLeftMultiComponentVectorDecoder.cs

    r9440 r9495  
    4141  [Item("Identical bin two dimensional multi component vector decoder", "<Description missing...>")]
    4242  [StorableClass]
    43   public class BottomLeftMultiComponentVectorDecoder : IdenticalBinPackingSolutionDecoder<
     43  public class BottomLeftMultiComponentVectorDecoder : PackingSolutionDecoder<
    4444      TwoDimensionalPacking,
    4545      RectangularPackingBin,
    46       RectangularPackingItem,
    47       PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> {
     46      RectangularPackingItem> {
    4847
    4948    public BottomLeftMultiComponentVectorDecoder()
     
    6160
    6261
    63     protected override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {
     62    public override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
    6463
    6564      var solution = encodedSolution as MultiComponentVectorEncoding;
     
    6867      PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> result =
    6968        new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
    70       int nrOfBins = solution.PackingInformations.Max(pi => pi.AssignedBin) + 1;
    71 
    72       //Get all indexes of items for every bin according to grouping-vector
    73       Dictionary<int, List<PackingInformation>> unpackedItemIndexesPerBin = new Dictionary<int, List<PackingInformation>>();
    74 
    75       for (int i = 0; i < nrOfBins; i++) {
    76         unpackedItemIndexesPerBin[i] = solution.PackingInformations
    77           .Where(pi => pi.AssignedBin == i)
    78           .ToList();
    79       }
    80 
    81       ObservableDictionary<int, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>();
    82       var remainingItems = new List<PackingInformation>();
    83 
    84       //Iterate over all bin-lists
    85       for (int binNr = 0; binNr < nrOfBins; binNr++) {
    86         //Iterate over the current bin-item-list and find feasible positions in the current bin for each item
    87         var unpackedItems = unpackedItemIndexesPerBin[binNr];
    88         for (int i = 0; i < unpackedItems.Count; i++) {
    89           var itemIndex = unpackedItems[i].ItemIndex;
    90           var item = PackingItemMeasuresParameter.ActualValue[itemIndex];
    91           TwoDimensionalPacking position = null;
    92 
    93           position = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue, unpackedItems[i].Rotated);
    94 
    95           if (position == null) {
    96             position = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue, !unpackedItems[i].Rotated);
    97           }
    98           if (position == null) {
    99             remainingItems.Add(unpackedItems[i]);
    100           } else {
    101             packingPositions[itemIndex] = position;
    102             solution.PackingInformations.Find(pi => pi.ItemIndex == itemIndex).Rotated = position.Rotated;
    103           }
    104         }
    105       }
    106 
    107       //Packing of remaining items
    108       //Iterate over all bin-lists
    109       for (int binNr = 0; binNr < nrOfBins && remainingItems.Count > 0; binNr++) {
    110         var unpackedItems = new List<PackingInformation>(remainingItems);
    111         for (int i = 0; i < unpackedItems.Count; i++) {
    112           var itemIndex = unpackedItems[i].ItemIndex;
    113           var item = PackingItemMeasuresParameter.ActualValue[itemIndex];
    114           TwoDimensionalPacking position = null;
    115 
    116           //Look for space in current bin
    117           position = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue, unpackedItems[i].Rotated);
    118 
    119           if (position == null) {
    120             position = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue, !unpackedItems[i].Rotated);
    121           }
    122           if (position != null) {
    123             packingPositions[itemIndex] = position;
    124             remainingItems.Remove(unpackedItems[i]);
    125             solution.PackingInformations.Find(pi => pi.ItemIndex == itemIndex).AssignedBin = binNr;
    126             solution.PackingInformations.Find(pi => pi.ItemIndex == itemIndex).Rotated = position.Rotated;
    127           }
    128         }
    129         if (remainingItems.Count > 0 && binNr + 1 >= nrOfBins) {
    130           nrOfBins++;
    131         }
    132       }
    133 
    134       result.PackingItemPositions = packingPositions;
     69     
     70      result.PackingItemPositions = BottomLeftFunctions.BottomLeftPacking(solution, binMeasures, itemMeasures);
    13571
    13672      return result;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/BL/BottomLeftPackingSequenceDecoder.cs

    r9440 r9495  
    4040  [Item("Identical bin, two dimensional, direct permutation decoder", "<Description missing...>")]
    4141  [StorableClass]
    42   public class BottomLeftPackingSequenceDecoder : IdenticalBinPackingSolutionDecoder<
     42  public class BottomLeftPackingSequenceDecoder : PackingSolutionDecoder<
    4343      TwoDimensionalPacking,
    4444      RectangularPackingBin,
    45       RectangularPackingItem,
    46       PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> {
     45      RectangularPackingItem> {
    4746
    4847    public BottomLeftPackingSequenceDecoder()
     
    6059
    6160
    62     protected override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {
     61    public override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
    6362
    6463      var solution = encodedSolution as PackingSequenceEncoding;
     
    6867        new PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>(PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
    6968
    70       ObservableDictionary<int, TwoDimensionalPacking> packingPositions = new ObservableDictionary<int, TwoDimensionalPacking>();
    71       int nrOfBins = 1;
    72       for (int i = 0; i < solution.PackingSequence.Length; i++) {
    73         var item = PackingItemMeasuresParameter.ActualValue[solution.PackingSequence[i]];
    74         TwoDimensionalPacking position = null;
    75         //Look for space in existing bins
    76         for (int binNr = 0; binNr < nrOfBins; binNr++) {
    77           position = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, binNr, item, packingPositions, PackingItemMeasuresParameter.ActualValue);
    78           if (position != null)
    79             break;
    80         }
    81         //Did not find enough space in any of the existing bins => create new bin
    82         if (position == null) {
    83           nrOfBins++;
    84           position = BottomLeftFunctions.BottomLeftPosition(PackingBinMeasuresParameter.ActualValue, nrOfBins - 1, item, packingPositions, PackingItemMeasuresParameter.ActualValue);
    85         }
    86 
    87         if (position == null)
    88           position = new TwoDimensionalPacking(-1, 0, 0);
    89 
    90         packingPositions[solution.PackingSequence[i]] = position;
    91       }
    92 
    93       result.PackingItemPositions = packingPositions;
     69      result.PackingItemPositions = BottomLeftFunctions.BottomLeftPacking (solution, binMeasures, itemMeasures);
    9470
    9571      return result;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/EP/ExtremePointGroupingVectorDecoder2D.cs

    r9440 r9495  
    4141  [Item("Identical bin, two dimensional, extreme points based decoder for the GroupingVector encoding.", "<Description missing...>")]
    4242  [StorableClass]
    43   public class ExtremePointGroupingVectorDecoder2D : IdenticalBinPackingSolutionDecoder<
     43  public class ExtremePointGroupingVectorDecoder2D : PackingSolutionDecoder<
    4444      TwoDimensionalPacking,
    4545      RectangularPackingBin,
    46       RectangularPackingItem,
    47       PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> {
     46      RectangularPackingItem> {
    4847
    4948    public ExtremePointGroupingVectorDecoder2D ()
     
    6867    }
    6968
    70     protected override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {
     69    public override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
    7170                     
    7271      var solution = encodedSolution as GroupingVectorEncoding;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/EP/ExtremePointMultiComponentVectorDecoder2D.cs

    r9440 r9495  
    4242  [Item("Identical bin, two dimensional, extreme points based decoder for the MultiComponentVector encoding.", "<Description missing...>")]
    4343  [StorableClass]
    44   public class ExtremePointMultiComponentVectorDecoder2D : IdenticalBinPackingSolutionDecoder<
     44  public class ExtremePointMultiComponentVectorDecoder2D : PackingSolutionDecoder<
    4545      TwoDimensionalPacking,
    4646      RectangularPackingBin,
    47       RectangularPackingItem,
    48       PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> {
     47      RectangularPackingItem> {
    4948
    5049    public ExtremePointMultiComponentVectorDecoder2D ()
     
    6968    }
    7069
    71     protected override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {
     70    public override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
    7271
    7372      var solution = encodedSolution as MultiComponentVectorEncoding;
    7473      if (solution == null) throw new InvalidOperationException("Encoding is not of type MultiComponentVector");
    7574
    76       return Decode(solution, PackingBinMeasuresParameter.ActualValue, PackingItemMeasuresParameter.ActualValue);
     75      return Decode(solution, binMeasures, itemMeasures);
    7776    }
    7877  }
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/EP/ExtremePointPackingSequenceDecoder2D.cs

    r9440 r9495  
    4040  [Item("Identical bin, two dimensional, extreme points based decoder for the PackingSequence encoding.", "<Description missing...>")]
    4141  [StorableClass]
    42   public class ExtremePointPackingSequenceDecoder2D : IdenticalBinPackingSolutionDecoder<
     42  public class ExtremePointPackingSequenceDecoder2D : PackingSolutionDecoder<
    4343      TwoDimensionalPacking,
    4444      RectangularPackingBin,
    45       RectangularPackingItem,
    46       PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem>> {
     45      RectangularPackingItem> {
    4746
    4847    public ExtremePointPackingSequenceDecoder2D ()
     
    5958
    6059
    61     protected override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution) {
     60    public override PackingPlan<TwoDimensionalPacking, RectangularPackingBin, RectangularPackingItem> CreatePackingPlanFromEncoding(IPackingSolutionEncoding encodedSolution, RectangularPackingBin binMeasures, ItemList<RectangularPackingItem> itemMeasures) {
    6261
    6362      var solution = encodedSolution as PackingSequenceEncoding;
  • branches/HeuristicLab.BinPacking/HeuristicLab.Problems.BinPacking/3.3/Decoders/2D/EP/ExtremePointsFunctions2D.cs

    r9440 r9495  
    2424
    2525      #region Preperations
    26       int nrOfBins = solution.PackingInformations.Max(x => x.AssignedBin) + 1;
     26          int nrOfBins = solution.NrOfBins;
    2727
    2828      //Get all indexes of items for every bin according to grouping-vector                     
     
    3232
    3333      for (int i = 0; i < nrOfBins; i++) {       
    34         unpackedItemIndexesPerBin[i] = solution.PackingInformations
    35           .Where(pi => pi.AssignedBin == i)
    36           .ToList();
     34        unpackedItemIndexesPerBin[i] = new List<PackingInformation> (solution.PackingInformations[i]);
    3735
    3836        extremePointsForBin[i] = new HashSet<TwoDimensionalPacking>();
     
    5250        var unpackedItems = unpackedItemIndexesPerBin[binNr];
    5351        for (int i = 0; i < unpackedItems.Count; i++) {
    54           var itemIndex = unpackedItems[i].ItemIndex;
     52          var itemIndex = unpackedItems[i].ItemID;
    5553          var item = itemMeasures[itemIndex];
    5654
    57           extremePointsForBin[binNr] = new HashSet<TwoDimensionalPacking>(extremePointsForBin[binNr].OrderBy(ep => ep.AssignedBin).ThenBy(ep => ShortestPossibleSideFromEP(ep, occupiedPoints, binMeasures)));
     55          extremePointsForBin[binNr] = OrderExtremePoints(extremePointsForBin[binNr], occupiedPoints, binMeasures);
    5856          var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePointsForBin[binNr], occupiedPoints, itemPositions, unpackedItems[i].Rotated);
    5957          if (positionFound != null) {
     
    6260            occupiedPoints = OccupyPointsForNewItem(occupiedPoints, item, positionFound, itemIndex);
    6361            extremePointsForBin[binNr] = GenerateNewExtremePointsForNewItem(extremePointsForBin[binNr], occupiedPoints, item, positionFound, binMeasures);
    64           } else
     62          } else {
    6563            remainingItems.Add(unpackedItems[i]);
     64            solution.PackingInformations[binNr].Remove(unpackedItems[i]);
     65          }
    6666        }
    6767      }
     
    7474        //Iterate over all the remaining items
    7575        for (int i = 0; i < unpackedItems.Count; i++) {
    76           var itemIndex = unpackedItems[i].ItemIndex;
     76          var itemIndex = unpackedItems[i].ItemID;
    7777          var item = itemMeasures[itemIndex];
    7878
    79           extremePointsForBin[binNr] = new HashSet<TwoDimensionalPacking>(extremePointsForBin[binNr].OrderBy(ep => ep.AssignedBin).ThenBy(ep => ShortestPossibleSideFromEP(ep, occupiedPoints, binMeasures)));
     79          extremePointsForBin[binNr] = OrderExtremePoints(extremePointsForBin[binNr], occupiedPoints, binMeasures);
    8080          var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePointsForBin[binNr], occupiedPoints, itemPositions, unpackedItems[i].Rotated);
    8181          if (positionFound != null) {
     
    8585            extremePointsForBin[binNr] = GenerateNewExtremePointsForNewItem(extremePointsForBin[binNr], occupiedPoints, item, positionFound, binMeasures);
    8686            remainingItems.Remove(unpackedItems[i]);
     87            solution.PackingInformations[binNr].Add(unpackedItems[i]);
    8788          }
    8889        }
     
    9192          extremePointsForBin[nrOfBins].Add(new TwoDimensionalPacking(nrOfBins, 0, 0, false));
    9293          occupiedPoints = IncreaseBinCountForOccupiedPoints(occupiedPoints, binMeasures);
     94          solution.PackingInformations[nrOfBins] = new ItemList<PackingInformation>();
    9395          nrOfBins++;
    9496        }
     
    136138          var item = itemMeasures[itemIndex];
    137139
    138           extremePointsForBin[binNr] = new HashSet<TwoDimensionalPacking>(extremePointsForBin[binNr].OrderBy(ep => ep.AssignedBin).ThenBy(ep => ShortestPossibleSideFromEP(ep, occupiedPoints, binMeasures)));
     140          extremePointsForBin[binNr] = OrderExtremePoints(extremePointsForBin[binNr], occupiedPoints, binMeasures);
    139141          var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePointsForBin[binNr], occupiedPoints, itemPositions);
    140142          if (positionFound != null) {
     
    159161          var item = itemMeasures[itemIndex];
    160162
    161           extremePointsForBin[binNr] = new HashSet<TwoDimensionalPacking>(extremePointsForBin[binNr].OrderBy(ep => ep.AssignedBin).ThenBy(ep => ShortestPossibleSideFromEP(ep, occupiedPoints, binMeasures)));
     163          extremePointsForBin[binNr] = OrderExtremePoints(extremePointsForBin[binNr], occupiedPoints, binMeasures);
    162164          var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePointsForBin[binNr], occupiedPoints, itemPositions);
    163165          if (positionFound != null) {
     
    197199      foreach (int itemIndex in solution.PackingSequence) {
    198200        var item = itemMeasures[itemIndex];
    199         extremePoints = new HashSet<TwoDimensionalPacking>(extremePoints.OrderBy(ep => ep.AssignedBin).ThenBy(ep => ShortestPossibleSideFromEP(ep, occupiedPoints, binMeasures)));
     201        extremePoints = OrderExtremePoints(extremePoints, occupiedPoints, binMeasures);
    200202        var positionFound = FindExtremePointForItem(itemIndex, itemMeasures, binMeasures, extremePoints, occupiedPoints, itemPositions);
    201203        if (positionFound != null) {
     
    296298      return extremePoints;
    297299    }
     300
     301    public static HashSet<TwoDimensionalPacking> OrderExtremePoints(HashSet<TwoDimensionalPacking> hashSet, List<int[,]> occupiedPoints, RectangularPackingBin binMeasures) {
     302      return new HashSet<TwoDimensionalPacking>(hashSet.OrderBy(ep => ep.AssignedBin).ThenBy(ep => ep.X).ThenBy(ep => ep.Y).ThenBy(ep => ShortestPossibleSideFromEP(ep, occupiedPoints, binMeasures)));
     303    }
    298304    private static int ShortestPossibleSideFromEP(TwoDimensionalPacking ep, List<int[,]> occupiedPoints, RectangularPackingBin binMeasures) {
    299305      int shortestSide = int.MaxValue;
Note: See TracChangeset for help on using the changeset viewer.