Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/14/17 15:31:22 (6 years ago)
Author:
rhanghof
Message:

#2817

  • Added some unit tests
  • Enhanced the documentation
File:
1 edited

Legend:

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

    r15463 r15471  
    88
    99namespace HeuristicLab.Problems.BinPacking3D.Sorting {
     10
     11  /// <summary>
     12  /// This is a extension class for sorting a permutation.
     13  /// </summary>
    1014  public static class PackingItemSorter {
     15
     16    /// <summary>
     17    /// Sorts a given permutation first by the volume and secoundly by the height.
     18    /// </summary>
     19    /// <param name="items">Permuation which should be sorted</param>
     20    /// <returns>A new sorted permutation</returns>
    1121    public static Permutation SortByVolumeHeight(this IList<PackingItem> items) {
    1222      return new Permutation(PermutationTypes.Absolute,
     
    1727    }
    1828
     29    /// <summary>
     30    /// Sorts a given permutation first by the heigth and secoundly by the volume.
     31    /// </summary>
     32    /// <param name="items">Permuation which should be sorted</param>
     33    /// <returns>A new sorted permutation</returns>
    1934    public static Permutation SortByHeightVolume(this IList<PackingItem> items) {
    2035      return new Permutation(PermutationTypes.Absolute,
     
    2540    }
    2641
     42    /// <summary>
     43    /// Sorts a given permutation first by the area and secondly by the height.
     44    /// </summary>
     45    /// <param name="items">Permuation which should be sorted</param>
     46    /// <returns>A new sorted permutation</returns>
    2747    public static Permutation SortByAreaHeight(this IList<PackingItem> items) {
    2848      return new Permutation(PermutationTypes.Absolute,
     
    3353    }
    3454
     55    /// <summary>
     56    /// Sorts a given permuation first by the height and secoundly by the area.
     57    /// </summary>
     58    /// <param name="items">Permuation which should be sorted</param>
     59    /// <returns>A new sorted permutation</returns>
    3560    public static Permutation SortByHeightArea(this IList<PackingItem> items) {
    3661      return new Permutation(PermutationTypes.Absolute,
     
    4166    }
    4267
     68    /// <summary>
     69    /// Sorts a given permutation. The items are being grouped by the cluster id.
     70    /// The cluster id is calulated as followed: clusterId = Ceiling( (width * depth) / (width * depth * delta))
     71    /// The permutation is first being sorted by the area and secoundly by the height.
     72    /// </summary>
     73    /// <param name="items">Permuation which should be sorted</param>
     74    /// <param name="bin">The bin is needed for building the cluster</param>
     75    /// <param name="delta">The delta is needed for building the cluster</param>
     76    /// <returns>A new sorted permutation</returns>
    4377    public static Permutation SortByClusteredAreaHeight(this IList<PackingItem> items, PackingShape bin, double delta) {
    4478      double clusterRange = bin.Width * bin.Depth * delta;
     
    5286    }
    5387
     88    /// <summary>
     89    /// Sorts a given permutation. The items are being grouped by the cluster id.
     90    /// The cluster id is calulated as followed: clusterId = Ceiling( (height) / (height * delta))
     91    /// The permutation is first being sorted by the height and secoundly by the area.
     92    /// </summary>
     93    /// <param name="items">Permuation which should be sorted</param>
     94    /// <param name="bin">The bin is needed for building the cluster</param>
     95    /// <param name="delta">The delta is needed for building the cluster</param>
     96    /// <returns>A new sorted permutation</returns>
    5497    public static Permutation SortByClusteredHeightArea(this IList<PackingItem> items, PackingShape bin, double delta) {
    5598      double clusterRange2 = bin.Height * delta;
     
    63106    }
    64107
     108    /// <summary>
     109    /// Sorts a given permutation first by the material, secoundly by the volume and finally by the height.
     110    /// </summary>
     111    /// <param name="items">Permuation which should be sorted</param>
     112    /// <returns>A new sorted permutation</returns>
    65113    public static Permutation SortByMaterialVolumeHeight(this IList<PackingItem> items) {
    66114      return new Permutation(PermutationTypes.Absolute,
     
    72120    }
    73121
     122    /// <summary>
     123    /// Sorts a given permutation first by the material, secoundly by the heigth and finally by the volume.
     124    /// </summary>
     125    /// <param name="items">Permuation which should be sorted</param>
     126    /// <returns>A new sorted permutation</returns>
    74127    public static Permutation SortByMaterialHeightVolume(this IList<PackingItem> items) {
    75128      return new Permutation(PermutationTypes.Absolute,
     
    81134    }
    82135
     136    /// <summary>
     137    /// Sorts a given permutation first by the material, secoundly by the area and finally by the height.
     138    /// </summary>
     139    /// <param name="items">Permuation which should be sorted</param>
     140    /// <returns>A new sorted permutation</returns>
    83141    public static Permutation SortByMaterialAreaHeight(this IList<PackingItem> items) {
    84142      return new Permutation(PermutationTypes.Absolute,
     
    90148    }
    91149
     150    /// <summary>
     151    /// Sorts a given permuation first by the material, secoundly by the height and finally by the area.
     152    /// </summary>
     153    /// <param name="items">Permuation which should be sorted</param>
     154    /// <returns>A new sorted permutation</returns>
    92155    public static Permutation SortByMaterialHeightArea(this IList<PackingItem> items) {
    93156      return new Permutation(PermutationTypes.Absolute,
     
    99162    }
    100163
     164    /// <summary>
     165    /// Sorts a given permutation. The items are being grouped by the cluster id.
     166    /// The cluster id is calulated as followed: clusterId = Ceiling( (width * depth) / (width * depth * delta))
     167    /// The permutation is being clusterd by the area, first sorted by the material, secoundly by the height.
     168    /// </summary>
     169    /// <param name="items">Permuation which should be sorted</param>
     170    /// <param name="bin">The bin is needed for building the cluster</param>
     171    /// <param name="delta">The delta is needed for building the cluster</param>
     172    /// <returns>A new sorted permutation</returns>
    101173    public static Permutation SortByMaterialClusteredAreaHeight(this IList<PackingItem> items, PackingShape bin, double delta) {
    102174      double clusterRange = bin.Width * bin.Depth * delta;
     
    104176                items.Select((v, i) => new { Index = i, Item = v, ClusterId = (int)(Math.Ceiling(v.Width * v.Depth / clusterRange)) })
    105177                    .GroupBy(x => x.ClusterId)
    106                     .Select(x => new { Cluster = x.Key, Items = x.OrderByDescending(y => y.Item.Height).ToList() })
    107                     .OrderByDescending(x => x.Cluster)
    108                     .SelectMany(x => x.Items)
    109                     .Select(x => x.Index).ToArray());
    110     }
    111 
     178                    .Select(x => new { Cluster = x.Key, Items = x.OrderByDescending(z => z.Item.Material).ThenByDescending(y => y.Item.Height).ToList() })
     179                    .OrderByDescending(x => x.Cluster)
     180                    .SelectMany(x => x.Items)
     181                    .Select(x => x.Index).ToArray());
     182    }
     183
     184    /// <summary>
     185    /// Sorts a given permutation. The items are being grouped by the cluster id.
     186    /// The cluster id is calulated as followed: clusterId = Ceiling( (height) / (height * delta))
     187    /// The permutation is being clusterd by the height, first sorted by the material, secoundly by the area.
     188    /// </summary>
     189    /// <param name="items">Permuation which should be sorted</param>
     190    /// <param name="bin">The bin is needed for building the cluster</param>
     191    /// <param name="delta">The delta is needed for building the cluster</param>
     192    /// <returns>A new sorted permutation</returns>
    112193    public static Permutation SortByMaterialClusteredHeightArea(this IList<PackingItem> items, PackingShape bin,  double delta) {
    113194      double clusterRange2 = bin.Height * delta;
     
    115196                items.Select((v, i) => new { Index = i, Item = v, ClusterId = (int)(Math.Ceiling(v.Height / clusterRange2)) })
    116197                    .GroupBy(x => x.ClusterId)
    117                     .Select(x => new { Cluster = x.Key, Items = x.OrderByDescending(y => y.Item.Depth * y.Item.Width).ToList() })
     198                    .Select(x => new { Cluster = x.Key, Items = x.OrderByDescending(z => z.Item.Material).ThenByDescending(y => y.Item.Depth * y.Item.Width).ToList() })
    118199                    .OrderByDescending(x => x.Cluster)
    119200                    .SelectMany(x => x.Items)
Note: See TracChangeset for help on using the changeset viewer.