Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/09/18 12:59:38 (6 years ago)
Author:
rhanghof
Message:

#2817:

  • Adjusted the unit tests
  • Refactoring of the sorter
  • Bugfix on the BinPackerResidualSpaceBestFit packer
Location:
branches/2817-BinPackingSpeedup
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Algorithms/ExtremePointAlgorithm.cs

    r15959 r15989  
    8383
    8484    [Storable]
    85     private readonly IValueParameter<BoolValue> sortByMaterialParameter;
    86 
    87     public IValueParameter<BoolValue> SortByMaterialParameter {
    88       get { return sortByMaterialParameter; }
     85    private readonly IValueParameter<BoolValue> sortBySequenceGroupParameter;
     86
     87    public IValueParameter<BoolValue> SortBySequenceGroupParameter {
     88      get { return sortBySequenceGroupParameter; }
    8989    }
    9090
     
    116116        "Delta", "[1;100]% Clustered sorting methods use a delta parameter to determine the clusters.", new PercentValue(.1)));
    117117
    118       Parameters.Add(sortByMaterialParameter = new ValueParameter<BoolValue>(
    119         "SortByMaterial", "If this parameter is set, the items will be sorted by their material first", new BoolValue(true)));
     118      Parameters.Add(sortBySequenceGroupParameter = new ValueParameter<BoolValue>(
     119        "SortBySequenceGroup", "If this parameter is set, the items will be sorted by their sequence group first", new BoolValue(true)));
    120120
    121121      Problem = new PermutationProblem();
     
    209209                  ExtremePointCreationMethod[] epCreationMethods,
    210210                  CancellationToken token) {
     211
    211212      SortingMethod? bestSorting = null;
    212213      FittingMethod? bestFitting = null;
     
    223224            Permutation sortedItems;
    224225
    225             if (SortByMaterialParameter.Value.Value) {
    226               sortedItems = SortItemsByMaterialAndSortingMethod(bin, items, sort, DeltaParameter.Value.Value);
    227             } else {
    228               sortedItems = SortItemsBySortingMethod(bin, items, sort, DeltaParameter.Value.Value);
    229             }
    230 
     226            sortedItems = SortItems(bin, items, sort, DeltaParameter.Value.Value, SortBySequenceGroupParameter.Value.Value);
     227           
    231228            var solution = Optimize(new OptimaizationParamters() {
    232229              SortedItems = sortedItems,
     
    265262    /// <returns></returns>
    266263    private static Solution Optimize(OptimaizationParamters parameters) {
    267 
    268264      var sol = parameters.Decoder.Decode(parameters.SortedItems, parameters.Bin, parameters.Items, parameters.StackingConstraints);
    269265
     
    281277    }
    282278   
    283     /// <summary>
    284     /// Returns a new permutation of the given items depending on the sorting method
    285     /// </summary>
    286     /// <param name="bin"></param>
    287     /// <param name="items"></param>
    288     /// <param name="sortingMethod"></param>
    289     /// <param name="delta"></param>
    290     /// <returns></returns>
    291     private Permutation SortItemsByMaterialAndSortingMethod(PackingShape bin, IList<PackingItem> items, SortingMethod sortingMethod, double delta) {
    292       Permutation sorted = null;
    293 
    294       switch (sortingMethod) {
    295         case SortingMethod.Given:
    296           sorted = new Permutation(PermutationTypes.Absolute, Enumerable.Range(0, items.Count).ToArray());
    297           break;
    298         case SortingMethod.VolumeHeight:
    299           sorted = items.SortByVolumeHeight();
    300           break;
    301         case SortingMethod.HeightVolume:
    302           sorted = items.SortByMaterialHeightVolume();
    303           break;
    304         case SortingMethod.AreaHeight:
    305           sorted = items.SortByMaterialAreaHeight();
    306           break;
    307         case SortingMethod.HeightArea:
    308           sorted = items.SortByMaterialHeightArea();
    309           break;
    310         case SortingMethod.ClusteredAreaHeight:
    311           sorted = items.SortByMaterialClusteredAreaHeight(bin, delta);
    312           break;
    313         case SortingMethod.ClusteredHeightArea:
    314           sorted = items.SortByMaterialClusteredHeightArea(bin, delta);
    315           break;
    316         default:
    317           throw new ArgumentException("Unknown sorting method: " + sortingMethod);
    318       }
    319       return sorted;
    320     }
    321 
    322     /// <summary>
    323     /// Returns a new permutation of the given items depending on the material and sorting method
    324     /// </summary>
    325     /// <param name="bin"></param>
    326     /// <param name="items"></param>
    327     /// <param name="sortingMethod"></param>
    328     /// <param name="delta"></param>
    329     /// <returns></returns>
    330     private Permutation SortItemsBySortingMethod(PackingShape bin, IList<PackingItem> items, SortingMethod sortingMethod, double delta) {
    331       Permutation sorted = null;
    332 
    333       switch (sortingMethod) {
    334         case SortingMethod.Given:
    335           sorted = new Permutation(PermutationTypes.Absolute, Enumerable.Range(0, items.Count).ToArray());
    336           break;
    337         case SortingMethod.VolumeHeight:
    338           sorted = items.SortByVolumeHeight();
    339           break;
    340         case SortingMethod.HeightVolume:
    341           sorted = items.SortByHeightVolume();
    342           break;
    343         case SortingMethod.AreaHeight:
    344           sorted = items.SortByAreaHeight();
    345           break;
    346         case SortingMethod.HeightArea:
    347           sorted = items.SortByHeightArea();
    348           break;
    349         case SortingMethod.ClusteredAreaHeight:
    350           sorted = items.SortByClusteredAreaHeight(bin, delta);
    351           break;
    352         case SortingMethod.ClusteredHeightArea:
    353           sorted = items.SortByClusteredHeightArea(bin, delta);
    354           break;
    355         default:
    356           throw new ArgumentException("Unknown sorting method: " + sortingMethod);
    357       }
    358       return sorted;
    359     }
     279
     280    private Permutation SortItems(PackingShape bin, IList<PackingItem> items, SortingMethod sortingMethod, double delta, bool sortBySequenceGroup) {
     281      Permutation sortedItems;
     282
     283      var sorter = PackingItemSorterFactory.CreatePackingItemSorter(sortingMethod);
     284      if (sorter is IPackingItemClusteredSorter) {
     285        if (sortBySequenceGroup) {
     286          sortedItems = (sorter as IPackingItemClusteredSorter).SortPackingItemsBySequenceGroup(items, bin, delta);
     287        } else {
     288          sortedItems = (sorter as IPackingItemClusteredSorter).SortPackingItems(items, bin, delta);
     289        }
     290      } else {
     291        if (sortBySequenceGroup) {
     292          sortedItems = sorter.SortPackingItemsBySequenceGroup(items, bin);
     293        } else {
     294          sortedItems = sorter.SortPackingItems(items, bin);
     295        }
     296      }
     297      return sortedItems;
     298    }   
    360299  }
    361300}
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Instances/RandomInstanceProvider.cs

    r15617 r15989  
    198198    protected virtual void SampleItemParameters(IRandom rand, out int w, out int h, out int d) {
    199199      Contract.Assert(@class >= 1 && @class <= 5);
    200       /*var weights = new double[] { 0.1, 0.1, 0.1, 0.1, 0.1 };
     200      var weights = new double[] { 0.1, 0.1, 0.1, 0.1, 0.1 };
    201201      weights[@class - 1] = 0.6;
    202202      var type = Enumerable.Range(1, 5).SampleProportional(rand, 1, weights).First();
    203       */
    204 
    205       // as by Martello and Vigo
    206       int type = @class;
    207       if (type <= 5) {
    208         var t = rand.Next(1, 10);
    209         if (t <= 5) {
    210           type = t;
    211         }
    212       }
    213203
    214204      switch (type) {
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Packer/BinPackerResidualSpaceBestFit.cs

    r15820 r15989  
    104104        foreach (var extremPoints in bp.ExtremePoints) {
    105105          var ep = extremPoints.Key;
    106           var residualSpaces = extremPoints.Value.Where(rs => rs.Width < item.Width || rs.Height < item.Height || rs.Depth < item.Depth);
     106          var residualSpaces = extremPoints.Value.Where(rs => rs.Width >= item.Width && rs.Height >= item.Height && rs.Depth >= item.Depth);
    107107          if (residualSpaces.Count() <= 0) {
    108108            continue;
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Sorting/IPackingItemClusteredSorter.cs

    r15646 r15989  
    3131    Permutation SortPackingItems(IList<PackingItem> items, PackingShape bin, double delta);
    3232
    33     Permutation SortPackingItemsByMaterial(IList<PackingItem> items, PackingShape bin, double delta);
     33    Permutation SortPackingItemsBySequenceGroup(IList<PackingItem> items, PackingShape bin, double delta);
    3434   
    3535  }
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Sorting/IPackingItemSorter.cs

    r15618 r15989  
    3232    Permutation SortPackingItems(IList<PackingItem> items, PackingShape bin);
    3333
    34     Permutation SortPackingItemsByMaterial(IList<PackingItem> items, PackingShape bin);
     34    Permutation SortPackingItemsBySequenceGroup(IList<PackingItem> items, PackingShape bin);
    3535  }
    3636}
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Sorting/PackingItemAreaHeightSorter.cs

    r15646 r15989  
    3434    }
    3535   
    36     public Permutation SortPackingItemsByMaterial(IList<PackingItem> items, PackingShape bin) {
     36    public Permutation SortPackingItemsBySequenceGroup(IList<PackingItem> items, PackingShape bin) {
    3737      return items.SortByMaterialAreaHeight();
    3838    }   
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Sorting/PackingItemClusterdHeightAreaSorter.cs

    r15618 r15989  
    3838    }
    3939
    40     public Permutation SortPackingItemsByMaterial(IList<PackingItem> items, PackingShape bin, double delta) {
     40    public Permutation SortPackingItemsBySequenceGroup(IList<PackingItem> items, PackingShape bin, double delta) {
    4141      return items.SortByMaterialClusteredHeightArea(bin, delta);
    4242    }
    4343
    44     public Permutation SortPackingItemsByMaterial(IList<PackingItem> items, PackingShape bin) {
    45       return SortPackingItemsByMaterial(items, bin, 10.0);
     44    public Permutation SortPackingItemsBySequenceGroup(IList<PackingItem> items, PackingShape bin) {
     45      return SortPackingItemsBySequenceGroup(items, bin, 10.0);
    4646    }
    4747  }
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Sorting/PackingItemClusteredAreaHeightSorter.cs

    r15618 r15989  
    3838    }
    3939
    40     public Permutation SortPackingItemsByMaterial(IList<PackingItem> items, PackingShape bin, double delta) {
     40    public Permutation SortPackingItemsBySequenceGroup(IList<PackingItem> items, PackingShape bin, double delta) {
    4141      return items.SortByMaterialClusteredAreaHeight(bin, delta);
    4242    }
    4343
    44     public Permutation SortPackingItemsByMaterial(IList<PackingItem> items, PackingShape bin) {
    45       return SortPackingItemsByMaterial(items, bin, 10.0);
     44    public Permutation SortPackingItemsBySequenceGroup(IList<PackingItem> items, PackingShape bin) {
     45      return SortPackingItemsBySequenceGroup(items, bin, 10.0);
    4646    }
    4747  }
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Sorting/PackingItemGivenSorter.cs

    r15618 r15989  
    3434    }
    3535
    36     public Permutation SortPackingItemsByMaterial(IList<PackingItem> items, PackingShape bin) {
     36    public Permutation SortPackingItemsBySequenceGroup(IList<PackingItem> items, PackingShape bin) {
    3737      return new Permutation(PermutationTypes.Absolute, Enumerable.Range(0, items.Count).ToArray());
    3838    }
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Sorting/PackingItemHeightAreaSorter.cs

    r15618 r15989  
    3434    }
    3535
    36     public Permutation SortPackingItemsByMaterial(IList<PackingItem> items, PackingShape bin) {
     36    public Permutation SortPackingItemsBySequenceGroup(IList<PackingItem> items, PackingShape bin) {
    3737      return items.SortByMaterialHeightArea();
    3838    }
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Sorting/PackingItemHeightVolumeSorter.cs

    r15646 r15989  
    3434    }
    3535
    36     public Permutation SortPackingItemsByMaterial(IList<PackingItem> items, PackingShape bin) {
     36    public Permutation SortPackingItemsBySequenceGroup(IList<PackingItem> items, PackingShape bin) {
    3737      return items.SortByMaterialHeightVolume();
    3838    }   
  • branches/2817-BinPackingSpeedup/HeuristicLab.Problems.BinPacking/3.3/3D/Sorting/PackingItemVolumeHeightSorter.cs

    r15618 r15989  
    3434    }
    3535
    36     public Permutation SortPackingItemsByMaterial(IList<PackingItem> items, PackingShape bin) {
     36    public Permutation SortPackingItemsBySequenceGroup(IList<PackingItem> items, PackingShape bin) {
    3737      return items.SortByMaterialVolumeHeight();
    3838    }
  • branches/2817-BinPackingSpeedup/HeuristicLab.Tests/HeuristicLab.Problems.Bin-Packing-3.3/3D/Algorithms/ExtremePointAlgorithmTest.cs

    r15959 r15989  
    8383      _extremPointAlgorithm.FittingMethodParameter.Value.Value = FittingMethod.FirstFit;
    8484      _extremPointAlgorithm.ExtremePointCreationMethodParameter.Value.Value = ExtremePointCreationMethod.PointProjection;
    85       _extremPointAlgorithm.SortByMaterialParameter.Value.Value = false;
     85      _extremPointAlgorithm.SortBySequenceGroupParameter.Value.Value = false;
    8686      var result = TestUtils.InvokeMethod(typeof(ExtremePointAlgorithm), _extremPointAlgorithm, "GetBest", parameters) as Tuple<Solution, double, SortingMethod?, FittingMethod?, ExtremePointCreationMethod?>;
    8787
  • branches/2817-BinPackingSpeedup/HeuristicLab.Tests/HeuristicLab.Problems.Bin-Packing-3.3/3D/Instances/RandomInstanceProviderTest.cs

    r15959 r15989  
    1717      public int Height { get; set; }
    1818      public int Depth { get; set; }
    19     }
    20 
    21     #region TestRandomInstanceProvider
    22 
    23 
    24     /// <summary>
    25     /// Tests if the generated random instance equals to the references generated by david pisinger
    26     /// http://www.diku.dk/~pisinger/new3dbpp/test3dbpp.c
    27     /// </summary>
    28     [TestMethod]
    29     [TestCategory("Problems.BinPacking.3D")]
    30     [TestProperty("Time", "long")]
    31     public void TestRandomInstanceProvider() {
    32 
    33       var referenceItemLists = ReadReferenceItemLists();
    34       TestRandomInstanceProviderByClass(new RandomInstanceClass1Provider(), referenceItemLists);
    35       TestRandomInstanceProviderByClass(new RandomInstanceClass2Provider(), referenceItemLists);
    36       TestRandomInstanceProviderByClass(new RandomInstanceClass3Provider(), referenceItemLists);
    37       TestRandomInstanceProviderByClass(new RandomInstanceClass4Provider(), referenceItemLists);
    38       TestRandomInstanceProviderByClass(new RandomInstanceClass5Provider(), referenceItemLists);
    39       TestRandomInstanceProviderByClass(new RandomInstanceClass6Provider(), referenceItemLists);
    40       TestRandomInstanceProviderByClass(new RandomInstanceClass7Provider(), referenceItemLists);
    41       TestRandomInstanceProviderByClass(new RandomInstanceClass8Provider(), referenceItemLists);
    42 
    43     }
    44 
    45     private IDictionary<string, List<Dimension>> ReadReferenceItemLists() {
    46       var itemList = new Dictionary<string, List<Dimension>>();
    47       string path = @".\..\HeuristicLab.Tests\HeuristicLab.Problems.Bin-Packing-3.3\TestInstances\ReferenceInstances";
    48 
    49       string[] files = Directory.GetFiles(path);
    50       foreach (string filePath in files) {
    51         string key = Path.GetFileNameWithoutExtension(filePath);
    52 
    53         using (StreamReader reader = new StreamReader(filePath)) {
    54           int lineNumber = 1;
    55           List<Dimension> dimensionList = new List<Dimension>();
    56           while (!reader.EndOfStream) {
    57             string line = reader.ReadLine();
    58             if (lineNumber > 2) {
    59               string[] lineValues = line.Split('\t');
    60               int id;
    61               int depth;
    62               int width;
    63               int height;
    64               Int32.TryParse(lineValues[0], out id);
    65               Int32.TryParse(lineValues[1], out depth);
    66               Int32.TryParse(lineValues[2], out width);
    67               Int32.TryParse(lineValues[3], out height);
    68               dimensionList.Add(new Dimension() {
    69                 Id = id,
    70                 Depth = depth,
    71                 Width = width,
    72                 Height = height
    73               });
    74             }
    75             lineNumber++;
    76           }
    77           itemList.Add(key, dimensionList);
    78         }
    79       }
    80       return itemList;
    81     }
    82 
    83     private void TestRandomInstanceProviderByClass(RandomInstanceProvider randomInstanceProvider, IDictionary<string, List<Dimension>> referenceItems) {
    84 
    85       var dataDescriptors = randomInstanceProvider.GetDataDescriptors();
    86       foreach (var dataDescriptor in dataDescriptors) {
    87         List<Dimension> testItemDimensions = null;
    88         if (referenceItems.TryGetValue(dataDescriptor.Name, out testItemDimensions)) {
    89           var packingItems = randomInstanceProvider.LoadData(dataDescriptor).Items;
    90           Assert.IsNotNull(packingItems);
    91           Assert.AreEqual(testItemDimensions.Count, packingItems.Length);
    92           for (int i = 0; i < packingItems.Length; i++) {
    93             Assert.AreEqual(testItemDimensions[i].Width, packingItems[i].Width);
    94             Assert.AreEqual(testItemDimensions[i].Height, packingItems[i].Height);
    95             Assert.AreEqual(testItemDimensions[i].Depth, packingItems[i].Depth);
    96           }
    97         }
    98       }
    99     }
    100     #endregion
     19    }   
    10120
    10221    #region TestExtremePointAlgorithm
     
    198117            algorithm.FittingMethodParameter.Value.Value = fittingMethod;
    199118            algorithm.ExtremePointCreationMethodParameter.Value.Value = epCreationMethod;
    200             algorithm.SortByMaterialParameter.Value.Value = false;
     119            algorithm.SortBySequenceGroupParameter.Value.Value = false;
    201120
    202121            algorithm.Problem.UseStackingConstraintsParameter.Value.Value = false;
  • branches/2817-BinPackingSpeedup/HeuristicLab.Tests/HeuristicLab.Problems.Bin-Packing-3.3/3D/Instances/ThreeDInstanceParserTest.cs

    r15959 r15989  
    1919
    2020      _items1.Add(new PackingItem(8, 10, 10, _packingShape, 800, 1, 1)); // 0,  V = 800,  A =  80, h = 10
    21       _items1.Add(new PackingItem(10, 8, 10, _packingShape, 800, 2, 1)); // 1,  V = 800,  A = 100, h =  8
    22       _items1.Add(new PackingItem(10, 10, 8, _packingShape, 800, 3, 1)); // 2,  V = 800,  A =  80, h = 10
    23       _items1.Add(new PackingItem(8, 8, 10,  _packingShape, 640, 4, 1)); // 3,   V = 640,  A =  80, h =  8
    24       _items1.Add(new PackingItem(10, 8, 8,  _packingShape, 640, 0, 1)); // 4,   V = 640,  A =  80, h =  8
     21      _items1.Add(new PackingItem(10, 8, 10, _packingShape, 800, 2, 2)); // 1,  V = 800,  A = 100, h =  8
     22      _items1.Add(new PackingItem(10, 10, 8, _packingShape, 800, 3, 3)); // 2,  V = 800,  A =  80, h = 10
     23      _items1.Add(new PackingItem(8, 8, 10,  _packingShape, 640, 4, 4)); // 3,   V = 640,  A =  80, h =  8
     24      _items1.Add(new PackingItem(10, 8, 8,  _packingShape, 640, 0, 0)); // 4,   V = 640,  A =  80, h =  8
    2525      _items1.Add(new PackingItem(8, 10, 8,  _packingShape, 640, 1, 1)); // 5,   V = 640,  A =  64, h = 10 
    26       _items1.Add(new PackingItem(8, 8, 8,   _packingShape, 512, 2, 1)); // 6,    V = 512,  A =  64, h =  8
     26      _items1.Add(new PackingItem(8, 8, 8,   _packingShape, 512, 2, 2)); // 6,    V = 512,  A =  64, h =  8
    2727
    28       _items1.Add(new PackingItem(10, 10, 10, _packingShape,1000,3, 1)); // 7, V = 1000, A = 100, h = 10
     28      _items1.Add(new PackingItem(10, 10, 10, _packingShape,1000,3, 3)); // 7, V = 1000, A = 100, h = 10
    2929
    30       _items1.Add(new PackingItem(9, 10, 10, _packingShape, 900, 4, 1)); // 8,  V = 900,  A =  90, h = 10
    31       _items1.Add(new PackingItem(10, 9, 10, _packingShape, 900, 0, 1)); // 9,  V = 900,  A = 100, h =  9
     30      _items1.Add(new PackingItem(9, 10, 10, _packingShape, 900, 4, 4)); // 8,  V = 900,  A =  90, h = 10
     31      _items1.Add(new PackingItem(10, 9, 10, _packingShape, 900, 0, 0)); // 9,  V = 900,  A = 100, h =  9
    3232      _items1.Add(new PackingItem(10, 10, 9, _packingShape, 900, 1, 1)); // 10, V = 900,  A =  90, h = 10
    33       _items1.Add(new PackingItem(9, 9, 10,  _packingShape, 810, 2, 1)); // 11,  V = 810,  A =  90, h =  9
    34       _items1.Add(new PackingItem(10, 9, 9,  _packingShape, 810, 3, 1)); // 12,  V = 810,  A =  90, h =  9
    35       _items1.Add(new PackingItem(9, 10, 9,  _packingShape, 810, 4, 1)); // 13,  V = 810,  A =  81, h = 10
    36       _items1.Add(new PackingItem(9, 9, 9,   _packingShape, 729, 0, 1)); // 14,   V = 729,  A =  81, h =  9
     33      _items1.Add(new PackingItem(9, 9, 10,  _packingShape, 810, 2, 2)); // 11,  V = 810,  A =  90, h =  9
     34      _items1.Add(new PackingItem(10, 9, 9,  _packingShape, 810, 3, 3)); // 12,  V = 810,  A =  90, h =  9
     35      _items1.Add(new PackingItem(9, 10, 9,  _packingShape, 810, 4, 4)); // 13,  V = 810,  A =  81, h = 10
     36      _items1.Add(new PackingItem(9, 9, 9,   _packingShape, 729, 0, 0)); // 14,   V = 729,  A =  81, h =  9
    3737
    3838      _items2 = new List<PackingItem>();
    3939      _items2.Add(new PackingItem(8, 10, 10, _packingShape, 800, 1, 1)); // 0,  V = 800,  A =  80, h = 10
    40       _items2.Add(new PackingItem(10, 8, 10, _packingShape, 800, 2, 1)); // 1,  V = 800,  A = 100, h =  8
    41       _items2.Add(new PackingItem(10, 10, 8, _packingShape, 800, 3, 1)); // 2,  V = 800,  A =  80, h = 10
    42       _items2.Add(new PackingItem(8, 8, 10, _packingShape, 640, 4, 1)); // 3,   V = 640,  A =  80, h =  8
    43       _items2.Add(new PackingItem(10, 8, 8, _packingShape, 640, 0, 1)); // 4,   V = 640,  A =  80, h =  8
     40      _items2.Add(new PackingItem(10, 8, 10, _packingShape, 800, 2, 2)); // 1,  V = 800,  A = 100, h =  8
     41      _items2.Add(new PackingItem(10, 10, 8, _packingShape, 800, 3, 3)); // 2,  V = 800,  A =  80, h = 10
     42      _items2.Add(new PackingItem(8, 8, 10, _packingShape, 640, 4, 4)); // 3,   V = 640,  A =  80, h =  8
     43      _items2.Add(new PackingItem(10, 8, 8, _packingShape, 640, 0, 0)); // 4,   V = 640,  A =  80, h =  8
    4444      _items2.Add(new PackingItem(8, 10, 8, _packingShape, 640, 1, 1)); // 5,   V = 640,  A =  64, h = 10 
    4545    }
  • branches/2817-BinPackingSpeedup/HeuristicLab.Tests/HeuristicLab.Problems.Bin-Packing-3.3/3D/Sorting/PermutationSortingTest.cs

    r15959 r15989  
    1818
    1919      _items.Add(new PackingItem(8, 10, 10, _packingShape, 1000, 1, 1)); // 0,  V = 800,  A =  80, h = 10
    20       _items.Add(new PackingItem(10, 8, 10, _packingShape, 1000, 2, 1)); // 1,  V = 800,  A = 100, h =  8
    21       _items.Add(new PackingItem(10, 10, 8, _packingShape, 1000, 3, 1)); // 2,  V = 800,  A =  80, h = 10
    22       _items.Add(new PackingItem(8, 8, 10, _packingShape, 1000, 4, 1)); // 3,   V = 640,  A =  80, h =  8
    23       _items.Add(new PackingItem(10, 8, 8, _packingShape, 1000, 0, 1)); // 4,   V = 640,  A =  80, h =  8
     20      _items.Add(new PackingItem(10, 8, 10, _packingShape, 1000, 2, 2)); // 1,  V = 800,  A = 100, h =  8
     21      _items.Add(new PackingItem(10, 10, 8, _packingShape, 1000, 3, 3)); // 2,  V = 800,  A =  80, h = 10
     22      _items.Add(new PackingItem(8, 8, 10, _packingShape, 1000, 4, 4)); // 3,   V = 640,  A =  80, h =  8
     23      _items.Add(new PackingItem(10, 8, 8, _packingShape, 1000, 0, 0)); // 4,   V = 640,  A =  80, h =  8
    2424      _items.Add(new PackingItem(8, 10, 8, _packingShape, 1000, 1, 1)); // 5,   V = 640,  A =  64, h = 10 
    25       _items.Add(new PackingItem(8, 8, 8, _packingShape, 1000, 2, 1)); // 6,    V = 512,  A =  64, h =  8
     25      _items.Add(new PackingItem(8, 8, 8, _packingShape, 1000, 2, 2)); // 6,    V = 512,  A =  64, h =  8
    2626
    27       _items.Add(new PackingItem(10, 10, 10, _packingShape, 1000, 3, 1)); // 7, V = 1000, A = 100, h = 10
     27      _items.Add(new PackingItem(10, 10, 10, _packingShape, 1000, 3, 3)); // 7, V = 1000, A = 100, h = 10
    2828
    29       _items.Add(new PackingItem(9, 10, 10, _packingShape, 1000, 4, 1)); // 8,  V = 900,  A =  90, h = 10
    30       _items.Add(new PackingItem(10, 9, 10, _packingShape, 1000, 0, 1)); // 9,  V = 900,  A = 100, h =  9
     29      _items.Add(new PackingItem(9, 10, 10, _packingShape, 1000, 4, 4)); // 8,  V = 900,  A =  90, h = 10
     30      _items.Add(new PackingItem(10, 9, 10, _packingShape, 1000, 0, 0)); // 9,  V = 900,  A = 100, h =  9
    3131      _items.Add(new PackingItem(10, 10, 9, _packingShape, 1000, 1, 1)); // 10, V = 900,  A =  90, h = 10
    32       _items.Add(new PackingItem(9, 9, 10, _packingShape, 1000, 2, 1)); // 11,  V = 810,  A =  90, h =  9
    33       _items.Add(new PackingItem(10, 9, 9, _packingShape, 1000, 3, 1)); // 12,  V = 810,  A =  90, h =  9
    34       _items.Add(new PackingItem(9, 10, 9, _packingShape, 1000, 4, 1)); // 13,  V = 810,  A =  81, h = 10
    35       _items.Add(new PackingItem(9, 9, 9, _packingShape, 1000, 0, 1)); // 14,   V = 729,  A =  81, h =  9
     32      _items.Add(new PackingItem(9, 9, 10, _packingShape, 1000, 2, 2)); // 11,  V = 810,  A =  90, h =  9
     33      _items.Add(new PackingItem(10, 9, 9, _packingShape, 1000, 3, 3)); // 12,  V = 810,  A =  90, h =  9
     34      _items.Add(new PackingItem(9, 10, 9, _packingShape, 1000, 4, 4)); // 13,  V = 810,  A =  81, h = 10
     35      _items.Add(new PackingItem(9, 9, 9, _packingShape, 1000, 0, 0)); // 14,   V = 729,  A =  81, h =  9
    3636    }
    3737
     
    4040    [TestCategory("Problems.BinPacking.3D")]
    4141    [TestProperty("Time", "short")]
    42     public void TestSortByVolumeHeightExtension() {
    43       Permutation actual = _items.SortByVolumeHeight();
     42    public void TestSortByVolumeHeight() {
     43      Permutation actual =  PackingItemSorterFactory.CreatePackingItemSorter(SortingMethod.VolumeHeight).SortPackingItems(_items, _packingShape);
    4444      Permutation expected = new Permutation(PermutationTypes.Absolute, new int[] { 7,  8, 10, 9, 13, 11, 12, 0, 2, 1, 14, 5, 3, 4, 6});
    4545      for (int i = 0; i < expected.Length; i++) {
     
    5151    [TestCategory("Problems.BinPacking.3D")]
    5252    [TestProperty("Time", "short")]
    53     public void TestSortByHeightVolumeExtension() {
    54       Permutation actual = _items.SortByHeightVolume();
     53    public void TestSortByHeightVolume() {
     54      Permutation actual = PackingItemSorterFactory.CreatePackingItemSorter(SortingMethod.HeightVolume).SortPackingItems(_items, _packingShape);
    5555      Permutation expected = new Permutation(PermutationTypes.Absolute, new int[] { 7, 8, 10, 13, 0, 2, 5, 9, 11, 12, 14, 1, 3, 4, 6 });
    5656      for (int i = 0; i < expected.Length; i++) {
     
    6363    [TestCategory("Problems.BinPacking.3D")]
    6464    [TestProperty("Time", "short")]
    65     public void TestSortByAreaHeightExtension() {
    66       Permutation actual = _items.SortByAreaHeight();
     65    public void TestSortByAreaHeight() {
     66      Permutation actual = PackingItemSorterFactory.CreatePackingItemSorter(SortingMethod.AreaHeight).SortPackingItems(_items, _packingShape);
    6767      Permutation expected = new Permutation(PermutationTypes.Absolute, new int[] { 7, 9, 1, 8, 10, 11, 12, 13, 14, 0, 2, 3, 4, 5, 6});
    6868      for (int i = 0; i < expected.Length; i++) {
     
    7575    [TestCategory("Problems.BinPacking.3D")]
    7676    [TestProperty("Time", "short")]
    77     public void TestSortByHeightAreaExtension() {
    78       Permutation actual = _items.SortByHeightArea();
     77    public void TestSortByHeightArea() {
     78      Permutation actual = PackingItemSorterFactory.CreatePackingItemSorter(SortingMethod.HeightArea).SortPackingItems(_items, _packingShape);
    7979      Permutation expected = new Permutation(PermutationTypes.Absolute, new int[] { 7, 8, 10, 13, 0, 2, 5, 9, 11, 12, 14, 1, 3, 4, 6});
    8080      for (int i = 0; i < expected.Length; i++) {
     
    8686    [TestCategory("Problems.BinPacking.3D")]
    8787    [TestProperty("Time", "short")]
    88     public void TestSortByClusteredAreaHeightExtension() {
    89       Permutation actual = _items.SortByClusteredAreaHeight(_packingShape, 1.0);
     88    public void TestSortByClusteredAreaHeight() {
     89      Permutation actual = ((IPackingItemClusteredSorter)PackingItemSorterFactory.CreatePackingItemSorter(SortingMethod.ClusteredAreaHeight)).SortPackingItems(_items, _packingShape, 1.0);
    9090      Permutation expected = new Permutation(PermutationTypes.Absolute, new int[] { 0, 2, 5, 7, 8, 10, 13, 9, 11, 12, 14, 1, 3, 4, 6 });
    9191      for (int i = 0; i < expected.Length; i++) {
     
    9797    [TestCategory("Problems.BinPacking.3D")]
    9898    [TestProperty("Time", "short")]
    99     public void TestSortByClusteredHeightAreaExtension() {
    100       Permutation actual = _items.SortByClusteredHeightArea(_packingShape, 1.0);
     99    public void TestSortByClusteredHeightArea() {
     100      Permutation actual = ((IPackingItemClusteredSorter)PackingItemSorterFactory.CreatePackingItemSorter(SortingMethod.ClusteredHeightArea)).SortPackingItems(_items, _packingShape, 1.0);
    101101      Permutation expected = new Permutation(PermutationTypes.Absolute, new int[] { 1, 7, 9, 8, 10, 11, 12, 13, 14, 0, 2, 3, 4, 5, 6 });
    102102      for (int i = 0; i < expected.Length; i++) {
     
    108108    [TestCategory("Problems.BinPacking.3D")]
    109109    [TestProperty("Time", "short")]
    110     public void TestSortByMaterialVolumeHeightExtension() {
    111       Permutation actual = _items.SortByMaterialVolumeHeight();
    112       Permutation expected = new Permutation(PermutationTypes.Absolute, new int[] { 8, 13, 3, 7, 12, 2, 11, 1, 6, 10, 0, 5, 9, 14, 4 });
     110    public void TestSortBySequenceGroupVolumeHeight() {
     111      Permutation actual = PackingItemSorterFactory.CreatePackingItemSorter(SortingMethod.VolumeHeight).SortPackingItemsBySequenceGroup(_items, _packingShape);
     112      Permutation expected = new Permutation(PermutationTypes.Absolute, new int[] { 9, 14, 4, 10, 0, 5, 11, 1, 6, 7, 12, 2, 8, 13, 3 });
    113113      for (int i = 0; i < expected.Length; i++) {
    114114        Assert.AreEqual(expected[i], actual[i]);
     
    119119    [TestCategory("Problems.BinPacking.3D")]
    120120    [TestProperty("Time", "short")]
    121     public void TestSortByMaterialHeightVolumeExtension() {
    122       Permutation actual = _items.SortByMaterialHeightVolume();
    123       Permutation expected = new Permutation(PermutationTypes.Absolute, new int[] { 8, 13, 3, 7, 2, 12, 11, 1, 6, 10, 0, 5, 9, 14, 4 });
     121    public void TestSortByMaterialHeightVolume() {
     122      Permutation actual = PackingItemSorterFactory.CreatePackingItemSorter(SortingMethod.HeightVolume).SortPackingItemsBySequenceGroup(_items, _packingShape);
     123      Permutation expected = new Permutation(PermutationTypes.Absolute, new int[] { 9, 14, 4, 10, 0, 5, 11, 1, 6, 7, 2, 12, 8, 13, 3 });
    124124      for (int i = 0; i < expected.Length; i++) {
    125125        Assert.AreEqual(expected[i], actual[i]);
     
    131131    [TestCategory("Problems.BinPacking.3D")]
    132132    [TestProperty("Time", "short")]
    133     public void TestSortByMaterialAreaHeightExtension() {
    134       Permutation actual = _items.SortByMaterialAreaHeight();
    135       Permutation expected = new Permutation(PermutationTypes.Absolute, new int[] { 8, 13, 3, 7, 12, 2, 1, 11, 6, 10, 0, 5, 9, 14, 4 });
     133    public void TestSortByMaterialAreaHeight() {
     134      Permutation actual = PackingItemSorterFactory.CreatePackingItemSorter(SortingMethod.AreaHeight).SortPackingItemsBySequenceGroup(_items, _packingShape);
     135      Permutation expected = new Permutation(PermutationTypes.Absolute, new int[] { 9, 14, 4, 10, 0, 5, 1, 11, 6, 7, 12, 2, 8, 13, 3 });
    136136      for (int i = 0; i < expected.Length; i++) {
    137137        Assert.AreEqual(expected[i], actual[i]);
     
    143143    [TestCategory("Problems.BinPacking.3D")]
    144144    [TestProperty("Time", "short")]
    145     public void TestSortByMaterialHeightAreaExtension() {
    146       Permutation actual = _items.SortByMaterialHeightArea();
    147       Permutation expected = new Permutation(PermutationTypes.Absolute, new int[] { 8, 13, 3, 7, 2, 12, 11, 1, 6, 10, 0, 5, 9, 14, 4 });
     145    public void TestSortByMaterialHeightArea() {
     146      Permutation actual = PackingItemSorterFactory.CreatePackingItemSorter(SortingMethod.HeightArea).SortPackingItemsBySequenceGroup(_items, _packingShape);
     147      Permutation expected = new Permutation(PermutationTypes.Absolute, new int[] { 9, 14, 4, 10, 0, 5, 11, 1, 6, 7, 2, 12, 8, 13, 3 });
    148148      for (int i = 0; i < expected.Length; i++) {
    149149        Assert.AreEqual(expected[i], actual[i]);
     
    154154    [TestCategory("Problems.BinPacking.3D")]
    155155    [TestProperty("Time", "short")]
    156     public void TestSortByMaterialClusteredAreaHeightExtension() {
    157       Permutation actual = _items.SortByMaterialClusteredAreaHeight(_packingShape, 1.0);
    158       Permutation expected = new Permutation(PermutationTypes.Absolute, new int[] { 8, 13, 3, 2, 7, 12, 11, 1, 6, 0, 5, 10, 9, 14, 4 });
     156    public void TestSortByMaterialClusteredAreaHeight() {
     157      Permutation actual = ((IPackingItemClusteredSorter)PackingItemSorterFactory.CreatePackingItemSorter(SortingMethod.ClusteredAreaHeight)).SortPackingItemsBySequenceGroup(_items, _packingShape, 1.0);
     158      Permutation expected = new Permutation(PermutationTypes.Absolute, new int[] { 9, 14, 4, 0, 5, 10, 11, 1, 6, 2, 7, 12, 8, 13, 3 });
    159159      for (int i = 0; i < expected.Length; i++) {
    160160        Assert.AreEqual(expected[i], actual[i]);
     
    165165    [TestCategory("Problems.BinPacking.3D")]
    166166    [TestProperty("Time", "short")]
    167     public void TestSortByMaterialClusteredHeightAreaExtension() {
    168       Permutation actual = _items.SortByClusteredHeightArea(_packingShape, 1.0);
    169       Permutation expected = new Permutation(PermutationTypes.Absolute, new int[] { 1, 7, 9, 8, 10, 11, 12, 13, 14, 0, 2, 3, 4, 5, 6 });
     167    public void TestSortByMaterialClusteredHeightArea() {
     168      Permutation actual = ((IPackingItemClusteredSorter)PackingItemSorterFactory.CreatePackingItemSorter(SortingMethod.ClusteredHeightArea)).SortPackingItemsBySequenceGroup(_items, _packingShape, 1.0);
     169      Permutation expected = new Permutation(PermutationTypes.Absolute, new int[] { 9, 14, 4, 10, 0, 5, 1, 11, 6, 7, 12, 2, 8, 13, 3});
    170170      for (int i = 0; i < expected.Length; i++) {
    171171        Assert.AreEqual(expected[i], actual[i]);
Note: See TracChangeset for help on using the changeset viewer.