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/EP
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 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.