Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/28/17 16:10:31 (6 years ago)
Author:
rhanghof
Message:

#2817:

  • Added line projection based bin packing
  • Added residual spaces to the view
File:
1 edited

Legend:

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

    r15473 r15488  
    4242  public enum FittingMethod { All, FirstFit, ResidualSpaceBestFit, FreeVolumeBestFit }
    4343
     44  public enum ExtremePointCreationMethod { All, PointProjection, LineProjection }
     45
    4446  [Item("Extreme-point-based Bin Packing (3d)", "An implementation of the extreme-point based packing described in Crainic, T. G., Perboli, G., & Tadei, R. (2008). Extreme point-based heuristics for three-dimensional bin packing. Informs Journal on computing, 20(3), 368-384.")]
    4547  [StorableClass]
     
    8385    public IValueParameter<BoolValue> SortByMaterialParameter {
    8486      get { return sortByMaterialParameter; }
    85     }   
     87    }
     88
     89    [Storable]
     90    private readonly IValueParameter<EnumValue<ExtremePointCreationMethod>> extremePointCreationMethodParameter;
     91    public IValueParameter<EnumValue<ExtremePointCreationMethod>> ExtremePointCreationMethodParameter {
     92      get { return extremePointCreationMethodParameter; }
     93    }
    8694
    8795    [StorableConstructor]
     
    100108        "FittingMethod", "Which method to fit should be used.", new EnumValue<FittingMethod>(FittingMethod.All)));
    101109
     110      Parameters.Add(extremePointCreationMethodParameter = new ValueParameter<EnumValue<ExtremePointCreationMethod>>(
     111        "ExtremePointCreationMethod", "Which method should be used for creatomg extreme points.", new EnumValue<ExtremePointCreationMethod>(ExtremePointCreationMethod.All)));
     112
    102113      Parameters.Add(deltaParameter = new ValueParameter<PercentValue>(
    103114        "Delta", "[1;100]% Clustered sorting methods use a delta parameter to determine the clusters.", new PercentValue(.1)));
     
    124135      var items = Problem.Items;
    125136      var bin = Problem.BinShape;
     137
    126138      var sorting = new[] { SortingMethodParameter.Value.Value };
    127139      if (sorting[0] == SortingMethod.All) {
    128140        sorting = Enum.GetValues(typeof(SortingMethod)).Cast<SortingMethod>().Where(x => x != SortingMethod.All).ToArray();
    129141      }
     142
    130143      var fitting = new[] { fittingMethodParameter.Value.Value };
    131144      if (fitting[0] == FittingMethod.All) {
     
    133146      }
    134147
     148      var extremePointCreation = new[] { ExtremePointCreationMethodParameter.Value.Value };
     149      if (extremePointCreation[0] == ExtremePointCreationMethod.All) {
     150        extremePointCreation = Enum.GetValues(typeof(ExtremePointCreationMethod))
     151                                     .Cast<ExtremePointCreationMethod>()
     152                                     .Where(x => x != ExtremePointCreationMethod.All)
     153                                     .ToArray();
     154      }
     155
    135156      //
    136       var result = GetBest(bin, items, sorting, fitting, token);
     157      var result = GetBest(bin, items, sorting, fitting, extremePointCreation, token);
    137158      if (result == null) {
    138159        throw new InvalidOperationException("No result obtained!");
     
    162183          new EnumValue<FittingMethod>(result.Item4.Value)));
    163184      }
     185
     186      if (result.Item5.HasValue && extremePointCreation.Length > 1) {
     187        Results.Add(new Result("Best extreme point creation method",
     188          "The extreme point creation method that found the best solution",
     189          new EnumValue<ExtremePointCreationMethod>(result.Item5.Value)));
     190      }
    164191    }
    165192
     
    173200    /// <param name="token"></param>
    174201    /// <returns></returns>
    175     private Tuple<Solution, double, SortingMethod?, FittingMethod?> GetBest(PackingShape bin, IList<PackingItem> items, SortingMethod[] sortings, FittingMethod[] fittings, CancellationToken token) {
     202    private Tuple<Solution, double, SortingMethod?, FittingMethod?, ExtremePointCreationMethod?>
     203          GetBest(PackingShape bin,
     204                  IList<PackingItem> items,
     205                  SortingMethod[] sortings,
     206                  FittingMethod[] fittings,
     207                  ExtremePointCreationMethod[] ePGeneration,
     208                  CancellationToken token) {
    176209      SortingMethod? bestSorting = null;
    177210      FittingMethod? bestFitting = null;
     211      ExtremePointCreationMethod? bestEPCreation = null;
    178212      var best = double.NaN;
    179213      Solution bestSolution = null;
    180214      foreach (var fit in fittings) {
    181215        foreach (var sort in sortings) {
    182           IDecoder<Permutation> decoder = new ExtremePointPermutationDecoder(BinPackerFactory.CreateBinPacker(fit));
    183           Permutation sortedItems;
     216          foreach (var epCreation in ePGeneration) {
     217            IDecoder<Permutation> decoder = new ExtremePointPermutationDecoder() {
     218              FittingMethod = fit,
     219              ExtremePointCreationMethod = epCreation
     220            };
     221            Permutation sortedItems;
    184222                   
    185           if (SortByMaterialParameter.Value.Value) {
    186             sortedItems = SortItemsByMaterialAndSortingMethod(bin, items, sort, DeltaParameter.Value.Value);
    187           } else {
    188             sortedItems = SortItemsBySortingMethod(bin, items, sort, DeltaParameter.Value.Value);
    189           }
     223            if (SortByMaterialParameter.Value.Value) {
     224              sortedItems = SortItemsByMaterialAndSortingMethod(bin, items, sort, DeltaParameter.Value.Value);
     225            } else {
     226              sortedItems = SortItemsBySortingMethod(bin, items, sort, DeltaParameter.Value.Value);
     227            }
     228
     229            var result = Optimize(new OptimaizationParamters() {
     230              SortedItems = sortedItems,
     231              Bin = bin,
     232              Items = items,
     233              StackingConstraints = Problem.UseStackingConstraints,
     234              Decoder = decoder,
     235              Evaluator = Problem.SolutionEvaluator,
     236              ExtremePointGeneration = epCreation
     237            });
    190238         
    191           var result = Optimize(sortedItems, bin, items, Problem.UseStackingConstraints, decoder, Problem.SolutionEvaluator);
    192          
    193           if (double.IsNaN(result.Item2) || double.IsInfinity(result.Item2)) {
    194             continue;
    195           }
    196 
    197           if (double.IsNaN(best) || Problem.Maximization && result.Item2 > best || !Problem.Maximization && result.Item2 < best) {
    198             bestSolution = result.Item1;
    199             best = result.Item2;
    200             bestSorting = sort;
    201             bestFitting = fit;
    202           }
    203           if (token.IsCancellationRequested) {
    204             return Tuple.Create(bestSolution, best, bestSorting, bestFitting);
     239            if (double.IsNaN(result.Item2) || double.IsInfinity(result.Item2)) {
     240              continue;
     241            }
     242
     243            if (double.IsNaN(best) || Problem.Maximization && result.Item2 > best || !Problem.Maximization && result.Item2 < best) {
     244              bestSolution = result.Item1;
     245              best = result.Item2;
     246              bestSorting = sort;
     247              bestFitting = fit;
     248              bestEPCreation = epCreation;
     249            }
     250            if (token.IsCancellationRequested) {
     251              return Tuple.Create(bestSolution, best, bestSorting, bestFitting, bestEPCreation);
     252            }
    205253          }
    206254        }
     
    209257        return null;
    210258      }
    211       return Tuple.Create(bestSolution, best, bestSorting, bestFitting);
     259      return Tuple.Create(bestSolution, best, bestSorting, bestFitting, bestEPCreation);
    212260    }
    213261
     
    215263    /// Returns a tuple with the solution and the packing ratio depending on the given parameters
    216264    /// </summary>
    217     /// <param name="sortedItems"></param>
    218     /// <param name="bin"></param>
    219     /// <param name="items"></param>
    220     /// <param name="stackingConstraints"></param>
    221     /// <param name="decoder"></param>
    222     /// <param name="evaluator"></param>
     265    /// <param name="parameters"></param>
    223266    /// <returns></returns>
    224     private static Tuple<Solution, double> Optimize(Permutation sortedItems, PackingShape bin, IList<PackingItem> items, bool stackingConstraints, IDecoder<Permutation> decoder, IEvaluator evaluator) {
     267    private static Tuple<Solution, double> Optimize(OptimaizationParamters parameters) {
    225268     
    226       var sol = decoder.Decode(sortedItems, bin, items, stackingConstraints);
    227       var fit = evaluator.Evaluate(sol);
     269      var sol = parameters.Decoder.Decode(parameters.SortedItems, parameters.Bin, parameters.Items, parameters.StackingConstraints);
     270      var fit = parameters.Evaluator.Evaluate(sol);
    228271
    229272      return Tuple.Create(sol, fit);
     273    }
     274
     275    private class OptimaizationParamters {
     276      public Permutation SortedItems { get; set; }
     277      public PackingShape Bin { get; set; }
     278      public IList<PackingItem> Items { get; set; }
     279      public bool StackingConstraints { get; set; }
     280      public IDecoder<Permutation> Decoder { get; set; }
     281      public IEvaluator Evaluator { get; set; }
     282      public ExtremePointCreationMethod ExtremePointGeneration { get; set; }
    230283    }
    231284   
Note: See TracChangeset for help on using the changeset viewer.